[BUG] Prevent using operator names as metadata keys #6
+96
−0
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.
Description of changes
Fixes chroma-core#4388
In
chromadb/api/types.py
:RESERVED_OPERATORS
constant that lists all operator names that are reservedvalidate_metadata()
to check metadata keys against this list and reject any that match$
to avoid future conflictsIn
chromadb/segment/impl/metadata/sqlite.py
:_where_map_criterion()
to explicitly check for$in
and$nin
operators at the top levelTest plan
python test_reproduce/test_complex_operator_bug.py
Scenario Represented in the Test Case
Create a collection with documents that have metadata keys matching operator names:
Execute a complex query that uses
$in
both as a metadata key name and as an operator in different parts of the where clause:Observe that the query returns no results, even though there should be a match (document with id4).
pytest
for python,yarn test
for js,cargo test
for rustMore details: