Searches that return binary fields fail with RESP3 and decode_responses=True (batch_query, and every search on a cluster)

オープン
#880 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

@pcbeingused33 がすでに取り組んでいます。

2026年12月2日 から。

  • #891 @pcbeingused33 による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python, redis
領域
backend, databases

調査の方向性

Read the four FT.SEARCH call sites named in redisvl/index/index.py and redisvl/redis/utils.py, then compare their argument handling with redis-py's search() implementation. Check the open pull request #891 and issue #877 for ongoing work. Done means batch queries and cluster searches return binary vector fields with RESP3 and decode_responses=True, while RESP2 behavior remains covered by tests.

索引モデルが issue の本文から書いたものです。

説明

Python version

3.13.9

Package versions
  • redisvl on main (92e93d20)
  • redis 8.1.0
Steps to reproduce
  1. Create a client with protocol=3, decode_responses=True.
  2. Build a HASH index with a vector field and load one document.
  3. Run batch_query with a query that returns the vector field. On a Redis Cluster, query is enough.
Expected behavior

batch_query returns the same documents as query does on a single node, and both work on a cluster.

Actual behavior

The search fails while decoding the vector bytes:

Client Single node 3-primary Redis Cluster
query works RedisSearchError: Unexpected error while searching: 'utf-8' codec can't decode byte 0xcd ...
batch_query UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcd in position 0: invalid continuation byte same UnicodeDecodeError

Each cell is the same for SearchIndex and AsyncSearchIndex, and with or without hiredis installed. With protocol=2, decode_responses=True, or with protocol=3 and no decode_responses, every case works.

Four places send FT.SEARCH themselves and set NEVER_DECODE only when the protocol isn't 3:

  • SearchIndex.batch_search (redisvl/index/index.py:2094)
  • AsyncSearchIndex.batch_search (redisvl/index/index.py:3444)
  • cluster_search (redisvl/redis/utils.py:440)
  • async_cluster_search (redisvl/redis/utils.py:465)

That matches what redis-py 7.x did. redis-py 8.1 sets NEVER_DECODE on every protocol in its own search() (redis/commands/search/commands.py:1338 and :1877), because a search reply can contain binary values such as vectors, and its RESP3 parser decodes text fields itself. So without NEVER_DECODE, the client tries to decode the vector bytes as UTF-8 and fails. On a single node, query() doesn't hit this because it calls redis-py's search(); on a cluster it goes through cluster_search or async_cluster_search instead.

Environment

macOS, Redis 8.2 in Docker: a single node, and a 3-primary Redis Cluster with no replicas.

Code sample
import time

import numpy as np
import redis

from redisvl.index import SearchIndex
from redisvl.query import VectorQuery

schema = {
    "index": {"name": "resp3_decode", "prefix": "resp3_decode", "storage_type": "hash"},
    "fields": [
        {"name": "name", "type": "tag"},
        {
            "name": "embedding",
            "type": "vector",
            "attrs": {
                "dims": 4,
                "distance_metric": "cosine",
                "algorithm": "flat",
                "datatype": "float32",
            },
        },
    ],
}

# For the cluster case, use redis.cluster.RedisCluster.from_url(...) here.
client = redis.Redis.from_url(
    "redis://localhost:6379", protocol=3, decode_responses=True
)
index = SearchIndex.from_dict(schema, redis_client=client)
index.create(overwrite=True, drop=True)
index.load(
    [{"name": "a", "embedding": np.array([-0.1, 0.2, 0.3, 0.4], dtype=np.float32).tobytes()}]
)
time.sleep(0.5)

query = VectorQuery(
    vector=[0.1, 0.2, 0.3, 0.4],
    vector_field_name="embedding",
    return_fields=["name", "embedding"],
)
print(index.query(query))  # works on a single node, fails on a cluster
print(index.batch_query([query]))  # UnicodeDecodeError
Suggested fix

Set NEVER_DECODE the way the installed redis-py does, in one shared helper used by all four places, and add a test that runs batch_query with this client configuration on RESP2 and RESP3. #877 adds a fifth copy of the same condition in AsyncSearchIndex.search; the review there suggests calling redis-py's search() instead.

主要言語
Python
スター
435
フォーク
123
平均マージ
8日 1時間
マージ済み PR(30日)
39

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

redis/redis-vl-python のほかの issue

redis/redis-vl-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。