fix: implement $not filter support in ChromaDB vector store (#5485)
This commit is contained in:
@@ -252,6 +252,48 @@ def test_generate_where_clause_non_string_values():
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_generate_where_clause_not_single_equality():
|
||||
"""Test $not with a single equality condition."""
|
||||
filters = {"$not": [{"status": "archived"}]}
|
||||
result = ChromaDB._generate_where_clause(filters)
|
||||
assert result == {"status": {"$ne": "archived"}}
|
||||
|
||||
|
||||
def test_generate_where_clause_not_multiple_conditions():
|
||||
"""Test $not with multiple conditions (OR semantics, negated to AND)."""
|
||||
filters = {"$not": [{"status": "archived"}, {"type": "draft"}]}
|
||||
result = ChromaDB._generate_where_clause(filters)
|
||||
assert result == {"$and": [{"status": {"$ne": "archived"}}, {"type": {"$ne": "draft"}}]}
|
||||
|
||||
|
||||
def test_generate_where_clause_not_with_operators():
|
||||
"""Test $not negates comparison operators correctly."""
|
||||
filters = {"$not": [{"count": {"gt": 5}}]}
|
||||
result = ChromaDB._generate_where_clause(filters)
|
||||
assert result == {"count": {"$lte": 5}}
|
||||
|
||||
|
||||
def test_generate_where_clause_not_in_to_nin():
|
||||
"""Test $not converts 'in' to $nin."""
|
||||
filters = {"$not": [{"status": {"in": ["archived", "deleted"]}}]}
|
||||
result = ChromaDB._generate_where_clause(filters)
|
||||
assert result == {"status": {"$nin": ["archived", "deleted"]}}
|
||||
|
||||
|
||||
def test_generate_where_clause_not_multi_field_condition():
|
||||
"""Test $not with multi-field condition uses De Morgan's (AND -> OR)."""
|
||||
filters = {"$not": [{"status": "archived", "type": "draft"}]}
|
||||
result = ChromaDB._generate_where_clause(filters)
|
||||
assert result == {"$or": [{"status": {"$ne": "archived"}}, {"type": {"$ne": "draft"}}]}
|
||||
|
||||
|
||||
def test_generate_where_clause_not_combined_with_other_filters():
|
||||
"""Test $not combined with regular filters."""
|
||||
filters = {"user_id": "alice", "$not": [{"status": "archived"}]}
|
||||
result = ChromaDB._generate_where_clause(filters)
|
||||
assert result == {"$and": [{"user_id": {"$eq": "alice"}}, {"status": {"$ne": "archived"}}]}
|
||||
|
||||
|
||||
def test_chroma_config_accepts_default_tmp_path():
|
||||
"""Test that ChromaDbConfig accepts the default /tmp/chroma path."""
|
||||
config = ChromaDbConfig(path="/tmp/chroma")
|
||||
|
||||
Reference in New Issue
Block a user