pub struct MultiVectorRetriever<E: MultiVectorEmbedder> { /* private fields */ }Expand description
Multi-vector retriever using WARP index for ColBERT-style late interaction.
This retriever uses token-level embeddings and MaxSim scoring for fine-grained semantic matching. Unlike single-vector dense retrieval, multi-vector approaches represent documents and queries as multiple token embeddings.
§Example
use trueno_rag::multivector::{
WarpIndexConfig, WarpSearchConfig,
MockMultiVectorEmbedder, MultiVectorRetriever,
};
let config = WarpIndexConfig::new(2, 256, 128);
let embedder = MockMultiVectorEmbedder::new(128, 512);
let mut retriever = MultiVectorRetriever::new(config, embedder);
// Train on sample documents
retriever.train(&sample_chunks)?;
// Index documents
for chunk in chunks {
retriever.index(chunk)?;
}
retriever.build()?;
// Search
let results = retriever.retrieve("What is machine learning?", 10)?;Implementations§
Source§impl<E: MultiVectorEmbedder> MultiVectorRetriever<E>
impl<E: MultiVectorEmbedder> MultiVectorRetriever<E>
Sourcepub fn new(config: WarpIndexConfig, embedder: E) -> Self
pub fn new(config: WarpIndexConfig, embedder: E) -> Self
Create a new multi-vector retriever with the given configuration and embedder.
§Arguments
config- WARP index configuration (nbits, num_centroids, token_dim)embedder- Multi-vector embedder for generating token embeddings
Sourcepub fn with_search_config(self, config: WarpSearchConfig) -> Self
pub fn with_search_config(self, config: WarpSearchConfig) -> Self
Set the search configuration.
Sourcepub fn train(&mut self, sample_chunks: &[Chunk]) -> Result<()>
pub fn train(&mut self, sample_chunks: &[Chunk]) -> Result<()>
Train the WARP index on sample chunks.
This builds the residual quantization codec by learning centroids from the provided sample embeddings. Should be called before indexing.
§Arguments
sample_chunks- Representative chunks for training the codec
Sourcepub fn index(&mut self, chunk: Chunk) -> Result<()>
pub fn index(&mut self, chunk: Chunk) -> Result<()>
Index a single chunk.
The chunk is embedded and compressed using the trained codec.
Call train() before indexing.
Sourcepub fn build(&mut self) -> Result<()>
pub fn build(&mut self) -> Result<()>
Build the index for efficient search.
This compacts the index by organizing embeddings by centroid (IVF structure). Call after all chunks have been indexed.
Sourcepub fn retrieve(&self, query: &str, k: usize) -> Result<Vec<RetrievalResult>>
pub fn retrieve(&self, query: &str, k: usize) -> Result<Vec<RetrievalResult>>
Retrieve relevant chunks for a query using multi-vector MaxSim scoring.
§Arguments
query- Query textk- Number of results to return
Sourcepub fn warp_index(&self) -> &WarpIndex
pub fn warp_index(&self) -> &WarpIndex
Get the underlying WARP index.
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Get memory usage statistics.
Auto Trait Implementations§
impl<E> Freeze for MultiVectorRetriever<E>where
E: Freeze,
impl<E> RefUnwindSafe for MultiVectorRetriever<E>where
E: RefUnwindSafe,
impl<E> Send for MultiVectorRetriever<E>
impl<E> Sync for MultiVectorRetriever<E>
impl<E> Unpin for MultiVectorRetriever<E>where
E: Unpin,
impl<E> UnsafeUnpin for MultiVectorRetriever<E>where
E: UnsafeUnpin,
impl<E> UnwindSafe for MultiVectorRetriever<E>where
E: UnwindSafe,
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> 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