store

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("memory not found")

ErrNotFound is returned by Get and Delete when the requested memory does not exist.

Functions

This section is empty.

Types

type ContradictionDetector added in v0.8.0

type ContradictionDetector interface {
	FindContradictions(ctx context.Context, content string, embedding []float32) ([]ContradictionHit, error)
}

ContradictionDetector is the interface the store uses to detect contradictions. Implemented by capture.MemoryContradictionDetector.

type ContradictionHit added in v0.8.0

type ContradictionHit struct {
	CandidateID string
	Reason      string
}

ContradictionHit describes a memory that contradicts a new one being stored.

type MockStore

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

MockStore is an in-memory implementation of Store for testing.

func NewMockStore

func NewMockStore() *MockStore

NewMockStore creates a new mock store.

func (*MockStore) Close

func (m *MockStore) Close() error

Close is a no-op for the mock store.

func (*MockStore) Delete

func (m *MockStore) Delete(_ context.Context, id string) error

Delete removes a memory by ID.

func (*MockStore) DeleteAllMemories added in v0.10.0

func (m *MockStore) DeleteAllMemories(_ context.Context) error

DeleteAllMemories clears all in-memory data from the mock store. MockStore's complete mutable state is exactly two maps — memories and entities — both reset here. There are no relationship or episode maps: MemgraphStore stores episodes and relationships as graph nodes/edges removed by MATCH (n) DETACH DELETE n; MockStore has no equivalent structures, so resetting memories + entities is a full wipe and matches the contract.

func (*MockStore) EnsureCollection

func (m *MockStore) EnsureCollection(_ context.Context) error

EnsureCollection is a no-op for the mock store.

func (*MockStore) FindDuplicates

func (m *MockStore) FindDuplicates(_ context.Context, vector []float32, threshold float64) ([]models.SearchResult, error)

FindDuplicates returns memories with cosine similarity above the threshold.

func (*MockStore) Get

func (m *MockStore) Get(_ context.Context, id string) (*models.Memory, error)

Get retrieves a single memory by ID.

func (*MockStore) GetChain added in v0.4.0

func (m *MockStore) GetChain(ctx context.Context, id string) ([]models.Memory, error)

GetChain follows the SupersedesID chain and returns the full history. The chain is returned newest first. Stops when SupersedesID is empty or the referenced memory is not found. A visited set prevents infinite loops.

func (*MockStore) GetEntity added in v0.4.0

func (m *MockStore) GetEntity(_ context.Context, id string) (*models.Entity, error)

GetEntity retrieves a single entity by ID.

func (*MockStore) GetHistory added in v0.8.0

func (m *MockStore) GetHistory(ctx context.Context, id string) ([]models.Memory, error)

GetHistory returns all versions of a memory chain (follows SupersedesID).

func (*MockStore) InvalidateMemory added in v0.8.0

func (m *MockStore) InvalidateMemory(_ context.Context, id string, validTo time.Time) error

InvalidateMemory sets valid_to on a memory without deleting it.

func (*MockStore) LinkMemoryToEntity added in v0.4.0

func (m *MockStore) LinkMemoryToEntity(_ context.Context, entityID, memoryID string) error

LinkMemoryToEntity adds a memory ID to an entity's MemoryIDs list.

func (*MockStore) List

func (m *MockStore) List(_ context.Context, filters *SearchFilters, limit uint64, cursor string) ([]models.Memory, string, error)

List returns memories matching filters with cursor-based pagination.

func (*MockStore) MigrateTemporalFields added in v0.8.0

func (m *MockStore) MigrateTemporalFields(_ context.Context) error

MigrateTemporalFields is a no-op in the mock store.

func (*MockStore) Search

func (m *MockStore) Search(_ context.Context, vector []float32, limit uint64, filters *SearchFilters) ([]models.SearchResult, error)

Search finds memories by cosine similarity to the query vector.

func (*MockStore) SearchEntities added in v0.4.0

func (m *MockStore) SearchEntities(_ context.Context, name, entityType string, limit int) ([]models.Entity, error)

SearchEntities finds entities whose Name or any Alias contains the given substring (case-insensitive). entityType filters by type (empty = all). limit caps results (0 = no cap).

func (*MockStore) Stats

Stats returns collection statistics computed from the in-memory store.

func (*MockStore) UpdateAccessMetadata

func (m *MockStore) UpdateAccessMetadata(_ context.Context, id string) error

UpdateAccessMetadata updates the last-accessed timestamp and increments the access count.

func (*MockStore) UpdateConflictFields added in v0.4.0

func (m *MockStore) UpdateConflictFields(_ context.Context, id, groupID, status string) error

UpdateConflictFields sets ConflictGroupID and ConflictStatus on an existing memory.

func (*MockStore) UpdateReinforcement added in v0.4.0

func (m *MockStore) UpdateReinforcement(_ context.Context, id string, boost float64) error

UpdateReinforcement boosts the confidence of an existing memory (capped at 1.0) and increments ReinforcedCount.

func (*MockStore) Upsert

func (m *MockStore) Upsert(_ context.Context, memory models.Memory, vector []float32) error

Upsert inserts or updates a memory in the mock store.

func (*MockStore) UpsertEntity added in v0.4.0

func (m *MockStore) UpsertEntity(_ context.Context, entity models.Entity) error

UpsertEntity inserts or updates an entity in the mock store.

type ResettableStore added in v0.10.0

type ResettableStore interface {
	Store
	// DeleteAllMemories removes all data from the store (memories, entities,
	// episodes, and any relationships between them). Intended for eval/test
	// isolation — destructive, use with care.
	DeleteAllMemories(ctx context.Context) error
}

ResettableStore extends Store with a full-wipe operation. Keeping DeleteAllMemories out of the main Store interface prevents production code paths (capture, recall, lifecycle) from accidentally calling it. Only cmd_reset.go and eval/benchmark harnesses interact with this interface.

type SearchFilters

type SearchFilters struct {
	Type           *models.MemoryType       `json:"type,omitempty"`
	Scope          *models.MemoryScope      `json:"scope,omitempty"`
	Visibility     *models.MemoryVisibility `json:"visibility,omitempty"`
	Project        *string                  `json:"project,omitempty"`
	Tags           []string                 `json:"tags,omitempty"`
	Source         *string                  `json:"source,omitempty"`
	ConflictStatus *models.ConflictStatus   `json:"conflict_status,omitempty"` // filter by conflict status ("active", "resolved", "")

	// UserID filters results to memories owned by this user. Empty = no filter (returns all).
	UserID string `json:"user_id,omitempty"`

	// IncludeInvalidated includes memories with valid_to set (historical versions).
	// Default: false (only return currently-valid memories).
	IncludeInvalidated bool `json:"include_invalidated,omitempty"`

	// AsOf returns memories valid at a specific point in time.
	// valid_from <= AsOf AND (valid_to IS NULL OR valid_to > AsOf)
	AsOf *time.Time `json:"as_of,omitempty"`
}

SearchFilters allows filtering search results.

type Store

type Store interface {
	// EnsureCollection creates the vector collection if it doesn't exist.
	EnsureCollection(ctx context.Context) error

	// Upsert inserts or updates a memory with its embedding vector.
	Upsert(ctx context.Context, memory models.Memory, vector []float32) error

	// Search finds memories similar to the query vector.
	Search(ctx context.Context, vector []float32, limit uint64, filters *SearchFilters) ([]models.SearchResult, error)

	// Get retrieves a single memory by ID.
	Get(ctx context.Context, id string) (*models.Memory, error)

	// Delete removes a memory by ID.
	Delete(ctx context.Context, id string) error

	// List returns memories matching the given filters.
	// The cursor parameter is opaque; pass "" for the first page.
	// The returned cursor is empty when no more results remain.
	List(ctx context.Context, filters *SearchFilters, limit uint64, cursor string) ([]models.Memory, string, error)

	// FindDuplicates returns memories with cosine similarity above the threshold.
	FindDuplicates(ctx context.Context, vector []float32, threshold float64) ([]models.SearchResult, error)

	// UpdateAccessMetadata increments access count and updates last_accessed time.
	UpdateAccessMetadata(ctx context.Context, id string) error

	// Stats returns collection statistics.
	Stats(ctx context.Context) (*models.CollectionStats, error)

	// UpsertEntity inserts or updates an entity.
	UpsertEntity(ctx context.Context, entity models.Entity) error

	// GetEntity retrieves a single entity by ID.
	GetEntity(ctx context.Context, id string) (*models.Entity, error)

	// SearchEntities finds entities whose name contains the given string.
	// entityType filters by entity type (empty = all types).
	// limit caps the number of results (0 = use implementation default).
	SearchEntities(ctx context.Context, name, entityType string, limit int) ([]models.Entity, error)

	// LinkMemoryToEntity adds a memory ID to an entity's memory list.
	LinkMemoryToEntity(ctx context.Context, entityID, memoryID string) error

	// GetChain follows the SupersedesID chain and returns the full history.
	// The chain is returned newest first, stopping when SupersedesID is empty
	// or the referenced memory is not found.
	GetChain(ctx context.Context, id string) ([]models.Memory, error)

	// UpdateConflictFields sets ConflictGroupID and ConflictStatus on an existing memory
	// without requiring a re-embed.
	UpdateConflictFields(ctx context.Context, id, conflictGroupID, conflictStatus string) error

	// UpdateReinforcement boosts the confidence of an existing memory (capped at 1.0)
	// and increments ReinforcedCount. Used when a near-duplicate is captured.
	UpdateReinforcement(ctx context.Context, id string, confidenceBoost float64) error

	// InvalidateMemory sets valid_to on a memory without deleting it.
	// Used when a superseding memory is stored (temporal versioning).
	InvalidateMemory(ctx context.Context, id string, validTo time.Time) error

	// GetHistory returns all versions of a memory chain, including invalidated ones.
	// Uses SupersedesID chain traversal. Newest version first.
	GetHistory(ctx context.Context, id string) ([]models.Memory, error)

	// MigrateTemporalFields backfills valid_from = created_at for all memories
	// that do not yet have valid_from set. Idempotent.
	MigrateTemporalFields(ctx context.Context) error

	// Close cleans up resources.
	Close() error
}

Store defines the interface for memory persistence with vector search.

Jump to

Keyboard shortcuts

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