Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fcd4cc3

Browse files
committedApr 4, 2025·
update doc strings for Hybrid and Text
1 parent d0c86ed commit fcd4cc3

File tree

3 files changed

+77
-42
lines changed

3 files changed

+77
-42
lines changed
 

‎docs/api/query.rst

+28
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@ VectorRangeQuery
3434
:show-inheritance:
3535
:exclude-members: add_filter,get_args,highlight,return_field,summarize
3636

37+
HybridQuery
38+
================
39+
40+
41+
.. currentmodule:: redisvl.query
42+
43+
44+
.. autoclass:: HybridQuery
45+
:members:
46+
:inherited-members:
47+
:show-inheritance:
48+
:exclude-members: add_filter,get_args,highlight,return_field,summarize
49+
50+
51+
TextQuery
52+
================
53+
54+
55+
.. currentmodule:: redisvl.query
56+
57+
58+
.. autoclass:: TextQuery
59+
:members:
60+
:inherited-members:
61+
:show-inheritance:
62+
:exclude-members: add_filter,get_args,highlight,return_field,summarize
63+
64+
3765
FilterQuery
3866
===========
3967

‎redisvl/query/aggregate.py

+25-23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,31 @@ class HybridQuery(AggregationQuery):
2323
HybridQuery combines text and vector search in Redis.
2424
It allows you to perform a hybrid search using both text and vector similarity.
2525
It scores documents based on a weighted combination of text and vector similarity.
26+
27+
.. code-block:: python
28+
29+
from redisvl.query import HybridQuery
30+
from redisvl.index import SearchIndex
31+
32+
index = SearchIndex.from_yaml("path/to/index.yaml")
33+
34+
query = HybridQuery(
35+
text="example text",
36+
text_field_name="text_field",
37+
vector=[0.1, 0.2, 0.3],
38+
vector_field_name="vector_field",
39+
text_scorer="BM25STD",
40+
filter_expression=None,
41+
alpha=0.7,
42+
dtype="float32",
43+
num_results=10,
44+
return_fields=["field1", "field2"],
45+
stopwords="english",
46+
dialect=2,
47+
)
48+
49+
results = index.query(query)
50+
2651
"""
2752

2853
DISTANCE_ID: str = "vector_distance"
@@ -72,29 +97,6 @@ def __init__(
7297
ValueError: If the text string is empty, or if the text string becomes empty after
7398
stopwords are removed.
7499
TypeError: If the stopwords are not a set, list, or tuple of strings.
75-
76-
.. code-block:: python
77-
from redisvl.query import HybridQuery
78-
from redisvl.index import SearchIndex
79-
80-
index = SearchIndex.from_yaml("path/to/index.yaml")
81-
82-
query = HybridQuery(
83-
text="example text",
84-
text_field_name="text_field",
85-
vector=[0.1, 0.2, 0.3],
86-
vector_field_name="vector_field",
87-
text_scorer="BM25STD",
88-
filter_expression=None,
89-
alpha=0.7,
90-
dtype="float32",
91-
num_results=10,
92-
return_fields=["field1", "field2"],
93-
stopwords="english",
94-
dialect=2,
95-
)
96-
97-
results = index.query(query)
98100
"""
99101

100102
if not text.strip():

‎redisvl/query/query.py

+24-19
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,30 @@ class RangeQuery(VectorRangeQuery):
690690

691691

692692
class TextQuery(BaseQuery):
693+
"""
694+
TextQuery is a query for running a full text search, along with an optional filter expression.
695+
696+
.. code-block:: python
697+
698+
from redisvl.query import TextQuery
699+
from redisvl.index import SearchIndex
700+
701+
index = SearchIndex.from_yaml(index.yaml)
702+
703+
query = TextQuery(
704+
text="example text",
705+
text_field_name="text_field",
706+
text_scorer="BM25STD",
707+
filter_expression=None,
708+
num_results=10,
709+
return_fields=["field1", "field2"],
710+
stopwords="english",
711+
dialect=2,
712+
)
713+
714+
results = index.query(query)
715+
"""
716+
693717
def __init__(
694718
self,
695719
text: str,
@@ -739,25 +763,6 @@ def __init__(
739763
Raises:
740764
ValueError: if stopwords language string cannot be loaded.
741765
TypeError: If stopwords is not a valid iterable set of strings.
742-
743-
.. code-block:: python
744-
from redisvl.query import TextQuery
745-
from redisvl.index import SearchIndex
746-
747-
index = SearchIndex.from_yaml(index.yaml)
748-
749-
query = TextQuery(
750-
text="example text",
751-
text_field_name="text_field",
752-
text_scorer="BM25STD",
753-
filter_expression=None,
754-
num_results=10,
755-
return_fields=["field1", "field2"],
756-
stopwords="english",
757-
dialect=2,
758-
)
759-
760-
results = index.query(query)
761766
"""
762767
self._text = text
763768
self._text_field = text_field_name

0 commit comments

Comments
 (0)
Please sign in to comment.