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§
Sourcefn 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 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,
创建集合
Sourcefn 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 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,
删除集合
Sourcefn 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 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 会覆盖)
Sourcefn 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 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)? 进行校验。
Sourcefn 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 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,
获取单个记录
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl PgVectorStore for InMemoryVectorStore
impl PgVectorStore for MemoryBatchOps
委托实现 PgVectorStore,将所有调用转发给内部 store