Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion redis/commands/search/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
HybridQuery,
)
from redis.commands.search.hybrid_result import HybridCursorResult, HybridResult
from redis.utils import deprecated_function
from redis.utils import deprecated_function, experimental_method

from ..helpers import get_protocol_version
from ._util import to_string
Expand Down Expand Up @@ -560,6 +560,7 @@ def search(
SEARCH_CMD, res, query=query, duration=(time.monotonic() - st) * 1000.0
)

@experimental_method()
def hybrid_search(
self,
query: HybridQuery,
Expand Down Expand Up @@ -1053,6 +1054,7 @@ async def search(
SEARCH_CMD, res, query=query, duration=(time.monotonic() - st) * 1000.0
)

@experimental_method()
async def hybrid_search(
self,
query: HybridQuery,
Expand Down
3 changes: 2 additions & 1 deletion redis/commands/search/hybrid_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def query_string(self) -> str:
def scorer(self, scorer: str) -> "HybridSearchQuery":
"""
Scoring algorithm for text search query.
Allowed values are "TFIDF", "DISMAX", "DOCSCORE", "BM25", etc.
Allowed values are "TFIDF", "TFIDF.DOCNORM", "DISMAX", "DOCSCORE", "BM25",
"BM25STD", "BM25STD.TANH", "HAMMING", etc.

For more information about supported scroring algorithms,
see https://redis.io/docs/latest/develop/ai/search-and-query/advanced-concepts/scoring/
Expand Down
39 changes: 39 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4250,6 +4250,45 @@ def test_hybrid_search_query_with_scorer(self, client):
)
assert res["warnings"] == []

@pytest.mark.redismod
@skip_if_server_version_lt("8.3.224")
def test_hybrid_search_query_with_supported_scorer(self, client):
# Create index and add data
self._create_hybrid_search_index(client)
self._add_data_for_hybrid_search(client, items_sets=10)

# set search query
search_query = HybridSearchQuery("shoes")

vsim_query = HybridVsimQuery(
vector_field_name="@embedding",
vector_data="$vec",
)

hybrid_query = HybridQuery(search_query, vsim_query)

supported_scorers = [
"TFIDF",
"TFIDF.DOCNORM",
"BM25",
"BM25STD",
"BM25STD.TANH",
"DISMAX",
"DOCSCORE",
"HAMMING",
]
for scorer in supported_scorers:
search_query.scorer(scorer)

res = client.ft().hybrid_search(
query=hybrid_query,
params_substitution={
"vec": np.array([1, 2, 2, 3], dtype=np.float32).tobytes()
},
timeout=10,
)
assert res is not None

@pytest.mark.redismod
@skip_if_server_version_lt("8.3.224")
def test_hybrid_search_query_with_vsim_method_defined_query_init(self, client):
Expand Down
Loading