Skip to content

Python: [Bug]: RedisContextProvider stores embeddings with the wrong vector data type #8624

Closed

Description

@Shy7777

Description

RedisContextProvider uses redis_vectorizer.dtype for its index schema and hybrid-search query, but _add() always converts stored embeddings to np.float32. A vectorizer configured with float16 or float64 therefore writes a buffer that does not match its declared Redis vector field. This affects memory stored through the public after_run() hook.

Steps to reproduce

The example captures the exact payload passed to RedisVL without requiring an embedding API or a Redis server:

import asyncio
from unittest.mock import AsyncMock, MagicMock

import numpy as np
from agent_framework import AgentSession, Message, SessionContext
from agent_framework_redis import RedisContextProvider
from redisvl.utils.vectorize import BaseVectorizer


async def main():
    for dtype in ("float16", "float32", "float64"):
        vectorizer = MagicMock(spec=BaseVectorizer)
        vectorizer.dims = 2
        vectorizer.dtype = dtype
        vectorizer.aembed_many = AsyncMock(return_value=[[1.0, 2.0]])
        index = AsyncMock()
        index.exists.return_value = False
        provider = RedisContextProvider(
            user_id="user-1",
            redis_vectorizer=vectorizer,
            vector_field_name="embedding",
            redis_index=index,
        )
        session = AgentSession(session_id="session-1")
        context = SessionContext(
            session_id=session.session_id,
            input_messages=[Message(role="user", contents=["I prefer tea"])],
        )
        await provider.after_run(agent=MagicMock(), session=session, context=context, state={})
        blob = index.load.await_args.args[0][0]["embedding"]
        print(dtype, len(blob), np.frombuffer(blob, dtype=dtype).tolist())


asyncio.run(main())

Expected behavior

Two-dimensional vectors should occupy 4 bytes for float16, 8 for float32, and 16 for float64, decoding to [1.0, 2.0] in the declared data type.

Actual behavior

All three cases produce 8-byte float32 buffers:

float16 8 [0.0, 1.875, 0.0, 2.0]
float32 8 [1.0, 2.0]
float64 8 [2.000000473111868]

Environment

  • Agent Framework main at a8acb4e0e9d7e4712b01b9c888cf943a2dfbee91
  • Python 3.12.14, macOS arm64
  • redisvl 0.15.0, redis 7.1.1, NumPy 2.5.1
  • Reproduced at the RedisVL payload boundary with a mocked index; no live Redis service was used.

Proposed fix

I will work on a focused fix that uses RedisVL's array_to_buffer with the configured vectorizer data type, plus a regression test through after_run() that checks the stored bytes and decoded values. This keeps writes consistent with the existing schema and query settings, including RedisVL-supported bfloat16, without changing the public API.

I searched existing issues and PRs for RedisContextProvider with dtype/float32, and for redis float64. The related #3880 and #3954 concern the older hybrid-query constructor and do not address stored embedding encoding.

Activity

  1. added
    python
    triage
    on Sep 22, 2026
  2. added
    reproduced
    on Sep 22, 2026
  3. github-actions commented on Sep 22, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    The bug occurs in python/packages/redis/agent_framework_redis/_context_provider.py::RedisContextProvider._add at line 344 when a vectorizer configured with a dtype other than float32 supplies embeddings. The public after_run() path reaches this conversion and passes an eight-byte float32 buffer to redis_index.load() despite the configured schema dtype. Minimal repro: mock a two-dimensional vectorizer for float16 or float64, invoke after_run() with one message, and compare the loaded embedding buffer length against the configured dtype.

    • Failing test: python/packages/redis/tests/test_context_provider_edges.py
    • Files examined: python/AGENTS.md, python/packages/redis/AGENTS.md, python/packages/redis/agent_framework_redis/_context_provider.py, python/packages/redis/tests/test_providers.py, python/packages/redis/tests/test_context_provider_edges.py, python/packages/redis/pyproject.toml
    • Tests run: test_add_vectorizes_documents_and_aplies_defaults (passed), test_after_run_stores_embeddings_using_vectorizer_dtype (float16 and float64 failed; float32 passed), test_context_provider_edges.py (2 failures)
    • Current version: 1.0.0b260918
  4. added
    memory
    and removed
    triage
    on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

memorypythonreproduced

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions