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 ¶
- Variables
- type DistanceMetric
- type Option
- type Store
- func (s *Store) Close() error
- func (s *Store) GetLinkedSignals(ctx context.Context, rootCauseID string) ([]string, error)
- func (s *Store) GetRootCause(ctx context.Context, id string) (rootcause.RootCause, error)
- func (s *Store) GetSignal(ctx context.Context, id string) (signal.Signal, error)
- func (s *Store) LinkSignal(ctx context.Context, signalID, rootCauseID string) error
- func (s *Store) ListRootCauses(ctx context.Context, filter consolidate.RootCauseFilter) ([]rootcause.RootCause, error)
- func (s *Store) NearestRootCauses(ctx context.Context, embedding []float32, topK int) ([]rootcause.RootCause, error)
- func (s *Store) SaveRootCause(ctx context.Context, rc rootcause.RootCause) error
- func (s *Store) SaveSignal(ctx context.Context, sig signal.Signal) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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) GetLinkedSignals ¶
GetLinkedSignals returns the signal IDs currently linked to rootCauseID.
func (*Store) GetRootCause ¶
GetRootCause retrieves a root cause by ID, with SignalIDs populated from the link table.
func (*Store) GetSignal ¶
GetSignal retrieves a signal by ID, with RootCauseID populated from the link table if one exists.
func (*Store) LinkSignal ¶
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 ¶
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 ¶
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.