Skip to main content

PgVectorStore

Trait PgVectorStore 

Source
pub trait PgVectorStore: Send + Sync {
    // Required methods
    fn create_collection<'life0, 'life1, 'async_trait>(
        &'life0 self,
        name: &'life1 str,
        dimension: usize,
        metric: Option<VectorMetric>,
    ) -> Pin<Box<dyn Future<Output = Result<(), VectorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete_collection<'life0, 'life1, 'async_trait>(
        &'life0 self,
        name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), VectorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn insert<'life0, 'life1, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        records: Vec<VectorRecord>,
    ) -> Pin<Box<dyn Future<Output = Result<(), VectorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn search<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        query: &'life2 [f32],
        top_k: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, VectorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn get<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        id: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<VectorRecord>, VectorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        ids: Vec<String>,
    ) -> Pin<Box<dyn Future<Output = Result<u64, VectorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn count<'life0, 'life1, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<usize, VectorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Vector Store 核心 trait

提供向量集合的 CRUD 和相似度搜索能力。 所有方法均为 async,适用于真实数据库 I/O。

Required Methods§

Source

fn create_collection<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, dimension: usize, metric: Option<VectorMetric>, ) -> Pin<Box<dyn Future<Output = Result<(), VectorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

创建集合

Source

fn delete_collection<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), VectorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

删除集合

Source

fn insert<'life0, 'life1, 'async_trait>( &'life0 self, collection: &'life1 str, records: Vec<VectorRecord>, ) -> Pin<Box<dyn Future<Output = Result<(), VectorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

插入向量记录(upsert 语义:相同 id 会覆盖)

Source

fn search<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, collection: &'life1 str, query: &'life2 [f32], top_k: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, VectorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

相似度搜索

M-16 修复:top_k 必须在 [1, MAX_TOP_K] 范围内。 实现方应在执行搜索前调用 validate_top_k(top_k)? 进行校验。

Source

fn get<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, collection: &'life1 str, id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<VectorRecord>, VectorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

获取单个记录

Source

fn delete<'life0, 'life1, 'async_trait>( &'life0 self, collection: &'life1 str, ids: Vec<String>, ) -> Pin<Box<dyn Future<Output = Result<u64, VectorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

删除记录

Source

fn count<'life0, 'life1, 'async_trait>( &'life0 self, collection: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<usize, VectorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

统计记录数

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl PgVectorStore for InMemoryVectorStore

Source§

impl PgVectorStore for MemoryBatchOps

委托实现 PgVectorStore,将所有调用转发给内部 store

Source§

impl PgVectorStore for StubVectorStore