sqlite

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package sqlite implements consolidate.Store on SQLite via Ent (github.com/plexusone/omnisignal/consolidate), plus embedding similarity search over the persisted corpus via sqlite-vec (modernc.org/sqlite/vec)'s vec0 virtual tables.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a requested Signal or RootCause doesn't exist.
	ErrNotFound = errors.New("sqlite: not found")

	// ErrDimensionRequired is returned by Open when no embedding dimension
	// was configured via WithEmbeddingDimension.
	ErrDimensionRequired = errors.New("sqlite: embedding dimension is required (WithEmbeddingDimension)")

	// ErrDimensionMismatch is returned when a saved embedding's length
	// doesn't match the store's configured dimension.
	ErrDimensionMismatch = errors.New("sqlite: embedding length does not match configured dimension")
)

Functions

This section is empty.

Types

type DistanceMetric

type DistanceMetric string

DistanceMetric selects the sqlite-vec distance function used by NearestRootCauses and NearestSignals.

const (
	// DistanceCosine ranks by cosine distance (the default).
	DistanceCosine DistanceMetric = "cosine"
	// DistanceL2 ranks by Euclidean (L2) distance.
	DistanceL2 DistanceMetric = "l2"
)

type Option

type Option func(*options)

Option configures a Store.

func WithDistanceMetric

func WithDistanceMetric(m DistanceMetric) Option

WithDistanceMetric sets the similarity metric used by nearest-neighbor queries. Defaults to DistanceCosine.

func WithEmbeddingDimension

func WithEmbeddingDimension(n int) Option

WithEmbeddingDimension sets the fixed vector length stored in the vec0 tables. Required — Open returns ErrDimensionRequired if unset, since the store has no way to infer the dimension of whichever embedder callers use.

type Store

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

Store persists signals and root causes to a local SQLite file, with sqlite-vec-backed similarity search over their embeddings. It implements consolidate.Store.

func Open

func Open(dbPath string, opts ...Option) (*Store, error)

Open opens or creates a SQLite database at dbPath, creating the Ent-managed tables and the sqlite-vec vec0 tables if they don't already exist. Safe to call repeatedly against an existing, populated file (schema creation is append-only, mirroring aha-studio's sync.Open).

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection (and the Ent client sharing it).

func (*Store) GetLinkedSignals

func (s *Store) GetLinkedSignals(ctx context.Context, rootCauseID string) ([]string, error)

GetLinkedSignals returns the signal IDs currently linked to rootCauseID.

func (*Store) GetRootCause

func (s *Store) GetRootCause(ctx context.Context, id string) (rootcause.RootCause, error)

GetRootCause retrieves a root cause by ID, with SignalIDs populated from the link table.

func (*Store) GetSignal

func (s *Store) GetSignal(ctx context.Context, id string) (signal.Signal, error)

GetSignal retrieves a signal by ID, with RootCauseID populated from the link table if one exists.

func (*Store) LinkSignal

func (s *Store) LinkSignal(ctx context.Context, signalID, rootCauseID string) error

LinkSignal associates signalID with rootCauseID, upserting by signalID so a signal reattached to a different root cause (e.g. after reject -> re-review) moves the pointer instead of accumulating duplicate links.

func (*Store) ListRootCauses

func (s *Store) ListRootCauses(ctx context.Context, filter consolidate.RootCauseFilter) ([]rootcause.RootCause, error)

ListRootCauses returns root causes matching filter, ordered by FirstSeen descending (most recent first).

func (*Store) NearestRootCauses

func (s *Store) NearestRootCauses(ctx context.Context, embedding []float32, topK int) ([]rootcause.RootCause, error)

NearestRootCauses returns the topK root causes whose embeddings are nearest to embedding, ordered nearest-first, via a sqlite-vec KNN query. This is the corpus-scale similarity search lever that consolidate.Pipeline's in-memory brute-force cosine comparison doesn't have; wiring it into Pipeline.Attach's caller is follow-up work, not part of this store.

func (*Store) SaveRootCause

func (s *Store) SaveRootCause(ctx context.Context, rc rootcause.RootCause) error

SaveRootCause persists a root cause, upserting by ID, plus its embedding (if set) into rootcause_vec. See the package doc on transaction handling: the Ent row is written first, so a failure upserting the embedding leaves the row intact and safe to repair by calling SaveRootCause again (idempotent), rather than risking a half-shared transaction across Ent's ORM layer and the hand-written vec0 SQL.

func (*Store) SaveSignal

func (s *Store) SaveSignal(ctx context.Context, sig signal.Signal) error

SaveSignal persists a signal, upserting by ID (the identity a provider assigns to the same source event across re-ingestion runs; Fingerprint carries its own separate unique index as a content-dedup guard), plus its embedding (if set) into signal_vec. Same non-transactional ordering rationale as SaveRootCause: the Ent row lands first, so a failed embedding write is safe to repair with a retried, idempotent SaveSignal call.

Directories

Path Synopsis
ent

Jump to

Keyboard shortcuts

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