Documentation
¶
Index ¶
- Variables
- type Adapter
- type Filters
- type PostgresAdapter
- func (a *PostgresAdapter) Close() error
- func (a *PostgresAdapter) Delete(ctx context.Context, id string) error
- func (a *PostgresAdapter) Get(ctx context.Context, id string) (*model.Note, error)
- func (a *PostgresAdapter) List(ctx context.Context, filters Filters, limit, offset int) ([]*model.Note, error)
- func (a *PostgresAdapter) MatchIDs(ctx context.Context, prefix string, limit int) ([]string, error)
- func (a *PostgresAdapter) Save(ctx context.Context, note *model.Note) (string, error)
- func (a *PostgresAdapter) SearchSimilar(ctx context.Context, vec []float32, topK int, filters Filters) ([]*model.Note, error)
- func (a *PostgresAdapter) SetSummary(ctx context.Context, id, summary string) error
- func (a *PostgresAdapter) UncheckedSensitive(ctx context.Context) ([]*model.Note, error)
- type SQLiteAdapter
- func (a *SQLiteAdapter) Close() error
- func (a *SQLiteAdapter) Delete(ctx context.Context, id string) error
- func (a *SQLiteAdapter) Get(ctx context.Context, id string) (*model.Note, error)
- func (a *SQLiteAdapter) List(ctx context.Context, filters Filters, limit, offset int) ([]*model.Note, error)
- func (a *SQLiteAdapter) MatchIDs(ctx context.Context, prefix string, limit int) ([]string, error)
- func (a *SQLiteAdapter) Save(ctx context.Context, note *model.Note) (string, error)
- func (a *SQLiteAdapter) SearchSimilar(ctx context.Context, vec []float32, topK int, filters Filters) ([]*model.Note, error)
- func (a *SQLiteAdapter) SetSummary(ctx context.Context, id, summary string) error
- func (a *SQLiteAdapter) UncheckedSensitive(ctx context.Context) ([]*model.Note, error)
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("note not found")
ErrNotFound is returned by Get and Delete when no note has the given ID.
var ErrSchemaTooNew = errors.New("database schema is newer than this version of inode supports; upgrade inode")
ErrSchemaTooNew is returned when a database was migrated by a newer inode than the one opening it. Opening it anyway could corrupt data the older code does not understand.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter interface {
// Save persists a note with its embedding. Returns the assigned ID.
Save(ctx context.Context, note *model.Note) (string, error)
// Get fetches a single note by its full ID. Returns ErrNotFound if absent.
Get(ctx context.Context, id string) (*model.Note, error)
// Delete removes a note by its full ID. Returns ErrNotFound if absent.
Delete(ctx context.Context, id string) error
// MatchIDs returns up to limit full IDs that start with prefix, compared
// literally (no wildcards), in ID order. Callers resolve short IDs with it.
MatchIDs(ctx context.Context, prefix string, limit int) ([]string, error)
// SearchSimilar returns the top-K notes by cosine similarity to vec,
// optionally filtered by Filters.
SearchSimilar(ctx context.Context, vec []float32, topK int, filters Filters) ([]*model.Note, error)
// List returns notes matching filters, with pagination.
List(ctx context.Context, filters Filters, limit, offset int) ([]*model.Note, error)
// UncheckedSensitive returns sensitive notes whose summary has not yet
// been validated against their content (notes saved before v0.5.0).
UncheckedSensitive(ctx context.Context) ([]*model.Note, error)
// SetSummary replaces a note's summary by full ID and marks it validated.
SetSummary(ctx context.Context, id, summary string) error
// Close releases the database connection.
Close() error
}
Adapter defines the contract for all database backends. Implementations: sqlite.go (Phase 1), postgres.go (Phase 2).
type PostgresAdapter ¶
type PostgresAdapter struct {
// contains filtered or unexported fields
}
PostgresAdapter implements db.Adapter using PostgreSQL + pgvector.
Compared to the SQLite path, this backend stores the embedding inline on the notes table (pgvector's vector(N) column type) rather than in a separate virtual table. L2 distance is computed by the `<->` operator, matching sqlite-vec's metric so the relevance threshold is portable.
id is stored as TEXT (not UUID) so prefix-match semantics on Get/Delete stay identical to the SQLite implementation.
func NewPostgresAdapter ¶
NewPostgresAdapter connects to Postgres, registers pgvector types, and runs migrations. The DSN follows libpq format, e.g.:
postgres://user:pass@host:5432/db?sslmode=disable
The pgvector extension is created if missing — the connecting role therefore needs CREATE privilege on the database (superuser in the standard pgvector/pgvector Docker image).
func (*PostgresAdapter) Delete ¶
func (a *PostgresAdapter) Delete(ctx context.Context, id string) error
Delete removes a note by full ID.
func (*PostgresAdapter) List ¶
func (a *PostgresAdapter) List(ctx context.Context, filters Filters, limit, offset int) ([]*model.Note, error)
List returns notes matching filters with pagination.
func (*PostgresAdapter) MatchIDs ¶ added in v0.5.1
MatchIDs returns up to limit IDs starting with prefix. left() compares the prefix literally, so % and _ in the input are not wildcards.
func (*PostgresAdapter) SearchSimilar ¶
func (a *PostgresAdapter) SearchSimilar(ctx context.Context, vec []float32, topK int, filters Filters) ([]*model.Note, error)
SearchSimilar returns top-K notes by L2 distance to vec, ascending. Each returned note has Distance populated from the pgvector `<->` operator.
Category filter is pushed down; tag filter is applied in-memory after fetching to match the SQLite path's semantics (OR across tags, not AND).
func (*PostgresAdapter) SetSummary ¶
func (a *PostgresAdapter) SetSummary(ctx context.Context, id, summary string) error
SetSummary replaces a note's summary and marks it validated.
func (*PostgresAdapter) UncheckedSensitive ¶
UncheckedSensitive returns sensitive notes whose summary has not been validated against their content.
type SQLiteAdapter ¶
type SQLiteAdapter struct {
// contains filtered or unexported fields
}
SQLiteAdapter implements DBAdapter using SQLite + sqlite-vec.
func NewSQLiteAdapter ¶
func NewSQLiteAdapter(path string, dimension int) (*SQLiteAdapter, error)
NewSQLiteAdapter opens (or creates) the SQLite database and runs migrations. dimension is the embedding vector size (e.g. 768 for nomic-embed-text, 1024 for voyage-3).
func (*SQLiteAdapter) Close ¶
func (a *SQLiteAdapter) Close() error
Close releases the database connection.
func (*SQLiteAdapter) Delete ¶
func (a *SQLiteAdapter) Delete(ctx context.Context, id string) error
Delete removes a note and its embedding by full ID.
func (*SQLiteAdapter) List ¶
func (a *SQLiteAdapter) List(ctx context.Context, filters Filters, limit, offset int) ([]*model.Note, error)
List returns notes matching filters with pagination.
func (*SQLiteAdapter) MatchIDs ¶ added in v0.5.1
MatchIDs returns up to limit IDs starting with prefix. substr compares the prefix literally, so % and _ in the input are not wildcards.
func (*SQLiteAdapter) SearchSimilar ¶
func (a *SQLiteAdapter) SearchSimilar(ctx context.Context, vec []float32, topK int, filters Filters) ([]*model.Note, error)
SearchSimilar returns top-K notes by L2 distance to vec, in ascending order. Each returned note has its Distance field populated.
func (*SQLiteAdapter) SetSummary ¶
func (a *SQLiteAdapter) SetSummary(ctx context.Context, id, summary string) error
SetSummary replaces a note's summary and marks it validated.
func (*SQLiteAdapter) UncheckedSensitive ¶
scanNote scans a single row into a Note. UncheckedSensitive returns sensitive notes whose summary has not been validated against their content.