@@ -49,6 +49,7 @@ def __init__(
4949 text_field_name : str ,
5050 vector : Union [bytes , List [float ]],
5151 vector_field_name : str ,
52+ vector_param_name : str = "vector" ,
5253 text_scorer : str = "BM25STD" ,
5354 yield_text_score_as : Optional [str ] = None ,
5455 vector_search_method : Optional [Literal ["KNN" , "RANGE" ]] = None ,
@@ -76,6 +77,7 @@ def __init__(
7677 text_field_name: The text field name to search in.
7778 vector: The vector to perform vector similarity search.
7879 vector_field_name: The vector field name to search in.
80+ vector_param_name: The name of the parameter substitution containing the vector blob.
7981 text_scorer: The text scorer to use. Options are {TFIDF, TFIDF.DOCNORM,
8082 BM25STD, BM25STD.NORM, BM25STD.TANH, DISMAX, DOCSCORE, HAMMING}. Defaults to "BM25STD". For more
8183 information about supported scoring algorithms,
@@ -123,6 +125,7 @@ def __init__(
123125 ValueError: If `vector_search_method` is "KNN" and `knn_k` is not provided.
124126 ValueError: If `vector_search_method` is "RANGE" and `range_radius` is not provided.
125127 """
128+
126129 try :
127130 from redis .commands .search .hybrid_query import (
128131 CombineResultsMethod ,
@@ -146,9 +149,18 @@ def __init__(
146149 text , text_field_name , filter_expression
147150 )
148151
152+ if isinstance (vector , bytes ):
153+ vector_data = vector
154+ else :
155+ vector_data = array_to_buffer (vector , dtype )
156+
157+ self .params = {
158+ vector_param_name : vector_data ,
159+ }
160+
149161 self .query = build_base_query (
150162 text_query = query_string ,
151- vector = vector ,
163+ vector_param_name = vector_param_name ,
152164 vector_field_name = vector_field_name ,
153165 text_scorer = text_scorer ,
154166 yield_text_score_as = yield_text_score_as ,
@@ -159,7 +171,6 @@ def __init__(
159171 range_epsilon = range_epsilon ,
160172 yield_vsim_score_as = yield_vsim_score_as ,
161173 filter_expression = filter_expression ,
162- dtype = dtype ,
163174 )
164175
165176 if combination_method :
@@ -178,7 +189,7 @@ def __init__(
178189
179190def build_base_query (
180191 text_query : str ,
181- vector : Union [ bytes , List [ float ]] ,
192+ vector_param_name : str ,
182193 vector_field_name : str ,
183194 text_scorer : str = "BM25STD" ,
184195 yield_text_score_as : Optional [str ] = None ,
@@ -189,13 +200,12 @@ def build_base_query(
189200 range_epsilon : Optional [float ] = None ,
190201 yield_vsim_score_as : Optional [str ] = None ,
191202 filter_expression : Optional [Union [str , FilterExpression ]] = None ,
192- dtype : str = "float32" ,
193203):
194204 """Build a Redis HybridQuery for performing hybrid search.
195205
196206 Args:
197207 text_query: The query for the text search.
198- vector : The vector to perform vector similarity search .
208+ vector_param_name : The name of the parameter substitution containing the vector blob .
199209 vector_field_name: The vector field name to search in.
200210 text_scorer: The text scorer to use. Options are {TFIDF, TFIDF.DOCNORM,
201211 BM25STD, BM25STD.NORM, BM25STD.TANH, DISMAX, DOCSCORE, HAMMING}. Defaults to "BM25STD". For more
@@ -210,7 +220,6 @@ def build_base_query(
210220 accuracy of the search.
211221 yield_vsim_score_as: The name of the field to yield the vector similarity score as.
212222 filter_expression: The filter expression to use for the vector similarity search. Defaults to None.
213- dtype: The data type of the vector. Defaults to "float32".
214223
215224 Notes:
216225 If RRF combination method is used, then at least one of `rrf_window` or `rrf_constant` must be provided.
@@ -242,11 +251,6 @@ def build_base_query(
242251 yield_score_as = yield_text_score_as ,
243252 )
244253
245- if isinstance (vector , bytes ):
246- vector_data = vector
247- else :
248- vector_data = array_to_buffer (vector , dtype )
249-
250254 # Serialize vector similarity search method and params, if specified
251255 vsim_search_method : Optional [VectorSearchMethods ] = None
252256 vsim_search_method_params : Dict [str , Any ] = {}
@@ -284,7 +288,7 @@ def build_base_query(
284288 # Serialize the vector similarity query
285289 vsim_query = HybridVsimQuery (
286290 vector_field_name = "@" + vector_field_name ,
287- vector_data = vector_data ,
291+ vector_data = "$" + vector_param_name ,
288292 vsim_search_method = vsim_search_method ,
289293 vsim_search_method_params = vsim_search_method_params ,
290294 filter = vsim_filter ,
0 commit comments