Skip to content

feat(retrieval): rrf fusion with hybrid_rrf mode wiring (T10) - #10

Merged
prateekchaplot merged 1 commit into
mainfrom
arch/caliper/t10
Nov 17, 2026
Merged

prateekchaplot merged 1 commit into
mainfrom
arch/caliper/t10

Conversation

@prateekchaplot

Copy link
Copy Markdown
Owner

Task T10 from docs/ARCHITECTURE.md §14.2 (spec §7.5, §9.3).

What

  • retrieval/fuse.py (new, pure): rrf(vector_list, fts_list, k=60) — textbook Reciprocal Rank Fusion score(d) = Σ 1/(k + rank_i(d)), 1-based ranks, dedup by chunk id, ties broken by ascending chunk_id. No I/O, no config, no db.
  • retrieval/__init__.py (dispatch-only touch): wires the hybrid_rrf mode per §7.5 — vec0 KNN top-vector_top_k (20) + FTS5 BM25 top-fts_top_k (20) → RRF (k=rrf_k=60) → top-final_k (5). Passages get score = RRF score (higher = more relevant) and stage = "rrf". T09's frozen public API (retrieve signature, Passage, RetrievalError) and the vector path are unchanged. Rerank pass-through untouched (T18).

Decisions

  • FTS terms double-quote-escaped; embedded quotes stripped; punctuation-only questions skip FTS gracefully (never an FTS5 syntax error).
  • FTS table has no chunk_id column — id selected as rowid AS chunk_id (external-content, content_rowid='chunk_id'); ORDER BY score, chunk_id for deterministic bm25 ties.
  • hybrid_rrf with fts_top_k < 1 or rrf_k < 1 raises RetrievalError (defense in depth; §11.4 validators already reject it).

Verification

  • uv run pytest -q — 187 passed (166 baseline + 21 new: 9 RRF unit tests incl. hand-computed fused scores, 12 hybrid-mode integration tests on a fixture DB with sqlite-vec).
  • uv run ruff check, uv run ruff format --check, uv run mypy (strict) — all clean.
  • End-to-end on the real v3 preset: fused scores matched hand computation (2/61, 2/62, 1/63).

§14.4 notes

Touches T09-owned retrieval/__init__.py dispatch only; frozen API unchanged. Dependents to re-run tests before merging: T11 (consumes passages) and T18 (rerank wiring — note: the hybrid path cuts to final_k before returning; the reranker needs the fusion candidate pool preserved).

@prateekchaplot
prateekchaplot merged commit 2af211e into main Nov 17, 2026
1 check passed
@prateekchaplot
prateekchaplot deleted the arch/caliper/t10 branch November 17, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant