mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Fixed Redis context provider and samples (#4030)
* Removed session_id filtering in Mem0 implementation * Fixed redis samples * Resolved comments
This commit is contained in:
committed by
GitHub
Unverified
parent
f087b864fb
commit
b0fd4946e6
@@ -129,7 +129,7 @@ class RedisContextProvider(BaseContextProvider):
|
||||
if not input_text.strip():
|
||||
return
|
||||
|
||||
memories = await self._redis_search(text=input_text, session_id=context.session_id)
|
||||
memories = await self._redis_search(text=input_text)
|
||||
line_separated_memories = "\n".join(
|
||||
str(memory.get("content", "")) for memory in memories if memory.get("content")
|
||||
)
|
||||
@@ -337,7 +337,7 @@ class RedisContextProvider(BaseContextProvider):
|
||||
filter_expression: Any | None = None,
|
||||
return_fields: list[str] | None = None,
|
||||
num_results: int = 10,
|
||||
alpha: float = 0.7,
|
||||
linear_alpha: float = 0.7,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Runs a text or hybrid vector-text search with optional filters."""
|
||||
await self._ensure_index()
|
||||
@@ -374,7 +374,7 @@ class RedisContextProvider(BaseContextProvider):
|
||||
vector_field_name=self.vector_field_name,
|
||||
text_scorer=text_scorer,
|
||||
filter_expression=combined_filter,
|
||||
alpha=alpha,
|
||||
linear_alpha=linear_alpha,
|
||||
dtype=self.redis_vectorizer.dtype,
|
||||
num_results=num_results,
|
||||
return_fields=return_fields,
|
||||
|
||||
@@ -170,6 +170,26 @@ class TestRedisContextProviderBeforeRun:
|
||||
mock_index.query.assert_not_called()
|
||||
assert "ctx" not in ctx.context_messages
|
||||
|
||||
async def test_before_run_searches_without_session_id(
|
||||
self,
|
||||
mock_index: AsyncMock,
|
||||
patch_index_from_dict: MagicMock, # noqa: ARG002
|
||||
):
|
||||
"""Verify that before_run performs cross-session retrieval (no session_id filter)."""
|
||||
mock_index.query = AsyncMock(return_value=[{"content": "Memory"}])
|
||||
provider = RedisContextProvider(source_id="ctx", user_id="u1")
|
||||
session = AgentSession(session_id="test-session")
|
||||
ctx = SessionContext(input_messages=[Message(role="user", contents=["test query"])], session_id="s1")
|
||||
|
||||
with patch.object(provider, "_redis_search", wraps=provider._redis_search) as spy:
|
||||
await provider.before_run(
|
||||
agent=None, session=session, context=ctx, state=session.state.setdefault(provider.source_id, {})
|
||||
) # type: ignore[arg-type]
|
||||
|
||||
spy.assert_called_once()
|
||||
# session_id should not be passed to _redis_search (cross-session retrieval)
|
||||
assert "session_id" not in spy.call_args.kwargs
|
||||
|
||||
async def test_empty_results_no_messages(
|
||||
self,
|
||||
mock_index: AsyncMock,
|
||||
|
||||
Reference in New Issue
Block a user