@@ -57,9 +57,9 @@ def _get_hybrid_query() -> str:
57
57
58
58
def _get_filtered_vector_query (
59
59
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 ,
63
63
) -> tuple [str , dict [str , Any ]]:
64
64
"""Build Cypher query for vector search with filters
65
65
Uses exact KNN.
@@ -85,31 +85,6 @@ def _get_filtered_vector_query(
85
85
return f"{ base_query } AND ({ where_filters } ) { vector_query } " , query_params
86
86
87
87
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
-
113
88
def get_search_query (
114
89
search_type : SearchType ,
115
90
return_properties : Optional [list [str ]] = None ,
@@ -138,13 +113,25 @@ def get_search_query(
138
113
"""
139
114
if search_type == SearchType .HYBRID :
140
115
if filters :
141
- raise Exception ("Filters is not supported with Hybrid Search" )
116
+ raise Exception ("Filters are not supported with Hybrid Search" )
142
117
query = _get_hybrid_query ()
143
118
params : dict [str , Any ] = {}
144
119
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 , {}
148
135
else :
149
136
raise ValueError (f"Search type is not supported: { search_type } " )
150
137
query_tail = get_query_tail (
0 commit comments