Description
All three retrievers compute a similarity score and throw it away:
InMemoryRetriever.retrieve — scores = self._matrix @ q, only used for ordering
FAISSRetriever.retrieve — _scores, labels = self._index.search(...)
ChromaRetriever.retrieve — include=["documents", "metadatas"] (omits "distances")
Users cannot filter by a relevance threshold, log retrieval quality, or show confidence in a UI.
Proposed design
- Add
score: float | None = None to the Chunk dataclass (last field, default None, so existing code is unaffected)
- Each retriever sets
score on the returned chunks. Returned chunks should be shallow copies (dataclasses.replace(chunk, score=s)) so the stored chunk is not mutated
- Document the scale: cosine similarity in
[-1, 1], higher is better. ChromaRetriever must convert Chroma's distance — create collections with metadata={"hnsw:space": "cosine"} explicitly (Chroma defaults to L2) and return 1 - distance
- Add
RAGConfig.score_threshold: float | None = None; RAGPipeline.query() drops chunks below it before generation
Acceptance criteria
Files to touch
ragframework/base.py — Chunk
ragframework/retriever/in_memory.py, faiss.py, chroma.py
ragframework/config.py, ragframework/pipeline/rag.py
- Tests for each
Resources
Estimated effort: Medium (half day)
Description
All three retrievers compute a similarity score and throw it away:
InMemoryRetriever.retrieve—scores = self._matrix @ q, only used for orderingFAISSRetriever.retrieve—_scores, labels = self._index.search(...)ChromaRetriever.retrieve—include=["documents", "metadatas"](omits"distances")Users cannot filter by a relevance threshold, log retrieval quality, or show confidence in a UI.
Proposed design
score: float | None = Noneto theChunkdataclass (last field, defaultNone, so existing code is unaffected)scoreon the returned chunks. Returned chunks should be shallow copies (dataclasses.replace(chunk, score=s)) so the stored chunk is not mutated[-1, 1], higher is better.ChromaRetrievermust convert Chroma's distance — create collections withmetadata={"hnsw:space": "cosine"}explicitly (Chroma defaults to L2) and return1 - distanceRAGConfig.score_threshold: float | None = None;RAGPipeline.query()drops chunks below it before generationAcceptance criteria
Chunk.scorefield added and documentedscorestaysNoneChromaRetrievercreates collections with an explicit cosine spacescore_thresholdimplemented in the pipeline with a testCHANGELOG.mdupdated under[Unreleased]→### AddedFiles to touch
ragframework/base.py—Chunkragframework/retriever/in_memory.py,faiss.py,chroma.pyragframework/config.py,ragframework/pipeline/rag.pyResources
dataclasses.replaceEstimated effort: Medium (half day)