Repository navigation
Retrieval Pipeline
Source: app/services/retriever.py. Public entry point: retrieve(query, top_k=3).
| Stage | What it does | Detail |
|---|---|---|
| 1. Semantic search | Dense vector search in ChromaDB | Embedding model all-mpnet-base-v2; top 10; score = 1 - distance (the collection uses Chroma's default L2 distance) |
| 2. BM25 search | Keyword search |
BM25Okapi over whitespace-split, lower-cased text; top 10; zero-score hits dropped |
| 3. Fusion | Reciprocal Rank Fusion |
0.6 / (60 + rank_semantic) + 0.4 / (60 + rank_bm25); top 15 pass on |
| 4. Re-ranking | Cross-encoder |
cross-encoder/ms-marco-MiniLM-L-6-v2 scores each (query, chunk) pair; best top_k returned |
The result for each chunk is {text, source, authority, domain}; internal scores are removed before the text reaches the model.
Chunks returned per endpoint: /query 3, /learn/structured 6, /learn/text 10.
Dense retrieval alone handles tables poorly: the food-composition document (209 of 810 chunks) is mostly numeric tables. Keyword matching recovers exact terms such as food names. The cross-encoder then fixes the ordering. Earlier measurements that motivated this are in Evaluation (historical).
- Index lifetime. The BM25 index is built in memory from the whole collection at first use (or at startup) and is never refreshed. After re-ingesting documents, restart the server.
-
Collection choice. The first collection returned by ChromaDB is used. The expected collection is
nutrition_kb. -
Source name bug. The vector store stores each chunk's file name under
source_document. The semantic path reads that key, but the BM25 path readssource, so a chunk found only by keyword search is reported withsource="unknown". Chunks found by semantic search, or by both, are correct (Known Issues and Limitations). - Tuning. Candidate counts (10, 10, 15), the RRF weights and constant (0.6, 0.4, 60) and the model names are constants in the file, not environment variables.
-
Missing store. If
app/chroma_storage/has no collection, retrieval raisesNo ChromaDB collections found. Build it first (Getting Started).
Documentation last verified against the code on 2026-11-05. Evaluation figures are historical, see Evaluation. Educational tool, not medical advice.
Use it
How it works
- Architecture
- Retrieval Pipeline
- LLM Layer
- Prompts and Lessons
- Grounding Verification
- Knowledge Base
- Data and Logging
Quality
Develop