Skip to content

Conversation

@vishal-bala
Copy link
Collaborator

This PR adds an interface for using the new FT.HYBRID search operation introduced in Redis Open Source 8.4.0.

Changes

redisvl.query.hybrid

This new module defines query constructors for working with the new hybrid search operation. Attempting to import this module without having redis-py>=7.1.0 will raise an ImportError. It defines a HybridQuery object which can be used to define a hybrid search operation in a format largely similar to what AggregateHybridSearch provides.

Under the hood, redis-py expects three separate configuration objects to run hybrid search - one for the text+vector searches, one for the score combination, and one for post-processing of the results (e.g. aggregations, loading, limiting, etc.). The HybridSearch class manages the definition of all three.

# old
from redisvl.query.aggregate import AggregateHybridQuery

query = AggregateHybridQuery(
    text="medical professional",
    text_field_name="description",
    vector=[0.1, 0.1, 0.5, ...],
    vector_field_name="user_embedding",
    alpha=0.7,  # LINEAR only
    return_fields=["user", "job"]
)

results = index.query(query)

# new
from redisvl.query.hybrid import HybridQuery

query = HybridQuery(
    text="medical professional",
    text_field_name="description",
    vector=[0.1, 0.1, 0.5, ...],
    vector_field_name="user_embedding",
    combination_method="LINEAR",
    linear_alpha=0.7,
    return_fields=["user", "job"]
)

results = index.hybrid_search(query)
results = await async_index.hybrid_search(query)

SearchIndex method

For redis-py>=7.1.0, the SearchIndex and AsyncSearchIndex classes define a hybrid_search method that takes a HybridQuery instance as an argument. For redis-py<7.1.0 the method is not defined. The method returns a list of retrieved dictionaries.

Additional Changes

  • Fixed a typo in a test for AggregateHybridQuery
  • redis-py 7.0.0 introduced a change to the type of Query._fields, changing it from a tuple to a list - a test had to be updated to differentiate the expectation based on the redis-py version.

@vishal-bala vishal-bala self-assigned this Dec 5, 2025
Copy link
Collaborator

@nkanu17 nkanu17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have forgotten to export HybridQuery from redisvl.query.hybrid in the redisvl.query __init__.py

from redisvl.query.hybrid import HybridQuery  # this works
from redisvl.query import HybridQuery  # this will fail

Basically because there are now two different HybridQuery classes

  • redisvl.query.aggregate.HybridQuery (old wrapper around AggregateHybridQuery)
  • redisvl.query.hybrid.HybridQuery (new one)

This might cause some confusion and we might have to either choose a different name or find a better solution and deprecate the older one. Might change the name of the older class

Copy link
Collaborator

@nkanu17 nkanu17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall!
Just need to verify how we need to handle the deprecated HybridQuery class
Don't forget to update the api/sphinx documentation and add a guide in ai-resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants