fix(qdrant): prevent invalid filter nesting when using preFilters#2270
Open
serhiizghama wants to merge 1 commit intorun-llama:mainfrom
Open
fix(qdrant): prevent invalid filter nesting when using preFilters#2270serhiizghama wants to merge 1 commit intorun-llama:mainfrom
serhiizghama wants to merge 1 commit intorun-llama:mainfrom
Conversation
When query.filters are passed without docIds, buildQueryFilter was
wrapping toQdrantMetadataFilters() output inside an extra must array,
producing { must: [{ must: [...] }] } instead of the flat
{ must: [...] } that Qdrant expects. This caused 400 Bad Request errors
whenever preFilters were used with QdrantVectorStore.
Changes:
- Return metadataFilters directly when no docIds are present
- When docIds and metadata filters coexist, spread AND-condition filter
conditions flat into mustConditions; keep OR-condition filters as a
nested filter to preserve their semantics
- Add three tests covering: filters-only AND, docId+filters combined,
and filters-only OR cases
|
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
Closes #2035
When using
preFilterswithQdrantVectorStore, all queries returned a 400 Bad Request from Qdrant. The root cause was inbuildQueryFilter:toQdrantMetadataFilters()already returns a fullQdrantFilterobject ({must: [...]}or{should: [...]}). Pushing that into anothermustarray creates one extra layer of nesting that the Qdrant REST API rejects.What changed
packages/providers/storage/qdrant/src/QdrantVectorStore.tsdocIdsare present, returnmetadataFiltersdirectly instead of wrapping itdocIdsand metadata filters exist, spread AND-condition filter conditions flat intomustConditions; keep OR-condition (should) filters as a nested filter object to preserve their semanticspackages/providers/storage/qdrant/tests/QdrantVectorStore.test.tsmustlevelshouldarray is produced at the top levelHow to test
Or run the unit tests: