sqlite_blob

package
v2.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package sqlite_blob implements the always-available zero-CGO VectorIndex adapter (ADR-05, REQ-VEC-001).

It wraps the existing SQLite BLOB vector scan (internal/store/sqlite) behind the domain.VectorIndex port. This is the single highest-leverage change of the vector modernization: bundle.Stores.Vectors changes from the concrete *sqlite.VectorStore to domain.VectorIndex, unblocking every future adapter (qdrant, pgvector) without touching MCP/HTTP/CLI/TUI.

Build-tag semantics are PRESERVED EXACTLY:

  • Default build (cortex_vectors NOT set, zero-CGO): the underlying sqlite.VectorStore is the stub that returns ErrVectorSearchDisabled. This adapter reports unhealthy/degraded and passes the disabled error through. No external service, no CGO.
  • cortex_vectors build tag: the underlying sqlite.VectorStore is the full O(N) cosine BLOB scan. This adapter delegates to it and reports healthy.

Dimension-mismatch corruption is FIXED (REQ-VEC-001 error scenario): the legacy cosine path logged a warning and scored mismatched vectors 0 (silent corruption). This adapter REJECTS any upsert whose vector dimension does not match the declared ModelInfo.Dimension with domain.ErrDimensionMismatch — the mismatched vector is never stored.

The adapter does NOT own the *sql.DB or the observation_vectors schema — it delegates to the existing concrete store, preserving byte-for-byte local behavior. Qdrant and pgvector adapters are separate (W8.2/W8.3).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter wraps the existing concrete *sqlite.VectorStore as a domain.VectorIndex. It is the zero-CGO default and is always available for wiring (operations return ErrVectorSearchDisabled when the cortex_vectors tag is not set).

func New

func New(db *sql.DB) *Adapter

New creates a sqlite_blob adapter over the existing concrete VectorStore. The db may be nil for capability/health-only wiring (tests, capability negotiation before the database is open). A nil db produces a stub store that reports unavailable, matching the zero-CGO default.

func (*Adapter) Capabilities

func (a *Adapter) Capabilities(_ context.Context) (domain.Capabilities, error)

Capabilities declares the sqlite_blob adapter's supported features for capability-driven strategy selection (ADR-05). sqlite_blob is an exact O(N) cosine scan with post-filtering, strong consistency (same SQLite tx), and batch upsert support.

func (*Adapter) Close

func (a *Adapter) Close() error

Close releases resources. sqlite_blob holds no resources beyond the shared *sql.DB (owned by the caller), so Close is a no-op.

func (*Adapter) Delete

func (a *Adapter) Delete(ctx context.Context, ids []int64) error

Delete removes vectors by observation ID. The underlying store's DeleteEmbedding handles the not-found case; missing IDs in the batch are tolerated (idempotent delete).

func (*Adapter) Health

func (a *Adapter) Health(_ context.Context) domain.Health

Health reports the adapter's current health. When the underlying store is unavailable (zero-CGO stub), Health returns degraded with a diagnostic message. When the store is available (cortex_vectors enabled), Health returns healthy.

func (*Adapter) ID

func (a *Adapter) ID() string

ID returns the stable adapter identifier.

func (*Adapter) Search

Search translates a domain.VectorQuery into the underlying store's VectorSearchOptions and returns VectorCandidate results. Filters map "project"/"scope" onto the legacy Project/Scope fields, preserving exact local behavior.

func (*Adapter) Upsert

func (a *Adapter) Upsert(ctx context.Context, points []domain.VectorPoint) error

Upsert stores a batch of vectors. Each point's vector dimension MUST match its declared ModelInfo.Dimension; a mismatch is rejected with domain.ErrDimensionMismatch (REQ-VEC-001 dim-mismatch corruption pin). The mismatched point and every subsequent point in the batch are rejected — the caller treats the batch atomically.

Model-version namespace: the ModelInfo.Name is forwarded to the underlying store so vectors are namespaced by model, preventing cross-model corruption.

Jump to

Keyboard shortcuts

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