Skip to main content

KnowledgeStore

Struct KnowledgeStore 

Source
pub struct KnowledgeStore<S, V, E> { /* private fields */ }
Expand description

Composes a [Store], a [VectorIndex], and an [Embedder] into one retrieval surface keyed by RecordKey.

Implementations§

Source§

impl<S: Store, V: VectorIndex, E: Embedder> KnowledgeStore<S, V, E>

Source

pub fn new(store: S, index: V, embedder: E) -> Self

Source

pub fn store(&self) -> &S

Borrow the underlying store (e.g. to put records before ingesting them).

Source

pub async fn ingest(&self, key: &RecordKey) -> Result<bool>

Ingest the record at key: split it into per-kind chunks, embed each, and index it under a derived per-chunk key. Returns Ok(false) (without indexing) if the record is absent or its kind is definitionally not knowledge-bearing; returns Err if a knowledge-bearing body fails to parse — a corrupt record is a real failure, not “not indexable” (#139).

Source

pub async fn remove(&self, key: &RecordKey) -> Result<()>

De-index the record at key: remove every chunk vector it contributed to the index and forget its chunk count. This is the counterpart to a record being deleted from the store — without it, the record’s chunk vectors are orphaned, still matching in [query] but de-duping to a parent that no longer resolves, so they silently shrink the result set (#150).

Idempotent: removing a record that was never ingested (chunk count 0) removes nothing. Uses the same [chunk_key] derivation as [ingest].

Source

pub async fn query( &self, text: &str, k: usize, filter: &KeyPrefix, ) -> Result<Vec<Hit>>

Semantic query, one hit per record. Embed text, over-fetch chunk matches (restricted to filter), collapse them to their parent records keeping each record’s best chunk score, and return the top-k records.

Because a record with many matching chunks can crowd the over-fetch window, pathological cases may return fewer than k hits.

Source

pub async fn query_chunks( &self, text: &str, k: usize, filter: &KeyPrefix, ) -> Result<Vec<ChunkHit>>

Chunk-granular query: the top-k matching chunks (restricted to filter), not de-duped to their parents. Each hit carries the parent record, the chunk’s ordinal, and the chunk’s text.

Auto Trait Implementations§

§

impl<S, V, E> !Freeze for KnowledgeStore<S, V, E>

§

impl<S, V, E> RefUnwindSafe for KnowledgeStore<S, V, E>

§

impl<S, V, E> Send for KnowledgeStore<S, V, E>
where S: Send, V: Send, E: Send,

§

impl<S, V, E> Sync for KnowledgeStore<S, V, E>
where S: Sync, V: Sync, E: Sync,

§

impl<S, V, E> Unpin for KnowledgeStore<S, V, E>
where S: Unpin, V: Unpin, E: Unpin,

§

impl<S, V, E> UnsafeUnpin for KnowledgeStore<S, V, E>

§

impl<S, V, E> UnwindSafe for KnowledgeStore<S, V, E>
where S: UnwindSafe, V: UnwindSafe, E: UnwindSafe,

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