Repository navigation
Commit 6e5a4b7
Patrick Ribbsaeter
Python: fix(python/redis): restore vector search broken by redisvl>=0.5 API change and KeyError on include_vectors=False (#14278)
## Summary
Fixes #13896.
Vector search (`FT.SEARCH`) via the Python Redis connector was
completely broken due to two independent bugs. Both have been fixed in
this PR.
---
## Bug 1 — `process_results()` API break with redisvl >= 0.5
### Root cause
`redisvl` 0.5.0 changed the signature of `process_results()`:
```python
# redisvl < 0.5 (old API)
process_results(results, query, storage_type: StorageType)
# redisvl >= 0.5 (new API)
process_results(results, query, schema: IndexSchema)
```
The `pyproject.toml` pin `redisvl ~= 0.4` resolves to `>=0.4, <1.0`
under PEP 440, so `uv.lock` silently picks up redisvl 0.15.x where the
old API is gone. Every call to `collection.search()` raised:
```
VectorSearchExecutionException: An error occurred during the search:
'StorageType' object has no attribute 'index'
```
### Fix
Detect the redisvl API signature at runtime via `inspect.signature` by
introspecting the third parameter name:
- If `third_parameter == "storage_type"` (redisvl < 0.5), pass the
`StorageType` enum.
- If `third_parameter == "schema"` (redisvl >= 0.5), load the schema via
`AsyncSearchIndex.from_existing(name=collection_name,
redis_client=redis_database)` and pass `index.schema`.
- If an unsupported third parameter is encountered, raise
`VectorSearchExecutionException` rather than guessing.
```python
parameters = list(inspect.signature(process_results).parameters.values())
if len(parameters) < 3:
raise VectorSearchExecutionException("Unsupported redisvl process_results() signature.")
third_parameter = parameters[2].name
if third_parameter == "storage_type":
return process_results(results, query, STORAGE_TYPE_MAP[collection_type])
if third_parameter == "schema":
index = await AsyncSearchIndex.from_existing(
name=collection_name,
redis_client=redis_database,
)
return process_results(results, query, index.schema)
raise VectorSearchExecutionException(
f"Unsupported redisvl process_results() parameter: {third_parameter}."
)
```
---
## Bug 2 — `KeyError` in
`RedisHashsetCollection._deserialize_store_models_to_dicts`
### Root cause
The deserializer unconditionally decoded every vector field:
```python
case "vector":
dtype = DATATYPE_MAP_VECTOR[field.type_ or "default"]
rec[field.name] = buffer_to_array(rec[field.name], dtype) # KeyError!
```
When `include_vectors=False` (the SDK default for search), Redis does
not return vector fields in the result dict, so `rec[field.name]` raised
`KeyError: 'vector'`.
### Fix
Guard with an existence check before decoding:
```python
case "vector":
storage_name = field.storage_name or field.name
if storage_name in rec:
dtype = DATATYPE_MAP_VECTOR[field.type_ or "default"]
rec[field.name] = buffer_to_array(rec[storage_name], dtype)
else:
rec[field.name] = None # vector not requested — leave as None
```
---
## Impact
Both bugs affected **every** Python user using the Redis connector for
vector search:
- Bug 1 blocked all search calls unconditionally.
- Bug 2 blocked hashset search whenever `include_vectors=False` (the
default).
The connector was written against redisvl 0.4.x; the dependency pin
allows installation of redisvl 0.15.x where the API changed.
---
## Testing
- Unit tests in
`python/tests/unit/connectors/memory/test_redis_store.py`:
- `test_process_search_results_with_legacy_redisvl_api`: verifies legacy
`storage_type` parameter dispatch.
- `test_process_search_results_with_current_redisvl_api`: verifies
`AsyncSearchIndex.from_existing` and `schema` dispatch.
- `test_hash_deserialization_handles_omitted_vector`: verifies hashset
deserialization when `vector` is omitted.
- The fix is backward-compatible across supported redisvl versions
without requiring a version pin change.
- Existing upsert/get/delete integration tests are unaffected.
Signed-off-by: Patrick Ribbsaeter <[email protected]>1 parent 8aa1dc5 commit 6e5a4b7
2 files changed
Lines changed: 111 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
166 | 168 | | |
167 | 169 | | |
168 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
169 | 197 | | |
170 | 198 | | |
171 | 199 | | |
| |||
321 | 349 | | |
322 | 350 | | |
323 | 351 | | |
324 | | - | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
325 | 364 | | |
326 | 365 | | |
327 | 366 | | |
| |||
616 | 655 | | |
617 | 656 | | |
618 | 657 | | |
619 | | - | |
620 | | - | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
621 | 667 | | |
622 | 668 | | |
623 | 669 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
306 | 307 | | |
307 | 308 | | |
308 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
0 commit comments