Skip to main content

Corpus

Struct Corpus 

Source
pub struct Corpus { /* private fields */ }
Expand description

Aggregate root that manages a collection of compressed embedding vectors.

§Domain contracts

  • CompressionPolicy is immutable after the first successful insert.
  • Domain events are buffered and drained atomically via drain_events.
  • insert_batch is all-or-nothing: on error the corpus is not modified.

§Usage

let mut corpus = Corpus::new(
    Arc::from("my-corpus"),
    config,
    codebook,
    CompressionPolicy::Compress,
    BTreeMap::new(),
);
corpus.insert(Arc::from("v1"), &vector, None)?;
let events = corpus.drain_events();

Implementations§

Source§

impl Corpus

Source

pub fn new( corpus_id: CorpusId, config: CodecConfig, codebook: Codebook, compression_policy: CompressionPolicy, metadata: BTreeMap<String, EntryMetaValue>, ) -> Self

Construct a new Corpus and emit a CorpusEvent::Created event.

timestamp must be supplied by the caller (nanoseconds since Unix epoch) to keep this crate no_std (no std::time).

Source

pub fn new_at( corpus_id: CorpusId, config: CodecConfig, codebook: Codebook, compression_policy: CompressionPolicy, metadata: BTreeMap<String, EntryMetaValue>, timestamp: Timestamp, ) -> Self

Construct a new Corpus with an explicit creation timestamp.

Use this variant in tests or callers that supply their own time source.

Source

pub const fn corpus_id(&self) -> &CorpusId

The stable string identifier for this corpus.

Source

pub const fn config(&self) -> &CodecConfig

The codec configuration used at construction time.

Source

pub const fn compression_policy(&self) -> CompressionPolicy

The active compression policy.

Source

pub fn vector_count(&self) -> usize

Number of vectors currently stored in the corpus.

Source

pub fn is_empty(&self) -> bool

Returns true when the corpus contains no vectors.

Source

pub fn contains(&self, id: &VectorId) -> bool

Returns true if a vector with the given id exists.

Source

pub fn iter(&self) -> impl Iterator<Item = (&VectorId, &VectorEntry)>

Iterate over (VectorId, VectorEntry) pairs in insertion order.

Source

pub const fn metadata(&self) -> &BTreeMap<String, EntryMetaValue>

Read-only access to the corpus-level metadata.

Source

pub fn drain_events(&mut self) -> Vec<CorpusEvent>

Drain and return all pending domain events.

Uses core::mem::take — O(1), no allocation. After this call pending_events is empty.

Source

pub fn insert( &mut self, id: VectorId, vector: &[f32], entry_metadata: Option<EntryMetaValue>, timestamp: Timestamp, ) -> Result<(), CorpusError>

Insert a single vector into the corpus.

§Errors
Source

pub fn insert_batch( &mut self, vectors: &[(VectorId, &[f32], Option<EntryMetaValue>)], timestamp: Timestamp, ) -> Result<BatchReport, CorpusError>

Insert a batch of vectors atomically (all-or-nothing).

On failure the corpus is unchanged and no events are emitted. On success, exactly one CorpusEvent::VectorsInserted is emitted covering all inserted ids.

§Errors
Source

pub fn decompress(&self, id: &VectorId) -> Result<Vec<f32>, CorpusError>

Decompress a single vector by id.

Does not emit a domain event (Python parity).

§Errors
Source

pub fn decompress_all_at( &mut self, timestamp: Timestamp, ) -> Result<BTreeMap<VectorId, Vec<f32>>, CorpusError>

Decompress all vectors and return them with an explicit timestamp.

Emits exactly one CorpusEvent::Decompressed on success. No event is emitted when the corpus is empty — matches Python parity.

§Errors

Propagates errors from the codec pipeline for any individual vector.

Source

pub fn remove(&mut self, id: &VectorId) -> Option<VectorEntry>

Remove a vector by id, returning the entry if present.

Silent: no domain event is emitted (Python parity — del corpus[id]).

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

Source§

type Output = T

Should always be Self
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