store

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 17 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 QdrantStore

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

QdrantStore implements Store using Qdrant's gRPC API.

func NewQdrantStore

func NewQdrantStore(host string, port int, collection string, dimension uint64, useTLS bool, logger *slog.Logger) (*QdrantStore, error)

NewQdrantStore creates a new Qdrant store connection.

func (*QdrantStore) Close

func (q *QdrantStore) Close() error

Close releases the gRPC connection.

func (*QdrantStore) Delete

func (q *QdrantStore) Delete(ctx context.Context, id string) error

Delete removes a memory by ID.

func (*QdrantStore) EnsureCollection

func (q *QdrantStore) EnsureCollection(ctx context.Context) error

EnsureCollection creates the vector collection if it doesn't exist.

func (*QdrantStore) FindDuplicates

func (q *QdrantStore) FindDuplicates(ctx context.Context, vector []float32, threshold float64) ([]models.SearchResult, error)

FindDuplicates returns memories with cosine similarity above the threshold.

func (*QdrantStore) Get

func (q *QdrantStore) Get(ctx context.Context, id string) (*models.Memory, error)

Get retrieves a single memory by ID.

func (*QdrantStore) GetChain added in v0.4.0

func (q *QdrantStore) 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, the referenced memory is not found, or a cycle is detected.

func (*QdrantStore) GetEntity added in v0.4.0

func (q *QdrantStore) GetEntity(ctx context.Context, id string) (*models.Entity, error)

GetEntity retrieves a single entity by ID from the Qdrant entity collection.

func (*QdrantStore) LinkMemoryToEntity added in v0.4.0

func (q *QdrantStore) LinkMemoryToEntity(ctx context.Context, entityID, memoryID string) error

LinkMemoryToEntity links a memory to an entity using read-modify-write. This is intentionally non-atomic: concurrent calls may lose a link if they race to update the same entity. This is an acceptable trade-off for the initial implementation.

The method is idempotent: if memoryID is already linked, it returns nil.

func (*QdrantStore) List

func (q *QdrantStore) List(ctx context.Context, filters *SearchFilters, limit uint64, cursor string) ([]models.Memory, string, error)

List returns memories matching the given filters with cursor-based pagination.

func (*QdrantStore) Search

func (q *QdrantStore) Search(ctx context.Context, vector []float32, limit uint64, filters *SearchFilters) ([]models.SearchResult, error)

Search finds memories similar to the query vector.

func (*QdrantStore) SearchEntities added in v0.4.0

func (q *QdrantStore) SearchEntities(ctx context.Context, name string) ([]models.Entity, error)

SearchEntities finds entities whose Name or Aliases contain the given substring (case-insensitive). It uses Qdrant's Scroll API to fetch all entities and filters in Go.

func (*QdrantStore) Stats

Stats returns collection statistics. Type and scope counts are fetched concurrently. Health metrics (temporal range, top accessed, reinforcement tiers, conflicts, TTL, storage) are computed by scrolling all points once.

func (*QdrantStore) UpdateAccessMetadata

func (q *QdrantStore) UpdateAccessMetadata(ctx context.Context, id string) error

UpdateAccessMetadata reads the current access_count, increments it, and writes both access_count and last_accessed via SetPayload. The read-modify-write is intentionally non-atomic: an approximate count is acceptable for ranking, and the simplicity outweighs the cost of a rare missed increment under concurrency.

func (*QdrantStore) UpdateConflictFields added in v0.4.0

func (q *QdrantStore) UpdateConflictFields(ctx context.Context, id, conflictGroupID, conflictStatus string) error

UpdateConflictFields sets ConflictGroupID and ConflictStatus on an existing memory without requiring a re-embed.

func (*QdrantStore) UpdateReinforcement added in v0.4.0

func (q *QdrantStore) UpdateReinforcement(ctx context.Context, id string, confidenceBoost float64) error

UpdateReinforcement boosts the confidence of an existing memory (capped at 1.0) and increments ReinforcedCount. Used when a near-duplicate is captured.

func (*QdrantStore) Upsert

func (q *QdrantStore) Upsert(ctx context.Context, memory models.Memory, vector []float32) error

Upsert inserts or updates a memory with its embedding vector.

func (*QdrantStore) UpsertEntity added in v0.4.0

func (q *QdrantStore) UpsertEntity(ctx context.Context, entity models.Entity) error

UpsertEntity inserts or updates an entity in the Qdrant entity collection.

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