Documentation
¶
Overview ¶
Package pgvector provides a interfaces.Memory implementation backed by PostgreSQL with pgvector.
Expected table schema (embedding dimension must match EmbedFunc output):
CREATE TABLE agent_memories (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
text TEXT NOT NULL,
kind TEXT NOT NULL DEFAULT '',
user_id TEXT,
tenant_id TEXT,
agent_id TEXT,
scope_tags TEXT[] NOT NULL DEFAULT '{}',
metadata JSONB NOT NULL DEFAULT '{}',
expires_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
embedding vector(1536)
);
Callers provide EmbedFunc to vectorize memory text on store and recall queries on load.
Index ¶
- Constants
- type EmbedFunc
- type Memory
- func (m *Memory) Clear(ctx context.Context, scope interfaces.MemoryScope) error
- func (m *Memory) Load(ctx context.Context, scope interfaces.MemoryScope, query string, ...) ([]interfaces.MemoryEntry, error)
- func (m *Memory) Store(ctx context.Context, scope interfaces.MemoryScope, ...) (string, error)
- type Option
- func WithDSN(dsn string) Option
- func WithDefaultLimit(limit int) Option
- func WithDefaultMinScore(minScore float32) Option
- func WithEmbeddingCol(col string) Option
- func WithLogLevel(level string) Option
- func WithLogger(l logger.Logger) Option
- func WithPool(pool *pgxpool.Pool) Option
- func WithTable(table string) Option
- func WithTextCol(col string) Option
Constants ¶
const ( DefaultTable = "agent_memories" DefaultTextCol = "text" DefaultEmbeddingCol = "embedding" ColID = "id" ColKind = "kind" ColMetadata = "metadata" ColScopeTags = "scope_tags" ColExpiresAt = "expires_at" ColCreatedAt = "created_at" ColUpdatedAt = "updated_at" ColUserID = memory.ScopeKeyUserID ColTenantID = memory.ScopeKeyTenantID ColAgentID = memory.ScopeKeyAgentID )
Default table and column names for Memory.
const DefaultLoadLimit = 10
DefaultLoadLimit is the maximum memories returned when interfaces.WithLoadLimit is zero or negative.
const DefaultMinScore float32 = 0.35
DefaultMinScore is the default cosine similarity when interfaces.WithMinScore is zero.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory stores and recalls agent memories in PostgreSQL with pgvector.
func NewMemory ¶
NewMemory builds a pgvector-backed interfaces.Memory. embed is required. When WithPool is omitted, WithDSN must be provided.
func (*Memory) Clear ¶
func (m *Memory) Clear(ctx context.Context, scope interfaces.MemoryScope) error
Clear removes all memories matching scope.
func (*Memory) Load ¶
func (m *Memory) Load(ctx context.Context, scope interfaces.MemoryScope, query string, opts ...interfaces.LoadMemoryOption) ([]interfaces.MemoryEntry, error)
Load recalls memories within scope. Non-empty query uses vector similarity; empty query lists by updated_at.
func (*Memory) Store ¶
func (m *Memory) Store(ctx context.Context, scope interfaces.MemoryScope, record interfaces.MemoryRecord, opts ...interfaces.StoreMemoryOption) (string, error)
Store persists a memory in scope and returns its ID.
type Option ¶
type Option func(*Memory)
Option configures Memory.
func WithDSN ¶
WithDSN sets the PostgreSQL connection string used to create a pool when WithPool is omitted.
func WithDefaultLimit ¶
WithDefaultLimit sets the load limit when callers omit interfaces.WithLoadLimit.
func WithDefaultMinScore ¶
WithDefaultMinScore sets the cosine similarity floor when callers omit interfaces.WithMinScore.
func WithEmbeddingCol ¶
WithEmbeddingCol sets the column that holds the pgvector embedding. Defaults to DefaultEmbeddingCol.
func WithLogLevel ¶
WithLogLevel sets the log level when no logger is provided.
func WithPool ¶
WithPool sets an existing pgxpool.Pool. When provided, WithDSN is ignored.
func WithTable ¶
WithTable sets the PostgreSQL table. Defaults to DefaultTable.
func WithTextCol ¶
WithTextCol sets the column that holds memory text. Defaults to DefaultTextCol.