Documentation
¶
Overview ¶
Package memkit 提供代理侧结构化记忆:偏好、知识库、Markdown 索引、PageIndex 检索等; 与会话聊天记录包 dino/chatstore(Provider / OpenSharedChatStore)职责分离。
Index ¶
- Constants
- Variables
- func IsMaxLimitExceeded(err error) bool
- func IsNotFound(err error) bool
- type DocSearchCandidate
- type ErrorCode
- type IndexConfig
- type IndexNode
- type IndexSearchResult
- type IndexStore
- type IndexTree
- type KnowledgeEntry
- type KnowledgeStore
- type LLMProvider
- type Manager
- type MemoryConfig
- type MemoryError
- type MemoryItem
- type MemoryStats
- type MemoryType
- type Message
- type MultiTenantManager
- func (m *MultiTenantManager) GetBuilder(userID string) *search.IndexBuilder
- func (m *MultiTenantManager) GetManager(userID string) Manager
- func (m *MultiTenantManager) PageIndexRAG(userID string) *search.PageIndexRAG
- func (m *MultiTenantManager) RemoveManager(userID string) error
- func (m *MultiTenantManager) TreeSearchWithMemory(ctx context.Context, userID, sourceID, query string) (*TreeSearchResult, error)
- type PageIndexDoc
- type PageIndexHit
- type PageIndexKind
- type PageIndexRAGResult
- type PageIndexSearchOptions
- type PageIndexStore
- type Preference
- type PreferenceStore
- type Priority
- type SearchOptions
- type SearchResult
- type Tool
- type TreeSearchResult
Constants ¶
View Source
const ( MemoryTypePreference = typescore.MemoryTypePreference MemoryTypeKnowledge = typescore.MemoryTypeKnowledge MemoryTypeIndex = typescore.MemoryTypeIndex PriorityLow = typescore.PriorityLow PriorityMedium = typescore.PriorityMedium PriorityHigh = typescore.PriorityHigh PageKindPreference = typescore.PageKindPreference PageKindKnowledge = typescore.PageKindKnowledge PageKindLongTerm = typescore.PageKindLongTerm PageKindKnowledgeBase = typescore.PageKindKnowledgeBase )
Variables ¶
View Source
var ( ErrNotFound = errors.New("memory: not found") ErrAlreadyExists = errors.New("memory: already exists") ErrInvalidInput = errors.New("memory: invalid input") ErrMaxLimitExceeded = errors.New("memory: max limit exceeded") ErrStoreNotReady = errors.New("memory: store not ready") ErrUnsupported = errors.New("memory: unsupported operation") )
Functions ¶
func IsMaxLimitExceeded ¶
func IsNotFound ¶
Types ¶
type DocSearchCandidate ¶
type DocSearchCandidate = typescore.DocSearchCandidate
type ErrorCode ¶
type ErrorCode string
const ( ErrCodeNotFound ErrorCode = "NOT_FOUND" ErrCodeAlreadyExists ErrorCode = "ALREADY_EXISTS" ErrCodeInvalidInput ErrorCode = "INVALID_INPUT" ErrCodeMaxLimitExceeded ErrorCode = "MAX_LIMIT_EXCEEDED" ErrCodeStoreNotReady ErrorCode = "STORE_NOT_READY" ErrCodeUnsupported ErrorCode = "UNSUPPORTED" ErrCodeInternal ErrorCode = "INTERNAL" )
type IndexConfig ¶
type IndexConfig = typescore.IndexConfig
func DefaultIndexConfig ¶
func DefaultIndexConfig() *IndexConfig
type IndexSearchResult ¶
type IndexSearchResult = typescore.IndexSearchResult
type IndexStore ¶
type IndexStore interface {
// CreateIndex create index
CreateIndex(ctx context.Context, userID, sourceID, title string, nodes []*IndexNode) (*IndexTree, error)
// GetIndex get index
GetIndex(ctx context.Context, userID, sourceID string) (*IndexTree, error)
// UpdateIndex update index
UpdateIndex(ctx context.Context, tree *IndexTree) error
// DeleteIndex delete index
DeleteIndex(ctx context.Context, userID, sourceID string) error
// SearchIndex search index nodes
SearchIndex(ctx context.Context, userID, query string, limit int) (*IndexSearchResult, error)
// GetAllIndexes get all user indexes
GetAllIndexes(ctx context.Context, userID string) ([]*IndexTree, error)
// AddNode add node
AddNode(ctx context.Context, userID, sourceID string, node *IndexNode, parentID string) error
// RemoveNode delete node
RemoveNode(ctx context.Context, userID, sourceID, nodeID string) error
// UpdateNode update node
UpdateNode(ctx context.Context, userID, sourceID string, node *IndexNode) error
}
IndexStore Manage Markdown index.
Error:
- ErrInvalidInput: userID or sourceID is empty
type KnowledgeEntry ¶
type KnowledgeEntry = typescore.KnowledgeEntry
type KnowledgeStore ¶
type KnowledgeStore interface {
// Add add knowledge entry
Add(ctx context.Context, entry KnowledgeEntry) error
// Update update knowledge entry
Update(ctx context.Context, entry KnowledgeEntry) error
// Get get knowledge entry
Get(ctx context.Context, id string) (*KnowledgeEntry, error)
// Delete delete knowledge entry
Delete(ctx context.Context, id string) error
// Search search knowledge
Search(ctx context.Context, userID string, opts *SearchOptions) (*SearchResult, error)
// GetByTags get knowledge by tags
GetByTags(ctx context.Context, userID string, tags []string) ([]KnowledgeEntry, error)
// GetByCategory 按分类获取知识
GetByCategory(ctx context.Context, userID, category string) ([]KnowledgeEntry, error)
// Clear 清除用户所有知识
Clear(ctx context.Context, userID string) error
// GetStats 获取知识条目数量
GetStats(ctx context.Context, userID string) (int, error)
}
KnowledgeStore Manage user knowledge base.
Error:
- ErrInvalidInput: userID is empty or content is empty
type LLMProvider ¶
type LLMProvider = typescore.LLMProvider
type Manager ¶
type Manager interface {
Preferences() PreferenceStore
Knowledge() KnowledgeStore
Indexes() IndexStore
GetUserPreferences(ctx context.Context, userID string) (map[string]string, error)
SetUserPreference(ctx context.Context, userID, category, key, value string) error
GetUserPreference(ctx context.Context, userID, category, key string) (string, error)
AddKnowledge(ctx context.Context, userID, content string, tags ...string) error
AddKnowledgeWithCategory(ctx context.Context, userID, content, category string, tags ...string) error
SearchKnowledge(ctx context.Context, userID, query string, limit int) ([]MemoryItem, error)
BuildIndex(ctx context.Context, userID, sourceID, title, content string) (*IndexTree, error)
SearchIndexes(ctx context.Context, userID, query string, limit int) (*IndexSearchResult, error)
GetStats(ctx context.Context, userID string) (*MemoryStats, error)
BuildSystemPrompt(ctx context.Context, userID string, maxTokens int) (string, error)
ExportToMarkdown(ctx context.Context, userID string) (string, error)
ExportPageIndexToMarkdown(ctx context.Context, userID string) (string, error)
PageIndex() PageIndexStore
SyncPageIndex(ctx context.Context, userID string) error
AddPageDoc(ctx context.Context, userID, title, text string, kind PageIndexKind) error
}
func NewManager ¶
func NewManager(cfg *MemoryConfig, optPage ...PageIndexStore) Manager
func NewManagerWithStores ¶
func NewManagerWithStores(prefs PreferenceStore, know KnowledgeStore, index IndexStore, cfg *MemoryConfig, optPage ...PageIndexStore) Manager
type MemoryConfig ¶
type MemoryConfig = typescore.MemoryConfig
func DefaultMemoryConfig ¶
func DefaultMemoryConfig() *MemoryConfig
type MemoryError ¶
func NewError ¶
func NewError(code ErrorCode, message string) *MemoryError
func (*MemoryError) Error ¶
func (e *MemoryError) Error() string
func (*MemoryError) Unwrap ¶
func (e *MemoryError) Unwrap() error
type MemoryItem ¶
type MemoryItem = typescore.MemoryItem
type MemoryStats ¶
type MemoryStats = typescore.MemoryStats
type MemoryType ¶
type MemoryType = typescore.MemoryType
type MultiTenantManager ¶
type MultiTenantManager struct {
// contains filtered or unexported fields
}
func NewMultiTenantManager ¶
func NewMultiTenantManager(cfg *MemoryConfig, llm LLMProvider) *MultiTenantManager
func NewMultiTenantManagerWithStores ¶
func NewMultiTenantManagerWithStores(prefs PreferenceStore, know KnowledgeStore, index IndexStore, cfg *MemoryConfig, llm LLMProvider, optPage ...PageIndexStore) *MultiTenantManager
func (*MultiTenantManager) GetBuilder ¶
func (m *MultiTenantManager) GetBuilder(userID string) *search.IndexBuilder
func (*MultiTenantManager) GetManager ¶
func (m *MultiTenantManager) GetManager(userID string) Manager
func (*MultiTenantManager) PageIndexRAG ¶
func (m *MultiTenantManager) PageIndexRAG(userID string) *search.PageIndexRAG
func (*MultiTenantManager) RemoveManager ¶
func (m *MultiTenantManager) RemoveManager(userID string) error
func (*MultiTenantManager) TreeSearchWithMemory ¶
func (m *MultiTenantManager) TreeSearchWithMemory(ctx context.Context, userID, sourceID, query string) (*TreeSearchResult, error)
type PageIndexDoc ¶
type PageIndexDoc = typescore.PageIndexDoc
type PageIndexHit ¶
type PageIndexHit = typescore.PageIndexHit
type PageIndexKind ¶
type PageIndexKind = typescore.PageIndexKind
type PageIndexRAGResult ¶
type PageIndexRAGResult = typescore.PageIndexRAGResult
type PageIndexSearchOptions ¶
type PageIndexSearchOptions = typescore.PageIndexSearchOptions
type PageIndexStore ¶
type PageIndexStore interface {
// Upsert insert or update document
Upsert(ctx context.Context, doc PageIndexDoc) error
// Delete delete document (only delete if id belongs to userID)
Delete(ctx context.Context, userID, id string) error
// DeleteByUser delete all user documents
DeleteByUser(ctx context.Context, userID string) error
// DeleteByKinds delete documents by type
DeleteByKinds(ctx context.Context, userID string, kinds []PageIndexKind) error
// CountByUser count documents
CountByUser(ctx context.Context, userID string) (int, error)
// Search search documents
Search(ctx context.Context, userID, query string, opts *PageIndexSearchOptions) ([]PageIndexHit, error)
}
PageIndexStore Manage and search text documents, for RAG scenarios.
Error:
- ErrInvalidInput: userID is empty and title/text are empty
type Preference ¶
type Preference = typescore.Preference
type PreferenceStore ¶
type PreferenceStore interface {
Set(ctx context.Context, pref Preference) error
Get(ctx context.Context, userID, category, key string) (*Preference, error)
GetByUser(ctx context.Context, userID string) ([]Preference, error)
GetByCategory(ctx context.Context, userID, category string) ([]Preference, error)
Delete(ctx context.Context, userID, category, key string) error
Clear(ctx context.Context, userID string) error
Search(ctx context.Context, userID string, opts *SearchOptions) (*SearchResult, error)
GetAllAsMap(ctx context.Context, userID string) (map[string]string, error)
}
PreferenceStore Manage user preferences.
Error:
- ErrInvalidInput: userID, category, key is invalid
type SearchOptions ¶
type SearchOptions = typescore.SearchOptions
type SearchResult ¶
type SearchResult = typescore.SearchResult
type TreeSearchResult ¶
type TreeSearchResult = typescore.TreeSearchResult
Source Files
¶
Click to show internal directories.
Click to hide internal directories.