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 ¶
- type Adapter
- func (a *Adapter) Capabilities(_ context.Context) (domain.Capabilities, error)
- func (a *Adapter) Close() error
- func (a *Adapter) Delete(ctx context.Context, ids []int64) error
- func (a *Adapter) Health(_ context.Context) domain.Health
- func (a *Adapter) ID() string
- func (a *Adapter) Search(ctx context.Context, q domain.VectorQuery) ([]domain.VectorCandidate, error)
- func (a *Adapter) Upsert(ctx context.Context, points []domain.VectorPoint) error
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) Search ¶
func (a *Adapter) Search(ctx context.Context, q domain.VectorQuery) ([]domain.VectorCandidate, error)
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 ¶
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.