Documentation
¶
Overview ¶
Package store provides storage implementations for gognee's knowledge graph.
Index ¶
- Variables
- func ComputeDocHash(topic, context string, decisions, rationale []string) string
- func CosineSimilarity(a, b []float32) float64
- func DisableSQLiteVec()
- func EnableSQLiteVec()
- type DocumentTracker
- type Edge
- type GraphStore
- type ListMemoriesOptions
- type MemoryRecord
- type MemoryStore
- type MemorySummary
- type MemoryUpdate
- type MemoryVectorStore
- type Node
- type SQLiteGraphStore
- func (s *SQLiteGraphStore) AddEdge(ctx context.Context, edge *Edge) error
- func (s *SQLiteGraphStore) AddNode(ctx context.Context, node *Node) error
- func (s *SQLiteGraphStore) ClearProcessedDocuments(ctx context.Context) error
- func (s *SQLiteGraphStore) Close() error
- func (s *SQLiteGraphStore) DB() *sql.DB
- func (s *SQLiteGraphStore) DeleteEdge(ctx context.Context, edgeID string) error
- func (s *SQLiteGraphStore) DeleteNode(ctx context.Context, nodeID string) error
- func (s *SQLiteGraphStore) EdgeCount(ctx context.Context) (int64, error)
- func (s *SQLiteGraphStore) FindNodeByName(ctx context.Context, name string) (*Node, error)
- func (s *SQLiteGraphStore) FindNodesByName(ctx context.Context, name string) ([]*Node, error)
- func (s *SQLiteGraphStore) GetAllNodes(ctx context.Context) ([]*Node, error)
- func (s *SQLiteGraphStore) GetEdges(ctx context.Context, nodeID string) ([]*Edge, error)
- func (s *SQLiteGraphStore) GetNeighbors(ctx context.Context, nodeID string, depth int) ([]*Node, error)
- func (s *SQLiteGraphStore) GetNode(ctx context.Context, id string) (*Node, error)
- func (s *SQLiteGraphStore) GetProcessedDocumentCount(ctx context.Context) (int64, error)
- func (s *SQLiteGraphStore) IsDocumentProcessed(ctx context.Context, hash string) (bool, error)
- func (s *SQLiteGraphStore) MarkDocumentProcessed(ctx context.Context, hash, source string, chunkCount int) error
- func (s *SQLiteGraphStore) NodeCount(ctx context.Context) (int64, error)
- func (s *SQLiteGraphStore) UpdateAccessTime(ctx context.Context, nodeIDs []string) error
- type SQLiteMemoryStore
- func (s *SQLiteMemoryStore) AddMemory(ctx context.Context, record *MemoryRecord) error
- func (s *SQLiteMemoryStore) BatchUpdateMemoryAccess(ctx context.Context, ids []string) error
- func (s *SQLiteMemoryStore) CountMemories(ctx context.Context) (int64, error)
- func (s *SQLiteMemoryStore) CountMemoryReferences(ctx context.Context, nodeID string) (int, error)
- func (s *SQLiteMemoryStore) DB() *sql.DB
- func (s *SQLiteMemoryStore) DeleteMemory(ctx context.Context, id string) error
- func (s *SQLiteMemoryStore) GarbageCollect(ctx context.Context) (nodesDeleted, edgesDeleted int, err error)
- func (s *SQLiteMemoryStore) GarbageCollectCandidates(ctx context.Context, nodeIDs, edgeIDs []string) (nodesDeleted, edgesDeleted int, err error)
- func (s *SQLiteMemoryStore) GetMemoriesByNodeID(ctx context.Context, nodeID string) ([]string, error)
- func (s *SQLiteMemoryStore) GetMemoriesByNodeIDBatched(ctx context.Context, nodeIDs []string) (map[string][]string, error)
- func (s *SQLiteMemoryStore) GetMemory(ctx context.Context, id string) (*MemoryRecord, error)
- func (s *SQLiteMemoryStore) GetOrphanedEdges(ctx context.Context) ([]string, error)
- func (s *SQLiteMemoryStore) GetOrphanedNodes(ctx context.Context) ([]string, error)
- func (s *SQLiteMemoryStore) GetProvenanceByMemory(ctx context.Context, memoryID string) (nodeIDs, edgeIDs []string, err error)
- func (s *SQLiteMemoryStore) GetSupersededMemories(ctx context.Context, memoryID string) ([]string, error)
- func (s *SQLiteMemoryStore) GetSupersedingMemory(ctx context.Context, memoryID string) (*string, error)
- func (s *SQLiteMemoryStore) GetSupersessionChain(ctx context.Context, memoryID string) ([]SupersessionRecord, error)
- func (s *SQLiteMemoryStore) LinkProvenance(ctx context.Context, memoryID string, nodeIDs, edgeIDs []string) error
- func (s *SQLiteMemoryStore) ListMemories(ctx context.Context, opts ListMemoriesOptions) ([]MemorySummary, error)
- func (s *SQLiteMemoryStore) RecordSupersession(ctx context.Context, supersedingID, supersededID, reason string) error
- func (s *SQLiteMemoryStore) UnlinkProvenance(ctx context.Context, memoryID string) error
- func (s *SQLiteMemoryStore) UpdateMemory(ctx context.Context, id string, updates MemoryUpdate) error
- func (s *SQLiteMemoryStore) UpdateMemoryAccess(ctx context.Context, id string) error
- type SQLiteVectorStore
- func (s *SQLiteVectorStore) Add(ctx context.Context, id string, embedding []float32) error
- func (s *SQLiteVectorStore) Close() error
- func (s *SQLiteVectorStore) Delete(ctx context.Context, id string) error
- func (s *SQLiteVectorStore) Search(ctx context.Context, query []float32, topK int) ([]SearchResult, error)
- type SearchResult
- type SupersessionRecord
- type VectorStore
Constants ¶
This section is empty.
Variables ¶
var ErrAmbiguousNode = errors.New("multiple nodes match the given name")
ErrAmbiguousNode indicates that multiple nodes matched the given name.
var ErrMemoryNotFound = fmt.Errorf("memory not found")
ErrMemoryNotFound indicates that no memory was found for the given ID.
var ErrNodeNotFound = errors.New("node not found")
ErrNodeNotFound indicates that no node was found for the given criteria.
Functions ¶
func ComputeDocHash ¶
ComputeDocHash computes a canonical hash of a memory's content. Uses JSON with sorted keys, trimmed whitespace, excluding metadata.
func CosineSimilarity ¶
CosineSimilarity computes the cosine similarity between two vectors. Returns a value between -1 and 1, where 1 means identical direction, 0 means orthogonal, and -1 means opposite direction. For normalized vectors (embeddings), the result is typically between 0 and 1.
func DisableSQLiteVec ¶ added in v1.3.0
func DisableSQLiteVec()
DisableSQLiteVec cancels the sqlite-vec auto-extension
func EnableSQLiteVec ¶ added in v1.3.0
func EnableSQLiteVec()
EnableSQLiteVec registers sqlite-vec as an auto-extension for all future database connections
Types ¶
type DocumentTracker ¶
type DocumentTracker interface {
// IsDocumentProcessed checks if a document with the given hash has been processed.
// hash: SHA-256 hash of the document text (content-based identity)
// Returns true if the document has been processed, false otherwise.
IsDocumentProcessed(ctx context.Context, hash string) (bool, error)
// MarkDocumentProcessed records that a document has been successfully processed.
// hash: SHA-256 hash of document text (content-based identity)
// source: Optional source identifier (metadata only, does not affect identity)
// chunkCount: Number of chunks generated from this document
// Uses INSERT OR REPLACE to support upsert semantics.
MarkDocumentProcessed(ctx context.Context, hash, source string, chunkCount int) error
// GetProcessedDocumentCount returns the total number of processed documents tracked.
GetProcessedDocumentCount(ctx context.Context) (int64, error)
// ClearProcessedDocuments removes all document tracking records.
// This does NOT delete nodes or edges - only clears the processed_documents table.
// Useful for forcing a full reprocess without losing the knowledge graph.
ClearProcessedDocuments(ctx context.Context) error
}
DocumentTracker provides operations for tracking processed documents. Separate from GraphStore to maintain interface cohesion. This enables document-level deduplication in incremental Cognify operations.
type Edge ¶
type Edge struct {
ID string // Unique identifier (UUID)
SourceID string // Source node ID
Relation string // Relationship type (USES, DEPENDS_ON, etc.)
TargetID string // Target node ID
Weight float64 // Relationship weight (default 1.0, reserved for future ranking)
CreatedAt time.Time // Timestamp of creation
}
Edge represents a relationship between two nodes in the knowledge graph.
type GraphStore ¶
type GraphStore interface {
// AddNode adds or updates a node in the graph.
// Uses upsert semantics (INSERT OR REPLACE by ID).
AddNode(ctx context.Context, node *Node) error
// GetNode retrieves a node by its ID.
// Returns (nil, nil) if the node is not found (no error).
GetNode(ctx context.Context, id string) (*Node, error)
// FindNodesByName searches for nodes by name using case-insensitive matching.
// Returns all matching nodes ordered deterministically (by created_at, then id).
// Callers must handle ambiguity when multiple matches are returned.
FindNodesByName(ctx context.Context, name string) ([]*Node, error)
// FindNodeByName is a convenience method that returns a single node if and only if
// exactly one node matches the name (case-insensitive).
// Returns an error if zero matches (not found) or multiple matches (ambiguous).
FindNodeByName(ctx context.Context, name string) (*Node, error)
// AddEdge adds or updates an edge in the graph.
// Uses upsert semantics (INSERT OR REPLACE by ID).
// If Edge.ID is empty, a new UUID will be generated.
AddEdge(ctx context.Context, edge *Edge) error
// GetEdges retrieves all edges incident to a node (both incoming and outgoing).
// This is direction-agnostic: returns edges where the node is either source or target.
// Returns an empty slice if no edges are found.
// Cognee-aligned: treats adjacency as undirected for discovery.
GetEdges(ctx context.Context, nodeID string) ([]*Edge, error)
// GetNeighbors retrieves all nodes adjacent to a given node, up to the specified depth.
// Depth=1 returns direct neighbors only (Cognee-aligned default).
// Depth>1 recursively traverses the graph (gognee extension).
// Traversal is direction-agnostic (treats edges as undirected).
// Returns unique nodes only (no duplicates).
GetNeighbors(ctx context.Context, nodeID string, depth int) ([]*Node, error)
// NodeCount returns the total number of nodes in the graph.
NodeCount(ctx context.Context) (int64, error)
// EdgeCount returns the total number of edges in the graph.
EdgeCount(ctx context.Context) (int64, error)
// Close releases any resources held by the store (e.g., database connections).
Close() error
}
GraphStore defines the interface for graph storage operations. Implementations must provide persistent storage for nodes and edges, supporting both direct access and graph traversal operations.
type ListMemoriesOptions ¶
type ListMemoriesOptions struct {
Offset int
Limit int // Default 50, max 100
Status *string // Filter by status (Active, Superseded, Pinned, etc.) (M10)
RetentionPolicy *string // Filter by retention_policy (M10)
Pinned *bool // Filter pinned only (M10)
OrderBy string // "created_at", "updated_at", "access_count", "last_accessed_at" (M10)
OrderDesc bool // Default true (newest/highest first) (M10)
}
ListMemoriesOptions provides pagination and filtering for memory listing (M10: Plan 021).
type MemoryRecord ¶
type MemoryRecord struct {
ID string `json:"id"`
Topic string `json:"topic"`
Context string `json:"context"`
Decisions []string `json:"decisions,omitempty"`
Rationale []string `json:"rationale,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Version int `json:"version"`
DocHash string `json:"doc_hash"`
Source string `json:"source,omitempty"`
Status string `json:"status"` // "pending", "complete", "Active", "Superseded", "Archived", "Pinned" (M3: Plan 021)
AccessCount int `json:"access_count"` // M1: Plan 021 - Number of times this memory was accessed
LastAccessedAt *time.Time `json:"last_accessed_at"` // M1: Plan 021 - Timestamp of last access
AccessVelocity float64 `json:"access_velocity"` // M1: Plan 021 - Computed access frequency (accesses / days since creation)
SupersededBy *string `json:"superseded_by"` // M3: Plan 021 - ID of memory that supersedes this one (nullable)
RetentionPolicy string `json:"retention_policy"` // M6: Plan 021 - Retention policy: permanent, decision, standard, ephemeral, session
RetentionUntil *time.Time `json:"retention_until"` // M6: Plan 021 - Explicit expiration timestamp (nullable)
Pinned bool `json:"pinned"` // M9: Plan 021 - Whether this memory is pinned
PinnedAt *time.Time `json:"pinned_at"` // M9: Plan 021 - When this memory was pinned
PinnedReason *string `json:"pinned_reason"` // M9: Plan 021 - Why this memory was pinned (nullable)
}
MemoryRecord represents a first-class memory with structured payload.
type MemoryStore ¶
type MemoryStore interface {
// AddMemory creates a new memory record.
AddMemory(ctx context.Context, record *MemoryRecord) error
// GetMemory retrieves a memory by ID, including provenance information.
GetMemory(ctx context.Context, id string) (*MemoryRecord, error)
// ListMemories returns paginated memory summaries.
ListMemories(ctx context.Context, opts ListMemoriesOptions) ([]MemorySummary, error)
// UpdateMemory applies partial updates to a memory.
UpdateMemory(ctx context.Context, id string, updates MemoryUpdate) error
// DeleteMemory removes a memory and its provenance links.
DeleteMemory(ctx context.Context, id string) error
// GetMemoriesByNodeID returns all memory IDs that reference a given node.
GetMemoriesByNodeID(ctx context.Context, nodeID string) ([]string, error)
// CountMemories returns the total number of memories in the store.
CountMemories(ctx context.Context) (int64, error)
// UpdateMemoryAccess increments access tracking for a single memory.
UpdateMemoryAccess(ctx context.Context, id string) error
// BatchUpdateMemoryAccess increments access tracking for multiple memories.
BatchUpdateMemoryAccess(ctx context.Context, ids []string) error
// RecordSupersession records that one memory supersedes another (M3: Plan 021).
RecordSupersession(ctx context.Context, supersedingID, supersededID, reason string) error
// GetSupersessionChain retrieves the full chain of supersessions for a memory (M3: Plan 021).
GetSupersessionChain(ctx context.Context, memoryID string) ([]SupersessionRecord, error)
// GetSupersedingMemory returns the ID of the memory that supersedes this one, if any (M3: Plan 021).
GetSupersedingMemory(ctx context.Context, memoryID string) (*string, error)
// GetSupersededMemories returns the IDs of memories this one supersedes (M3: Plan 021).
GetSupersededMemories(ctx context.Context, memoryID string) ([]string, error)
}
MemoryStore defines the interface for memory CRUD operations.
type MemorySummary ¶
type MemorySummary struct {
ID string `json:"id"`
Topic string `json:"topic"`
Preview string `json:"preview"` // Truncated context
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DecisionCount int `json:"decision_count"`
Status string `json:"status"`
RetentionPolicy string `json:"retention_policy"` // M10: Plan 021
Pinned bool `json:"pinned"` // M10: Plan 021
AccessCount int `json:"access_count"` // M10: Plan 021
SupersededBy *string `json:"superseded_by"` // M10: Plan 021
}
MemorySummary provides a lightweight view of a memory for list operations.
type MemoryUpdate ¶
type MemoryUpdate struct {
Topic *string
Context *string
Decisions *[]string
Rationale *[]string
Metadata *map[string]interface{}
Status *string
}
MemoryUpdate represents partial updates to a memory. All fields are pointers to distinguish between "not provided" and "set to zero value".
type MemoryVectorStore ¶
type MemoryVectorStore struct {
// contains filtered or unexported fields
}
MemoryVectorStore is an in-memory implementation of VectorStore. It uses a map to store vectors and provides thread-safe access via RWMutex. Note: This implementation does not persist vectors across restarts.
func NewMemoryVectorStore ¶
func NewMemoryVectorStore() *MemoryVectorStore
NewMemoryVectorStore creates a new in-memory vector store.
func (*MemoryVectorStore) Delete ¶
func (m *MemoryVectorStore) Delete(ctx context.Context, id string) error
Delete removes a vector from the store.
func (*MemoryVectorStore) Search ¶
func (m *MemoryVectorStore) Search(ctx context.Context, query []float32, topK int) ([]SearchResult, error)
Search finds the most similar vectors to the query. Returns up to topK results sorted by similarity score (descending).
type Node ¶
type Node struct {
ID string // Unique identifier (UUID)
Name string // Entity name
Type string // Entity type (Person, Concept, System, etc.)
Description string // Brief description
Embedding []float32 // Vector embedding for semantic search
CreatedAt time.Time // Timestamp of creation
LastAccessedAt *time.Time // Timestamp of last access (for decay tracking)
Metadata map[string]interface{} // Additional metadata as JSON
}
Node represents a knowledge graph entity with embeddings and metadata.
type SQLiteGraphStore ¶
type SQLiteGraphStore struct {
// contains filtered or unexported fields
}
SQLiteGraphStore implements GraphStore using SQLite as the backend.
func NewSQLiteGraphStore ¶
func NewSQLiteGraphStore(dbPath string) (*SQLiteGraphStore, error)
NewSQLiteGraphStore creates a new SQLite-backed graph store. The dbPath can be a file path or ":memory:" for an in-memory database. Creates tables and indexes if they don't exist.
func (*SQLiteGraphStore) AddEdge ¶
func (s *SQLiteGraphStore) AddEdge(ctx context.Context, edge *Edge) error
AddEdge adds or updates an edge in the graph.
func (*SQLiteGraphStore) AddNode ¶
func (s *SQLiteGraphStore) AddNode(ctx context.Context, node *Node) error
AddNode adds or updates a node in the graph.
func (*SQLiteGraphStore) ClearProcessedDocuments ¶
func (s *SQLiteGraphStore) ClearProcessedDocuments(ctx context.Context) error
ClearProcessedDocuments removes all document tracking records without affecting the knowledge graph.
func (*SQLiteGraphStore) Close ¶
func (s *SQLiteGraphStore) Close() error
Close releases database resources.
func (*SQLiteGraphStore) DB ¶
func (s *SQLiteGraphStore) DB() *sql.DB
DB returns the underlying database connection. This connection is shared with other stores (e.g., SQLiteVectorStore) and must not be closed by consumers.
func (*SQLiteGraphStore) DeleteEdge ¶
func (s *SQLiteGraphStore) DeleteEdge(ctx context.Context, edgeID string) error
DeleteEdge removes an edge from the graph.
func (*SQLiteGraphStore) DeleteNode ¶
func (s *SQLiteGraphStore) DeleteNode(ctx context.Context, nodeID string) error
DeleteNode removes a node from the graph.
func (*SQLiteGraphStore) EdgeCount ¶
func (s *SQLiteGraphStore) EdgeCount(ctx context.Context) (int64, error)
EdgeCount returns the total number of edges in the graph.
func (*SQLiteGraphStore) FindNodeByName ¶
FindNodeByName is a convenience method that returns a single node if exactly one matches.
func (*SQLiteGraphStore) FindNodesByName ¶
FindNodesByName searches for nodes by name using case-insensitive matching.
func (*SQLiteGraphStore) GetAllNodes ¶
func (s *SQLiteGraphStore) GetAllNodes(ctx context.Context) ([]*Node, error)
GetAllNodes returns all nodes in the graph (for pruning operations).
func (*SQLiteGraphStore) GetEdges ¶
GetEdges retrieves all edges incident to a node (both incoming and outgoing).
func (*SQLiteGraphStore) GetNeighbors ¶
func (s *SQLiteGraphStore) GetNeighbors(ctx context.Context, nodeID string, depth int) ([]*Node, error)
GetNeighbors retrieves all nodes adjacent to a given node, up to the specified depth. Uses a recursive CTE for efficient single-query graph expansion (v1.4.0 optimization).
func (*SQLiteGraphStore) GetNode ¶
GetNode retrieves a node by its ID. Also updates last_accessed_at timestamp to track access for decay.
func (*SQLiteGraphStore) GetProcessedDocumentCount ¶
func (s *SQLiteGraphStore) GetProcessedDocumentCount(ctx context.Context) (int64, error)
GetProcessedDocumentCount returns the total number of processed documents tracked.
func (*SQLiteGraphStore) IsDocumentProcessed ¶
IsDocumentProcessed checks if a document with the given hash has been processed.
func (*SQLiteGraphStore) MarkDocumentProcessed ¶
func (s *SQLiteGraphStore) MarkDocumentProcessed(ctx context.Context, hash, source string, chunkCount int) error
MarkDocumentProcessed records that a document has been successfully processed.
func (*SQLiteGraphStore) NodeCount ¶
func (s *SQLiteGraphStore) NodeCount(ctx context.Context) (int64, error)
NodeCount returns the total number of nodes in the graph.
func (*SQLiteGraphStore) UpdateAccessTime ¶
func (s *SQLiteGraphStore) UpdateAccessTime(ctx context.Context, nodeIDs []string) error
UpdateAccessTime updates the last_accessed_at timestamp for a batch of nodes. This is used for access reinforcement in memory decay.
type SQLiteMemoryStore ¶
type SQLiteMemoryStore struct {
// contains filtered or unexported fields
}
SQLiteMemoryStore implements MemoryStore using SQLite.
func NewSQLiteMemoryStore ¶
func NewSQLiteMemoryStore(db *sql.DB) *SQLiteMemoryStore
NewSQLiteMemoryStore creates a new SQLite-backed memory store. Shares the database connection with SQLiteGraphStore.
func (*SQLiteMemoryStore) AddMemory ¶
func (s *SQLiteMemoryStore) AddMemory(ctx context.Context, record *MemoryRecord) error
AddMemory creates a new memory record.
func (*SQLiteMemoryStore) BatchUpdateMemoryAccess ¶ added in v1.5.0
func (s *SQLiteMemoryStore) BatchUpdateMemoryAccess(ctx context.Context, ids []string) error
BatchUpdateMemoryAccess increments access tracking for multiple memories efficiently. This is critical for the search path where multiple memories are accessed simultaneously.
func (*SQLiteMemoryStore) CountMemories ¶ added in v1.0.2
func (s *SQLiteMemoryStore) CountMemories(ctx context.Context) (int64, error)
CountMemories returns the total number of memories in the store. Uses an indexed query for O(1) performance.
func (*SQLiteMemoryStore) CountMemoryReferences ¶
CountMemoryReferences returns the number of memories referencing a node.
func (*SQLiteMemoryStore) DB ¶
func (s *SQLiteMemoryStore) DB() *sql.DB
DB returns the underlying database connection for advanced operations.
func (*SQLiteMemoryStore) DeleteMemory ¶
func (s *SQLiteMemoryStore) DeleteMemory(ctx context.Context, id string) error
DeleteMemory removes a memory and its provenance links (via CASCADE).
func (*SQLiteMemoryStore) GarbageCollect ¶
func (s *SQLiteMemoryStore) GarbageCollect(ctx context.Context) (nodesDeleted, edgesDeleted int, err error)
GarbageCollect removes provenance-tracked nodes/edges with zero references. Returns counts of deleted nodes and edges. CRITICAL: Only affects provenance-tracked artifacts. Legacy nodes/edges are preserved.
func (*SQLiteMemoryStore) GarbageCollectCandidates ¶
func (s *SQLiteMemoryStore) GarbageCollectCandidates(ctx context.Context, nodeIDs, edgeIDs []string) (nodesDeleted, edgesDeleted int, err error)
GarbageCollectCandidates removes candidate nodes/edges if they have zero provenance references. This is the actual GC implementation called after unlinking provenance.
func (*SQLiteMemoryStore) GetMemoriesByNodeID ¶
func (s *SQLiteMemoryStore) GetMemoriesByNodeID(ctx context.Context, nodeID string) ([]string, error)
GetMemoriesByNodeID returns all memory IDs that reference a given node. Returns memory IDs sorted by updated_at DESC (most recent first).
func (*SQLiteMemoryStore) GetMemoriesByNodeIDBatched ¶
func (s *SQLiteMemoryStore) GetMemoriesByNodeIDBatched(ctx context.Context, nodeIDs []string) (map[string][]string, error)
GetMemoriesByNodeIDBatched returns memory IDs for multiple nodes in a single query. Returns a map of nodeID -> []memoryID (sorted by updated_at DESC per node).
func (*SQLiteMemoryStore) GetMemory ¶
func (s *SQLiteMemoryStore) GetMemory(ctx context.Context, id string) (*MemoryRecord, error)
GetMemory retrieves a memory by ID.
func (*SQLiteMemoryStore) GetOrphanedEdges ¶
func (s *SQLiteMemoryStore) GetOrphanedEdges(ctx context.Context) ([]string, error)
GetOrphanedEdges returns edge IDs that were provenance-tracked but now have zero references.
func (*SQLiteMemoryStore) GetOrphanedNodes ¶
func (s *SQLiteMemoryStore) GetOrphanedNodes(ctx context.Context) ([]string, error)
GetOrphanedNodes returns node IDs that were provenance-tracked but now have zero references.
func (*SQLiteMemoryStore) GetProvenanceByMemory ¶
func (s *SQLiteMemoryStore) GetProvenanceByMemory(ctx context.Context, memoryID string) (nodeIDs, edgeIDs []string, err error)
GetProvenanceByMemory returns all node and edge IDs linked to a memory.
func (*SQLiteMemoryStore) GetSupersededMemories ¶ added in v1.5.0
func (s *SQLiteMemoryStore) GetSupersededMemories(ctx context.Context, memoryID string) ([]string, error)
GetSupersededMemories returns the IDs of memories this one supersedes (M3: Plan 021).
func (*SQLiteMemoryStore) GetSupersedingMemory ¶ added in v1.5.0
func (s *SQLiteMemoryStore) GetSupersedingMemory(ctx context.Context, memoryID string) (*string, error)
GetSupersedingMemory returns the ID of the memory that supersedes this one, if any (M3: Plan 021).
func (*SQLiteMemoryStore) GetSupersessionChain ¶ added in v1.5.0
func (s *SQLiteMemoryStore) GetSupersessionChain(ctx context.Context, memoryID string) ([]SupersessionRecord, error)
GetSupersessionChain retrieves the full chain of supersessions for a memory (M3: Plan 021). Returns the chain from oldest to newest, including the given memoryID.
func (*SQLiteMemoryStore) LinkProvenance ¶
func (s *SQLiteMemoryStore) LinkProvenance(ctx context.Context, memoryID string, nodeIDs, edgeIDs []string) error
LinkProvenance links derived nodes/edges to a memory.
func (*SQLiteMemoryStore) ListMemories ¶
func (s *SQLiteMemoryStore) ListMemories(ctx context.Context, opts ListMemoriesOptions) ([]MemorySummary, error)
ListMemories returns paginated memory summaries.
func (*SQLiteMemoryStore) RecordSupersession ¶ added in v1.5.0
func (s *SQLiteMemoryStore) RecordSupersession(ctx context.Context, supersedingID, supersededID, reason string) error
RecordSupersession records that one memory supersedes another (M3: Plan 021).
func (*SQLiteMemoryStore) UnlinkProvenance ¶
func (s *SQLiteMemoryStore) UnlinkProvenance(ctx context.Context, memoryID string) error
UnlinkProvenance removes provenance links for a memory.
func (*SQLiteMemoryStore) UpdateMemory ¶
func (s *SQLiteMemoryStore) UpdateMemory(ctx context.Context, id string, updates MemoryUpdate) error
UpdateMemory applies partial updates to a memory.
func (*SQLiteMemoryStore) UpdateMemoryAccess ¶ added in v1.5.0
func (s *SQLiteMemoryStore) UpdateMemoryAccess(ctx context.Context, id string) error
UpdateMemoryAccess increments access tracking for a single memory. Updates access_count, last_accessed_at, and recomputes access_velocity in real-time.
type SQLiteVectorStore ¶
type SQLiteVectorStore struct {
// contains filtered or unexported fields
}
SQLiteVectorStore implements VectorStore using SQLite with sqlite-vec as the persistence layer. It uses vec0 virtual tables for indexed approximate nearest neighbor (ANN) vector search.
Implementation notes: - Embeddings are stored in the vec_nodes virtual table (vec0) for indexed ANN search - A mapping table (vec_node_ids) correlates vec0 rowids with string node IDs - Search uses vec0 MATCH operator for efficient O(log n) complexity instead of O(n) linear scan - Legacy nodes.embedding column is maintained for backwards compatibility - The database connection is shared with SQLiteGraphStore and must not be closed by this store
func NewSQLiteVectorStore ¶
func NewSQLiteVectorStore(db *sql.DB) *SQLiteVectorStore
NewSQLiteVectorStore creates a new SQLite-backed vector store. The database connection is shared and owned by the caller (typically SQLiteGraphStore). The SQLiteVectorStore must not close this connection.
func (*SQLiteVectorStore) Add ¶
Add adds or updates an embedding for the given node ID. The node must already exist in the nodes table. Returns an error if the node doesn't exist or if the database operation fails.
Implementation uses vec0 virtual table for indexed vector storage: 1. Checks if node exists in nodes table 2. Inserts/updates entry in vec_node_ids mapping table 3. Inserts/replaces vector in vec_nodes virtual table 4. Updates legacy embedding column in nodes table for backwards compatibility
func (*SQLiteVectorStore) Close ¶
func (s *SQLiteVectorStore) Close() error
Close is a no-op for SQLiteVectorStore because it shares the database connection with SQLiteGraphStore. The connection lifecycle is managed by the owner (GraphStore).
func (*SQLiteVectorStore) Delete ¶
func (s *SQLiteVectorStore) Delete(ctx context.Context, id string) error
Delete removes the embedding for the given node ID. The node itself is not deleted, only the embedding is removed from: - vec_nodes virtual table - vec_node_ids mapping table - nodes.embedding column (legacy, set to NULL) This allows the node to remain in the graph while removing it from vector search.
func (*SQLiteVectorStore) Search ¶
func (s *SQLiteVectorStore) Search(ctx context.Context, query []float32, topK int) ([]SearchResult, error)
Search finds the most similar vectors to the query using vec0 indexed search. Uses sqlite-vec's MATCH operator for efficient approximate nearest neighbor (ANN) search.
Behavior: - Performs indexed ANN search via vec0 virtual table (O(log n) complexity) - Returns distance metric from vec0, converted to similarity score (1 - distance) - Maps rowid back to node string ID via vec_node_ids table - Results are sorted by similarity score in descending order (best matches first) - Returns up to topK results
type SearchResult ¶
type SearchResult struct {
ID string // Node ID
Score float64 // Cosine similarity score (0-1, higher is more similar)
}
SearchResult represents a vector search result with similarity score.
type SupersessionRecord ¶ added in v1.5.0
type SupersessionRecord struct {
ID string `json:"id"`
SupersedingID string `json:"superseding_id"` // New memory that replaces old one
SupersededID string `json:"superseded_id"` // Old memory being replaced
Reason string `json:"reason,omitempty"` // Optional explanation
CreatedAt time.Time `json:"created_at"`
}
SupersessionRecord represents a memory supersession relationship (M3: Plan 021).
type VectorStore ¶
type VectorStore interface {
// Add adds or updates a vector for the given ID.
Add(ctx context.Context, id string, embedding []float32) error
// Search finds the most similar vectors to the query.
// Returns up to topK results sorted by similarity score (descending).
Search(ctx context.Context, query []float32, topK int) ([]SearchResult, error)
// Delete removes a vector from the store.
Delete(ctx context.Context, id string) error
}
VectorStore defines the interface for vector storage and similarity search.