Documentation
¶
Overview ¶
Package sqlindex implements a persistent SQLite-backed keyword index.
The schema:
concepts(id TEXT PRIMARY KEY, content_hash TEXT NOT NULL, body TEXT NOT NULL) concepts_fts(id UNINDEXED, title, meta, body) — FTS5, trigram tokenizer with diacritics removed, ranked by bm25 weights 5 / 2 / 1 (D246)
The schema version lives in PRAGMA user_version (schemaVersion). Opening an older database recreates concepts_fts and empties concepts: the index is disposable, and the next reconciliation reindexes every concept.
A database created before D135 may still carry an embeddings table: it is never read nor written, and opening such a file is not an error.
Index ¶
- type Hit
- type Index
- func (ix *Index) AllHashes() (map[string]string, error)
- func (ix *Index) Close() error
- func (ix *Index) Count() (int, error)
- func (ix *Index) Delete(id string) error
- func (ix *Index) SearchFTS(query, scope string, limit int) ([]Hit, error)
- func (ix *Index) SearchFTSFiltered(query, scope string, limit int, allow func(id string) bool) ([]Hit, error)
- func (ix *Index) Upsert(id, contentHash, body string) 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) AllHashes ¶ added in v0.2.0
AllHashes returns the persisted content hash for every indexed concept. Callers use it to reconcile the derived index with the KB files on disk.
func (*Index) Delete ¶
Delete removes a concept's content from both the concepts table and the FTS5 index (used by concept_delete).
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.
func (*Index) SearchFTSFiltered ¶ added in v0.4.0
func (ix *Index) SearchFTSFiltered(query, scope string, limit int, allow func(id string) bool) ([]Hit, error)
SearchFTSFiltered scans ranked FTS rows in bounded pages until it collects limit allowed hits or reaches EOF. The predicate is applied before a hit is returned, preventing IDs, snippets, and result counts of hidden concepts from escaping into caller-visible pagination.