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
- type PgxDB
- type Store
- func (s *Store) Get(ctx context.Context, scope brain.Scope, id uuid.UUID) (brain.Object, error)
- func (s *Store) GetByProperty(ctx context.Context, scope brain.Scope, key, value string) (brain.Object, error)
- func (s *Store) GetKind(ctx context.Context, kind string) (brain.ObjectKind, error)
- func (s *Store) GetMany(ctx context.Context, scope brain.Scope, ids []uuid.UUID) ([]brain.Object, error)
- func (s *Store) KindsWithObjects(ctx context.Context, scope brain.Scope) ([]string, error)
- func (s *Store) ListByKind(ctx context.Context, scope brain.Scope, kind string, limit int) ([]brain.Object, error)
- func (s *Store) ListChildren(ctx context.Context, scope brain.Scope, parentID uuid.UUID) ([]brain.Object, error)
- func (s *Store) ListKinds(ctx context.Context) ([]brain.ObjectKind, error)
- func (s *Store) Put(ctx context.Context, obj brain.Object) error
- func (s *Store) PutKind(ctx context.Context, k brain.ObjectKind) error
- func (s *Store) SearchLexical(ctx context.Context, scope brain.Scope, query string, filters brain.Filter, ...) ([]brain.ScoredID, error)
- func (s *Store) SearchTrigram(ctx context.Context, scope brain.Scope, query string, filters brain.Filter, ...) ([]brain.ScoredID, error)
- func (s *Store) SearchVector(ctx context.Context, scope brain.Scope, embedding []float32, ...) ([]brain.ScoredID, error)
- func (s *Store) Setup(ctx context.Context, kinds ...brain.KindSpec) error
- func (s *Store) SoftDelete(ctx context.Context, scope brain.Scope, id uuid.UUID) error
Constants ¶
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 ¶
New wraps a pgx pool or connection. Query/Exec emit otelpgx client spans as children of ctx (after telemetry.Init).
func (*Store) GetByProperty ¶
func (s *Store) GetByProperty(ctx context.Context, scope brain.Scope, key, value string) (brain.Object, error)
GetByProperty implements ObjectLister.
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 ¶
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) 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.