Fix multi-collection filtering in search/query/vsearch#218
Open
Fix multi-collection filtering in search/query/vsearch#218
Conversation
82b6597 to
e237ae7
Compare
Co-authored-by: Alyx <kunaclawd@gmail.com>
e237ae7 to
78587ec
Compare
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.
Problem
When multiple
-c/--collectionflags are passed toqmd search,query, orvsearch, results are often empty or incomplete.Root cause: With a single
-c, the collection filter is pushed into the SQL query (AND d.collection = ?). With multiple-cflags, qmd performs a global unfiltered top-K search then post-filters byqmd://{collection}/prefix. Large collections dominate the global top-K, so post-filtering removes everything from smaller requested collections.Fix
Push the collection filter into the underlying retrieval for all three search paths instead of post-filtering a limited result set:
WHERE ... AND d.collection IN (?, ...)via a shared SQL helperhash_seqvalues for requested collections and applyAND hash_seq IN (...)directly in the sqlite-vec KNN queryAdded
normalizeCollectionFilter()andappendCollectionFilterSql()helpers instore.tsto handle single vs. multi-collection SQL generation consistently.Type changes
searchFTSandsearchVec(both theStoremethods and the exported functions) now acceptstring | string[]for the collection parameterHybridQueryOptions.collectionandVectorSearchOptions.collectionupdated tostring | string[]Tests
Added 4 test files/scenarios (TDD, written before the fix, confirmed failing, then passing):
test/cli.test.ts— end-to-end CLI regression with 80-doc noisy collection vs 2 small target collectionstest/store.test.ts—searchFTSwith multi-collection array filtertest/query-collection-routing.test.ts— verifieshybridQuery/vectorSearchQuerypass array filters throughtest/searchvec-multi-collection.test.ts— vector search under top-K domination with collection IN filterFull test suite passes (5 pre-existing LLM timeout failures unrelated to this change).