Documentation
¶
Overview ¶
Package sqlindex implements a persistent SQLite-backed keyword and embedding index with per-content-hash embedding caching.
The schema:
concepts(id TEXT PRIMARY KEY, content_hash TEXT NOT NULL, body TEXT NOT NULL) concepts_fts — FTS5 virtual table with trigram tokenizer embeddings(id TEXT PRIMARY KEY, content_hash TEXT NOT NULL, model TEXT NOT NULL, vec BLOB NOT NULL)
Index ¶
- type Hit
- type Index
- func (ix *Index) AllEmbeddings() (ids []string, vecs [][]float64, model string, err error)
- func (ix *Index) Close() error
- func (ix *Index) Count() (int, error)
- func (ix *Index) Delete(id string) error
- func (ix *Index) EmbeddingFresh(id, contentHash string) (bool, error)
- func (ix *Index) Path() string
- func (ix *Index) SearchFTS(query, scope string, limit int) ([]Hit, error)
- func (ix *Index) Upsert(id, contentHash, body string) error
- func (ix *Index) UpsertEmbedding(id, contentHash, model string, vec []float64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hit ¶
type Hit struct {
ID string
Score float64
Snippet string // excerpt around the match, from FTS5's native snippet()
}
Hit is a single search result.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is a persistent SQLite-backed search and embedding index.
func Open ¶
Open opens a SQLite index at dbPath. It creates the schema if it does not exist and enables WAL mode. If FTS5 support is missing, Open returns an error — the caller should fall back to the in-memory path.
func (*Index) AllEmbeddings ¶
AllEmbeddings reads all stored embedding vectors. Returns parallel slices of ids and vectors, plus the model identifier. If no embeddings are stored, returns nil slices and empty model.
func (*Index) Delete ¶
Delete removes a concept's content from both the concepts table and the FTS5 index (used by concept_delete). It does not touch the embeddings table: a stale cached embedding for a removed id is harmless, since it is only ever looked up by content-hash match on a live concept.
func (*Index) EmbeddingFresh ¶
EmbeddingFresh returns true if an embedding exists for the given id with a matching content hash (i.e. the cached embedding is still valid).
func (*Index) SearchFTS ¶
SearchFTS performs a keyword search via FTS5 trigram tokenizer. If scope is non-empty, only concepts whose id starts with scope are returned. Results are sorted by BM25 relevance (higher score = better match). Each hit carries a Snippet excerpt produced by FTS5's native snippet() function.