Skip to main content

CorpusWorkspace

Struct CorpusWorkspace 

Source
pub struct CorpusWorkspace<T> { /* private fields */ }
Expand description

A corpus prepared once for repeated scoring under a fixed Metric.

Build it with CorpusWorkspace::build, then score many queries with query_corpus_scores / query_corpus_scores_into or rerank a single query with rerank_with. The corpus and metric are fixed for the life of the workspace.

Implementations§

Source§

impl<T: NabledReal> CorpusWorkspace<T>

Source

pub fn build( corpus: &ArrayView2<'_, T>, metric: Metric, ) -> Result<Self, EmbeddingError>

Precompute reusable corpus state for metric.

For Metric::Cosine this computes and caches the corpus row norms (rejecting zero-norm rows up front, exactly as the stateless cosine path would).

§Errors

Returns EmbeddingError::EmptyInput when corpus is empty and EmbeddingError::ZeroNorm when a cosine corpus contains a zero-norm row.

Source

pub const fn metric(&self) -> Metric

The metric this workspace was built for.

Source

pub fn len(&self) -> usize

Number of corpus rows.

Source

pub fn is_empty(&self) -> bool

Whether the corpus has no rows. Always false for a successfully built workspace.

Source

pub fn dim(&self) -> usize

Feature dimension of the corpus rows.

Source

pub fn query_corpus_scores( &self, queries: &ArrayView2<'_, T>, ) -> Result<Array2<T>, EmbeddingError>

Score every queries row against the cached corpus, reusing precomputed corpus state.

Returns a (queries.nrows(), corpus_len) matrix identical to the stateless query_corpus_scores result.

§Errors

Returns EmbeddingError::EmptyInput for empty queries, EmbeddingError::DimensionMismatch when the feature dimension differs, and EmbeddingError::ZeroNorm for cosine queries with zero-norm rows.

Source

pub fn query_corpus_scores_into( &self, queries: &ArrayView2<'_, T>, out: &mut Array2<T>, ) -> Result<(), EmbeddingError>

Score every queries row against the cached corpus into a caller-provided out buffer.

out must be shaped (queries.nrows(), corpus_len).

§Errors

See query_corpus_scores; also returns EmbeddingError::DimensionMismatch when out is mis-sized.

Source

pub fn rerank_with( &self, query: &ArrayView1<'_, T>, k: usize, ) -> Result<Vec<Neighbor<T>>, EmbeddingError>

Rerank the cached corpus against a single query, returning the best k neighbors.

Equivalent to rerank against this workspace’s corpus and metric, but reusing the precomputed corpus state.

§Errors

See query_corpus_scores.

Source

pub fn knn_with( &self, queries: &ArrayView2<'_, T>, k: usize, ) -> Result<Vec<Vec<Neighbor<T>>>, EmbeddingError>

Exact brute-force kNN over the cached corpus for every queries row.

Per-query best-first neighbor lists, reusing the precomputed corpus state.

§Errors

See query_corpus_scores.

Trait Implementations§

Source§

impl<T: Clone> Clone for CorpusWorkspace<T>

Source§

fn clone(&self) -> CorpusWorkspace<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for CorpusWorkspace<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for CorpusWorkspace<T>

§

impl<T> RefUnwindSafe for CorpusWorkspace<T>
where T: RefUnwindSafe,

§

impl<T> Send for CorpusWorkspace<T>
where T: Send,

§

impl<T> Sync for CorpusWorkspace<T>
where T: Sync,

§

impl<T> Unpin for CorpusWorkspace<T>

§

impl<T> UnsafeUnpin for CorpusWorkspace<T>

§

impl<T> UnwindSafe for CorpusWorkspace<T>
where T: RefUnwindSafe,

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