Documentation
¶
Overview ¶
Package memory provides enhanced memory capabilities for agents
Index ¶
- Constants
- type ChromaClient
- type ChromaQueryResult
- type ChromaVectorStore
- func (s *ChromaVectorStore) Clear(ctx context.Context) error
- func (s *ChromaVectorStore) Delete(ctx context.Context, id string) error
- func (s *ChromaVectorStore) GenerateEmbedding(ctx context.Context, content interface{}) ([]float32, error)
- func (s *ChromaVectorStore) Search(ctx context.Context, query []float32, k int, threshold float64) ([]string, []float64, error)
- func (s *ChromaVectorStore) Size() int
- func (s *ChromaVectorStore) Store(ctx context.Context, id string, vector []float32) error
- type Config
- type ConversationStore
- type Embedder
- type EmbeddingModel
- type EmbeddingVectorStore
- type EnhancedMemory
- type HierarchicalMemory
- func (m *HierarchicalMemory) Associate(ctx context.Context, id1, id2 string, strength float64) error
- func (m *HierarchicalMemory) Clear(ctx context.Context) error
- func (m *HierarchicalMemory) Consolidate(ctx context.Context) error
- func (m *HierarchicalMemory) Forget(ctx context.Context, threshold float64) error
- func (m *HierarchicalMemory) Get(ctx context.Context, key string) (interface{}, error)
- func (m *HierarchicalMemory) GetAssociated(ctx context.Context, id string, limit int) ([]*MemoryEntry, error)
- func (m *HierarchicalMemory) GetByType(ctx context.Context, memType MemoryType, limit int) ([]*MemoryEntry, error)
- func (m *HierarchicalMemory) GetStats() *MemoryStats
- func (m *HierarchicalMemory) Search(ctx context.Context, query string, limit int) ([]interface{}, error)
- func (m *HierarchicalMemory) Shutdown(ctx context.Context) error
- func (m *HierarchicalMemory) Store(ctx context.Context, key string, value interface{}, opts StoreOptions) error
- func (m *HierarchicalMemory) StoreTyped(ctx context.Context, key string, value interface{}, memType MemoryType, ...) error
- func (m *HierarchicalMemory) VectorSearch(ctx context.Context, embedding []float32, limit int, threshold float64) ([]*MemoryEntry, error)
- type InMemoryManager
- func (m *InMemoryManager) AddCase(ctx context.Context, caseMemory *interfaces.Case) error
- func (m *InMemoryManager) AddConversation(ctx context.Context, conv *interfaces.Conversation) error
- func (m *InMemoryManager) Clear(ctx context.Context) error
- func (m *InMemoryManager) ClearConversation(ctx context.Context, sessionID string) error
- func (m *InMemoryManager) Delete(ctx context.Context, key string) error
- func (m *InMemoryManager) GetConversationHistory(ctx context.Context, sessionID string, limit int) ([]*interfaces.Conversation, error)
- func (m *InMemoryManager) Retrieve(ctx context.Context, key string) (interface{}, error)
- func (m *InMemoryManager) SearchSimilarCases(ctx context.Context, query string, limit int) ([]*interfaces.Case, error)
- func (m *InMemoryManager) Store(ctx context.Context, key string, value interface{}) error
- type InMemoryVectorStore
- func (s *InMemoryVectorStore) Clear(ctx context.Context) error
- func (s *InMemoryVectorStore) Delete(ctx context.Context, id string) error
- func (s *InMemoryVectorStore) GenerateEmbedding(ctx context.Context, content interface{}) ([]float32, error)
- func (s *InMemoryVectorStore) Search(ctx context.Context, query []float32, k int, threshold float64) ([]string, []float64, error)
- func (s *InMemoryVectorStore) Size() int
- func (s *InMemoryVectorStore) Store(ctx context.Context, id string, vector []float32) error
- type LongTermMemory
- func (m *LongTermMemory) Clear()
- func (m *LongTermMemory) Forget(threshold float64) []string
- func (m *LongTermMemory) Get(ctx context.Context, id string) (*MemoryEntry, error)
- func (m *LongTermMemory) GetAll() []*MemoryEntry
- func (m *LongTermMemory) GetByType(memType MemoryType, limit int) []*MemoryEntry
- func (m *LongTermMemory) Search(ctx context.Context, query string, limit int) ([]interface{}, error)
- func (m *LongTermMemory) Size() int
- func (m *LongTermMemory) Store(ctx context.Context, entry *MemoryEntry) error
- type MemoryConsolidator
- type MemoryEntry
- type MemoryOption
- type MemoryStats
- type MemoryType
- type SearchResult
- type ShortTermMemory
- func (m *ShortTermMemory) Clear()
- func (m *ShortTermMemory) Forget(threshold float64) []string
- func (m *ShortTermMemory) Get(ctx context.Context, id string) (*MemoryEntry, error)
- func (m *ShortTermMemory) GetAll() []*MemoryEntry
- func (m *ShortTermMemory) GetByType(memType MemoryType, limit int) []*MemoryEntry
- func (m *ShortTermMemory) GetConsolidationCandidates(threshold float64) []*MemoryEntry
- func (m *ShortTermMemory) Remove(ctx context.Context, id string) error
- func (m *ShortTermMemory) Search(ctx context.Context, query string, limit int) ([]interface{}, error)
- func (m *ShortTermMemory) Size() int
- func (m *ShortTermMemory) Store(ctx context.Context, entry *MemoryEntry) error
- type SimpleEmbeddingModel
- type SimpleVectorStore
- type StoreOptions
- type VectorStore
Constants ¶
const ( VectorStoreTypeMemory = "memory" // 内存存储 VectorStoreTypeChroma = "chroma" // Chroma 向量数据库 VectorStoreTypePinecone = "pinecone" // Pinecone VectorStoreTypeWeaviate = "weaviate" // Weaviate )
向量存储类型
const ( EmbedderProviderOpenAI = "openai" // OpenAI EmbedderProviderLocal = "local" // 本地模型 EmbedderProviderMock = "mock" // Mock(测试用) )
嵌入提供商
const ( DefaultMaxConversationLength = 10 // 默认最大对话长度 DefaultSearchLimit = 5 // 默认搜索结果数量 DefaultSimilarityThreshold = 0.7 // 默认相似度阈值 DefaultEmbeddingDimension = 1536 // OpenAI text-embedding-ada-002 维度 )
默认配置值
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChromaClient ¶
type ChromaClient interface {
// CreateCollection creates a new collection
CreateCollection(ctx context.Context, name string, metadata map[string]interface{}) error
// AddDocuments adds documents to a collection
AddDocuments(ctx context.Context, collection string, ids []string, embeddings [][]float32, documents []map[string]interface{}) error
// Query queries a collection
Query(ctx context.Context, collection string, queryEmbeddings [][]float32, k int) (*ChromaQueryResult, error)
// Delete deletes documents from a collection
Delete(ctx context.Context, collection string, ids []string) error
// DeleteCollection deletes a collection
DeleteCollection(ctx context.Context, name string) error
}
ChromaClient interface for Chroma database operations
type ChromaQueryResult ¶
type ChromaQueryResult struct {
IDs [][]string `json:"ids"`
Distances [][]float64 `json:"distances"`
Documents [][]map[string]interface{} `json:"documents"`
}
ChromaQueryResult represents query results from Chroma
type ChromaVectorStore ¶
type ChromaVectorStore struct {
// contains filtered or unexported fields
}
ChromaVectorStore integrates with Chroma vector database
func NewChromaVectorStore ¶
func NewChromaVectorStore(client ChromaClient, collection string, dimension int) *ChromaVectorStore
NewChromaVectorStore creates a new Chroma vector store
func (*ChromaVectorStore) Clear ¶
func (s *ChromaVectorStore) Clear(ctx context.Context) error
Clear clears the collection
func (*ChromaVectorStore) Delete ¶
func (s *ChromaVectorStore) Delete(ctx context.Context, id string) error
Delete deletes from Chroma
func (*ChromaVectorStore) GenerateEmbedding ¶
func (s *ChromaVectorStore) GenerateEmbedding(ctx context.Context, content interface{}) ([]float32, error)
GenerateEmbedding generates embeddings (requires external model)
func (*ChromaVectorStore) Search ¶
func (s *ChromaVectorStore) Search(ctx context.Context, query []float32, k int, threshold float64) ([]string, []float64, error)
Search searches in Chroma
func (*ChromaVectorStore) Size ¶
func (s *ChromaVectorStore) Size() int
Size returns the size (not implemented for Chroma)
type Config ¶
type Config struct {
// 对话记忆配置
EnableConversation bool `json:"enable_conversation"` // 是否启用对话记忆
MaxConversationLength int `json:"max_conversation_length"` // 最大对话长度
// 向量存储配置
EnableVectorStore bool `json:"enable_vector_store"` // 是否启用向量存储
VectorStoreType string `json:"vector_store_type"` // 向量存储类型
VectorStorePath string `json:"vector_store_path"` // 向量存储路径
EmbeddingDimension int `json:"embedding_dimension"` // 嵌入维度
// 嵌入器配置
EmbeddingModel string `json:"embedding_model"` // 嵌入模型
EmbeddingProvider string `json:"embedding_provider"` // 嵌入提供商
// 搜索配置
DefaultSearchLimit int `json:"default_search_limit"` // 默认搜索结果数量
SimilarityThreshold float64 `json:"similarity_threshold"` // 相似度阈值
}
Config 记忆管理器配置
type ConversationStore ¶
type ConversationStore interface {
// Add 添加对话
Add(ctx context.Context, conv *interfaces.Conversation) error
// Get 获取对话历史
Get(ctx context.Context, sessionID string, limit int) ([]*interfaces.Conversation, error)
// Clear 清空会话
Clear(ctx context.Context, sessionID string) error
// Count 获取会话对话数量
Count(ctx context.Context, sessionID string) (int, error)
}
ConversationStore 对话存储接口
type Embedder ¶
type Embedder interface {
// Embed 生成文本嵌入
Embed(ctx context.Context, text string) ([]float64, error)
// EmbedBatch 批量生成嵌入
EmbedBatch(ctx context.Context, texts []string) ([][]float64, error)
}
Embedder 嵌入生成器接口
type EmbeddingModel ¶
type EmbeddingModel interface {
// Embed generates embeddings for text
Embed(ctx context.Context, text string) ([]float32, error)
// EmbedBatch generates embeddings for multiple texts
EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
// Dimension returns the embedding dimension
Dimension() int
}
EmbeddingModel interface for generating embeddings
type EmbeddingVectorStore ¶
type EmbeddingVectorStore struct {
*InMemoryVectorStore
// contains filtered or unexported fields
}
EmbeddingVectorStore uses an external embedding model
func NewEmbeddingVectorStore ¶
func NewEmbeddingVectorStore(embedder EmbeddingModel) *EmbeddingVectorStore
NewEmbeddingVectorStore creates a vector store with an embedding model
func (*EmbeddingVectorStore) GenerateEmbedding ¶
func (s *EmbeddingVectorStore) GenerateEmbedding(ctx context.Context, content interface{}) ([]float32, error)
GenerateEmbedding uses the embedding model to generate embeddings
type EnhancedMemory ¶
type EnhancedMemory interface {
// Store memory with specific type
StoreTyped(ctx context.Context, key string, value interface{}, memType MemoryType, opts StoreOptions) error
// Retrieve memories by type
GetByType(ctx context.Context, memType MemoryType, limit int) ([]*MemoryEntry, error)
// Search memories using vector similarity
VectorSearch(ctx context.Context, embedding []float32, limit int, threshold float64) ([]*MemoryEntry, error)
// Consolidate short-term to long-term memory
Consolidate(ctx context.Context) error
// Forget old or unimportant memories
Forget(ctx context.Context, threshold float64) error
// Get memory statistics
GetStats() *MemoryStats
// Create associations between memories
Associate(ctx context.Context, id1, id2 string, strength float64) error
// Get associated memories
GetAssociated(ctx context.Context, id string, limit int) ([]*MemoryEntry, error)
}
EnhancedMemory provides advanced memory capabilities
type HierarchicalMemory ¶
type HierarchicalMemory struct {
// contains filtered or unexported fields
}
HierarchicalMemory implements a hierarchical memory system
func NewHierarchicalMemoryWithContext ¶
func NewHierarchicalMemoryWithContext(parentCtx context.Context, vectorStore VectorStore, opts ...MemoryOption) *HierarchicalMemory
NewHierarchicalMemoryWithContext creates a new hierarchical memory system with a parent context
func (*HierarchicalMemory) Associate ¶
func (m *HierarchicalMemory) Associate(ctx context.Context, id1, id2 string, strength float64) error
Associate creates associations between memories
func (*HierarchicalMemory) Clear ¶
func (m *HierarchicalMemory) Clear(ctx context.Context) error
Clear clears all memory
func (*HierarchicalMemory) Consolidate ¶
func (m *HierarchicalMemory) Consolidate(ctx context.Context) error
Consolidate consolidates short-term to long-term memory
func (*HierarchicalMemory) Forget ¶
func (m *HierarchicalMemory) Forget(ctx context.Context, threshold float64) error
Forget removes old or unimportant memories
func (*HierarchicalMemory) Get ¶
func (m *HierarchicalMemory) Get(ctx context.Context, key string) (interface{}, error)
Get retrieves a value from memory
func (*HierarchicalMemory) GetAssociated ¶
func (m *HierarchicalMemory) GetAssociated(ctx context.Context, id string, limit int) ([]*MemoryEntry, error)
GetAssociated retrieves associated memories
func (*HierarchicalMemory) GetByType ¶
func (m *HierarchicalMemory) GetByType(ctx context.Context, memType MemoryType, limit int) ([]*MemoryEntry, error)
GetByType retrieves memories by type
func (*HierarchicalMemory) GetStats ¶
func (m *HierarchicalMemory) GetStats() *MemoryStats
GetStats returns memory statistics
func (*HierarchicalMemory) Search ¶
func (m *HierarchicalMemory) Search(ctx context.Context, query string, limit int) ([]interface{}, error)
Search searches for memories matching a query
func (*HierarchicalMemory) Shutdown ¶
func (m *HierarchicalMemory) Shutdown(ctx context.Context) error
Shutdown gracefully shuts down the memory system
func (*HierarchicalMemory) Store ¶
func (m *HierarchicalMemory) Store(ctx context.Context, key string, value interface{}, opts StoreOptions) error
Store stores a value in memory
func (*HierarchicalMemory) StoreTyped ¶
func (m *HierarchicalMemory) StoreTyped(ctx context.Context, key string, value interface{}, memType MemoryType, opts StoreOptions) error
StoreTyped stores memory with specific type
func (*HierarchicalMemory) VectorSearch ¶
func (m *HierarchicalMemory) VectorSearch(ctx context.Context, embedding []float32, limit int, threshold float64) ([]*MemoryEntry, error)
VectorSearch searches memories using vector similarity
type InMemoryManager ¶
type InMemoryManager struct {
// contains filtered or unexported fields
}
InMemoryManager 内存记忆管理器实现
func NewInMemoryManager ¶
func NewInMemoryManager(config *Config) *InMemoryManager
NewInMemoryManager 创建内存记忆管理器
func (*InMemoryManager) AddCase ¶
func (m *InMemoryManager) AddCase(ctx context.Context, caseMemory *interfaces.Case) error
AddCase 添加案例
func (*InMemoryManager) AddConversation ¶
func (m *InMemoryManager) AddConversation(ctx context.Context, conv *interfaces.Conversation) error
AddConversation 添加对话
func (*InMemoryManager) Clear ¶
func (m *InMemoryManager) Clear(ctx context.Context) error
Clear 清空所有记忆 Lock acquisition order: convMu -> storeMu -> casesMu (always maintain this order to prevent deadlock)
func (*InMemoryManager) ClearConversation ¶
func (m *InMemoryManager) ClearConversation(ctx context.Context, sessionID string) error
ClearConversation 清空会话对话
func (*InMemoryManager) Delete ¶
func (m *InMemoryManager) Delete(ctx context.Context, key string) error
Delete 删除键值对
func (*InMemoryManager) GetConversationHistory ¶
func (m *InMemoryManager) GetConversationHistory(ctx context.Context, sessionID string, limit int) ([]*interfaces.Conversation, error)
GetConversationHistory 获取对话历史
func (*InMemoryManager) Retrieve ¶
func (m *InMemoryManager) Retrieve(ctx context.Context, key string) (interface{}, error)
Retrieve 检索值
func (*InMemoryManager) SearchSimilarCases ¶
func (m *InMemoryManager) SearchSimilarCases(ctx context.Context, query string, limit int) ([]*interfaces.Case, error)
SearchSimilarCases 搜索相似案例
注意:这是一个简单的文本匹配实现,实际应用中应使用向量相似度搜索
type InMemoryVectorStore ¶
type InMemoryVectorStore struct {
// contains filtered or unexported fields
}
InMemoryVectorStore is a simple in-memory vector store implementation
func NewInMemoryVectorStore ¶
func NewInMemoryVectorStore(dimension int) *InMemoryVectorStore
NewInMemoryVectorStore creates a new in-memory vector store
func (*InMemoryVectorStore) Clear ¶
func (s *InMemoryVectorStore) Clear(ctx context.Context) error
Clear clears all vectors
func (*InMemoryVectorStore) Delete ¶
func (s *InMemoryVectorStore) Delete(ctx context.Context, id string) error
Delete removes a vector
func (*InMemoryVectorStore) GenerateEmbedding ¶
func (s *InMemoryVectorStore) GenerateEmbedding(ctx context.Context, content interface{}) ([]float32, error)
GenerateEmbedding generates a simple embedding for content
func (*InMemoryVectorStore) Search ¶
func (s *InMemoryVectorStore) Search(ctx context.Context, query []float32, k int, threshold float64) ([]string, []float64, error)
Search searches for similar vectors using cosine similarity
func (*InMemoryVectorStore) Size ¶
func (s *InMemoryVectorStore) Size() int
Size returns the number of stored vectors
type LongTermMemory ¶
type LongTermMemory struct {
// contains filtered or unexported fields
}
LongTermMemory implements long-term/persistent memory
func NewLongTermMemory ¶
func NewLongTermMemory(vectorStore VectorStore) *LongTermMemory
NewLongTermMemory creates a new long-term memory
func (*LongTermMemory) Forget ¶
func (m *LongTermMemory) Forget(threshold float64) []string
Forget removes memories below importance threshold
func (*LongTermMemory) Get ¶
func (m *LongTermMemory) Get(ctx context.Context, id string) (*MemoryEntry, error)
Get retrieves an entry from long-term memory
func (*LongTermMemory) GetAll ¶
func (m *LongTermMemory) GetAll() []*MemoryEntry
GetAll returns all entries
func (*LongTermMemory) GetByType ¶
func (m *LongTermMemory) GetByType(memType MemoryType, limit int) []*MemoryEntry
GetByType retrieves entries by memory type
func (*LongTermMemory) Search ¶
func (m *LongTermMemory) Search(ctx context.Context, query string, limit int) ([]interface{}, error)
Search searches for entries in long-term memory
func (*LongTermMemory) Size ¶
func (m *LongTermMemory) Size() int
Size returns the number of entries
func (*LongTermMemory) Store ¶
func (m *LongTermMemory) Store(ctx context.Context, entry *MemoryEntry) error
Store stores an entry in long-term memory
type MemoryConsolidator ¶
type MemoryConsolidator struct {
// contains filtered or unexported fields
}
MemoryConsolidator handles memory consolidation
func NewMemoryConsolidator ¶
func NewMemoryConsolidator() *MemoryConsolidator
NewMemoryConsolidator creates a new memory consolidator
func (*MemoryConsolidator) Consolidate ¶
func (c *MemoryConsolidator) Consolidate(shortTerm []*MemoryEntry, longTerm *LongTermMemory) ([]*MemoryEntry, error)
Consolidate performs memory consolidation
type MemoryEntry ¶
type MemoryEntry struct {
ID string `json:"id"`
Type MemoryType `json:"type"`
Content interface{} `json:"content"`
Embedding []float32 `json:"embedding,omitempty"`
Timestamp time.Time `json:"timestamp"`
LastAccess time.Time `json:"last_access"`
AccessCount int `json:"access_count"`
Importance float64 `json:"importance"`
Decay float64 `json:"decay"`
Tags []string `json:"tags,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Related []string `json:"related,omitempty"` // IDs of related memories
}
MemoryEntry represents a single memory entry
type MemoryOption ¶
type MemoryOption func(*HierarchicalMemory)
MemoryOption configures memory
func WithDecayRate ¶
func WithDecayRate(rate float64) MemoryOption
WithDecayRate sets memory decay rate
func WithShortTermCapacity ¶
func WithShortTermCapacity(capacity int) MemoryOption
WithShortTermCapacity sets short-term memory capacity
type MemoryStats ¶
type MemoryStats struct {
TotalEntries int `json:"total_entries"`
ShortTermCount int `json:"short_term_count"`
LongTermCount int `json:"long_term_count"`
EpisodicCount int `json:"episodic_count"`
SemanticCount int `json:"semantic_count"`
ProceduralCount int `json:"procedural_count"`
TotalSize int64 `json:"total_size"`
LastConsolidation time.Time `json:"last_consolidation"`
AccessPatterns map[string]int `json:"access_patterns"`
}
MemoryStats contains memory statistics
type MemoryType ¶
type MemoryType string
MemoryType represents the type of memory
const ( MemoryTypeShortTerm MemoryType = "short_term" MemoryTypeLongTerm MemoryType = "long_term" MemoryTypeEpisodic MemoryType = "episodic" MemoryTypeSemantic MemoryType = "semantic" MemoryTypeProcedural MemoryType = "procedural" )
type SearchResult ¶
type SearchResult struct {
ID string `json:"id"` // ID
Score float64 `json:"score"` // 相似度分数
Embedding []float64 `json:"embedding"` // 向量
Metadata map[string]interface{} `json:"metadata"` // 元数据
}
SearchResult 搜索结果
type ShortTermMemory ¶
type ShortTermMemory struct {
// contains filtered or unexported fields
}
ShortTermMemory implements short-term/working memory
func NewShortTermMemory ¶
func NewShortTermMemory(capacity int) *ShortTermMemory
NewShortTermMemory creates a new short-term memory
func (*ShortTermMemory) Forget ¶
func (m *ShortTermMemory) Forget(threshold float64) []string
Forget removes memories below importance threshold
func (*ShortTermMemory) Get ¶
func (m *ShortTermMemory) Get(ctx context.Context, id string) (*MemoryEntry, error)
Get retrieves an entry from short-term memory
func (*ShortTermMemory) GetAll ¶
func (m *ShortTermMemory) GetAll() []*MemoryEntry
GetAll returns all entries
func (*ShortTermMemory) GetByType ¶
func (m *ShortTermMemory) GetByType(memType MemoryType, limit int) []*MemoryEntry
GetByType retrieves entries by memory type
func (*ShortTermMemory) GetConsolidationCandidates ¶
func (m *ShortTermMemory) GetConsolidationCandidates(threshold float64) []*MemoryEntry
GetConsolidationCandidates gets memories ready for consolidation
func (*ShortTermMemory) Remove ¶
func (m *ShortTermMemory) Remove(ctx context.Context, id string) error
Remove removes an entry from short-term memory
func (*ShortTermMemory) Search ¶
func (m *ShortTermMemory) Search(ctx context.Context, query string, limit int) ([]interface{}, error)
Search searches for entries in short-term memory
func (*ShortTermMemory) Size ¶
func (m *ShortTermMemory) Size() int
Size returns the number of entries
func (*ShortTermMemory) Store ¶
func (m *ShortTermMemory) Store(ctx context.Context, entry *MemoryEntry) error
Store stores an entry in short-term memory
type SimpleEmbeddingModel ¶
type SimpleEmbeddingModel struct {
// contains filtered or unexported fields
}
SimpleEmbeddingModel is a simple embedding model for testing
func NewSimpleEmbeddingModel ¶
func NewSimpleEmbeddingModel(dimension int) *SimpleEmbeddingModel
NewSimpleEmbeddingModel creates a simple embedding model
func (*SimpleEmbeddingModel) Dimension ¶
func (m *SimpleEmbeddingModel) Dimension() int
Dimension returns the embedding dimension
func (*SimpleEmbeddingModel) EmbedBatch ¶
EmbedBatch generates embeddings for multiple texts
type SimpleVectorStore ¶
type SimpleVectorStore interface {
// Store stores a vector with an ID
Store(ctx context.Context, id string, vector []float32) error
// Search searches for similar vectors
Search(ctx context.Context, query []float32, k int, threshold float64) (ids []string, scores []float64, err error)
// Delete removes a vector
Delete(ctx context.Context, id string) error
// GenerateEmbedding generates an embedding for content
GenerateEmbedding(ctx context.Context, content interface{}) ([]float32, error)
// Clear clears all vectors
Clear(ctx context.Context) error
// Size returns the number of stored vectors
Size() int
}
SimpleVectorStore interface for vector-based memory storage
type StoreOptions ¶
type StoreOptions struct {
TTL time.Duration // Time to live
Priority float64 // Priority for retrieval
Tags []string // Tags for categorization
Metadata map[string]interface{} // Additional metadata
}
StoreOptions provides options for storing memory
type VectorStore ¶
type VectorStore interface {
// Add 添加向量
Add(ctx context.Context, id string, embedding []float64, metadata map[string]interface{}) error
// Search 搜索相似向量
Search(ctx context.Context, embedding []float64, limit int) ([]*SearchResult, error)
// Delete 删除向量
Delete(ctx context.Context, id string) error
// Clear 清空存储
Clear(ctx context.Context) error
}
VectorStore 向量存储接口