Repository navigation
Description
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
mainata8acb4e0e9d7e4712b01b9c888cf943a2dfbee91 - 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.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Sep 22, 2026
🤖 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._addat line 344 when a vectorizer configured with a dtype other than float32 supplies embeddings. The publicafter_run()path reaches this conversion and passes an eight-byte float32 buffer toredis_index.load()despite the configured schema dtype. Minimal repro: mock a two-dimensional vectorizer for float16 or float64, invokeafter_run()with one message, and compare the loaded embedding buffer length against the configured dtype.python/packages/redis/tests/test_context_provider_edges.py1.0.0b260918