Skip to main content

SparseVectorQuery

Struct SparseVectorQuery 

Source
pub struct SparseVectorQuery {
    pub field: Field,
    pub vector: Vec<(u32, f32)>,
    pub combiner: MultiValueCombiner,
}
Expand description

Sparse vector query for similarity search

Fields§

§field: Field

Field containing the sparse vectors

§vector: Vec<(u32, f32)>

Query vector as (dimension_id, weight) pairs

§combiner: MultiValueCombiner

How to combine scores for multi-valued documents

Implementations§

Source§

impl SparseVectorQuery

Source

pub fn new(field: Field, vector: Vec<(u32, f32)>) -> Self

Create a new sparse vector query

Source

pub fn with_combiner(self, combiner: MultiValueCombiner) -> Self

Set the multi-value score combiner

Source

pub fn from_indices_weights( field: Field, indices: Vec<u32>, weights: Vec<f32>, ) -> Self

Create from separate indices and weights vectors

Source

pub fn from_text( field: Field, text: &str, tokenizer_name: &str, weighting: QueryWeighting, sparse_index: Option<&SparseIndex>, ) -> Result<Self>

Create from raw text using a HuggingFace tokenizer (single segment)

This method tokenizes the text and creates a sparse vector query. For multi-segment indexes, use from_text_with_stats instead.

§Arguments
  • field - The sparse vector field to search
  • text - Raw text to tokenize
  • tokenizer_name - HuggingFace tokenizer path (e.g., “bert-base-uncased”)
  • weighting - Weighting strategy for tokens
  • sparse_index - Optional sparse index for IDF lookup (required for IDF weighting)
Source

pub fn from_text_with_stats( field: Field, text: &str, tokenizer: &HfTokenizer, weighting: QueryWeighting, global_stats: Option<&GlobalStats>, ) -> Result<Self>

Create from raw text using global statistics (multi-segment)

This is the recommended method for multi-segment indexes as it uses aggregated IDF values across all segments for consistent ranking.

§Arguments
  • field - The sparse vector field to search
  • text - Raw text to tokenize
  • tokenizer - Pre-loaded HuggingFace tokenizer
  • weighting - Weighting strategy for tokens
  • global_stats - Global statistics for IDF computation
Source

pub fn from_text_with_tokenizer_bytes( field: Field, text: &str, tokenizer_bytes: &[u8], weighting: QueryWeighting, global_stats: Option<&GlobalStats>, ) -> Result<Self>

Create from raw text, loading tokenizer from index directory

This method supports the index:// prefix for tokenizer paths, loading tokenizer.json from the index directory.

§Arguments
  • field - The sparse vector field to search
  • text - Raw text to tokenize
  • tokenizer_bytes - Tokenizer JSON bytes (pre-loaded from directory)
  • weighting - Weighting strategy for tokens
  • global_stats - Global statistics for IDF computation

Trait Implementations§

Source§

impl Clone for SparseVectorQuery

Source§

fn clone(&self) -> SparseVectorQuery

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 Debug for SparseVectorQuery

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Query for SparseVectorQuery

Source§

fn scorer<'a>( &self, reader: &'a SegmentReader, limit: usize, ) -> ScorerFuture<'a>

Create a scorer for this query against a single segment (async) Read more
Source§

fn count_estimate<'a>(&self, _reader: &'a SegmentReader) -> CountFuture<'a>

Estimated number of matching documents in a segment (async)
Source§

fn as_term_query_info(&self) -> Option<TermQueryInfo>

Return term info if this is a simple term query eligible for WAND optimization Read more

Auto Trait Implementations§

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, 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<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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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