Skip to main content

FactStore

Trait FactStore 

Source
pub trait FactStore {
    // Required methods
    fn store(
        &self,
        id: u64,
        content: &str,
        embedding: &[f32],
    ) -> Result<(), MemoryError>;
    fn store_with_metadata(
        &self,
        id: u64,
        content: &str,
        embedding: &[f32],
        metadata: &Metadata,
    ) -> Result<(), MemoryError>;
    fn store_with_ttl(
        &self,
        id: u64,
        content: &str,
        embedding: &[f32],
        ttl_seconds: u64,
    ) -> Result<(), MemoryError>;
    fn update_metadata(
        &self,
        id: u64,
        metadata: &Metadata,
    ) -> Result<(), MemoryError>;
    fn get(&self, id: u64) -> Result<Option<(String, Vec<f32>)>, MemoryError>;
    fn get_metadata(&self, id: u64) -> Result<Option<Metadata>, MemoryError>;
    fn get_metadata_batch(
        &self,
        ids: &[u64],
    ) -> Result<Vec<Option<Metadata>>, MemoryError>;
    fn delete(&self, id: u64) -> Result<(), MemoryError>;
    fn count(&self) -> usize;

    // Provided methods
    fn store_with_metadata_and_ttl(
        &self,
        id: u64,
        content: &str,
        embedding: &[f32],
        metadata: &Metadata,
        ttl_seconds: u64,
    ) -> Result<(), MemoryError> { ... }
    fn list(
        &self,
        cursor: Option<u64>,
        limit: usize,
    ) -> Result<(Vec<RawListedFact>, Option<u64>), MemoryError> { ... }
}
Expand description

Fact storage: write, by-id lookup, deletion, corpus size — the core facet every backend must provide. The other facets (RecallStore, GraphStore, ColumnStore) build on stored facts; a partial backend, or a test double, implements only the facets it serves and the compiler refuses calls to the rest (#1959).

Required Methods§

Source

fn store( &self, id: u64, content: &str, embedding: &[f32], ) -> Result<(), MemoryError>

Store a fact with no metadata or expiry.

§Errors

Returns MemoryError if persistence fails.

Source

fn store_with_metadata( &self, id: u64, content: &str, embedding: &[f32], metadata: &Metadata, ) -> Result<(), MemoryError>

Store a fact tagged with metadata, no expiry.

§Errors

Returns MemoryError if persistence fails.

Source

fn store_with_ttl( &self, id: u64, content: &str, embedding: &[f32], ttl_seconds: u64, ) -> Result<(), MemoryError>

Store a fact that expires after ttl_seconds, no metadata.

§Errors

Returns MemoryError if persistence fails.

Source

fn update_metadata( &self, id: u64, metadata: &Metadata, ) -> Result<(), MemoryError>

Merge metadata into an already-stored fact’s payload, preserving any durable TTL. Used to combine metadata with an expiry (store both in two calls rather than needing every metadata×TTL combination as a separate primitive).

§Errors

Returns MemoryError if id is unknown or persistence fails.

Source

fn get(&self, id: u64) -> Result<Option<(String, Vec<f32>)>, MemoryError>

A fact’s content and embedding, or None if unknown/expired.

§Errors

Returns MemoryError if storage access fails.

Source

fn get_metadata(&self, id: u64) -> Result<Option<Metadata>, MemoryError>

A fact’s raw stored payload — reserved system keys (_veles_*) included, so the service layer can check the hub flag before stripping them for the caller — or None when the fact is unknown/expired.

§Errors

Returns MemoryError if storage access fails.

Source

fn get_metadata_batch( &self, ids: &[u64], ) -> Result<Vec<Option<Metadata>>, MemoryError>

Batched Self::get_metadata: one storage round trip for every id in ids, results in the same order and length (an unknown or expired id maps to None). Same raw-payload semantics as the single-id form.

§Errors

Returns MemoryError if storage access fails.

Source

fn delete(&self, id: u64) -> Result<(), MemoryError>

Delete a fact.

§Errors

Returns MemoryError if deletion fails.

Source

fn count(&self) -> usize

The total number of live (non-expired) tracked facts, including internal entity hubs — used as a corpus-size proxy for idf weighting.

Provided Methods§

Source

fn store_with_metadata_and_ttl( &self, id: u64, content: &str, embedding: &[f32], metadata: &Metadata, ttl_seconds: u64, ) -> Result<(), MemoryError>

Store a fact with BOTH metadata and a durable TTL, in ONE write.

Default: the historical two-call sequence, so a backend written before this method keeps compiling and behaving as it did. Backends that can write both at once should override it — the two-call form leaves the fact live and expiring between the calls, so a short TTL can lapse in the gap and the metadata write then fails on a fact that was perfectly valid when the caller asked for it.

§Errors

Returns MemoryError if persistence fails.

Source

fn list( &self, cursor: Option<u64>, limit: usize, ) -> Result<(Vec<RawListedFact>, Option<u64>), MemoryError>

One cursor page of the store’s live facts, ids ascending: up to limit entries strictly after cursor (None starts the walk), plus the cursor for the next page (None ends it). Payloads come back RAW — reserved keys and scaffolding markers included — because the policy of what a caller may see (hub filtering, key stripping) belongs to the service layer, in one place, for every backend.

TTL-expired facts are skipped, not listed: an audit must show what the store will still serve, and a fact past its expiry is not it.

Defaulted to a refusal rather than required, same reasoning as GraphStore::edge_count: an out-of-crate backend keeps compiling, and its list_memories answers with this error instead of a wrong walk.

§Errors

Returns MemoryError::Unsupported if the backend cannot enumerate at all, or MemoryError if the walk fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl FactStore for NativeStore

Available on crate feature persistence only.