pub struct HybridQuery<'a> { /* private fields */ }Expand description
Native Redis hybrid query dispatched via FT.HYBRID.
This query combines text search and vector similarity search with
configurable fusion methods. It requires Redis 8.4.0+ and produces
FT.HYBRID commands (not FT.SEARCH).
§Example
use redis_vl::query::{HybridQuery, HybridCombinationMethod, Vector};
let query = HybridQuery::new(
"a medical professional",
"description",
Vector::new(vec![0.1, 0.1, 0.5]),
"user_embedding",
)
.with_num_results(10)
.with_combination_method(HybridCombinationMethod::Rrf)
.with_yield_combined_score_as("hybrid_score")
.with_return_fields(["user", "age", "job"]);Implementations§
Source§impl<'a> HybridQuery<'a>
impl<'a> HybridQuery<'a>
Sourcepub fn new(
text: impl Into<String>,
text_field_name: impl Into<String>,
vector: Vector<'a>,
vector_field_name: impl Into<String>,
) -> Self
pub fn new( text: impl Into<String>, text_field_name: impl Into<String>, vector: Vector<'a>, vector_field_name: impl Into<String>, ) -> Self
Creates a hybrid query with the given text, text field, vector, and vector field.
Sourcepub fn with_num_results(self, num_results: usize) -> Self
pub fn with_num_results(self, num_results: usize) -> Self
Sets the number of results to return.
Sourcepub fn with_text_scorer(self, scorer: impl Into<String>) -> Self
pub fn with_text_scorer(self, scorer: impl Into<String>) -> Self
Sets the text scorer algorithm (e.g. "BM25STD", "TFIDF", "TFIDF.DOCNORM").
Sourcepub fn with_yield_text_score_as(self, alias: impl Into<String>) -> Self
pub fn with_yield_text_score_as(self, alias: impl Into<String>) -> Self
Sets the alias for the text search score in results.
Sourcepub fn with_knn(self, ef_runtime: Option<usize>) -> Self
pub fn with_knn(self, ef_runtime: Option<usize>) -> Self
Sets the vector search method to KNN with optional EF runtime.
Sourcepub fn with_range(self, radius: f32, epsilon: Option<f32>) -> Self
pub fn with_range(self, radius: f32, epsilon: Option<f32>) -> Self
Sets the vector search method to RANGE.
Sourcepub fn with_yield_vsim_score_as(self, alias: impl Into<String>) -> Self
pub fn with_yield_vsim_score_as(self, alias: impl Into<String>) -> Self
Sets the alias for the vector similarity score in results.
Sourcepub fn with_filter(self, filter_expression: FilterExpression) -> Self
pub fn with_filter(self, filter_expression: FilterExpression) -> Self
Attaches a filter expression.
Sourcepub fn with_combination_method(self, method: HybridCombinationMethod) -> Self
pub fn with_combination_method(self, method: HybridCombinationMethod) -> Self
Selects the hybrid combination method.
Sourcepub fn with_rrf(self, window: Option<usize>, constant: Option<usize>) -> Self
pub fn with_rrf(self, window: Option<usize>, constant: Option<usize>) -> Self
Sets RRF parameters.
Sourcepub fn with_linear(self, alpha: f32) -> Self
pub fn with_linear(self, alpha: f32) -> Self
Sets LINEAR combination with an alpha weight for the text score.
Sourcepub fn with_yield_combined_score_as(self, alias: impl Into<String>) -> Self
pub fn with_yield_combined_score_as(self, alias: impl Into<String>) -> Self
Sets the alias for the combined score in results.
Sourcepub fn with_return_fields<I, S>(self, return_fields: I) -> Self
pub fn with_return_fields<I, S>(self, return_fields: I) -> Self
Replaces the return field list.
Sourcepub fn with_stopwords(self, stopwords: HashSet<String>) -> Self
pub fn with_stopwords(self, stopwords: HashSet<String>) -> Self
Sets stopwords to filter from the query text.
Sourcepub fn with_text_weights(self, weights: HashMap<String, f32>) -> Self
pub fn with_text_weights(self, weights: HashMap<String, f32>) -> Self
Sets word weights for the text search.
Sourcepub fn with_vector_param_name(self, name: impl Into<String>) -> Self
pub fn with_vector_param_name(self, name: impl Into<String>) -> Self
Sets the parameter name used for the vector blob.
Sourcepub fn build_cmd(&self, index_name: &str) -> Cmd
pub fn build_cmd(&self, index_name: &str) -> Cmd
Builds an FT.HYBRID command for this query.
The command targets the given index_name and encodes all hybrid
query clauses (SEARCH, VSIM, COMBINE, LOAD, LIMIT).
The wire format follows the redis-py HybridQuery / HybridSearchQuery
/ HybridVsimQuery / CombineResultsMethod protocol:
FT.HYBRID index
SEARCH query_string [SCORER s] [YIELD_SCORE_AS a]
VSIM @vec_field $param [method count kv…] [FILTER f] [YIELD_SCORE_AS a]
[COMBINE method count kv…]
[LOAD count @field…]
[LIMIT offset num]
PARAMS count key value…Trait Implementations§
Source§impl<'a> Clone for HybridQuery<'a>
impl<'a> Clone for HybridQuery<'a>
Source§fn clone(&self) -> HybridQuery<'a>
fn clone(&self) -> HybridQuery<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<'a> Freeze for HybridQuery<'a>
impl<'a> RefUnwindSafe for HybridQuery<'a>
impl<'a> Send for HybridQuery<'a>
impl<'a> Sync for HybridQuery<'a>
impl<'a> Unpin for HybridQuery<'a>
impl<'a> UnsafeUnpin for HybridQuery<'a>
impl<'a> UnwindSafe for HybridQuery<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more