sqlite

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSchemaVersion

func GetSchemaVersion(ctx context.Context, db *sql.DB) (int, error)

GetSchemaVersion returns the current schema version.

func IsFTS5Available

func IsFTS5Available(ctx context.Context, db *sql.DB) bool

IsFTS5Available checks if FTS5 was successfully initialized.

Types

type Backend

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

Backend implements storage.Backend using SQLite with the vec0 extension.

func New

func New(cfg *config.Config) (*Backend, error)

New creates a new SQLite storage backend.

func NewWithDB

func NewWithDB(db *sql.DB) *Backend

NewWithDB creates a Backend with an existing database connection. Useful for testing with in-memory databases.

func (*Backend) AppendMessage

func (b *Backend) AppendMessage(ctx context.Context, msg *types.Message) error

AppendMessage adds a message to a thread, creating the thread if it doesn't exist.

func (*Backend) Backup

func (b *Backend) Backup(ctx context.Context, destPath string) error

Backup creates a consistent backup of the database to the specified path. This uses SQLite's online backup API for hot backups without downtime.

func (*Backend) BackupWithProgress

func (b *Backend) BackupWithProgress(ctx context.Context, destPath string, progress func(BackupProgress)) error

BackupWithProgress creates a backup with progress callback. The progress function is called periodically during the backup.

func (*Backend) CleanupContextHistory

func (b *Backend) CleanupContextHistory(ctx context.Context, olderThan time.Duration) (int64, error)

CleanupContextHistory removes context version history entries older than the specified duration. Returns the number of history entries deleted.

func (*Backend) CleanupExpiredContext

func (b *Backend) CleanupExpiredContext(ctx context.Context) (int64, error)

CleanupExpiredContext removes entries past their TTL expiration. Returns the number of entries deleted.

func (*Backend) CleanupOldRunContext

func (b *Backend) CleanupOldRunContext(ctx context.Context, olderThan time.Duration) (int64, error)

CleanupOldRunContext removes run-scoped context entries older than the specified duration. Returns the number of entries deleted.

func (*Backend) CleanupRunContext

func (b *Backend) CleanupRunContext(ctx context.Context, namespace, runID string) error

CleanupRunContext removes all context entries for a specific run.

func (*Backend) Close

func (b *Backend) Close() error

Close closes the database connection.

func (*Backend) CollectionStats

func (b *Backend) CollectionStats(ctx context.Context, namespace, collectionID string) (*types.CollectionStats, error)

CollectionStats returns statistics for a collection.

func (*Backend) CompleteExtraction

func (b *Backend) CompleteExtraction(ctx context.Context, itemID int64, status string) error

CompleteExtraction marks an extraction queue item as completed or failed.

func (*Backend) CreateCollection

func (b *Backend) CreateCollection(ctx context.Context, col *types.Collection) error

CreateCollection creates a new collection.

func (*Backend) DB

func (b *Backend) DB() *sql.DB

DB returns the underlying database connection. Use with caution - prefer using Backend methods.

func (*Backend) DeleteCollection

func (b *Backend) DeleteCollection(ctx context.Context, namespace, collectionID string) error

DeleteCollection removes a collection and all its documents.

func (*Backend) DeleteContext

func (b *Backend) DeleteContext(ctx context.Context, namespace, key string, runID *string) error

DeleteContext removes a context entry.

func (*Backend) DeleteDocument

func (b *Backend) DeleteDocument(ctx context.Context, namespace, docID string) error

DeleteDocument removes a document and all its chunks.

func (*Backend) DeleteEntity

func (b *Backend) DeleteEntity(ctx context.Context, namespace, entityID string) error

DeleteEntity removes an entity and all its mentions/relationships.

func (*Backend) DeleteOldConversations

func (b *Backend) DeleteOldConversations(ctx context.Context, olderThan time.Duration) (int64, error)

DeleteOldConversations removes threads and their messages older than the specified duration. Returns the number of threads deleted.

func (*Backend) DeleteOrphanedChunks

func (b *Backend) DeleteOrphanedChunks(ctx context.Context) (int64, error)

DeleteOrphanedChunks removes chunks whose parent documents no longer exist. Returns the number of chunks deleted.

func (*Backend) DeleteThread

func (b *Backend) DeleteThread(ctx context.Context, namespace, threadID string) error

DeleteThread removes a thread and all its messages.

func (*Backend) DequeueExtraction

func (b *Backend) DequeueExtraction(ctx context.Context, batchSize int) ([]*types.ExtractionQueueItem, error)

DequeueExtraction retrieves pending items from the extraction queue.

func (*Backend) EnqueueExtraction

func (b *Backend) EnqueueExtraction(ctx context.Context, item *types.ExtractionQueueItem) error

