Documentation
¶
Index ¶
- type Backend
- func (b *Backend) AppendMessage(ctx context.Context, msg *types.Message) error
- func (b *Backend) CleanupContextHistory(ctx context.Context, olderThan time.Duration) (int64, error)
- func (b *Backend) CleanupExpiredContext(ctx context.Context) (int64, error)
- func (b *Backend) CleanupOldRunContext(ctx context.Context, olderThan time.Duration) (int64, error)
- func (b *Backend) CleanupRunContext(ctx context.Context, namespace, runID string) error
- func (b *Backend) Close() error
- func (b *Backend) CollectionStats(ctx context.Context, namespace, collectionID string) (*types.CollectionStats, error)
- func (b *Backend) CompleteExtraction(ctx context.Context, itemID int64, status string) error
- func (b *Backend) CreateCollection(ctx context.Context, col *types.Collection) error
- func (b *Backend) DeleteCollection(ctx context.Context, namespace, collectionID string) error
- func (b *Backend) DeleteContext(ctx context.Context, namespace, key string, runID *string) error
- func (b *Backend) DeleteDocument(ctx context.Context, namespace, docID string) error
- func (b *Backend) DeleteEntity(ctx context.Context, namespace, entityID string) error
- func (b *Backend) DeleteOldConversations(ctx context.Context, olderThan time.Duration) (int64, error)
- func (b *Backend) DeleteOrphanedChunks(ctx context.Context) (int64, error)
- func (b *Backend) DeleteThread(ctx context.Context, namespace, threadID string) error
- func (b *Backend) DequeueExtraction(ctx context.Context, batchSize int) ([]*types.ExtractionQueueItem, error)
- func (b *Backend) EnqueueExtraction(ctx context.Context, item *types.ExtractionQueueItem) error
- func (b *Backend) GetAdjacentChunks(ctx context.Context, chunkID string, window int) ([]*types.Chunk, error)
- func (b *Backend) GetCollection(ctx context.Context, namespace, collectionID string) (*types.Collection, error)
- func (b *Backend) GetContext(ctx context.Context, namespace, key string, runID *string) (*types.ContextEntry, error)
- func (b *Backend) GetContextHistory(ctx context.Context, namespace, key string, runID *string, cursor string, ...) ([]*types.ContextHistoryEntry, string, error)
- func (b *Backend) GetDocument(ctx context.Context, namespace, docID string) (*types.Document, error)
- func (b *Backend) GetEntityByID(ctx context.Context, namespace, entityID string) (*types.Entity, error)
- func (b *Backend) GetEntityByName(ctx context.Context, namespace, name string) (*types.Entity, error)
- func (b *Backend) GetExtractionQueueStats(ctx context.Context) (*storage.ExtractionQueueStats, error)
- func (b *Backend) GetMentions(ctx context.Context, entityID string, limit int) ([]*types.EntityMention, error)
- func (b *Backend) GetMessages(ctx context.Context, namespace, threadID string, limit int, cursor string) ([]*types.Message, string, error)
- func (b *Backend) GetRelationships(ctx context.Context, namespace, entityID string, opts storage.RelationshipOpts) ([]*types.EntityRelationship, error)
- func (b *Backend) GetThread(ctx context.Context, namespace, threadID string) (*types.Thread, error)
- func (b *Backend) Health(ctx context.Context) error
- func (b *Backend) HybridSearchChunks(ctx context.Context, namespace string, query string, embedding []float32, ...) ([]*types.ChunkResult, error)
- func (b *Backend) HybridSearchEntities(ctx context.Context, namespace string, query string, embedding []float32, ...) ([]*types.EntityResult, error)
- func (b *Backend) HybridSearchMessages(ctx context.Context, namespace string, query string, embedding []float32, ...) ([]*types.MessageResult, error)
- func (b *Backend) InsertChunks(ctx context.Context, chunks []*types.Chunk) error
- func (b *Backend) InsertDocument(ctx context.Context, doc *types.Document) error
- func (b *Backend) InsertMention(ctx context.Context, mention *types.EntityMention) error
- func (b *Backend) ListCollections(ctx context.Context, namespace string, cursor string, limit int) ([]*types.Collection, string, error)
- func (b *Backend) ListContextKeys(ctx context.Context, namespace string, prefix *string, runID *string, ...) ([]string, string, error)
- func (b *Backend) ListEntities(ctx context.Context, namespace string, opts storage.EntityListOpts) ([]*types.Entity, string, error)
- func (b *Backend) ListThreads(ctx context.Context, namespace string, cursor string, limit int) ([]*types.Thread, string, error)
- func (b *Backend) MarkMessagesSummarized(ctx context.Context, namespace, threadID string, beforeTime int64) error
- func (b *Backend) MergeEntities(ctx context.Context, namespace, sourceID, targetID string) error
- func (b *Backend) Migrate(ctx context.Context) error
- func (b *Backend) PruneStaleEntities(ctx context.Context, staleDuration time.Duration, minMentions int) (int64, error)
- func (b *Backend) RegisterAlias(ctx context.Context, namespace, alias, entityID string) error
- func (b *Backend) RequeueExtraction(ctx context.Context, itemID int64, nextRetryAt time.Time, countFailure bool) error
- func (b *Backend) ResolveAlias(ctx context.Context, namespace, alias string) (*types.Entity, error)
- func (b *Backend) SearchChunks(ctx context.Context, namespace string, embedding []float32, ...) ([]*types.ChunkResult, error)
- func (b *Backend) SearchEntities(ctx context.Context, namespace string, embedding []float32, ...) ([]*types.EntityResult, error)
- func (b *Backend) SearchMessages(ctx context.Context, namespace string, embedding []float32, ...) ([]*types.MessageResult, error)
- func (b *Backend) SetContext(ctx context.Context, entry *types.ContextEntry, expectedVersion *int64) error
- func (b *Backend) StoreEntityEmbedding(ctx context.Context, entityID string, embedding []float32) error
- func (b *Backend) StoreMessageEmbedding(ctx context.Context, messageID string, embedding []float32) error
- func (b *Backend) UpdateThread(ctx context.Context, thread *types.Thread) error
- func (b *Backend) UpsertEntity(ctx context.Context, entity *types.Entity) error
- func (b *Backend) UpsertRelationship(ctx context.Context, rel *types.EntityRelationship) error
- type Migration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend implements storage.Backend using PostgreSQL with pgvector.
func (*Backend) AppendMessage ¶
AppendMessage adds a message to a thread, creating the thread if it doesn't exist.
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 ¶
CleanupExpiredContext removes entries past their TTL expiration. Returns the number of entries deleted.
func (*Backend) CleanupOldRunContext ¶
CleanupOldRunContext removes run-scoped context entries older than the specified duration. Returns the number of entries deleted.
func (*Backend) CleanupRunContext ¶
CleanupRunContext removes all context entries for a specific run.
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 ¶
CompleteExtraction marks an extraction queue item as completed or failed.
func (*Backend) CreateCollection ¶
CreateCollection creates a new collection.
func (*Backend) DeleteCollection ¶
DeleteCollection removes a collection and all its documents.
func (*Backend) DeleteContext ¶
DeleteContext removes a context entry.
func (*Backend) DeleteDocument ¶
DeleteDocument removes a document and all its chunks.
func (*Backend) DeleteEntity ¶
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 ¶
DeleteOrphanedChunks removes chunks whose parent documents no longer exist. Returns the number of chunks deleted.
func (*Backend) DeleteThread ¶
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 ¶
EnqueueExtraction adds an item to the entity extraction queue.
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) 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.
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.
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.
func (*Backend) InsertChunks ¶
InsertChunks adds chunks for a document. Embeddings should already be populated.
func (*Backend) InsertDocument ¶
InsertDocument adds a new document to the store.
func (*Backend) InsertMention ¶
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 ¶
MergeEntities combines two entities, moving all data from source to target.
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 ¶
RegisterAlias adds an alias for an entity.
func (*Backend) RequeueExtraction ¶ added in v1.0.0
func (b *Backend) RequeueExtraction(ctx context.Context, itemID int64, nextRetryAt time.Time, countFailure bool) error
RequeueExtraction returns a dequeued ("processing") item to the pending state, scheduling its next attempt no earlier than nextRetryAt (a zero time means immediately eligible). When countFailure is false the attempt increment applied at dequeue is undone.
func (*Backend) ResolveAlias ¶
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 pgvector's HNSW index for approximate nearest neighbor 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 pgvector's HNSW index for approximate nearest neighbor 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 pgvector's HNSW index for approximate nearest neighbor 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.
func (*Backend) StoreMessageEmbedding ¶
func (b *Backend) StoreMessageEmbedding(ctx context.Context, messageID string, embedding []float32) error
StoreMessageEmbedding stores the embedding for a message.
func (*Backend) UpdateThread ¶
UpdateThread updates a thread's metadata (title, summary).
func (*Backend) UpsertEntity ¶
UpsertEntity creates or updates an entity.
func (*Backend) UpsertRelationship ¶
UpsertRelationship creates or updates a relationship between entities.
type Migration ¶ added in v1.0.0
Migration represents a versioned database migration. Each migration is applied in a single transaction; Up is the ordered list of statements pgx executes (pgx's extended-protocol Exec runs one statement per call, unlike the SQLite driver which accepts multi-statement strings).