memory

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDocNotFound is returned when a document doesn't exist.
	ErrDocNotFound = errors.New("memory: document not found")
)
View Source
var (
	// ErrNotFound is returned when a memory entry doesn't exist.
	ErrNotFound = errors.New("memory: entry not found")
)

Functions

This section is empty.

Types

type ChatMessage added in v1.0.0

type ChatMessage struct {
	Role    string
	Content string
}

ChatMessage represents a conversation message.

type Document added in v1.0.0

type Document struct {
	ID        string
	Content   string
	Embedding []float32
	Metadata  map[string]string
	Score     float32 // For search results
}

Document represents a vector document.

type Embedder added in v1.0.0

type Embedder interface {
	Embed(ctx context.Context, text string) ([]float32, error)
	EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
}

Embedder generates vector embeddings from text.

type Entry

type Entry struct {
	ID        string
	SessionID string
	Content   string
	Tags      []string
	CreatedAt time.Time
	TTL       time.Duration
}

Entry represents a short-term memory item.

type InMemoryStore

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

InMemoryStore implements ShortTermStore using an in-memory map.

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

NewInMemoryStore creates a new in-memory store.

func (*InMemoryStore) ClearSession

func (s *InMemoryStore) ClearSession(ctx context.Context, sessionID string) error

ClearSession removes all entries for a session.

func (*InMemoryStore) Delete

func (s *InMemoryStore) Delete(ctx context.Context, id string) error

Delete removes a memory entry.

func (*InMemoryStore) ListBySession

func (s *InMemoryStore) ListBySession(ctx context.Context, sessionID string) ([]Entry, error)

ListBySession returns all entries for a session.

func (*InMemoryStore) Retrieve

func (s *InMemoryStore) Retrieve(ctx context.Context, id string) (*Entry, error)

Retrieve gets a memory entry by ID.

func (*InMemoryStore) Store

func (s *InMemoryStore) Store(ctx context.Context, entry Entry) error

Store saves a memory entry.

type LLMSummarizer added in v1.0.0

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

LLMSummarizer uses an LLM to summarize conversations.

func NewLLMSummarizer added in v1.0.0

func NewLLMSummarizer() *LLMSummarizer

NewLLMSummarizer creates a summarizer.

func (*LLMSummarizer) ShouldSummarize added in v1.0.0

func (s *LLMSummarizer) ShouldSummarize(messages []ChatMessage) bool

ShouldSummarize returns true if conversation is long enough.

func (*LLMSummarizer) Summarize added in v1.0.0

func (s *LLMSummarizer) Summarize(ctx context.Context, messages []ChatMessage) (string, error)

Summarize compresses messages into a summary.

type LocalEmbedder added in v1.0.0

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

LocalEmbedder is a stub embedder for V1 (deterministic hash-based). Replace with OpenAI/local model in production.

func NewLocalEmbedder added in v1.0.0

func NewLocalEmbedder() *LocalEmbedder

NewLocalEmbedder creates a stub embedder.

func (*LocalEmbedder) Embed added in v1.0.0

func (e *LocalEmbedder) Embed(ctx context.Context, text string) ([]float32, error)

Embed generates a deterministic embedding from text.

func (*LocalEmbedder) EmbedBatch added in v1.0.0

func (e *LocalEmbedder) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

EmbedBatch generates embeddings for multiple texts.

type MemoryManager added in v1.0.0

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

MemoryManager orchestrates the embed → store → summarize pipeline.

On each message:

  • Generate embedding for the message
  • Store in vector store (scoped by tenant + user)

On session threshold:

  • Summarize conversation
  • Store summary as long-term memory

func NewMemoryManager added in v1.0.0

func NewMemoryManager(embedder Embedder, store *MilvusStore, summarizer Summarizer) *MemoryManager

NewMemoryManager creates a new MemoryManager with the given components.

func (*MemoryManager) Initialize added in v1.0.0

func (m *MemoryManager) Initialize(ctx context.Context) error

Initialize sets up required collections.

func (*MemoryManager) OnMessage added in v1.0.0

func (m *MemoryManager) OnMessage(ctx context.Context, sessionID, tenantID, userID, role, content string) error

OnMessage processes a new message: embed and store, then check summarization threshold.

func (*MemoryManager) Recall added in v1.0.0

func (m *MemoryManager) Recall(ctx context.Context, query string, topK int) ([]Document, error)

Recall retrieves relevant memories for context enrichment.

type MilvusStore added in v1.0.0

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

MilvusStore implements vector storage with Milvus (in-memory stub).

func NewMilvusStore added in v1.0.0

func NewMilvusStore() *MilvusStore

NewMilvusStore creates a new Milvus store.

func (*MilvusStore) CreateCollection added in v1.0.0

func (m *MilvusStore) CreateCollection(ctx context.Context, name string, dimension int) error

CreateCollection creates a new collection.

func (*MilvusStore) Delete added in v1.0.0

func (m *MilvusStore) Delete(ctx context.Context, collection, id string) error

Delete removes a document by ID.

func (*MilvusStore) Get added in v1.0.0

func (m *MilvusStore) Get(ctx context.Context, collection, id string) (*Document, error)

Get retrieves a document by ID.

func (*MilvusStore) Search added in v1.0.0

func (m *MilvusStore) Search(ctx context.Context, collection string, query []float32, topK int) ([]Document, error)

Search performs vector similarity search.

func (*MilvusStore) Upsert added in v1.0.0

func (m *MilvusStore) Upsert(ctx context.Context, collection string, doc Document) error

Upsert inserts or updates a document.

type RedisMemoryStore

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

RedisMemoryStore implements ShortTermStore using Redis.

func NewRedisMemoryStore

func NewRedisMemoryStore(client *redis.Client) *RedisMemoryStore

NewRedisMemoryStore creates a new Redis memory store.

func (*RedisMemoryStore) ClearSession

func (s *RedisMemoryStore) ClearSession(ctx context.Context, sessionID string) error

ClearSession removes all entries for a session.

func (*RedisMemoryStore) Delete

func (s *RedisMemoryStore) Delete(ctx context.Context, id string) error

Delete removes a memory entry.

func (*RedisMemoryStore) ListBySession

func (s *RedisMemoryStore) ListBySession(ctx context.Context, sessionID string) ([]Entry, error)

ListBySession returns all entries for a session.

func (*RedisMemoryStore) Retrieve

func (s *RedisMemoryStore) Retrieve(ctx context.Context, id string) (*Entry, error)

Retrieve gets a memory entry by ID.

func (*RedisMemoryStore) Store

func (s *RedisMemoryStore) Store(ctx context.Context, entry Entry) error

Store saves a memory entry.

type ShortTermStore

type ShortTermStore interface {
	Store(ctx context.Context, entry Entry) error
	Retrieve(ctx context.Context, id string) (*Entry, error)
	ListBySession(ctx context.Context, sessionID string) ([]Entry, error)
	Delete(ctx context.Context, id string) error
	ClearSession(ctx context.Context, sessionID string) error
}

ShortTermStore provides short-term memory operations.

type Summarizer added in v1.0.0

type Summarizer interface {
	Summarize(ctx context.Context, messages []ChatMessage) (string, error)
	ShouldSummarize(messages []ChatMessage) bool
}

Summarizer compresses conversation history.

Jump to

Keyboard shortcuts

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