sqlindex

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 7 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 index.

The schema:

concepts(id TEXT PRIMARY KEY, content_hash TEXT NOT NULL, body TEXT NOT NULL)
concepts_fts — FTS5 virtual table with trigram tokenizer

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

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

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

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.

Jump to

Keyboard shortcuts

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