Skip to main content

VectorDB

Trait VectorDB 

Source
pub trait VectorDB: Send + Sync {
    // Required methods
    fn create_collection<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        data_type: &'life1 str,
        field_name: &'life2 str,
        dimension: usize,
    ) -> Pin<Box<dyn Future<Output = VectorDBResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn has_collection<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        data_type: &'life1 str,
        field_name: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = VectorDBResult<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn index_points<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        data_type: &'life1 str,
        field_name: &'life2 str,
        points: &'life3 [VectorPoint],
    ) -> Pin<Box<dyn Future<Output = VectorDBResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
    fn search_similar<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        data_type: &'life1 str,
        field_name: &'life2 str,
        query_vector: &'life3 [f32],
        top_k: usize,
    ) -> Pin<Box<dyn Future<Output = VectorDBResult<Vec<SearchResult>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
    fn delete_collection<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        data_type: &'life1 str,
        field_name: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = VectorDBResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn collection_size<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        data_type: &'life1 str,
        field_name: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = VectorDBResult<usize>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn delete_points<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        data_type: &'life1 str,
        field_name: &'life2 str,
        point_ids: &'life3 [Uuid],
    ) -> Pin<Box<dyn Future<Output = VectorDBResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn list_collections<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = VectorDBResult<Vec<(String, String)>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn prune<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = VectorDBResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn batch_search_similar<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        data_type: &'life1 str,
        field_name: &'life2 str,
        query_vectors: &'life3 [Vec<f32>],
        top_k: usize,
    ) -> Pin<Box<dyn Future<Output = VectorDBResult<Vec<Vec<SearchResult>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
}
Expand description

Vector database trait

Required Methods§

Source

fn create_collection<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, data_type: &'life1 str, field_name: &'life2 str, dimension: usize, ) -> Pin<Box<dyn Future<Output = VectorDBResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Create a collection for (data_type, field_name) pair

§Arguments
  • data_type - Type name (e.g., “DocumentChunk”, “Entity”)
  • field_name - Field name (e.g., “text”, “name”)
  • dimension - Vector dimension (e.g., 384 for MiniLM)
§Example
vector_db.create_collection("DocumentChunk", "text", 384).await?;
Source

fn has_collection<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, data_type: &'life1 str, field_name: &'life2 str, ) -> Pin<Box<dyn Future<Output = VectorDBResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Check if collection exists

§Arguments
  • data_type - Type name
  • field_name - Field name
Source

fn index_points<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, data_type: &'life1 str, field_name: &'life2 str, points: &'life3 [VectorPoint], ) -> Pin<Box<dyn Future<Output = VectorDBResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Index data points (batch upsert with embeddings already generated)

§Arguments
  • data_type - Type name
  • field_name - Field name
  • points - Vector points with embeddings
§Example
let points = vec![
    VectorPoint::new(chunk_id, embedding)
        .with_metadata("type", json!("DocumentChunk"))
        .with_metadata("field", json!("text")),
];
vector_db.index_points("DocumentChunk", "text", &points).await?;
Source

fn search_similar<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, data_type: &'life1 str, field_name: &'life2 str, query_vector: &'life3 [f32], top_k: usize, ) -> Pin<Box<dyn Future<Output = VectorDBResult<Vec<SearchResult>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Search for similar vectors

§Arguments
  • data_type - Type name
  • field_name - Field name
  • query_vector - Query embedding vector
  • top_k - Number of results to return
§Returns

Vector of search results sorted by similarity (descending)

Source

fn delete_collection<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, data_type: &'life1 str, field_name: &'life2 str, ) -> Pin<Box<dyn Future<Output = VectorDBResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Delete collection

Source

fn collection_size<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, data_type: &'life1 str, field_name: &'life2 str, ) -> Pin<Box<dyn Future<Output = VectorDBResult<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get collection statistics

Provided Methods§

Source

fn delete_points<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, data_type: &'life1 str, field_name: &'life2 str, point_ids: &'life3 [Uuid], ) -> Pin<Box<dyn Future<Output = VectorDBResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Delete points by IDs from an existing collection.

Source

fn list_collections<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = VectorDBResult<Vec<(String, String)>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all existing vector collections as (data_type, field_name) pairs.

Default implementation returns an empty list. Backends should override to return the actual collections they hold.

Source

fn prune<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = VectorDBResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove all vector collections.

Default implementation lists all collections and deletes each one. Backends may override with a more efficient bulk operation.

Equivalent to Python’s vector_engine.prune().

Source

fn batch_search_similar<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, data_type: &'life1 str, field_name: &'life2 str, query_vectors: &'life3 [Vec<f32>], top_k: usize, ) -> Pin<Box<dyn Future<Output = VectorDBResult<Vec<Vec<SearchResult>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Perform multiple vector similarity searches in sequence.

Default implementation loops over [search_similar]. Backends may override this with a native batch API for better performance.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§