feat(search): BM25Index — build-once / query-many lexical index#23
Merged
Conversation
bm25_lexical_search re-tokenized every document and recomputed document frequencies/lengths on every call (O(N) per query, O(N*Q) for a batch), which did not scale. Extract a reusable BM25Index that builds the query-independent term statistics once and answers many queries via .search(query, *, limit, k1, b); bm25_lexical_search becomes a thin one-shot wrapper (BM25Index(collection, filter=...).search(...)) with identical behavior. Adds equivalence + reuse + filter tests. First customer: i2mint/ir (caches a BM25Index per corpus). Closes #22
CI installed no optional extras, so pytest-asyncio (declared only in the dev group) was absent and all 12 tests/test_async.py tests errored with 'async def functions are not natively supported' — a pre-existing failure surfaced by dependency drift (master's last CI run predates it). Add a lightweight 'test' extra (pytest + pytest-cov + pytest-asyncio, no heavy backend deps) and point [tool.wads.ci.install].extras at it.
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.
bm25_lexical_searchre-tokenizes every document and recomputes document frequencies/lengths on every call (O(N) per query, O(N·Q) for a batch) — it doesn't scale (a batch lexical/hybrid pass over a ~16.8k-doc collection didn't finish in 10 min CPU, surfaced via theireval run).Change: extract a reusable
BM25Indexthat builds the query-independent term statistics (df, lengths, mean length, per-doc tokens) once in__init__, then answers many queries via.search(query, *, limit, k1, b).bm25_lexical_searchbecomes a thin one-shot wrapper —BM25Index(collection, filter=...).search(...)— so existing behavior is exactly preserved (covered by a new equivalence test). Also exposesvd.BM25Indexand adds reuse/filter/empty-query tests + a doctest.First customer:
i2mint/ir(ir.retrievecaches a BM25Index per corpus). 49 hybrid tests + 8 doctests pass.Closes #22