sqlite

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package sqlite is an agentmemory.Store over one SQLite database file with full-text search. It is a nested module so the driver (modernc.org/sqlite, pure Go) stays out of the root module's dependency graph. Entries are rows of memory_entries, the journal is memory_journal, whose line column holds the same JSON record filestore's journal.jsonl would, so a database can be dumped to that file without conversion, and Search runs over memory_entries_fts, an FTS5 index of each entry's name, meta and content, ranked by relevance. Every table is prefixed memory_, so the file can be shared with other stores, such as agentsession's.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Store)

Option configures Open.

func WithClock

func WithClock(now func() time.Time) Option

WithClock sets the clock that stamps Updated and At, for tests that want a fixed one.

func WithMaxEntryBytes

func WithMaxEntryBytes(n int) Option

WithMaxEntryBytes sets the content bound; the default is agentmemory.DefaultMaxEntryBytes.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a SQLite-backed agentmemory.Store. It is safe for concurrent use within one process, and several processes may share the file: every write is one immediate transaction, so writers queue on the database's own lock.

func Open

func Open(path string, opts ...Option) (*Store, error)

Open opens or creates the database at path and applies the schema. Every connection runs in WAL mode with a busy timeout, and writes go through a single-connection pool so writers queue instead of failing.

func (*Store) Close

func (s *Store) Close() error

Close runs PRAGMA optimize and closes both pools.

func (*Store) Forget

func (s *Store) Forget(ctx context.Context, scope agentmemory.Scope, name string) (*agentmemory.Change, error)

Forget implements agentmemory.Store.

func (*Store) Get

func (s *Store) Get(ctx context.Context, scope agentmemory.Scope, name string) (*agentmemory.Entry, error)

Get implements agentmemory.Store.

func (*Store) Journal

func (s *Store) Journal(ctx context.Context, after uint64) iter.Seq2[agentmemory.Change, error]

Journal implements agentmemory.Store.

func (*Store) LastSeq added in v0.0.11

func (s *Store) LastSeq(ctx context.Context) (uint64, error)

LastSeq implements agentmemory.LastSeqer: the largest seq in the journal table, a row whose line does not decode included, since the next record is numbered after it.

func (*Store) List

func (s *Store) List(ctx context.Context, scope agentmemory.Scope) ([]agentmemory.Entry, error)

List implements agentmemory.Store.

func (*Store) MaxEntryBytes

func (s *Store) MaxEntryBytes() int

MaxEntryBytes implements agentmemory.Store.

func (*Store) Path

func (s *Store) Path() string

Path returns the database file.

func (*Store) Put

Put implements agentmemory.Store: one immediate transaction reads the stored entry, checks the bound and the precondition against it, writes the row, refreshes the search index and appends the journal record with the next sequence number.

func (*Store) Search

func (s *Store) Search(ctx context.Context, scopes []agentmemory.Scope, query string, limit int) ([]agentmemory.Entry, error)

Search implements agentmemory.Store over the FTS5 index: every word of the query must match a token of the entry's name, meta or content, as a prefix and ignoring case, and results come in relevance order, then by scope and name. An empty query lists the scopes' entries in scope order then name.

func (*Store) SearchOptions added in v0.0.11

func (s *Store) SearchOptions() []string

SearchOptions implements agentmemory.Searcher: every option.

func (*Store) SearchWith added in v0.0.11

func (s *Store) SearchWith(ctx context.Context, scopes []agentmemory.Scope, query string, limit int, opts agentmemory.SearchOptions) ([]agentmemory.Entry, error)

SearchWith implements agentmemory.Searcher. Under Any a word need match only one token, and the index ranks the entries by bm25, so an entry matching more of the words, and rarer ones, comes first. Meta and the updated bounds are applied to what the index returns, before the limit.

Jump to

Keyboard shortcuts

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