Skip to main content

Crate sz_orm_vector

Crate sz_orm_vector 

Source
Expand description

SZ-ORM pgvector 扩展

提供 PostgreSQL pgvector 向量相似度搜索能力,支持三种实现:

  • 内存实现InMemoryVectorStore):纯 Rust 向量计算,不连接数据库,适用于测试和基准
  • Stub 实现StubVectorStore):所有方法返回 Unsupported,适用于调试占位
  • 真实实现RealPgVectorStore,需启用 real-pg feature):通过 tokio-postgres 连接 PostgreSQL + pgvector

§快速入门

use sz_orm_vector::{InMemoryVectorStore, PgVectorStore, VectorRecord, VectorMetric};

let store = InMemoryVectorStore::new();
store.create_collection("docs", 3, None).await?;

let record = VectorRecord::new("doc1", vec![1.0, 0.0, 0.0]);
store.insert("docs", vec![record]).await?;

let results = store.search("docs", &[1.0, 0.0, 0.0], 5).await?;
println!("found {} results", results.len());

Re-exports§

pub use error::VectorError;
pub use memory::InMemoryVectorStore;
pub use stub::StubVectorStore;

Modules§

error
Vector 操作错误类型
memory
内存实现:纯 Rust 向量计算(不连接数据库)
stub
Stub 实现:所有方法返回 Unsupported 错误

Structs§

SearchResult
搜索结果
VectorRecord
向量记录

Enums§

VectorMetric
向量距离度量

Constants§

MAX_TOP_K
M-16 修复:top_k 最大限制

Traits§

PgVectorStore
Vector Store 核心 trait

Functions§

validate_top_k
M-16 修复:校验 top_k 是否在合理范围内