Skip to main content

VectorStore

Trait VectorStore 

Source
pub trait VectorStore:
    Send
    + Sync
    + Debug {
    // Required methods
    fn upsert(
        &self,
        chunks: Vec<StoredChunk>,
    ) -> BoxFuture<'_, Result<(), RagError>>;
    fn delete_document<'a>(
        &'a self,
        dataset_id: &'a str,
        document_id: &'a str,
    ) -> BoxFuture<'a, Result<usize, RagError>>;
    fn delete_dataset<'a>(
        &'a self,
        dataset_id: &'a str,
    ) -> BoxFuture<'a, Result<usize, RagError>>;
    fn document_chunks<'a>(
        &'a self,
        dataset_id: &'a str,
        document_id: &'a str,
    ) -> BoxFuture<'a, Result<Vec<StoredChunk>, RagError>>;
    fn delete_chunks<'a>(
        &'a self,
        dataset_id: &'a str,
        ids: &'a [String],
    ) -> BoxFuture<'a, Result<usize, RagError>>;
    fn search<'a>(
        &'a self,
        query: VectorQuery<'a>,
    ) -> BoxFuture<'a, Result<Vec<Hit>, RagError>>;

    // Provided methods
    fn list_documents<'a>(
        &'a self,
        dataset_id: &'a str,
        limit: usize,
        after: Option<&'a str>,
    ) -> BoxFuture<'a, Result<Vec<DocumentSummary>, RagError>> { ... }
    fn supports_keyword(&self) -> bool { ... }
    fn keyword_search<'a>(
        &'a self,
        query: KeywordQuery<'a>,
    ) -> BoxFuture<'a, Result<Vec<Hit>, RagError>> { ... }
    fn contains_hash<'a>(
        &'a self,
        dataset_id: &'a str,
        content_hash: &'a str,
    ) -> BoxFuture<'a, Result<bool, RagError>> { ... }
}
Expand description

Stores chunks with vectors and answers similarity queries.

Required Methods§

Source

fn upsert( &self, chunks: Vec<StoredChunk>, ) -> BoxFuture<'_, Result<(), RagError>>

Insert or replace chunks (by id).

Source

fn delete_document<'a>( &'a self, dataset_id: &'a str, document_id: &'a str, ) -> BoxFuture<'a, Result<usize, RagError>>

Remove every chunk of a document. Returns the number removed when known.

Source

fn delete_dataset<'a>( &'a self, dataset_id: &'a str, ) -> BoxFuture<'a, Result<usize, RagError>>

Remove every chunk of a dataset.

Source

fn document_chunks<'a>( &'a self, dataset_id: &'a str, document_id: &'a str, ) -> BoxFuture<'a, Result<Vec<StoredChunk>, RagError>>

Every chunk of one document, vectors included. The ingestor uses this to re-ingest a document without re-embedding unchanged chunks and to find the chunks a new version no longer contains.

Source

fn delete_chunks<'a>( &'a self, dataset_id: &'a str, ids: &'a [String], ) -> BoxFuture<'a, Result<usize, RagError>>

Remove chunks by id. Returns the number removed when known.

Source

fn search<'a>( &'a self, query: VectorQuery<'a>, ) -> BoxFuture<'a, Result<Vec<Hit>, RagError>>

Nearest neighbours by cosine similarity, best first.

Provided Methods§

Source

fn list_documents<'a>( &'a self, dataset_id: &'a str, limit: usize, after: Option<&'a str>, ) -> BoxFuture<'a, Result<Vec<DocumentSummary>, RagError>>

Up to limit documents of a dataset ordered by document id, starting after after (a document id from the previous page). Stores that cannot list return RagError::Unsupported.

Source

fn supports_keyword(&self) -> bool

Whether VectorStore::keyword_search is implemented.

Keyword (BM25) search, best first. Stores without a keyword index return nothing.

Source

fn contains_hash<'a>( &'a self, dataset_id: &'a str, content_hash: &'a str, ) -> BoxFuture<'a, Result<bool, RagError>>

Whether a chunk with this content hash already exists in the dataset. Stores that cannot answer cheaply return false. The built-in crate::Ingestor does not use this (it de-duplicates per document via VectorStore::document_chunks).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§