Skip to main content

HybridQuery

Struct HybridQuery 

Source
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>

Source

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.

Source

pub fn with_num_results(self, num_results: usize) -> Self

Sets the number of results to return.

Source

pub fn with_text_scorer(self, scorer: impl Into<String>) -> Self

Sets the text scorer algorithm (e.g. "BM25STD", "TFIDF", "TFIDF.DOCNORM").

Source

pub fn with_yield_text_score_as(self, alias: impl Into<String>) -> Self

Sets the alias for the text search score in results.

Source

pub fn with_knn(self, ef_runtime: Option<usize>) -> Self

Sets the vector search method to KNN with optional EF runtime.

Source

pub fn with_range(self, radius: f32, epsilon: Option<f32>) -> Self

Sets the vector search method to RANGE.

Source

pub fn with_yield_vsim_score_as(self, alias: impl Into<String>) -> Self

Sets the alias for the vector similarity score in results.

Source

pub fn with_filter(self, filter_expression: FilterExpression) -> Self

Attaches a filter expression.

Source

pub fn with_combination_method(self, method: HybridCombinationMethod) -> Self

Selects the hybrid combination method.

Source

pub fn with_rrf(self, window: Option<usize>, constant: Option<usize>) -> Self

Sets RRF parameters.

Source

pub fn with_linear(self, alpha: f32) -> Self

Sets LINEAR combination with an alpha weight for the text score.

Source

pub fn with_yield_combined_score_as(self, alias: impl Into<String>) -> Self

Sets the alias for the combined score in results.

Source

pub fn with_return_fields<I, S>(self, return_fields: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Replaces the return field list.

Source

pub fn with_stopwords(self, stopwords: HashSet<String>) -> Self

Sets stopwords to filter from the query text.

Source

pub fn with_text_weights(self, weights: HashMap<String, f32>) -> Self

Sets word weights for the text search.

Source

pub fn with_vector_param_name(self, name: impl Into<String>) -> Self

Sets the parameter name used for the vector blob.

Source

pub fn vector(&self) -> &Vector<'a>

Returns the encoded query vector.

Source

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>

Source§

fn clone(&self) -> HybridQuery<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for HybridQuery<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more