@@ -57,9 +57,9 @@ def _get_hybrid_query() -> str:
5757
5858def _get_filtered_vector_query (
5959 filters : dict [str , Any ],
60- node_label : Optional [ str ] ,
61- embedding_node_property : Optional [ str ] ,
62- embedding_dimension : Optional [ int ] ,
60+ node_label : str ,
61+ embedding_node_property : str ,
62+ embedding_dimension : int ,
6363) -> tuple [str , dict [str , Any ]]:
6464 """Build Cypher query for vector search with filters
6565 Uses exact KNN.
@@ -85,31 +85,6 @@ def _get_filtered_vector_query(
8585 return f"{ base_query } AND ({ where_filters } ) { vector_query } " , query_params
8686
8787
88- def _get_vector_query (
89- filters : Optional [dict [str , Any ]],
90- node_label : Optional [str ],
91- embedding_node_property : Optional [str ],
92- embedding_dimension : Optional [int ],
93- ) -> tuple [str , dict [str , Any ]]:
94- """Build the vector query with or without filters
95-
96- Args:
97- filters (dict[str, Any]): filters used to pre-filter the nodes before vector search
98- node_label (str): node label we want to search for
99- embedding_node_property (str): the name of the property holding the embeddings
100- embedding_dimension (int): the dimension of the embeddings
101-
102- Returns:
103- tuple[str, dict[str, Any]]: query and parameters
104-
105- """
106- if filters :
107- return _get_filtered_vector_query (
108- filters , node_label , embedding_node_property , embedding_dimension
109- )
110- return VECTOR_INDEX_QUERY , {}
111-
112-
11388def get_search_query (
11489 search_type : SearchType ,
11590 return_properties : Optional [list [str ]] = None ,
@@ -138,13 +113,25 @@ def get_search_query(
138113 """
139114 if search_type == SearchType .HYBRID :
140115 if filters :
141- raise Exception ("Filters is not supported with Hybrid Search" )
116+ raise Exception ("Filters are not supported with Hybrid Search" )
142117 query = _get_hybrid_query ()
143118 params : dict [str , Any ] = {}
144119 elif search_type == SearchType .VECTOR :
145- query , params = _get_vector_query (
146- filters , node_label , embedding_node_property , embedding_dimension
147- )
120+ if filters :
121+ if (
122+ node_label is not None
123+ and embedding_node_property is not None
124+ and embedding_dimension is not None
125+ ):
126+ query , params = _get_filtered_vector_query (
127+ filters , node_label , embedding_node_property , embedding_dimension
128+ )
129+ else :
130+ raise Exception (
131+ "Vector Search with filters requires: node_label, embedding_node_property, embedding_dimension"
132+ )
133+ else :
134+ query , params = VECTOR_INDEX_QUERY , {}
148135 else :
149136 raise ValueError (f"Search type is not supported: { search_type } " )
150137 query_tail = get_query_tail (
0 commit comments