Documentation
¶
Overview ¶
Package postgres implements oasis.Store and oasis.MemoryStore using PostgreSQL with pgvector for native vector similarity search and tsvector for full-text keyword search.
Both Store and MemoryStore accept an externally-owned *pgxpool.Pool via constructor injection. The caller creates and closes the pool.
Index ¶
- func ConfigurePoolConfig(cfg *pgxpool.Config, opts ...Option)
- type MemoryStore
- func (s *MemoryStore) BuildContext(ctx context.Context, queryEmbedding []float32) (string, error)
- func (s *MemoryStore) DecayOldFacts(ctx context.Context) error
- func (s *MemoryStore) DeleteFact(ctx context.Context, factID string) error
- func (s *MemoryStore) DeleteMatchingFacts(ctx context.Context, pattern string) error
- func (s *MemoryStore) Init(ctx context.Context) error
- func (s *MemoryStore) SearchFacts(ctx context.Context, embedding []float32, topK int) ([]oasis.ScoredFact, error)
- func (s *MemoryStore) UpsertFact(ctx context.Context, fact, category string, embedding []float32) error
- type Option
- type Store
- func (s *Store) Close() error
- func (s *Store) CreateScheduledAction(ctx context.Context, action oasis.ScheduledAction) error
- func (s *Store) CreateThread(ctx context.Context, thread oasis.Thread) error
- func (s *Store) DeleteAllScheduledActions(ctx context.Context) (int, error)
- func (s *Store) DeleteCheckpoint(ctx context.Context, id string) error
- func (s *Store) DeleteDocument(ctx context.Context, id string) error
- func (s *Store) DeleteScheduledAction(ctx context.Context, id string) error
- func (s *Store) DeleteThread(ctx context.Context, id string) error
- func (s *Store) FindScheduledActionsByDescription(ctx context.Context, pattern string) ([]oasis.ScheduledAction, error)
- func (s *Store) GetBothEdges(ctx context.Context, chunkIDs []string) ([]oasis.ChunkEdge, error)
- func (s *Store) GetChunksByDocument(ctx context.Context, docID string) ([]oasis.Chunk, error)
- func (s *Store) GetChunksByIDs(ctx context.Context, ids []string) ([]oasis.Chunk, error)
- func (s *Store) GetConfig(ctx context.Context, key string) (string, error)
- func (s *Store) GetDocumentsByIDs(ctx context.Context, ids []string) ([]oasis.Document, error)
- func (s *Store) GetDueScheduledActions(ctx context.Context, now int64) ([]oasis.ScheduledAction, error)
- func (s *Store) GetEdges(ctx context.Context, chunkIDs []string) ([]oasis.ChunkEdge, error)
- func (s *Store) GetIncomingEdges(ctx context.Context, chunkIDs []string) ([]oasis.ChunkEdge, error)
- func (s *Store) GetMessages(ctx context.Context, threadID string, limit int) ([]oasis.Message, error)
- func (s *Store) GetThread(ctx context.Context, id string) (oasis.Thread, error)
- func (s *Store) Init(ctx context.Context) error
- func (s *Store) ListCheckpoints(ctx context.Context) ([]oasis.IngestCheckpoint, error)
- func (s *Store) ListDocumentMeta(ctx context.Context, limit int) ([]oasis.Document, error)
- func (s *Store) ListDocuments(ctx context.Context, limit int) ([]oasis.Document, error)
- func (s *Store) ListScheduledActions(ctx context.Context) ([]oasis.ScheduledAction, error)
- func (s *Store) ListThreads(ctx context.Context, chatID string, limit int) ([]oasis.Thread, error)
- func (s *Store) LoadCheckpoint(ctx context.Context, id string) (oasis.IngestCheckpoint, error)
- func (s *Store) PruneOrphanEdges(ctx context.Context) (int, error)
- func (s *Store) SaveCheckpoint(ctx context.Context, cp oasis.IngestCheckpoint) error
- func (s *Store) SearchChunks(ctx context.Context, embedding []float32, topK int, ...) ([]oasis.ScoredChunk, error)
- func (s *Store) SearchChunksKeyword(ctx context.Context, query string, topK int, filters ...oasis.ChunkFilter) ([]oasis.ScoredChunk, error)
- func (s *Store) SearchMessages(ctx context.Context, embedding []float32, topK int) ([]oasis.ScoredMessage, error)
- func (s *Store) SetConfig(ctx context.Context, key, value string) error
- func (s *Store) StoreDocument(ctx context.Context, doc oasis.Document, chunks []oasis.Chunk) error
- func (s *Store) StoreEdges(ctx context.Context, edges []oasis.ChunkEdge) error
- func (s *Store) StoreMessage(ctx context.Context, msg oasis.Message) error
- func (s *Store) UpdateScheduledAction(ctx context.Context, action oasis.ScheduledAction) error
- func (s *Store) UpdateScheduledActionEnabled(ctx context.Context, id string, enabled bool) error
- func (s *Store) UpdateThread(ctx context.Context, thread oasis.Thread) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigurePoolConfig ¶ added in v0.10.0
ConfigurePoolConfig applies store settings that require per-connection setup to a pgxpool.Config. Call this before pgxpool.NewWithConfig so every connection in the pool inherits the settings.
Currently applies: hnsw.ef_search (HNSW query-time candidate list size). If no relevant options are set, cfg is returned unmodified.
Types ¶
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore implements oasis.MemoryStore backed by PostgreSQL with pgvector. Semantic deduplication uses pgvector cosine distance instead of brute-force.
func NewMemoryStore ¶
func NewMemoryStore(pool *pgxpool.Pool, opts ...Option) *MemoryStore
NewMemoryStore creates a MemoryStore using an existing pgxpool.Pool. The caller owns the pool and is responsible for closing it. Accepts the same Option functions as New (e.g. WithEmbeddingDimension, WithHNSWM, WithEFConstruction).
func (*MemoryStore) BuildContext ¶
BuildContext builds a markdown summary of known user facts for LLM context.
func (*MemoryStore) DecayOldFacts ¶
func (s *MemoryStore) DecayOldFacts(ctx context.Context) error
DecayOldFacts reduces confidence of stale facts and prunes very low ones. Facts older than 7 days get confidence * 0.95. Facts with confidence < 0.3 and age > 30 days are deleted.
func (*MemoryStore) DeleteFact ¶
func (s *MemoryStore) DeleteFact(ctx context.Context, factID string) error
DeleteFact removes a single fact by its ID.
func (*MemoryStore) DeleteMatchingFacts ¶
func (s *MemoryStore) DeleteMatchingFacts(ctx context.Context, pattern string) error
DeleteMatchingFacts removes facts whose text matches a LIKE pattern.
func (*MemoryStore) Init ¶
func (s *MemoryStore) Init(ctx context.Context) error
Init creates the pgvector extension, user_facts table, and HNSW index. Safe to call multiple times (all statements are idempotent).
Requires WithEmbeddingDimension to be set — pgvector HNSW indexes need typed vector(N) columns.
func (*MemoryStore) SearchFacts ¶
func (s *MemoryStore) SearchFacts(ctx context.Context, embedding []float32, topK int) ([]oasis.ScoredFact, error)
SearchFacts returns facts semantically similar to the query embedding, sorted by score descending. Only facts with confidence >= 0.3 are returned.
func (*MemoryStore) UpsertFact ¶
func (s *MemoryStore) UpsertFact(ctx context.Context, fact, category string, embedding []float32) error
UpsertFact inserts a new fact or merges with an existing one if cosine similarity exceeds 0.85. Merging updates the text and bumps confidence.
type Option ¶ added in v0.5.0
type Option func(*pgConfig)
Option configures a PostgreSQL Store or MemoryStore.
func WithEFConstruction ¶ added in v0.5.0
WithEFConstruction sets the HNSW ef_construction parameter (build-time candidate list size). Higher values improve index quality at the cost of slower builds. Default: pgvector's 64. Only affects index creation (CREATE INDEX IF NOT EXISTS).
func WithEFSearch ¶ added in v0.5.0
WithEFSearch sets the HNSW ef_search parameter (query-time candidate list size). Higher values improve recall at the cost of latency. Default: pgvector's 40. Applied via SET (session-level) during Init().
func WithEmbeddingDimension ¶ added in v0.5.0
WithEmbeddingDimension sets the vector column dimension (e.g. 1536, 768). When set, CREATE TABLE uses vector(N) instead of untyped vector, enabling better index optimization and catching dimension mismatches at insert time. Only affects new table creation (no ALTER on existing tables).
func WithHNSWM ¶ added in v0.5.0
WithHNSWM sets the HNSW m parameter (max connections per node). Higher values improve recall at the cost of memory. Default: pgvector's 16. Only affects index creation (CREATE INDEX IF NOT EXISTS).
func WithLogger ¶ added in v0.10.0
WithLogger sets a structured logger for the store. When set, the store emits debug logs for every operation including timing, row counts, and key parameters. If not set, no logs are emitted.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements oasis.Store backed by PostgreSQL with pgvector. Vector search uses HNSW indexes with cosine distance.
func New ¶
New creates a Store using an existing pgxpool.Pool. The caller owns the pool and is responsible for closing it.
func (*Store) CreateScheduledAction ¶
func (*Store) CreateThread ¶
CreateThread inserts a new thread.
func (*Store) DeleteAllScheduledActions ¶
func (*Store) DeleteCheckpoint ¶ added in v0.10.0
DeleteCheckpoint removes an ingest checkpoint by ID.
func (*Store) DeleteDocument ¶ added in v0.5.0
DeleteDocument removes a document and all its chunks in a single transaction.
func (*Store) DeleteScheduledAction ¶
func (*Store) DeleteThread ¶
DeleteThread removes a thread and its messages.
func (*Store) FindScheduledActionsByDescription ¶
func (*Store) GetBothEdges ¶ added in v0.10.0
GetBothEdges returns both outgoing and incoming edges for the given chunk IDs in a single query. Implements oasis.BidirectionalGraphStore.
func (*Store) GetChunksByDocument ¶ added in v0.10.0
GetChunksByDocument returns all chunks belonging to a specific document, including their embeddings. This implements ingest.DocumentChunkLister.
func (*Store) GetChunksByIDs ¶
GetChunksByIDs returns chunks matching the given IDs.
func (*Store) GetDocumentsByIDs ¶ added in v0.10.0
GetDocumentsByIDs returns documents matching the given IDs.
func (*Store) GetDueScheduledActions ¶
func (*Store) GetIncomingEdges ¶ added in v0.6.0
func (*Store) GetMessages ¶
func (s *Store) GetMessages(ctx context.Context, threadID string, limit int) ([]oasis.Message, error)
GetMessages returns the most recent messages for a thread, ordered chronologically (oldest first).
func (*Store) Init ¶
Init creates the pgvector extension, all required tables, and indexes. Safe to call multiple times (all statements are idempotent).
Requires WithEmbeddingDimension to be set — pgvector HNSW indexes need typed vector(N) columns.
func (*Store) ListCheckpoints ¶ added in v0.10.0
ListCheckpoints returns all stored ingest checkpoints.
func (*Store) ListDocumentMeta ¶ added in v0.10.0
ListDocumentMeta returns all documents without the Content field, ordered by creation time (newest first). Use this instead of ListDocuments when only ID, Title, Source, and CreatedAt are needed to avoid loading large document bodies into memory.
func (*Store) ListDocuments ¶ added in v0.5.0
ListDocuments returns all documents ordered by most recently created first.
func (*Store) ListScheduledActions ¶
func (*Store) ListThreads ¶
ListThreads returns threads for a chatID, ordered by most recently updated first.
func (*Store) LoadCheckpoint ¶ added in v0.10.0
LoadCheckpoint retrieves an ingest checkpoint by ID.
func (*Store) PruneOrphanEdges ¶ added in v0.6.0
func (*Store) SaveCheckpoint ¶ added in v0.10.0
SaveCheckpoint upserts an ingest checkpoint by ID.
func (*Store) SearchChunks ¶
func (s *Store) SearchChunks(ctx context.Context, embedding []float32, topK int, filters ...oasis.ChunkFilter) ([]oasis.ScoredChunk, error)
SearchChunks performs vector similarity search over document chunks using pgvector's cosine distance operator with HNSW index.
func (*Store) SearchChunksKeyword ¶
func (s *Store) SearchChunksKeyword(ctx context.Context, query string, topK int, filters ...oasis.ChunkFilter) ([]oasis.ScoredChunk, error)
SearchChunksKeyword performs full-text keyword search over document chunks using PostgreSQL tsvector/tsquery with a GIN index.
func (*Store) SearchMessages ¶
func (s *Store) SearchMessages(ctx context.Context, embedding []float32, topK int) ([]oasis.ScoredMessage, error)
SearchMessages performs vector similarity search over messages using pgvector's cosine distance operator with HNSW index.
func (*Store) StoreDocument ¶
StoreDocument inserts a document and all its chunks in a single transaction.
func (*Store) StoreEdges ¶ added in v0.6.0
func (*Store) StoreMessage ¶
StoreMessage inserts or replaces a message.