fixed Bug in PreFilter of AzureCosmosDBNoSqlVectorSearch (#29613)

Description: Fixes PreFilter value handling in Azure Cosmos DB NoSQL
vectorstore. The current implementation fails to handle numeric values
in filter conditions, causing an undefined value variable error. This PR
adds support for numeric, boolean, and NULL values while maintaining the
existing string and list handling.

Changes:
Added handling for numeric types (int/float)
Added boolean value support
Added NULL value handling
Added type validation for unsupported values
Fixed scope of value variable initialization

Issue: 
Fixes #29610

Implementation Notes:
No changes to public API
Backwards compatible
Maintains consistent behavior with existing MongoDB-style filtering
Preserves SQL injection prevention through proper value handling

---------

Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
Mohammad Anash 2025-02-06 07:50:26 +05:30 committed by GitHub
parent 6ff0d5c807
commit f849305a56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -789,6 +789,13 @@ class AzureCosmosDBNoSqlVectorSearch(VectorStore):
elif isinstance(condition.value, list):
# e.g., for IN clauses
value = f"({', '.join(map(str, condition.value))})"
elif isinstance(condition.value, (int, float, bool)):
value = str(condition.value)
elif condition.value is None:
value = "NULL"
else:
raise ValueError(f"Unsupported value type: {type(condition.value)}")
clauses.append(f"c.{condition.property} {sql_operator} {value}")
return f""" WHERE {' {} '.format(sql_logical_operator).join(clauses)}""".strip()