Commit b5ba960
authored
Implement interface for unified hybrid search in Redis 8.4.0+ (#447)
This PR adds an interface for using the new
[`FT.HYBRID`](https://redis.io/docs/latest/commands/ft.hybrid) search
operation introduced in Redis Open Source 8.4.0.
## Changes
### `redisvl.query.hybrid`
This new module defines query constructors for working with the new
hybrid search operation. Attempting to import this module without having
`redis-py>=7.1.0` will raise an `ImportError`. It defines a
`HybridQuery` object which can be used to define a hybrid search
operation in a format largely similar to what `AggregateHybridQuery`
provides.
Under the hood, `redis-py` expects three separate configuration objects
to run hybrid search - one for the text+vector searches, one for the
score combination, and one for post-processing of the results (e.g.
aggregations, loading, limiting, etc.). The `HybridQuery` class manages
the definition of all three.
```python
# old
from redisvl.query.aggregate import AggregateHybridQuery
query = AggregateHybridQuery(
text="medical professional",
text_field_name="description",
vector=[0.1, 0.1, 0.5, ...],
vector_field_name="user_embedding",
alpha=0.7, # LINEAR only
return_fields=["user", "job"]
)
results = index.query(query)
# new
from redisvl.query.hybrid import HybridQuery
query = HybridQuery(
text="medical professional",
text_field_name="description",
vector=[0.1, 0.1, 0.5, ...],
vector_field_name="user_embedding",
combination_method="LINEAR",
linear_alpha=0.3, # NOTE: The linear combination is defined inconsistently between the two approaches
return_fields=["user", "job"]
)
results = index.hybrid_search(query)
results = await async_index.hybrid_search(query)
```
### SearchIndex method
For `redis-py>=7.1.0`, the `SearchIndex` and `AsyncSearchIndex` classes
define a `hybrid_search` method that takes a `HybridQuery` instance as
an argument. For `redis-py<7.1.0` the method raises a
`NotImplementedError`. The method returns a list of retrieved
dictionaries.
### Additional Changes
- Fixed a typo in a test for `AggregateHybridQuery`
- `redis-py 7.0.0` introduced a change to the type of `Query._fields`,
changing it from a tuple to a list - a test had to be updated to
differentiate the expectation based on the redis-py version.1 parent 8747a3a commit b5ba960
File tree
16 files changed
+2821
-385
lines changed- .github/workflows
- docs
- api
- overview
- user_guide
- redisvl
- index
- query
- utils
- tests
- integration
- unit
16 files changed
+2821
-385
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
| 99 | + | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
| 135 | + | |
| 136 | + | |
135 | 137 | | |
136 | 138 | | |
137 | 139 | | |
138 | 140 | | |
139 | | - | |
| 141 | + | |
140 | 142 | | |
141 | 143 | | |
142 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
126 | 129 | | |
127 | 130 | | |
128 | 131 | | |
129 | 132 | | |
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
133 | | - | |
| 136 | + | |
134 | 137 | | |
135 | | - | |
| 138 | + | |
136 | 139 | | |
137 | 140 | | |
138 | 141 | | |
139 | | - | |
| 142 | + | |
140 | 143 | | |
141 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
142 | 147 | | |
143 | 148 | | |
| 149 | + | |
| 150 | + | |
144 | 151 | | |
145 | 152 | | |
146 | | - | |
147 | 153 | | |
148 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
149 | 174 | | |
150 | 175 | | |
151 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
0 commit comments