pub struct RetrievalEngine<B: Backend> { /* private fields */ }Expand description
Cross-modal retrieval engine.
Pre-computes embeddings for an indexed database of sensor recordings and/or text captions and enables fast nearest-neighbour search.
Implementations§
Source§impl<B: Backend> RetrievalEngine<B>
impl<B: Backend> RetrievalEngine<B>
Sourcepub fn new(model: SensorLMModel<B>) -> Self
pub fn new(model: SensorLMModel<B>) -> Self
Create a new retrieval engine.
Sourcepub fn index_sensor(
&mut self,
sensor_batches: impl IntoIterator<Item = Tensor<B, 3>>,
)
pub fn index_sensor( &mut self, sensor_batches: impl IntoIterator<Item = Tensor<B, 3>>, )
Pre-compute and store sensor embeddings from a batch of sensor data.
§Arguments
sensor_batches– Iterator of(B, T, C)sensor tensors.
Sourcepub fn index_text(
&mut self,
text_batches: impl IntoIterator<Item = (Tensor<B, 2, Int>, Tensor<B, 2, Int>)>,
)
pub fn index_text( &mut self, text_batches: impl IntoIterator<Item = (Tensor<B, 2, Int>, Tensor<B, 2, Int>)>, )
Pre-compute and store text embeddings from batches of token sequences.
Sourcepub fn sensor_to_text(
&self,
query_sensor: Tensor<B, 3>,
top_k: usize,
) -> Vec<Vec<RetrievalResult>>
pub fn sensor_to_text( &self, query_sensor: Tensor<B, 3>, top_k: usize, ) -> Vec<Vec<RetrievalResult>>
Retrieve the top-k most similar texts for each sensor query.
§Arguments
query_sensor–(Q, T, C)query sensor tensors.top_k– Number of results to return per query.
§Returns
A vector of Q lists, each containing top_k RetrievalResults
sorted by descending similarity.
§Panics
Panics if no text embeddings have been indexed.
Sourcepub fn text_to_sensor(
&self,
query_ids: Tensor<B, 2, Int>,
query_mask: Tensor<B, 2, Int>,
top_k: usize,
) -> Vec<Vec<RetrievalResult>>
pub fn text_to_sensor( &self, query_ids: Tensor<B, 2, Int>, query_mask: Tensor<B, 2, Int>, top_k: usize, ) -> Vec<Vec<RetrievalResult>>
Retrieve the top-k most similar sensor recordings for each text query.
§Panics
Panics if no sensor embeddings have been indexed.
Sourcepub fn evaluate_recall(
&self,
sensor: Tensor<B, 3>,
ids: Tensor<B, 2, Int>,
mask: Tensor<B, 2, Int>,
k: usize,
) -> (f32, f32)
pub fn evaluate_recall( &self, sensor: Tensor<B, 3>, ids: Tensor<B, 2, Int>, mask: Tensor<B, 2, Int>, k: usize, ) -> (f32, f32)
Evaluate Recall@k on a paired (sensor, text) evaluation set.
Assumes ground truth is the diagonal: sensor i corresponds to text i.
§Arguments
sensor–(N, T, C)evaluation sensor data.ids–(N, L)token IDs.mask–(N, L)attention mask.k– Recall@k.
Auto Trait Implementations§
impl<B> !Freeze for RetrievalEngine<B>
impl<B> !RefUnwindSafe for RetrievalEngine<B>
impl<B> Send for RetrievalEngine<B>
impl<B> !Sync for RetrievalEngine<B>
impl<B> Unpin for RetrievalEngine<B>where
<B as Backend>::FloatTensorPrimitive<2>: Unpin,
<B as Backend>::QuantizedTensorPrimitive<2>: Unpin,
<B as Backend>::FloatTensorPrimitive<1>: Unpin,
<B as Backend>::QuantizedTensorPrimitive<1>: Unpin,
<B as Backend>::FloatTensorPrimitive<3>: Unpin,
<B as Backend>::QuantizedTensorPrimitive<3>: Unpin,
<B as Backend>::Device: Unpin,
<B as Backend>::FloatTensorPrimitive<4>: Unpin,
<B as Backend>::QuantizedTensorPrimitive<4>: Unpin,
impl<B> UnsafeUnpin for RetrievalEngine<B>where
<B as Backend>::FloatTensorPrimitive<2>: UnsafeUnpin,
<B as Backend>::QuantizedTensorPrimitive<2>: UnsafeUnpin,
<B as Backend>::FloatTensorPrimitive<1>: UnsafeUnpin,
<B as Backend>::QuantizedTensorPrimitive<1>: UnsafeUnpin,
<B as Backend>::FloatTensorPrimitive<3>: UnsafeUnpin,
<B as Backend>::QuantizedTensorPrimitive<3>: UnsafeUnpin,
<B as Backend>::Device: UnsafeUnpin,
<B as Backend>::FloatTensorPrimitive<4>: UnsafeUnpin,
<B as Backend>::QuantizedTensorPrimitive<4>: UnsafeUnpin,
impl<B> UnwindSafe for RetrievalEngine<B>where
<B as Backend>::FloatTensorPrimitive<2>: UnwindSafe,
<B as Backend>::QuantizedTensorPrimitive<2>: UnwindSafe,
<B as Backend>::FloatTensorPrimitive<1>: UnwindSafe,
<B as Backend>::QuantizedTensorPrimitive<1>: UnwindSafe,
<B as Backend>::FloatTensorPrimitive<3>: UnwindSafe,
<B as Backend>::QuantizedTensorPrimitive<3>: UnwindSafe,
<B as Backend>::FloatTensorPrimitive<4>: UnwindSafe,
<B as Backend>::QuantizedTensorPrimitive<4>: 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