Python: Fix RedisContextProvider for redisvl 0.14.0 by using AggregateHybridQuery (#3954)

* Initial plan

* Fix: Replace alpha with linear_alpha in HybridQuery for redisvl 0.14.0 compatibility

Co-authored-by: markwallace-microsoft <127216156+markwallace-microsoft@users.noreply.github.com>

* Address code review: Improve test readability and add explanatory comment

Co-authored-by: markwallace-microsoft <127216156+markwallace-microsoft@users.noreply.github.com>

* Add CHANGELOG entry for redisvl 0.14.0 compatibility fix

Co-authored-by: eavanvalkenburg <13749212+eavanvalkenburg@users.noreply.github.com>

* Use AggregateHybridQuery instead of HybridQuery for backward compatibility

Replace HybridQuery with AggregateHybridQuery to preserve existing functionality that works with older Redis versions. The new HybridQuery in redisvl 0.14.0 requires Redis 8.4.0+ and uses a different API, while AggregateHybridQuery maintains compatibility with the original implementation.

Co-authored-by: TaoChenOSU <12570346+TaoChenOSU@users.noreply.github.com>

* Fix test to use linear_alpha parameter matching _redis_search implementation

The test was passing alpha as a keyword argument to _redis_search(), but the
method uses linear_alpha to match the redisvl 0.14.0 AggregateHybridQuery API.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix pyright error: use alpha parameter matching AggregateHybridQuery API

AggregateHybridQuery expects 'alpha', not 'linear_alpha'. Updated the
_redis_search method parameter and the test accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: markwallace-microsoft <127216156+markwallace-microsoft@users.noreply.github.com>
Co-authored-by: eavanvalkenburg <13749212+eavanvalkenburg@users.noreply.github.com>
Co-authored-by: TaoChenOSU <12570346+TaoChenOSU@users.noreply.github.com>
Co-authored-by: Ben Thomas <ben.thomas@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Copilot
2026-03-05 17:34:35 -08:00
committed by GitHub
Unverified
parent 8664d19285
commit 1ac68f65bf
3 changed files with 46 additions and 4 deletions
+4
View File
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- **agent-framework-redis**: Fix `RedisContextProvider` compatibility with redisvl 0.14.0 by using `AggregateHybridQuery` ([#3954](https://github.com/microsoft/agent-framework/pull/3954))
## [1.0.0rc3] - 2026-03-04
### Added
@@ -22,7 +22,7 @@ from agent_framework.exceptions import (
IntegrationInvalidRequestException,
)
from redisvl.index import AsyncSearchIndex
from redisvl.query import HybridQuery, TextQuery
from redisvl.query import AggregateHybridQuery, TextQuery
from redisvl.query.filter import FilterExpression, Tag
from redisvl.utils.token_escaper import TokenEscaper
from redisvl.utils.vectorize import BaseVectorizer
@@ -341,7 +341,7 @@ class RedisContextProvider(BaseContextProvider):
filter_expression: Any | None = None,
return_fields: list[str] | None = None,
num_results: int = 10,
linear_alpha: float = 0.7,
alpha: float = 0.7,
) -> list[dict[str, Any]]:
"""Runs a text or hybrid vector-text search with optional filters."""
await self._ensure_index()
@@ -371,14 +371,14 @@ class RedisContextProvider(BaseContextProvider):
try:
if self.redis_vectorizer and self.vector_field_name:
vector = await self.redis_vectorizer.aembed(q) # pyright: ignore[reportUnknownMemberType]
query = HybridQuery(
query = AggregateHybridQuery(
text=q,
text_field_name="content",
vector=vector,
vector_field_name=self.vector_field_name,
text_scorer=text_scorer,
filter_expression=combined_filter,
linear_alpha=linear_alpha,
alpha=alpha,
dtype=self.redis_vectorizer.dtype, # pyright: ignore[reportUnknownMemberType]
num_results=num_results,
return_fields=return_fields,
@@ -271,6 +271,44 @@ class TestRedisContextProviderContextManager:
assert p is provider
class TestRedisContextProviderHybridQuery:
"""Test for AggregateHybridQuery parameter compatibility with redisvl 0.14.0."""
async def test_aggregate_hybrid_query_uses_alpha(
self,
mock_index: AsyncMock,
patch_index_from_dict: MagicMock, # noqa: ARG002 - fixture modifies behavior via side effects
):
"""Ensure AggregateHybridQuery is called with alpha parameter."""
from redisvl.utils.vectorize import BaseVectorizer
# Create a mock vectorizer that inherits from BaseVectorizer
mock_vectorizer = MagicMock(spec=BaseVectorizer)
mock_vectorizer.dims = 128
mock_vectorizer.dtype = "float32"
mock_vectorizer.aembed = AsyncMock(return_value=[0.1] * 128)
mock_index.query = AsyncMock(return_value=[{"content": "test result"}])
provider = RedisContextProvider(
source_id="ctx",
user_id="u1",
redis_vectorizer=mock_vectorizer,
vector_field_name="embedding",
)
# Call _redis_search with custom alpha
with patch("agent_framework_redis._context_provider.AggregateHybridQuery") as mock_hybrid_query:
mock_hybrid_query.return_value = MagicMock()
await provider._redis_search(text="test query", alpha=0.5)
# Verify AggregateHybridQuery was called with alpha parameter
mock_hybrid_query.assert_called_once()
call_kwargs = mock_hybrid_query.call_args.kwargs
assert "alpha" in call_kwargs
assert call_kwargs["alpha"] == 0.5
# ===========================================================================
# RedisHistoryProvider tests
# ===========================================================================