RAG Evals

- Backend & AI Engineer
- November 2026
- In Progress
In numbers
- Recall@10 on 300 SciFact claims, vector search
- 0.829
- Median retrieval time, query embedding included
- 6.0ms
- Recall@10 of equal-weight hybrid search: lower, and 6.6× slower
- 0.756
- Tests in CI, 6 of them against real Postgres + pgvector
- 31
About the Project
RAG Evals is a retrieval-augmented generation service built around its own evaluation. It indexes documents, answers questions with Claude, and cites the exact chunks it used, but the point is the harness next to it: every run writes recall, MRR and latency to a JSON file, and only those files feed the numbers I quote.
The API is FastAPI with async SQLAlchemy 2.x, Pydantic v2 and Alembic migrations over Postgres 17 with pgvector. Documents are split into 220-word chunks and embedded locally with bge-small through fastembed, so there is no embedding bill and CI uses the same vectors as production. A question is embedded, matched against an HNSW index, and the top six chunks go to Claude Haiku as native search result blocks, so every citation points back to a chunk id the API returned. The evaluation uses BEIR SciFact: 5,183 scientific abstracts and 300 test claims with expert relevance labels.
The plan was hybrid search, full text plus vectors fused with Reciprocal Rank Fusion. Measured, equal-weight hybrid reached a recall@10 of 0.756 against 0.829 for vectors alone, and was 6.6 times slower. Tuning the full-text weight on the train split drove it to zero, so vector search became the default and hybrid stayed as an option. I built it in November 2026 because RAG is easy to demo and hard to prove; the answer-quality evaluation with an LLM judge is written and still to be run.
How it works
The path a request takes, step by step.
- ClientAsks a question on /ask
- FastAPIAsync SQLAlchemy and Pydantic v2
- Embeddingsbge-small, local, no API cost
- pgvectorHNSW index, top 6 chunks
- Claude HaikuChunks sent as search result blocks
- AnswerCitations that point to real chunk ids, and its cost
Decisions
The choices that shaped it, and what each one cost.
Let the evaluation pick the search mode
- Hybrid search was the plan. Measured, equal-weight hybrid reached a recall@10 of 0.756 against 0.829 for vectors, and tuning its full-text weight drove it to zero.
- SciFact is one domain. On keyword-heavy documents hybrid may win, so it stays available as an option.
Tune on train, report on test
- The fusion weight was tuned on 809 train claims and the metrics come from the 300 test claims, so the reported number is not fitted to the test.
- Every change to retrieval needs two evaluation runs instead of one.
Run the embeddings locally
- bge-small through fastembed means no embedding bill and the same vectors in CI and production.
- A small model with 384 dimensions, and indexing 5,183 abstracts takes about four minutes on a laptop CPU.
Send chunks as search result blocks
- Claude cites the blocks it was given, so every citation points back to a chunk id the API returned instead of text the model made up.
- Generation is tied to Claude’s API format.
