sqlindex

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func Open(dbPath string) (*Index, error)

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

func (ix *Index) AllEmbeddings() (ids []string, vecs [][]float64, model string, err error)

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) AllHashes added in v0.2.0

func (ix *Index) AllHashes() (map[string]string, error)

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) Close

func (ix *Index) Close() error

Close closes the underlying database connection.

func (*Index) Count

func (ix *Index) Count() (int, error)

Count returns the number of indexed concepts.

func (*Index) Delete

func (ix *Index) Delete(id string) error

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

func (ix *Index) EmbeddingFresh(id, contentHash string) (bool, error)

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) Path

func (ix *Index) Path() string

Path returns the filesystem path of the SQLite database.

func (*Index) SearchFTS

func (ix *Index) SearchFTS(query, scope string, limit int) ([]Hit, error)

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) Upsert

func (ix *Index) Upsert(id, contentHash, body string) error

Upsert inserts or updates a concept's content in both the concepts table and the FTS5 index.

func (*Index) UpsertEmbedding

func (ix *Index) UpsertEmbedding(id, contentHash, model string, vec []float64) error

UpsertEmbedding stores (or replaces) an embedding vector for a concept. vec is serialized as a blob of float64 values in little-endian order.

Jump to

Keyboard shortcuts

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