Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
max-parallel: 15
fail-fast: false
matrix:
redis-version: ['8.4-RC1-pre.2', '${{ needs.redis_version.outputs.CURRENT }}', '8.0.2' ,'7.4.4', '7.2.9']
redis-version: ['8.4-GA-pre.2', '${{ needs.redis_version.outputs.CURRENT }}', '8.0.2' ,'7.4.4', '7.2.9']
python-version: ['3.10', '3.14']
parser-backend: ['plain']
event-loop: ['asyncio']
Expand Down
14 changes: 12 additions & 2 deletions redis/commands/search/hybrid_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __init__(
vsim_search_method: Optional[VectorSearchMethods] = None,
vsim_search_method_params: Optional[Dict[str, Any]] = None,
filter: Optional["Filter"] = None,
yield_score_as: Optional[str] = None,
) -> None:
"""
Create a new hybrid vsim query object.
Expand All @@ -96,8 +97,7 @@ def __init__(
Example for RANGE: {"RADIUS": 10, "EPSILON": 0.1}
where RADIUS is mandatory and defines the radius of the search
and EPSILON is optional and defines the accuracy of the search.
For both KNN and RANGE, the following parameter is optional:
YIELD_SCORE_AS: The name of the field to yield the calculated score as.
yield_score_as: The name of the field to yield the score as.

filter: If defined, a filter will be applied on the vsim query results.
"""
Expand All @@ -108,6 +108,7 @@ def __init__(
else:
self._vsim_method_params = None
self._filter = filter
self._yield_score_as = yield_score_as

def vector_field(self) -> str:
"""Return the vector field name of this query object."""
Expand Down Expand Up @@ -149,12 +150,21 @@ def filter(self, flt: "HybridFilter") -> "HybridVsimQuery":
self._filter = flt
return self

def yield_score_as(self, alias: str) -> "HybridVsimQuery":
"""
Return the score as a field with name `alias`.
"""
self._yield_score_as = alias
return self

def get_args(self) -> List[str]:
args = ["VSIM", self._vector_field, self._vector_data]
if self._vsim_method_params:
args.extend(self._vsim_method_params)
if self._filter:
args.extend(self._filter.args)
if self._yield_score_as:
args.extend(("YIELD_SCORE_AS", self._yield_score_as))

return args

Expand Down
7 changes: 2 additions & 5 deletions tests/test_asyncio/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2636,11 +2636,8 @@ async def test_hybrid_search_query_with_combine_all_score_aliases(self, decoded_
vector_field_name="@embedding-hnsw",
vector_data="abcd1234efgh5678",
vsim_search_method=VectorSearchMethods.KNN,
vsim_search_method_params={
"K": 3,
"EF_RUNTIME": 1,
"YIELD_SCORE_AS": "vsim_score",
},
vsim_search_method_params={"K": 3, "EF_RUNTIME": 1},
yield_score_as="vsim_score",
)

hybrid_query = HybridQuery(search_query, vsim_query)
Expand Down
14 changes: 4 additions & 10 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4347,11 +4347,8 @@ def test_hybrid_search_query_with_vsim_score_aliases(self, client):
vector_field_name="@embedding-hnsw",
vector_data="abcd1234efgh5678",
vsim_search_method=VectorSearchMethods.KNN,
vsim_search_method_params={
"K": 3,
"EF_RUNTIME": 1,
"YIELD_SCORE_AS": "vsim_score",
},
vsim_search_method_params={"K": 3, "EF_RUNTIME": 1},
yield_score_as="vsim_score",
)

hybrid_query = HybridQuery(search_query, vsim_query)
Expand Down Expand Up @@ -4433,11 +4430,8 @@ def test_hybrid_search_query_with_combine_all_score_aliases(self, client):
vector_field_name="@embedding-hnsw",
vector_data="abcd1234efgh5678",
vsim_search_method=VectorSearchMethods.KNN,
vsim_search_method_params={
"K": 3,
"EF_RUNTIME": 1,
"YIELD_SCORE_AS": "vsim_score",
},
vsim_search_method_params={"K": 3, "EF_RUNTIME": 1},
yield_score_as="vsim_score",
)

hybrid_query = HybridQuery(search_query, vsim_query)
Expand Down