pub struct SqliteVecStore { /* private fields */ }Expand description
sqlite-vec 向量存储实现
特性:
- 零外部依赖(通过 sqlx + sqlite)
- 余弦距离搜索
- 元数据过滤通过 SQL WHERE 子句实现
- WAL 模式支持并发读
Implementations§
Source§impl SqliteVecStore
impl SqliteVecStore
Sourcepub async fn new(
path: &str,
dimensions: usize,
max_pool_size: Option<usize>,
) -> Result<Self, StoreError>
pub async fn new( path: &str, dimensions: usize, max_pool_size: Option<usize>, ) -> Result<Self, StoreError>
创建新的 sqlite-vec 存储
Sourcepub fn with_table_name(self, name: &str) -> Self
pub fn with_table_name(self, name: &str) -> Self
设置表名
Sourcepub fn with_max_capacity(self, capacity: Option<u64>) -> Self
pub fn with_max_capacity(self, capacity: Option<u64>) -> Self
设置最大存储容量
Sourcepub async fn purge_expired(&self) -> Result<usize, StoreError>
pub async fn purge_expired(&self) -> Result<usize, StoreError>
清理过期数据
Trait Implementations§
Source§impl Debug for SqliteVecStore
impl Debug for SqliteVecStore
Source§impl StoreLifecycle for SqliteVecStore
impl StoreLifecycle for SqliteVecStore
Source§fn initialize<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn initialize<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
初始化存储(创建表结构等)
Source§fn close<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn close<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
优雅关闭
Source§fn checkpoint<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn checkpoint<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
强制持久化检查点
Source§fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<bool, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<bool, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
是否健康
Source§impl VectorStore for SqliteVecStore
impl VectorStore for SqliteVecStore
Source§fn insert<'life0, 'async_trait>(
&'life0 self,
entry: VectorEntry,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn insert<'life0, 'async_trait>(
&'life0 self,
entry: VectorEntry,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
插入单条向量
Source§fn insert_batch<'life0, 'async_trait>(
&'life0 self,
entries: Vec<VectorEntry>,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn insert_batch<'life0, 'async_trait>(
&'life0 self,
entries: Vec<VectorEntry>,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
批量插入向量(推荐的高吞吐写入路径)
Source§fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 [f32],
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 [f32],
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
相似度搜索(cosine 相似度,返回 Top-K)
Source§fn search_with_filter<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
query: &'life1 [f32],
filter: &'life2 MetadataFilter,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn search_with_filter<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
query: &'life1 [f32],
filter: &'life2 MetadataFilter,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, StoreError>> + 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,
ids: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<usize, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
ids: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<usize, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
按 ID 批量删除
Source§fn delete_by_filter<'life0, 'life1, 'async_trait>(
&'life0 self,
filter: &'life1 MetadataFilter,
) -> Pin<Box<dyn Future<Output = Result<usize, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete_by_filter<'life0, 'life1, 'async_trait>(
&'life0 self,
filter: &'life1 MetadataFilter,
) -> Pin<Box<dyn Future<Output = Result<usize, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
按元数据过滤条件删除
Source§fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
清空存储
Source§fn count<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<usize, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn count<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<usize, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
存储中的总条目数
Source§fn rebuild_index<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn rebuild_index<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
创建/重建索引(后台线程,不阻塞写入)
Source§fn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<StoreStats, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<StoreStats, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
存储统计信息
Auto Trait Implementations§
impl Freeze for SqliteVecStore
impl !RefUnwindSafe for SqliteVecStore
impl Send for SqliteVecStore
impl Sync for SqliteVecStore
impl Unpin for SqliteVecStore
impl UnsafeUnpin for SqliteVecStore
impl !UnwindSafe for SqliteVecStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more