EnqueueExtraction adds an item to the entity extraction queue.

func (*Backend) Export

func (b *Backend) Export(ctx context.Context, namespace string, opts storage.ExportOptions) (*storage.ExportData, error)

Export exports all data for a namespace.

func (*Backend) FTS5Available

func (b *Backend) FTS5Available(ctx context.Context) bool

FTS5Available checks if FTS5 full-text search is available.

func (*Backend) GetAdjacentChunks

func (b *Backend) GetAdjacentChunks(ctx context.Context, chunkID string, window int) ([]*types.Chunk, error)

GetAdjacentChunks retrieves chunks adjacent to a given chunk for context.

func (*Backend) GetCollection

func (b *Backend) GetCollection(ctx context.Context, namespace, collectionID string) (*types.Collection, error)

GetCollection retrieves a collection by ID.

func (*Backend) GetContext

func (b *Backend) GetContext(ctx context.Context, namespace, key string, runID *string) (*types.ContextEntry, error)

GetContext retrieves a context entry by key. runID is optional: nil means persistent (cross-run) context.

func (*Backend) GetContextHistory

func (b *Backend) GetContextHistory(ctx context.Context, namespace, key string, runID *string, cursor string, limit int) ([]*types.ContextHistoryEntry, string, error)

GetContextHistory returns the version history for a context key.

func (*Backend) GetDocument

func (b *Backend) GetDocument(ctx context.Context, namespace, docID string) (*types.Document, error)

GetDocument retrieves a document by ID.

func (*Backend) GetEntityByID

func (b *Backend) GetEntityByID(ctx context.Context, namespace, entityID string) (*types.Entity, error)

GetEntityByID retrieves an entity by its ID.

func (*Backend) GetEntityByName

func (b *Backend) GetEntityByName(ctx context.Context, namespace, name string) (*types.Entity, error)

GetEntityByName retrieves an entity by its canonical name (case-insensitive).

func (*Backend) GetExtractionQueueStats

func (b *Backend) GetExtractionQueueStats(ctx context.Context) (*storage.ExtractionQueueStats, error)

GetExtractionQueueStats returns statistics about the extraction queue.

func (*Backend) GetMentions

func (b *Backend) GetMentions(ctx context.Context, entityID string, limit int) ([]*types.EntityMention, error)

GetMentions retrieves recent mentions of an entity.

func (*Backend) GetMessages

func (b *Backend) GetMessages(ctx context.Context, namespace, threadID string, limit int, cursor string) ([]*types.Message, string, error)

GetMessages retrieves messages from a thread, ordered by creation time.

func (*Backend) GetRelationships

func (b *Backend) GetRelationships(ctx context.Context, namespace, entityID string, opts storage.RelationshipOpts) ([]*types.EntityRelationship, error)

GetRelationships retrieves relationships for an entity.

func (*Backend) GetThread

func (b *Backend) GetThread(ctx context.Context, namespace, threadID string) (*types.Thread, error)

GetThread retrieves a single thread by ID.

func (*Backend) Health

func (b *Backend) Health(ctx context.Context) error

Health checks the database connection.

func (*Backend) HybridSearchChunks

func (b *Backend) HybridSearchChunks(ctx context.Context, namespace string, query string, embedding []float32, opts storage.HybridChunkSearchOpts) ([]*types.ChunkResult, error)

HybridSearchChunks performs combined vector and full-text search on chunks. Falls back to vector-only search if FTS5 is not available.

func (*Backend) HybridSearchEntities

func (b *Backend) HybridSearchEntities(ctx context.Context, namespace string, query string, embedding []float32, opts storage.HybridEntitySearchOpts) ([]*types.EntityResult, error)

HybridSearchEntities performs combined vector and full-text search on entities. Falls back to vector-only search if FTS5 is not available.

func (*Backend) HybridSearchMessages

func (b *Backend) HybridSearchMessages(ctx context.Context, namespace string, query string, embedding []float32, opts storage.HybridSearchOpts) ([]*types.MessageResult, error)

HybridSearchMessages performs combined vector and full-text search on messages. Uses Reciprocal Rank Fusion (RRF) to combine results. Falls back to vector-only search if FTS5 is not available.

func (*Backend) InsertChunks

func (b *Backend) InsertChunks(ctx context.Context, chunks []*types.Chunk) error

InsertChunks adds chunks for a document. Embeddings should already be populated.

func (*Backend) InsertDocument

func (b *Backend) InsertDocument(ctx context.Context, doc *types.Document) error

InsertDocument adds a new document to the store.

func (*Backend) InsertMention

func (b *Backend) InsertMention(ctx context.Context, mention *types.EntityMention) error

InsertMention records a mention of an entity in source content.

func (*Backend) ListCollections

