1111
1212try :
1313 from redisvl .query .hybrid import HybridQuery
14+
15+ REDIS_HYBRID_AVAILABLE = True
16+ SKIP_REASON = ""
1417except (ImportError , ModuleNotFoundError ):
18+ REDIS_HYBRID_AVAILABLE = False
19+ SKIP_REASON = "Requires redis>=8.4.0 and redis-py>=7.1.0"
1520 HybridQuery = None # type: ignore
1621
1722
@@ -109,9 +114,8 @@ def hash_preprocess(item: dict) -> dict:
109114 await index .delete (drop = True )
110115
111116
117+ @pytest .mark .skipif (not REDIS_HYBRID_AVAILABLE , reason = SKIP_REASON )
112118def test_hybrid_query (index ):
113- skip_if_redis_version_below (index .client , "8.4.0" )
114-
115119 text = "a medical professional with expertise in lung cancer"
116120 text_field = "description"
117121 vector = [0.1 , 0.1 , 0.5 ]
@@ -167,9 +171,8 @@ def test_hybrid_query(index):
167171 )
168172
169173
174+ @pytest .mark .skipif (not REDIS_HYBRID_AVAILABLE , reason = SKIP_REASON )
170175def test_hybrid_query_with_filter (index ):
171- skip_if_redis_version_below (index .client , "8.4.0" )
172-
173176 text = "a medical professional with expertise in lung cancer"
174177 text_field = "description"
175178 vector = [0.1 , 0.1 , 0.5 ]
@@ -194,9 +197,8 @@ def test_hybrid_query_with_filter(index):
194197 assert int (result ["age" ]) > 30
195198
196199
200+ @pytest .mark .skipif (not REDIS_HYBRID_AVAILABLE , reason = SKIP_REASON )
197201def test_hybrid_query_with_geo_filter (index ):
198- skip_if_redis_version_below (index .client , "8.4.0" )
199-
200202 text = "a medical professional with expertise in lung cancer"
201203 text_field = "description"
202204 vector = [0.1 , 0.1 , 0.5 ]
@@ -220,10 +222,9 @@ def test_hybrid_query_with_geo_filter(index):
220222 assert result ["location" ] is not None
221223
222224
225+ @pytest .mark .skipif (not REDIS_HYBRID_AVAILABLE , reason = SKIP_REASON )
223226@pytest .mark .parametrize ("alpha" , [0.1 , 0.5 , 0.9 ])
224227def test_hybrid_query_alpha (index , alpha ):
225- skip_if_redis_version_below (index .client , "8.4.0" )
226-
227228 text = "a medical professional with expertise in lung cancer"
228229 text_field = "description"
229230 vector = [0.1 , 0.1 , 0.5 ]
@@ -252,9 +253,8 @@ def test_hybrid_query_alpha(index, alpha):
252253 ) # allow for small floating point error
253254
254255
256+ @pytest .mark .skipif (not REDIS_HYBRID_AVAILABLE , reason = SKIP_REASON )
255257def test_hybrid_query_stopwords (index ):
256- skip_if_redis_version_below (index .client , "8.4.0" )
257-
258258 text = "a medical professional with expertise in lung cancer"
259259 text_field = "description"
260260 vector = [0.1 , 0.1 , 0.5 ]
@@ -289,9 +289,8 @@ def test_hybrid_query_stopwords(index):
289289 ) # allow for small floating point error
290290
291291
292+ @pytest .mark .skipif (not REDIS_HYBRID_AVAILABLE , reason = SKIP_REASON )
292293def test_hybrid_query_with_text_filter (index ):
293- skip_if_redis_version_below (index .client , "8.4.0" )
294-
295294 text = "a medical professional with expertise in lung cancer"
296295 text_field = "description"
297296 vector = [0.1 , 0.1 , 0.5 ]
@@ -338,10 +337,9 @@ def test_hybrid_query_with_text_filter(index):
338337 assert "research" not in result [text_field ].lower ()
339338
340339
340+ @pytest .mark .skipif (not REDIS_HYBRID_AVAILABLE , reason = SKIP_REASON )
341341@pytest .mark .parametrize ("scorer" , ["BM25STD" , "TFIDF" , "TFIDF.DOCNORM" ])
342342def test_hybrid_query_word_weights (index , scorer ):
343- skip_if_redis_version_below (index .client , "8.4.0" )
344-
345343 text = "a medical professional with expertise in lung cancers"
346344 text_field = "description"
347345 vector = [0.1 , 0.1 , 0.5 ]
@@ -401,10 +399,9 @@ def test_hybrid_query_word_weights(index, scorer):
401399 assert weighted_results != unweighted_results
402400
403401
402+ @pytest .mark .skipif (not REDIS_HYBRID_AVAILABLE , reason = SKIP_REASON )
404403@pytest .mark .asyncio
405404async def test_hybrid_query_async (async_index ):
406- await skip_if_redis_version_below_async (async_index .client , "8.4.0" )
407-
408405 text = "a medical professional with expertise in lung cancer"
409406 text_field = "description"
410407 vector = [0.1 , 0.1 , 0.5 ]
0 commit comments