Class HybridQuery
Ported from Python: redisvl/query/hybrid.py (HybridQuery class)
This query uses the native FT.HYBRID command available in Redis 8.4+ which provides built-in score fusion via RRF (Reciprocal Rank Fusion) or LINEAR combination methods. This is the recommended approach for hybrid search on Redis 8.4+.
For older Redis versions (7.4+) that use FT.AGGREGATE with manual score fusion, see AggregateHybridQuery.
Alpha Semantics: In this class, linearAlpha represents the text
weight in the LINEAR combiner (matching the Python convention). This differs from AggregateHybridQuery where alpha represents the vector weight. The different parameter
names prevent confusion.
Python equivalent:
query = HybridQuery(
text="example text",
text_field_name="text_field",
vector=[0.1, 0.2, 0.3],
vector_field_name="vector_field",
text_scorer="BM25STD",
combination_method="RRF",
num_results=10,
)
results = index.query(query)
Java equivalent:
HybridQuery query = HybridQuery.builder()
.text("example text")
.textFieldName("text_field")
.vector(new float[]{0.1f, 0.2f, 0.3f})
.vectorFieldName("vector_field")
.textScorer("BM25STD")
.combinationMethod(CombinationMethod.RRF)
.numResults(10)
.build();
List<Map<String, Object>> results = index.query(query);
This class is final to prevent finalizer attacks, as it throws exceptions in constructors for input validation (SEI CERT OBJ11-J).
- Since:
- 0.2.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumScore combination method for FT.HYBRID COMBINE clause.static classBuilder for creating HybridQuery instances with fluent API.static enumVector search method for FT.HYBRID VSIM clause. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()redis.clients.jedis.search.hybrid.FTHybridParamsBuild theFTHybridParamsfor the native FT.HYBRID command.Build the query string for the SEARCH clause.getDtype()intfloatintGet the parameters map for the query (vector parameter).floatintintgetText()float[]loadDefaultStopwords(String language) Convert this HybridQuery to an AggregateHybridQuery for fallback when FT.HYBRID is not available.
-
Method Details
-
builder
-
loadDefaultStopwords
-
getText
-
getTextFieldName
-
getVector
public float[] getVector() -
getVectorFieldName
-
getVectorParamName
-
getTextScorer
-
getYieldTextScoreAs
-
getVectorSearchMethod
-
getKnnEfRuntime
public int getKnnEfRuntime() -
getRangeRadius
-
getRangeEpsilon
public float getRangeEpsilon() -
getYieldVsimScoreAs
-
getFilterExpression
-
getCombinationMethod
-
getRrfWindow
public int getRrfWindow() -
getRrfConstant
public int getRrfConstant() -
getLinearAlpha
public float getLinearAlpha() -
getYieldCombinedScoreAs
-
getDtype
-
getNumResults
public int getNumResults() -
getReturnFields
-
getStopwords
-
buildQueryString
Build the query string for the SEARCH clause.Tokenizes the text, removes stopwords, escapes special characters, and adds optional filter expression.
- Returns:
- the query string for FT.HYBRID SEARCH clause
-
buildFTHybridParams
public redis.clients.jedis.search.hybrid.FTHybridParams buildFTHybridParams()Build theFTHybridParamsfor the native FT.HYBRID command.- Returns:
- the configured FTHybridParams
-
toAggregateHybridQuery
Convert this HybridQuery to an AggregateHybridQuery for fallback when FT.HYBRID is not available.Maps the LINEAR alpha semantics: HybridQuery's linearAlpha (text weight) maps to AggregateHybridQuery's alpha as (1 - linearAlpha) since AggregateHybridQuery's alpha is the vector weight.
- Returns:
- an AggregateHybridQuery with equivalent parameters
-
getParams
Get the parameters map for the query (vector parameter).- Returns:
- parameter map with vector bytes
-