HASH-backed `SearchIndex.fetch()` raises `UnicodeDecodeError` with `decode_responses=True`

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

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

@mohsinaliwork686-rgb がすでに取り組んでいます。

2026年12月2日 から。

  • #879 @guangyuli2026 による — マージされずにクローズ
  • #893 @mohsinaliwork686-rgb による — オープン

評価

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

調査の方向性

Start in the HASH storage read paths, HashStorage._get() and its async counterpart, which call hgetall; compare the search paths in redisvl/index/index.py and redisvl/redis/utils.py for NEVER_DECODE handling. Add sync and async regression coverage for both decode_responses settings, verifying the text and original embedding bytes, then run the relevant tests.

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

説明

Summary

SearchIndex.fetch() raises UnicodeDecodeError when fetching an existing HASH record containing a binary embedding through a Redis client configured with decode_responses=True.

Loading the record succeeds. Fetching it with decode_responses=False also succeeds.

Verified with Python 3.13.14, RedisVL 0.33.0, redis-py 8.1.0, and Redis 8.4.8 using Docker.

Related: [redis/redis-vl-python#844](https://github.com/redis/redis-vl-python/pull/844) also edits HashStorage.get()/aget() to handle missing records.

Cause

HashStorage._get() calls client.hgetall(key). With decode_responses=True, redis-py attempts to decode every HASH value, including the binary embedding. Embedding bytes that are invalid UTF-8 cause the read to fail before RedisVL receives the record.

The async path through aget()/_aget() makes the same hgetall call. That path has not been tested in this reproduction.

Reproduction

Requires Redis with Search support. REDIS_URL defaults to redis://localhost:6379.

import os
from uuid import uuid4

from redis import Redis
from redisvl.index import SearchIndex
from redisvl.redis.utils import array_to_buffer

for decode in (False, True):
    client = Redis.from_url(
        os.getenv("REDIS_URL", "redis://localhost:6379"),
        decode_responses=decode,
    )
    name = f"fetch_decode_{uuid4().hex}"
    index = SearchIndex.from_dict(
        {
            "index": {
                "name": name,
                "prefix": name,
                "storage_type": "hash",
            },
            "fields": [
                {"name": "text", "type": "text"},
                {
                    "name": "embedding",
                    "type": "vector",
                    "attrs": {
                        "algorithm": "flat",
                        "dims": 4,
                        "datatype": "float32",
                        "distance_metric": "cosine",
                    },
                },
            ],
        },
        redis_client=client,
    )
    index.create()
    try:
        index.load(
            [{
                "text": "hello",
                "embedding": array_to_buffer([0.1] * 4, "float32"),
            }],
            keys=[index.key("doc")],
        )
        try:
            record = index.fetch("doc")
            print(
                f"decode_responses={decode}: {record['text']!r}, "
                f"embedding type={type(record['embedding']).__name__}"
            )
        except UnicodeDecodeError as exc:
            print(
                f"decode_responses={decode}: "
                f"{type(exc).__name__}: {exc}"
            )
    finally:
        index.delete(drop=True)
        client.close()
Current behaviour

Fetching succeeds with decode_responses=False and raises with decode_responses=True.

decode_responses=False: 'hello', embedding type=bytes
decode_responses=True: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcd in position 0: invalid continuation byte
Expected behaviour

Both fetches should succeed and return the stored record. In each case, record["text"] should equal "hello" and record["embedding"] should contain the exact bytes originally written.

The reproduction should print the following output.

decode_responses=False: 'hello', embedding type=bytes
decode_responses=True: 'hello', embedding type=bytes

Suggested fix

Read the HASH reply with redis-py’s NEVER_DECODE option, following the search paths in redisvl/index/index.py and redisvl/redis/utils.py, then decode the non-vector fields while preserving vector fields as bytes.

NEVER_DECODE applies to the entire reply. Keep these reads in the existing non-transactional pipelines, since the option is ignored inside MULTI/EXEC.

Apply the handling to both synchronous and asynchronous HASH reads. Add regression coverage for decode_responses=True and False, asserting that fetching succeeds and the original embedding bytes are preserved.

主要言語
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 を短くまとめたダイジェスト。