pgvector

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DSN PostgreSQL 连接串, 如:
	//   postgres://user:password@localhost:5432/dbname?sslmode=disable
	DSN string

	// Table 存储向量的表名, 默认 "agent_vectors"。
	// 表结构示例:
	//   CREATE TABLE agent_vectors (
	//     id TEXT PRIMARY KEY,
	//     namespace TEXT,
	//     embedding VECTOR(1536),
	//     metadata JSONB
	//   );
	Table string

	// Dimension 向量维度, 需要与 embedding 模型一致。
	Dimension int

	// Metric 相似度度量, 当前支持 "cosine" (默认) 或 "l2"。
	Metric string
}

Config 配置 PgVector 向量存储。 需要数据库已安装 pgvector 扩展:

CREATE EXTENSION IF NOT EXISTS vector;

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store 使用 pgvector 实现的 VectorStore。

func New

func New(cfg *Config) (*Store, error)

New 创建 PgVector 向量存储。

func (*Store) Close

func (s *Store) Close() error

Close 关闭连接池。

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, ids []string) error

Delete 从 pgvector 表中删除指定文档。

func (*Store) Query

func (s *Store) Query(ctx context.Context, q vector.Query) ([]vector.Hit, error)

Query 在指定命名空间内执行向量检索。

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, docs []vector.Document) error

Upsert 将文档插入或更新到 pgvector 表。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL