Documentation
¶
Overview ¶
Package pgvector 提供 PostgreSQL pgvector 扩展的向量存储集成
pgvector 是 PostgreSQL 的开源向量搜索扩展,适合已有 PostgreSQL 基础设施的团队。
特性:
- 基于成熟的 PostgreSQL 生态
- 支持 IVFFlat 和 HNSW 索引
- 精确和近似最近邻搜索
- 事务支持,ACID 保证
- 与现有 SQL 数据无缝结合
前置条件:
- PostgreSQL 15+
- pgvector 扩展 (CREATE EXTENSION vector)
使用示例:
store, err := pgvector.NewStore(ctx,
pgvector.WithDSN("postgres://user:pass@localhost:5432/mydb"),
pgvector.WithTable("embeddings"),
pgvector.WithDimension(1536),
)
defer store.Close()
// 添加文档
store.Add(ctx, docs)
// 搜索
results, err := store.Search(ctx, queryEmbedding, 5)
Index ¶
- type DistanceMetric
- type IndexType
- type Option
- type Store
- func (s *Store) Add(ctx context.Context, docs []vector.Document) error
- func (s *Store) Clear(ctx context.Context) error
- func (s *Store) Close() error
- func (s *Store) Count(ctx context.Context) (int, error)
- func (s *Store) Delete(ctx context.Context, ids []string) error
- func (s *Store) Search(ctx context.Context, embedding []float32, topK int, filter map[string]any) ([]vector.Document, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DistanceMetric ¶
type DistanceMetric string
DistanceMetric 距离度量方式
const ( // DistanceCosine 余弦距离(默认) DistanceCosine DistanceMetric = "cosine" // DistanceL2 欧几里得距离(L2) DistanceL2 DistanceMetric = "l2" // DistanceInnerProduct 内积距离 DistanceInnerProduct DistanceMetric = "inner_product" )
Click to show internal directories.
Click to hide internal directories.