|
2 | 2 |
|
3 | 3 | import ast
|
4 | 4 | import asyncio
|
5 |
| -import json |
6 | 5 | import sys
|
7 | 6 | from collections.abc import Sequence
|
8 | 7 | from importlib import metadata
|
@@ -795,33 +794,38 @@ async def _inner_search(
|
795 | 794 | if isinstance(where_clauses, str)
|
796 | 795 | else f"WHERE ({' AND '.join(where_clauses)}) "
|
797 | 796 | )
|
| 797 | + else: |
| 798 | + where_clauses = "" # Empty string instead of None |
798 | 799 | vector_field_name = vector_field.storage_name or vector_field.name
|
799 | 800 | select_clause = self._build_select_clause(options.include_vectors)
|
800 | 801 | params.append({"name": "@vector", "value": vector})
|
801 | 802 | if vector_field.distance_function not in DISTANCE_FUNCTION_MAP_NOSQL:
|
802 | 803 | raise VectorStoreModelException(
|
803 | 804 | f"Distance function '{vector_field.distance_function}' is not supported by Azure Cosmos DB NoSQL."
|
804 | 805 | )
|
805 |
| - distance_obj = json.dumps({"distanceFunction": DISTANCE_FUNCTION_MAP_NOSQL[vector_field.distance_function]}) |
| 806 | + # Cosmos DB VectorDistance function only accepts 2 parameters: field and vector |
| 807 | + # Distance function is configured in the vector index, not in the query |
806 | 808 | if search_type == SearchType.VECTOR:
|
807 |
| - distance_clause = f"VectorDistance(c.{vector_field_name}, @vector, false {distance_obj})" |
| 809 | + distance_clause = f"VectorDistance(c.{vector_field_name}, @vector)" |
808 | 810 | elif search_type == SearchType.KEYWORD_HYBRID:
|
809 | 811 | # Hybrid search: requires both a vector and keywords
|
810 | 812 | params.append({"name": "@keywords", "value": values})
|
811 | 813 | text_field = options.additional_property_name
|
812 | 814 | if not text_field:
|
813 | 815 | raise VectorStoreModelException("Hybrid search requires 'keyword_field_name' in options.")
|
814 |
| - distance_clause = f"RRF(VectorDistance(c.{vector_field_name}, @vector, false, {distance_obj}), " |
815 |
| - f"FullTextScore(c.{text_field}, @keywords))" |
| 816 | + distance_clause = ( |
| 817 | + f"RRF(VectorDistance(c.{vector_field_name}, @vector), FullTextScore(c.{text_field}, @keywords))" |
| 818 | + ) |
816 | 819 | else:
|
817 | 820 | raise VectorStoreModelException(f"Search type '{search_type}' is not supported.")
|
818 | 821 | query = (
|
819 | 822 | f"SELECT TOP @top {select_clause}, " # nosec: B608
|
820 | 823 | f"{distance_clause} as {NOSQL_SCORE_PROPERTY_NAME} " # nosec: B608
|
821 | 824 | "FROM c "
|
822 | 825 | f"{where_clauses}" # nosec: B608
|
823 |
| - f"ORDER BY RANK {distance_clause}" # nosec: B608 |
| 826 | + f"ORDER BY {distance_clause}" # nosec: B608 |
824 | 827 | )
|
| 828 | + |
825 | 829 | container_proxy = await self._get_container_proxy(self.collection_name, **kwargs)
|
826 | 830 | try:
|
827 | 831 | results = container_proxy.query_items(query, parameters=params)
|
|
0 commit comments