postgres

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package postgres is the optional Postgres implementation of brain.Store.

Hosts construct a Store with New(pool) and inject it into brain.NewEngine. Call Setup once per database to create extensions, tables, and indexes. Query/Exec emit otelpgx spans under the caller context after telemetry.Init.

Package brain does not import this package. MemoryStore stays in brain for tests and offline hosts.

Index

Constants

View Source
const DefaultEmbeddingDim = 1536

DefaultEmbeddingDim is the pgvector column size when Store.EmbeddingDim is 0.

Variables

This section is empty.

Functions

This section is empty.

Types

type PgxDB

type PgxDB interface {
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
}

PgxDB is satisfied by *pgx.Conn and *pgxpool.Pool.

type Store

type Store struct {
	// EmbeddingDim is the pgvector size Setup uses. Zero means DefaultEmbeddingDim.
	EmbeddingDim int
	// contains filtered or unexported fields
}

Store is the optional Postgres brain.Store. Hosts inject it into NewEngine. Call Setup once per database. Setup does not migrate an existing vector column.

func New

func New(db PgxDB) (*Store, error)

New wraps a pgx pool or connection. Query/Exec emit otelpgx client spans as children of ctx (after telemetry.Init).

func (*Store) Get

func (s *Store) Get(ctx context.Context, scope brain.Scope, id uuid.UUID) (brain.Object, error)

Get implements ObjectReader.

func (*Store) GetByProperty

func (s *Store) GetByProperty(ctx context.Context, scope brain.Scope, key, value string) (brain.Object, error)

GetByProperty implements ObjectLister.

func (*Store) GetKind

func (s *Store) GetKind(ctx context.Context, kind string) (brain.ObjectKind, error)

GetKind implements KindReader.

func (*Store) GetMany

func (s *Store) GetMany(ctx context.Context, scope brain.Scope, ids []uuid.UUID) ([]brain.Object, error)

GetMany implements ObjectReader.

func (*Store) KindsWithObjects

func (s *Store) KindsWithObjects(ctx context.Context, scope brain.Scope) ([]string, error)

KindsWithObjects implements ObjectLister.

func (*Store) ListByKind

func (s *Store) ListByKind(ctx context.Context, scope brain.Scope, kind string, limit int) ([]brain.Object, error)

ListByKind implements ObjectLister (first-class objects only).

func (*Store) ListChildren

func (s *Store) ListChildren(ctx context.Context, scope brain.Scope, parentID uuid.UUID) ([]brain.Object, error)

ListChildren implements ObjectReader.

func (*Store) ListKinds

func (s *Store) ListKinds(ctx context.Context) ([]brain.ObjectKind, error)

ListKinds implements KindReader.

func (*Store) Put

func (s *Store) Put(ctx context.Context, obj brain.Object) error

Put implements ObjectWriter (full-column upsert; clears soft-delete on revive).

func (*Store) PutKind

func (s *Store) PutKind(ctx context.Context, k brain.ObjectKind) error

PutKind implements KindWriter.

func (*Store) SearchLexical

func (s *Store) SearchLexical(ctx context.Context, scope brain.Scope, query string, filters brain.Filter, k int) ([]brain.ScoredID, error)

SearchLexical implements PartSearcher using pg_textsearch BM25.

func (*Store) SearchTrigram

func (s *Store) SearchTrigram(ctx context.Context, scope brain.Scope, query string, filters brain.Filter, k int) ([]brain.ScoredID, error)

SearchTrigram implements PartSearcher using pg_trgm similarity.

func (*Store) SearchVector

func (s *Store) SearchVector(ctx context.Context, scope brain.Scope, embedding []float32, filters brain.Filter, k int) ([]brain.ScoredID, error)

SearchVector implements PartSearcher using pgvector cosine distance.

func (*Store) Setup

func (s *Store) Setup(ctx context.Context, kinds ...brain.KindSpec) error

Setup creates extensions, tables, and indexes (idempotent), then upserts kinds into object_kinds. EmbeddingDim is the pgvector size and must match the embedder; zero uses DefaultEmbeddingDim. This does not migrate an existing column to a new size.

func (*Store) SoftDelete

func (s *Store) SoftDelete(ctx context.Context, scope brain.Scope, id uuid.UUID) error

SoftDelete implements ObjectWriter.

Jump to

Keyboard shortcuts

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