Documentation
¶
Overview ¶
Package sqlite provides an embedded memory.Store backed by SQLite.
Lexical retrieval uses an FTS5 virtual table with the built-in BM25 ranker; vector retrieval computes cosine similarity in process. The two modes are picked per query: when memory.Query.Embedding is set, vector search runs; otherwise FTS5 BM25 runs on memory.Query.Text. Hybrid scoring is left as a future optimization.
A metadata equality filter (memory.Query.Filter) is pushed into SQL via json_extract on the vector path, so a scoped query — e.g. a single topic — only reads and scores the matching subset instead of the whole table.
The backing driver is the pure-Go modernc.org/sqlite — no CGO and therefore no platform-specific build hurdles. The cost is that very large, unfiltered corpora hit the brute-force cosine path; pgvector / qdrant adapters land in their own modules for that case.
Index ¶
- type Store
- func (s *Store) Add(ctx context.Context, chunks []memory.Chunk) error
- func (s *Store) Close() error
- func (s *Store) Delete(ctx context.Context, documentID string) error
- func (s *Store) Len(ctx context.Context) (int, error)
- func (s *Store) Retrieve(ctx context.Context, q memory.Query) ([]memory.Result, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a SQLite-backed memory.Store. Open returns a usable instance; Close releases the underlying *sql.DB.
The store is goroutine-safe (delegated to database/sql's connection pool). Concurrent Add and Retrieve calls are supported; FTS5 updates are wrapped in a transaction per Add.
func Open ¶
Open opens (or creates) a SQLite database at the given path. Use ":memory:" for an ephemeral in-process database, useful for tests. The schema is created on first open and is idempotent across re-opens.
func (*Store) Add ¶
Add ingests chunks. Chunks with an empty ID are rejected (callers are expected to assign IDs; see uuid.NewString or any stable hash of the chunk content). Re-adding a chunk with an existing ID overwrites the previous entry, making re-ingestion idempotent.
func (*Store) Delete ¶
Delete removes every chunk whose DocumentID matches the argument. Returns nil even when no chunks were removed (idempotent).
func (*Store) Len ¶
Len reports the total number of chunks currently stored. Not part of the Store interface; useful for tests.