Repository navigation
Hybrid retrieval: BM25 + RRF + optional rerank hook - #17
Merged
Merged
Conversation
ir.search gains mode='dense'|'lexical'|'hybrid' (default 'dense', fully backward compatible). Hybrid fuses dense cosine with Okapi BM25 via Reciprocal Rank Fusion to recover exact identifiers and rare terms that dense-only retrieval misses -- the high-value gain for short, identifier-heavy capability text (skills/packages/tools). Reuses the ecosystem rather than reinventing: vd.bm25_lexical_search (BM25 over a zero-copy candidate view), vd.reciprocal_rank_fusion (RRF), and ef.rerank (optional ef.Reranker hook, default None = offline). Lexical and fusion degrade gracefully when vd is unavailable. New kwargs on search(): mode, rrf_k, fetch_k, rerank, bm25. CLI: ir search --mode dense|lexical|hybrid. Refs #1, #16.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #16. Refs #1 (the seam deferred from the now-closed #7).
What
Adds a hybrid retrieval mode to
ir.search:mode='dense' | 'lexical' | 'hybrid'— defaultdense, so existing callers are unaffected (byte-identical path, verified by the unchanged pipeline tests).rerankhook (anyef.Reranker); defaultNonekeeps retrieval offline (no model download / API call).rrf_k,fetch_k,rerank,bm25(Okapi params).ir search <corpus> <query> --mode dense|lexical|hybrid.Why
Per the retrieval research (
misc/docs/ir_02), dense-only retrieval fails silently on exact identifiers, code, and rare terms — exactly the regime of short, identifier-heavy capability text (skill / package / tool names). BM25 + RRF + rerank is the production-consensus fix; ToolRet found lexical BM25 beating several dense models on tool retrieval.Reuse, not reinvention
vd.bm25_lexical_search— BM25, run over the already-filtered candidates via a zero-copy mapping view (record_id -> objwith.text/.metadata); no vectors duplicated.vd.reciprocal_rank_fusion— RRF.ef.rerank/ef.Reranker— the rerank contract.vdis unavailable, hybrid falls back to dense and lexical returns no results, each with a warning — a missing optional dep never hard-fails a search.Validation
tests/test_hybrid.py), ruff clean.zxqv) ranks last under dense, first under lexical, and is lifted under hybrid; the rerank hook reorders across all three modes (incl.per_artifact=False).packagescorpus with MiniLM: all three modes return sensible rankings (hybrid RRF scores ~1/(k+1)magnitude as expected).Follow-ups (not in this PR)
ir's storage behind avd.Collectionto reusevd.hybrid_searchwholesale.