store

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 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 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) 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) 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) 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 string) ([]models.Entity, error)

SearchEntities finds entities whose Name or any Alias contains the given substring (case-insensitive).

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 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", "")
}

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.
	SearchEntities(ctx context.Context, name string) ([]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

	// 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