memory

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DaprVectorStore

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

DaprVectorStore implements VectorStore using Dapr state store

func NewDaprVectorStore

func NewDaprVectorStore(client dapr.Client, storeName, indexName string) *DaprVectorStore

NewDaprVectorStore creates a Dapr-backed vector store

func (*DaprVectorStore) Delete

func (d *DaprVectorStore) Delete(ctx context.Context, id string) error

func (*DaprVectorStore) Search

func (d *DaprVectorStore) Search(ctx context.Context, queryEmbedding []float64, limit int, filters map[string]interface{}) ([]VectorSearchResult, error)

func (*DaprVectorStore) Store

func (d *DaprVectorStore) Store(ctx context.Context, id string, embedding []float64, metadata map[string]interface{}) error

func (*DaprVectorStore) Update

func (d *DaprVectorStore) Update(ctx context.Context, id string, embedding []float64, metadata map[string]interface{}) error

type EmbeddingProvider

type EmbeddingProvider interface {
	Embed(ctx context.Context, text string) ([]float64, error)
}

EmbeddingProvider generates embeddings

type Episode

type Episode struct {
	ID           string                 `json:"id"`
	Summary      string                 `json:"summary"`
	Interactions []Interaction          `json:"interactions"`
	Outcome      string                 `json:"outcome"`
	Lessons      []string               `json:"lessons"`
	Metadata     map[string]interface{} `json:"metadata"`
	StartTime    time.Time              `json:"start_time"`
	EndTime      time.Time              `json:"end_time"`
}

Episode represents an episodic memory

type HybridMemory

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

HybridMemory combines multiple memory types for optimal retrieval

func NewHybridMemory

func NewHybridMemory(shortTerm, episodic *Memory, rag *RAGMemory) *HybridMemory

NewHybridMemory creates a hybrid memory system

func (*HybridMemory) RetrieveHybrid

func (h *HybridMemory) RetrieveHybrid(ctx context.Context, query string, limit int) (string, error)

RetrieveHybrid retrieves from all memory types and combines results

type Interaction

type Interaction struct {
	Role      string    `json:"role"`
	Content   string    `json:"content"`
	Timestamp time.Time `json:"timestamp"`
}

Interaction represents one turn in an episode

type Memory

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

Memory represents agent memory storage

func NewMemory

func NewMemory(daprClient dapr.Client, storeName, agentID string) *Memory

NewMemory creates a new memory instance

func (*Memory) Add

func (m *Memory) Add(ctx context.Context, memType MemoryType, content string, metadata map[string]interface{}) error

Add adds a memory entry

func (*Memory) AddEpisode

func (m *Memory) AddEpisode(ctx context.Context, episode Episode) error

AddEpisode records an episodic memory

func (*Memory) Clear

func (m *Memory) Clear(memType MemoryType)

Clear clears memory

func (*Memory) GetContext

func (m *Memory) GetContext(ctx context.Context, query string, maxTokens int) (string, error)

GetContext builds context from relevant memories

func (*Memory) GetEpisodes

func (m *Memory) GetEpisodes(ctx context.Context, filters map[string]interface{}) ([]Episode, error)

GetEpisodes retrieves past episodes

func (*Memory) LoadFromState

func (m *Memory) LoadFromState(ctx context.Context) error

LoadFromState loads memory from Dapr state store

func (*Memory) Reflect

func (m *Memory) Reflect(ctx context.Context) ([]string, error)

Reflect performs memory reflection to extract insights

func (*Memory) Retrieve

func (m *Memory) Retrieve(ctx context.Context, query string, limit int) ([]MemoryEntry, error)

Retrieve retrieves relevant memories

func (*Memory) SaveToState

func (m *Memory) SaveToState(ctx context.Context) error

SaveToState persists all memory to Dapr state store

type MemoryCompression

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

MemoryCompression compresses old memories to save space

func (*MemoryCompression) CompressMemories

func (m *MemoryCompression) CompressMemories(ctx context.Context, memories []MemoryEntry) ([]MemoryEntry, error)

CompressMemories compresses old memories into summaries

type MemoryEntry