func (b *Backend) ListCollections(ctx context.Context, namespace string, cursor string, limit int) ([]*types.Collection, string, error)

ListCollections returns all collections in a namespace.

func (*Backend) ListContextKeys

func (b *Backend) ListContextKeys(ctx context.Context, namespace string, prefix *string, runID *string, cursor string, limit int) ([]string, string, error)

ListContextKeys returns all keys in a namespace, optionally filtered by prefix.

func (*Backend) ListEntities

func (b *Backend) ListEntities(ctx context.Context, namespace string, opts storage.EntityListOpts) ([]*types.Entity, string, error)

ListEntities returns entities in a namespace with optional filtering.

func (*Backend) ListThreads

func (b *Backend) ListThreads(ctx context.Context, namespace string, cursor string, limit int) ([]*types.Thread, string, error)

ListThreads returns all threads in a namespace.

func (*Backend) MarkMessagesSummarized

func (b *Backend) MarkMessagesSummarized(ctx context.Context, namespace, threadID string, beforeTime int64) error

MarkMessagesSummarized marks messages as having been included in a summary.

func (*Backend) MergeEntities

func (b *Backend) MergeEntities(ctx context.Context, namespace, sourceID, targetID string) error

MergeEntities combines two entities, moving all data from source to target.

func (*Backend) Migrate

func (b *Backend) Migrate(ctx context.Context) error

Migrate runs database migrations.

func (*Backend) PruneStaleEntities

func (b *Backend) PruneStaleEntities(ctx context.Context, staleDuration time.Duration, minMentions int) (int64, error)

PruneStaleEntities removes entities that haven't been mentioned recently and have fewer mentions than the threshold. Returns the number of entities deleted.

func (*Backend) RegisterAlias

func (b *Backend) RegisterAlias(ctx context.Context, namespace, alias, entityID string) error

RegisterAlias adds an alias for an entity.

func (*Backend) ResolveAlias

func (b *Backend) ResolveAlias(ctx context.Context, namespace, alias string) (*types.Entity, error)

ResolveAlias looks up an entity by an alias.

func (*Backend) SearchChunks

func (b *Backend) SearchChunks(ctx context.Context, namespace string, embedding []float32, opts storage.ChunkSearchOpts) ([]*types.ChunkResult, error)

SearchChunks performs semantic search across chunks in a namespace. Uses sqlite-vec's vec_distance_cosine for brute-force KNN search.

func (*Backend) SearchEntities

func (b *Backend) SearchEntities(ctx context.Context, namespace string, embedding []float32, opts storage.EntitySearchOpts) ([]*types.EntityResult, error)

SearchEntities performs semantic search across entity summaries. Uses sqlite-vec's vec_distance_cosine for brute-force KNN search.

func (*Backend) SearchMessages

func (b *Backend) SearchMessages(ctx context.Context, namespace string, embedding []float32, opts storage.MessageSearchOpts) ([]*types.MessageResult, error)

SearchMessages performs semantic search across messages in a namespace. Uses sqlite-vec's vec_distance_cosine for brute-force KNN search.

func (*Backend) SetContext

func (b *Backend) SetContext(ctx context.Context, entry *types.ContextEntry, expectedVersion *int64) error

SetContext stores a context entry, incrementing the version. If expectedVersion is provided, the operation fails if the current version doesn't match.

func (*Backend) StoreEntityEmbedding

func (b *Backend) StoreEntityEmbedding(ctx context.Context, entityID string, embedding []float32) error

StoreEntityEmbedding stores the embedding for an entity's summary. Embeddings are stored in binary format for use with sqlite-vec.

func (*Backend) StoreMessageEmbedding

func (b *Backend) StoreMessageEmbedding(ctx context.Context, messageID string, embedding []float32) error

StoreMessageEmbedding stores the embedding for a message. Embeddings are stored in binary format for use with sqlite-vec.

func (*Backend) UpdateThread

func (b *Backend) UpdateThread(ctx context.Context, thread *types.Thread) error

UpdateThread updates a thread's metadata (title, summary).

func (*Backend) UpsertEntity

func (b *Backend) UpsertEntity(ctx context.Context, entity *types.Entity) error

UpsertEntity creates or updates an entity.

func (*Backend) UpsertRelationship

func (b *Backend) UpsertRelationship(ctx context.Context, rel *types.EntityRelationship) error

UpsertRelationship creates or updates a relationship between entities.

type BackupProgress

type BackupProgress struct {
	Remaining int // Pages remaining
	Total     int // Total pages
}

BackupProgress represents the progress of a backup operation.

type Migration

type Migration struct {
	Version int
	Name    string
	Up      string
}

Migration represents a database migration.

Jump to

Keyboard shortcuts

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