|
1 | 1 | import pytest |
2 | 2 | from packaging.version import Version |
3 | 3 | from redis import ResponseError |
| 4 | +from redis import __version__ as redis_version |
4 | 5 |
|
5 | 6 | from redisvl.index import AsyncSearchIndex, SearchIndex |
6 | 7 | from redisvl.query.filter import Geo, GeoRadius, Num, Tag, Text |
| 8 | +from redisvl.query.hybrid import HybridQuery |
7 | 9 | from redisvl.redis.utils import array_to_buffer |
8 | 10 | from redisvl.schema import IndexSchema |
9 | 11 | from tests.conftest import ( |
|
12 | 14 | skip_if_redis_version_below_async, |
13 | 15 | ) |
14 | 16 |
|
15 | | -try: |
16 | | - from redisvl.query.hybrid import HybridQuery |
17 | | - |
18 | | - REDIS_HYBRID_AVAILABLE = True |
19 | | - SKIP_REASON = "" |
20 | | -except (ImportError, ModuleNotFoundError): |
21 | | - REDIS_HYBRID_AVAILABLE = False |
22 | | - SKIP_REASON = "Requires redis>=8.4.0 and redis-py>=7.1.0" |
23 | | - # HybridQuery = None # type: ignore |
| 17 | +REDIS_HYBRID_AVAILABLE = Version(redis_version) >= Version("7.1.0") |
| 18 | +SKIP_REASON = "Requires Redis >= 8.4.0 and redis-py>=7.1.0" |
24 | 19 |
|
25 | 20 |
|
26 | 21 | @pytest.fixture |
@@ -496,9 +491,21 @@ def test_hybrid_search_not_available_in_server(index): |
496 | 491 | @pytest.mark.skipif( |
497 | 492 | REDIS_HYBRID_AVAILABLE, reason="Requires hybrid search to NOT be available" |
498 | 493 | ) |
499 | | -def test_hybrid_query_not_available(): |
| 494 | +def test_hybrid_query_not_available(index): |
| 495 | + hybrid_query = HybridQuery( |
| 496 | + text="a medical professional with expertise in lung cancer", |
| 497 | + text_field_name="description", |
| 498 | + yield_text_score_as="text_score", |
| 499 | + vector=[0.1, 0.1, 0.5], |
| 500 | + vector_field_name="user_embedding", |
| 501 | + yield_vsim_score_as="vsim_score", |
| 502 | + combination_method="RRF", |
| 503 | + yield_combined_score_as="hybrid_score", |
| 504 | + return_fields=["user", "credit_score", "age", "job", "location", "description"], |
| 505 | + ) |
| 506 | + |
500 | 507 | with pytest.raises(ImportError): |
501 | | - from redisvl.query.hybrid import HybridQuery # noqa: F401 |
| 508 | + index.query(hybrid_query) |
502 | 509 |
|
503 | 510 |
|
504 | 511 | @pytest.mark.skipif( |
|
0 commit comments