Documentation
¶
Index ¶
- Variables
- type ChatMessage
- type Document
- type Embedder
- type Entry
- type InMemoryStore
- func (s *InMemoryStore) ClearSession(ctx context.Context, sessionID string) error
- func (s *InMemoryStore) Delete(ctx context.Context, id string) error
- func (s *InMemoryStore) ListBySession(ctx context.Context, sessionID string) ([]Entry, error)
- func (s *InMemoryStore) Retrieve(ctx context.Context, id string) (*Entry, error)
- func (s *InMemoryStore) Store(ctx context.Context, entry Entry) error
- type LLMSummarizer
- type LocalEmbedder
- type MemoryManager
- type MilvusStore
- func (m *MilvusStore) CreateCollection(ctx context.Context, name string, dimension int) error
- func (m *MilvusStore) Delete(ctx context.Context, collection, id string) error
- func (m *MilvusStore) Get(ctx context.Context, collection, id string) (*Document, error)
- func (m *MilvusStore) Search(ctx context.Context, collection string, query []float32, topK int) ([]Document, error)
- func (m *MilvusStore) Upsert(ctx context.Context, collection string, doc Document) error
- type RedisMemoryStore
- func (s *RedisMemoryStore) ClearSession(ctx context.Context, sessionID string) error
- func (s *RedisMemoryStore) Delete(ctx context.Context, id string) error
- func (s *RedisMemoryStore) ListBySession(ctx context.Context, sessionID string) ([]Entry, error)
- func (s *RedisMemoryStore) Retrieve(ctx context.Context, id string) (*Entry, error)
- func (s *RedisMemoryStore) Store(ctx context.Context, entry Entry) error
- type ShortTermStore
- type Summarizer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDocNotFound is returned when a document doesn't exist. ErrDocNotFound = errors.New("memory: document not found") )
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
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 ¶
ListBySession returns all entries for a session.
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) EmbedBatch ¶ added in v1.0.0
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.
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
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.
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 ¶
ListBySession returns all entries for a session.
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.