type MemoryEntry struct {
	ID         string                 `json:"id"`
	Type       MemoryType             `json:"type"`
	Content    string                 `json:"content"`
	Embedding  []float64              `json:"embedding,omitempty"`
	Metadata   map[string]interface{} `json:"metadata"`
	Timestamp  time.Time              `json:"timestamp"`
	Importance float64                `json:"importance"` // 0-1 scale
}

MemoryEntry represents a single memory

type MemoryPrioritization

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

MemoryPrioritization prioritizes memories based on multiple factors

func (*MemoryPrioritization) PriorityScore

func (m *MemoryPrioritization) PriorityScore(entry *MemoryEntry, accessCount int) float64

PriorityScore calculates priority score for a memory

func (*MemoryPrioritization) PruneMemories

func (m *MemoryPrioritization) PruneMemories(entries []MemoryEntry, accessCounts map[string]int, keepCount int) []MemoryEntry

PruneMemories removes low-priority memories

type MemoryType

type MemoryType string

MemoryType defines different memory types

const (
	ShortTerm  MemoryType = "short-term" // Recent conversation
	LongTerm   MemoryType = "long-term"  // Persistent facts
	Episodic   MemoryType = "episodic"   // Past episodes/experiences
	Semantic   MemoryType = "semantic"   // General knowledge
	Procedural MemoryType = "procedural" // How-to knowledge
)

type RAGMemory

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

RAGMemory implements Retrieval-Augmented Generation memory

func NewRAGMemory

func NewRAGMemory(base *Memory, vectorStore VectorStore, embedder EmbeddingProvider) *RAGMemory

NewRAGMemory creates a new RAG-enabled memory system

func (*RAGMemory) AddDocument

func (r *RAGMemory) AddDocument(ctx context.Context, docID, content string, metadata map[string]interface{}) error

AddDocument adds a document to RAG memory with chunking

func (*RAGMemory) RetrieveContext

func (r *RAGMemory) RetrieveContext(ctx context.Context, query string, limit int, filters map[string]interface{}) (string, error)

RetrieveContext retrieves relevant context for a query using RAG

type Reranker

type Reranker interface {
	Rerank(ctx context.Context, query string, results []VectorSearchResult) ([]VectorSearchResult, error)
}

Reranker reorders search results for better relevance

type SimpleReranker

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

SimpleReranker implements cross-encoder style reranking

func NewSimpleReranker

func NewSimpleReranker(embedder EmbeddingProvider) *SimpleReranker

func (*SimpleReranker) Rerank

func (s *SimpleReranker) Rerank(ctx context.Context, query string, results []VectorSearchResult) ([]VectorSearchResult, error)

type SummarizerProvider

type SummarizerProvider interface {
	Summarize(ctx context.Context, content string) (string, error)
}

SummarizerProvider generates summaries of content

type VectorEntry

type VectorEntry struct {
	ID        string
	Embedding []float64
	Metadata  map[string]interface{}
	Timestamp time.Time
}

VectorEntry represents a stored vector

type VectorMemory

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

VectorMemory provides vector-based semantic memory

func NewVectorMemory

func NewVectorMemory(base *Memory, embedder EmbeddingProvider) *VectorMemory

NewVectorMemory creates vector-enabled memory

func (*VectorMemory) AddWithEmbedding

func (v *VectorMemory) AddWithEmbedding(ctx context.Context, memType MemoryType, content string, metadata map[string]interface{}) error

AddWithEmbedding adds memory with vector embedding

func (*VectorMemory) SemanticSearch

func (v *VectorMemory) SemanticSearch(ctx context.Context, query string, limit int) ([]MemoryEntry, error)

SemanticSearch performs vector similarity search

type VectorSearchResult

type VectorSearchResult struct {
	ID        string
	Score     float64
	Embedding []float64
	Metadata  map[string]interface{}
	Content   string
}

VectorSearchResult represents a search result from vector store

type VectorStore

type VectorStore interface {
	Store(ctx context.Context, id string, embedding []float64, metadata map[string]interface{}) error
	Search(ctx context.Context, queryEmbedding []float64, limit int, filters map[string]interface{}) ([]VectorSearchResult, error)
	Delete(ctx context.Context, id string) error
	Update(ctx context.Context, id string, embedding []float64, metadata map[string]interface{}) error
}

VectorStore interface for vector database operations

Jump to

Keyboard shortcuts

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