perf(retrieve): cache BM25 index per corpus (lexical/hybrid no longer rebuild per query)#22
Merged
Merged
Conversation
_lexical_ranked built the candidate collection and recomputed all BM25 term statistics on every query, making lexical/hybrid O(corpus*queries) — they did not scale (a full lexical/hybrid pass over the 16,836-record reports corpus did not finish in 10 min CPU; ir_05 §6.1). Now a vd.BM25Index is built once per candidate set and cached on the corpus instance (keyed by surfaces+filter); the index's query-independent statistics are reused across queries. Behavior-preserving: skills strict reproduces dense 0.6585 / lexical 0.6407 / hybrid 0.6941 exactly. Needs vd.BM25Index (i2mint/vd#22). Closes #21. Refs #12
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 #21. Needs i2mint/vd#23 (
vd.BM25Index).ir.retrieve._lexical_rankedrebuilt the candidate collection and recomputed every BM25 term statistic on every query → lexical/hybrid were O(corpus×queries) and did not scale (surfaced by the eval run, ir_05 §6.1).Change: build a
vd.BM25Indexonce per candidate set and cache it on the corpus instance (keyed by surfaces+filter); the query-independent statistics are reused across queries.surfacesis materialized once (it feeds both the filter and the cache key).Behavior-preserving: skills strict reproduces dense 0.6585 / lexical 0.6407 / hybrid 0.6941 exactly. 94 tests pass.
Scaling proof: the full 600-query
reportsrun (16,836-record corpus, all three modes) that previously didn't finish in 10 min of CPU (killed, down-sampled to 100) now completes in ~3 min 16 s — and confirms the finding on the full set: hybrid 0.537 > dense 0.500 > lexical 0.401.Refs #12.