GraphRAG++
A document question-answering API that fuses vector, BM25 and knowledge-graph search, and returns a typed warning instead of a confident wrong answer.
- REST endpoints
- 11
- tests in CI
- 66
- typed failure states
- 5
- Python
- FastAPI
- Pydantic
- NetworkX
- PostgreSQL
- Prometheus
- pytest
- GitHub Actions
The problem
Most retrieval-augmented generation pipelines answer every question with the same confidence, whether or not they found good evidence. I wanted a service that says when it does not know.
Pipeline
- Question
- In parallelVector searchBM25Graph expansion
- Weighted fusion
- Failure classifier
- Answer with evidence
How it works
Documents and URLs are ingested into isolated corpora. Rule-based extraction builds a NetworkX knowledge graph, which is snapshotted on every ingest.
A query runs vector, BM25 and graph-expansion retrieval, fuses the results with weighted scoring, and passes the evidence to the model. Each answer comes back with its sources and a confidence score.
A failure classifier maps weak results to typed states (NO_EVIDENCE, LOW_CONFIDENCE, CONFLICTING_EVIDENCE, HIGH_UNCERTAINTY, LLM_FAILURE), so the API returns a warning or a partial answer instead of guessing.
A Prometheus /metrics endpoint exposes per-stage latency histograms and error counters. GitHub Actions runs ruff, black, mypy and 66 pytest tests with coverage on every commit.
The decision
- I chose
- Make heavy dependencies optional and degrade gracefully without them.
- Instead of
- Requiring PyTorch, FAISS and sentence-transformers on every install.
- Because
- The core installs in about 150 MB. Without torch the reranker falls back to a deterministic linear blend, and without prometheus-client /metrics still answers. CI stays fast, and anyone can try it without a GPU.
What broke, and the fix
A stored answer can silently go stale when new documents arrive.
Every ingest snapshots the graph and tags answers with the version they came from, so an answer is flagged stale when its supporting nodes change.
Corpora from different domains contaminate each other's retrieval.
Each ingest creates an isolated corpus by default, with its domain detected from the text.
URL ingestion is an open door for server-side request forgery.
A scheme allowlist, blocked private, loopback and link-local addresses, re-validated redirects and a response size cap.
What I would do next
- Build a labelled question set and measure retrieval hit rate. The /evaluate endpoint is a lightweight check, not a benchmark, so I make no accuracy claim yet.
- Check how well the confidence score tracks correctness against that labelled set.