Ask the Docs:如何構建可投入生產環境的 RAG 系統
How I built a production RAG system (hybrid retrieval, citations, evals)
Ask the Docs 是一套已部署的 RAG 系統,結合 BM25 與嵌入向量檢索,並以 Reciprocal Rank Fusion 融合結果,要求答案根據檢索內容生成並附上行內引文。系統以離線 golden set 在 CI 評估檢索召回率,5/5 項測試通過;評估分數低於 80% 便會失敗。系統使用 Docker、Traefik 和 GitHub Actions,推送後部署。
How I built a production RAG system (Ask the Docs)
Most RAG demos are a notebook. This is a deployed system: hybrid retrieval, grounded answers with inline citations, and an eval gate that blocks regressions.
TL;DR
- Hybrid retrieval — BM25 (exact terms) + embeddings (paraphrases), fused with Reciprocal Rank Fusion.
-
Grounded answers —
deepseekvia OpenRouter, forced to answer from context and cite[chunk_id]. - Eval gate — offline golden set, retrieval recall scored in CI (5/5 passing).
- Shipped — Docker + Traefik + GitHub Actions → GHCR, deployed on push.
Why another RAG project?
"Chat with your PDF" is saturated, and most of those fail on real documents. The things that matter in production are boring: retrieval that finds the right chunk, an answer you can verify, and a test that blocks regressions. This project makes those three explicit.
The pipeline
- Chunking — 500-char windows with 80-char overlap, so a thought is never cut in half.
- Hybrid retrieval — run BM25 and embeddings in parallel, then fuse with Reciprocal Rank Fusion:
rrf = {}
for rank, (_, i) in enumerate(bm25):
rrf[i] = rrf.get(i, 0) + 1 / (60 + rank + 1)
for rank, (_, i) in enumerate(cosine):
rrf[i] = rrf.get(i, 0) + 1 / (60 + rank + 1)
order = sorted(rrf, key=rrf.get, reverse=True)[:k]
- Grounding — the model answers only from the retrieved chunks and cites them inline.
- Eval gate — substring recall over top-k context; below 80% it fails.
Stack
| Layer | Choice |
|---|---|
| Retrieval | BM25 + embeddings, RRF fusion |
| LLM | OpenRouter (deepseek/deepseek-chat) |
| Embeddings |
text-embedding-3-small (OpenRouter) |
| Backend | FastAPI |
| Frontend | Next.js |
| Eval | offline golden set, gate 80% |
| Deploy | Docker + Traefik + GitHub Actions → GHCR |
Try it
- Live: ask.josuebarros.com
- Source: github.com/joshbarros/ask-the-docs
- Benchmark: BM25 vs embeddings vs RRF on Kaggle
This is the kind of artifact that earns the "production AI" claim: it runs, it cites, and it has a gate.
來源:DEV Community · dev.to