Documentation
¶
Overview ¶
Package memory provides persistent knowledge storage with BM25 text search.
Package memory provides persistent knowledge storage with BM25 text search.
Package memory provides persistent knowledge storage with BM25 text search.
Package memory provides persistent knowledge storage with BM25 text search.
Index ¶
- type BleveObservationStore
- type BleveStore
- func (s *BleveStore) Close() error
- func (s *BleveStore) ConsolidateSession(ctx context.Context, sessionID string, transcript []Message) error
- func (s *BleveStore) Get(key string) (string, error)
- func (s *BleveStore) List(prefix string) ([]string, error)
- func (s *BleveStore) ListAll(ctx context.Context, category string, limit int) ([]ObservationItem, error)
- func (s *BleveStore) Recall(ctx context.Context, queryText string, opts RecallOpts) ([]MemoryResult, error)
- func (s *BleveStore) RecallByCategory(ctx context.Context, queryText, category string, limit int) ([]string, error)
- func (s *BleveStore) RecallFIL(ctx context.Context, queryText string, limitPerCategory int) (*FILResult, error)
- func (s *BleveStore) RememberFIL(ctx context.Context, findings, insights, lessons []string, source string) ([]string, error)
- func (s *BleveStore) RememberObservation(ctx context.Context, content, category, source string) (string, error)
- func (s *BleveStore) RetrieveByID(ctx context.Context, id string) (*ObservationItem, error)
- func (s *BleveStore) Search(queryStr string) ([]SearchResult, error)
- func (s *BleveStore) Set(key, value string) error
- type BleveStoreConfig
- type Consolidator
- type FILResult
- type InMemoryStore
- func (s *InMemoryStore) Close() error
- func (s *InMemoryStore) ConsolidateSession(ctx context.Context, sessionID string, transcript []Message) error
- func (s *InMemoryStore) Get(key string) (string, error)
- func (s *InMemoryStore) List(prefix string) ([]string, error)
- func (s *InMemoryStore) Recall(ctx context.Context, query string, opts RecallOpts) ([]MemoryResult, error)
- func (s *InMemoryStore) RecallByCategory(ctx context.Context, query, category string, limit int) ([]string, error)
- func (s *InMemoryStore) RecallFIL(ctx context.Context, query string, limitPerCategory int) (*FILResult, error)
- func (s *InMemoryStore) RememberFIL(ctx context.Context, findings, insights, lessons []string, source string) ([]string, error)
- func (s *InMemoryStore) RememberObservation(ctx context.Context, content, category, source string) (string, error)
- func (s *InMemoryStore) RetrieveByID(ctx context.Context, id string) (*ObservationItem, error)
- func (s *InMemoryStore) Search(query string) ([]SearchResult, error)
- func (s *InMemoryStore) Set(key, value string) error
- type Memory
- type MemoryResult
- type Message
- type Observation
- type ObservationDocument
- type ObservationExtractor
- type ObservationItem
- type RecallOpts
- type SearchResult
- type Store
- type TimeRange
- type ToolsAdapter
- func (a *ToolsAdapter) Close() error
- func (a *ToolsAdapter) ConsolidateSession(ctx context.Context, sessionID string, transcript []Message) error
- func (a *ToolsAdapter) Recall(ctx context.Context, query string, limit int) ([]ToolsMemoryResult, error)
- func (a *ToolsAdapter) RecallFIL(ctx context.Context, query string, limitPerCategory int) (*FILResult, error)
- func (a *ToolsAdapter) RememberFIL(ctx context.Context, findings, insights, lessons []string, source string) ([]string, error)
- func (a *ToolsAdapter) RetrieveByID(ctx context.Context, id string) (*ToolsObservationItem, error)
- type ToolsMemoryResult
- type ToolsObservationItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BleveObservationStore ¶
type BleveObservationStore struct {
// contains filtered or unexported fields
}
BleveObservationStore implements observation storage using BleveStore.
func NewBleveObservationStore ¶
func NewBleveObservationStore(store *BleveStore) *BleveObservationStore
NewBleveObservationStore creates an observation store backed by BleveStore.
func (*BleveObservationStore) QueryRelevantObservations ¶
func (s *BleveObservationStore) QueryRelevantObservations(ctx context.Context, query string, limit int) ([]interface{}, error)
QueryRelevantObservations retrieves observations relevant to a query as FIL. Returns []interface{} to match executor.ObservationStore interface.
func (*BleveObservationStore) StoreObservation ¶
func (s *BleveObservationStore) StoreObservation(ctx context.Context, obsRaw interface{}) error
StoreObservation stores an observation in the Bleve store. Each finding/insight/lesson is stored as a separate document with its category.
type BleveStore ¶
type BleveStore struct {
// contains filtered or unexported fields
}
BleveStore implements Store using Bleve for BM25 full-text search.
func NewBleveStore ¶
func NewBleveStore(cfg BleveStoreConfig) (*BleveStore, error)
NewBleveStore creates a new Bleve-based memory store.
func (*BleveStore) Close ¶
func (s *BleveStore) Close() error
Close closes the store and saves state.
func (*BleveStore) ConsolidateSession ¶
func (s *BleveStore) ConsolidateSession(ctx context.Context, sessionID string, transcript []Message) error
ConsolidateSession extracts and stores insights from a session transcript.
func (*BleveStore) Get ¶
func (s *BleveStore) Get(key string) (string, error)
Get retrieves a value by key (KV store).
func (*BleveStore) List ¶
func (s *BleveStore) List(prefix string) ([]string, error)
List returns keys matching a prefix.
func (*BleveStore) ListAll ¶
func (s *BleveStore) ListAll(ctx context.Context, category string, limit int) ([]ObservationItem, error)
ListAll returns all observations, optionally filtered by category. If category is empty, returns all observations.
func (*BleveStore) Recall ¶
func (s *BleveStore) Recall(ctx context.Context, queryText string, opts RecallOpts) ([]MemoryResult, error)
Recall performs semantic search for relevant memories.
func (*BleveStore) RecallByCategory ¶
func (s *BleveStore) RecallByCategory(ctx context.Context, queryText, category string, limit int) ([]string, error)
RecallByCategory performs semantic search for a specific category.
func (*BleveStore) RecallFIL ¶
func (s *BleveStore) RecallFIL(ctx context.Context, queryText string, limitPerCategory int) (*FILResult, error)
RecallFIL performs semantic search and returns results grouped as Findings, Insights, Lessons.
func (*BleveStore) RememberFIL ¶
func (s *BleveStore) RememberFIL(ctx context.Context, findings, insights, lessons []string, source string) ([]string, error)
RememberFIL stores multiple observations and returns their IDs.
func (*BleveStore) RememberObservation ¶
func (s *BleveStore) RememberObservation(ctx context.Context, content, category, source string) (string, error)
RememberObservation stores an observation with its category and returns the ID.
func (*BleveStore) RetrieveByID ¶
func (s *BleveStore) RetrieveByID(ctx context.Context, id string) (*ObservationItem, error)
RetrieveByID gets a single observation by ID.
func (*BleveStore) Search ¶
func (s *BleveStore) Search(queryStr string) ([]SearchResult, error)
Search performs substring search on KV store.
func (*BleveStore) Set ¶
func (s *BleveStore) Set(key, value string) error
Set stores a key-value pair.
type BleveStoreConfig ¶
type BleveStoreConfig struct {
// BasePath is the directory for all storage files
BasePath string
}
BleveStoreConfig configures the Bleve-based memory store.
type Consolidator ¶
type Consolidator interface {
// Extract extracts key insights from a transcript.
Extract(ctx context.Context, transcript []Message) ([]string, error)
}
Consolidator extracts insights from session transcripts.
type FILResult ¶
type FILResult struct {
Findings []string `json:"findings"`
Insights []string `json:"insights"`
Lessons []string `json:"lessons"`
}
FILResult holds categorized observation results.
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStore is an in-memory implementation of Store for testing. All data is lost when the process exits.
func NewInMemoryStore ¶
func NewInMemoryStore() *InMemoryStore
NewInMemoryStore creates a new in-memory store.
func (*InMemoryStore) Close ¶
func (s *InMemoryStore) Close() error
Close is a no-op for in-memory store.
func (*InMemoryStore) ConsolidateSession ¶
func (s *InMemoryStore) ConsolidateSession(ctx context.Context, sessionID string, transcript []Message) error
ConsolidateSession is a no-op for in-memory store.
func (*InMemoryStore) Get ¶
func (s *InMemoryStore) Get(key string) (string, error)
Get retrieves a value by key (KV store).
func (*InMemoryStore) List ¶
func (s *InMemoryStore) List(prefix string) ([]string, error)
List returns keys matching the prefix.
func (*InMemoryStore) Recall ¶
func (s *InMemoryStore) Recall(ctx context.Context, query string, opts RecallOpts) ([]MemoryResult, error)
Recall searches for memories matching the query (all categories).
func (*InMemoryStore) RecallByCategory ¶
func (s *InMemoryStore) RecallByCategory(ctx context.Context, query, category string, limit int) ([]string, error)
RecallByCategory searches for memories in a specific category using simple substring match.
func (*InMemoryStore) RecallFIL ¶
func (s *InMemoryStore) RecallFIL(ctx context.Context, query string, limitPerCategory int) (*FILResult, error)
RecallFIL performs search and returns results grouped as FIL.
func (*InMemoryStore) RememberFIL ¶
func (s *InMemoryStore) RememberFIL(ctx context.Context, findings, insights, lessons []string, source string) ([]string, error)
RememberFIL stores multiple observations and returns their IDs.
func (*InMemoryStore) RememberObservation ¶
func (s *InMemoryStore) RememberObservation(ctx context.Context, content, category, source string) (string, error)
RememberObservation stores an observation with its category and returns the ID.
func (*InMemoryStore) RetrieveByID ¶
func (s *InMemoryStore) RetrieveByID(ctx context.Context, id string) (*ObservationItem, error)
RetrieveByID gets a single observation by ID.
func (*InMemoryStore) Search ¶
func (s *InMemoryStore) Search(query string) ([]SearchResult, error)
Search performs a simple substring search on KV values.
func (*InMemoryStore) Set ¶
func (s *InMemoryStore) Set(key, value string) error
Set stores a key-value pair.
type Memory ¶
type Memory struct {
ID string `json:"id"`
Content string `json:"content"`
Category string `json:"category"` // "finding" | "insight" | "lesson"
Source string `json:"source"` // "GOAL:step-name", "session:xyz", etc.
CreatedAt time.Time `json:"created_at"`
}
Memory represents a stored memory with metadata.
type MemoryResult ¶
type MemoryResult struct {
Memory
Score float32 `json:"score"` // relevance score (BM25, normalized)
}
MemoryResult is a memory with relevance score from search.
type Observation ¶
type Observation struct {
// Findings are factual discoveries (e.g., "API rate limit is 100/min")
Findings []string `json:"findings,omitempty"`
// Insights are conclusions or inferences (e.g., "REST is better than GraphQL for this use case")
Insights []string `json:"insights,omitempty"`
// Lessons are learnings for future (e.g., "Avoid library X - it lacks TypeScript support")
Lessons []string `json:"lessons,omitempty"`
// StepName identifies the source step
StepName string `json:"step_name,omitempty"`
// StepType is the type of step (GOAL, AGENT, RUN)
StepType string `json:"step_type,omitempty"`
}
Observation represents extracted observations from a step.
type ObservationDocument ¶
type ObservationDocument struct {
ID string `json:"id"`
Content string `json:"content"`
Category string `json:"category"` // "finding" | "insight" | "lesson"
Source string `json:"source"` // "GOAL:step-name" for provenance
CreatedAt time.Time `json:"created_at"`
}
ObservationDocument represents a stored observation in Bleve.
type ObservationExtractor ¶
type ObservationExtractor struct {
// contains filtered or unexported fields
}
ObservationExtractor extracts observations from step outputs using an LLM.
func NewObservationExtractor ¶
func NewObservationExtractor(provider llm.Provider) *ObservationExtractor
NewObservationExtractor creates a new observation extractor.
type ObservationItem ¶
type ObservationItem struct {
ID string `json:"id"`
Content string `json:"content"`
Category string `json:"category"` // "finding" | "insight" | "lesson"
}
ObservationItem represents a stored observation with its metadata.
type RecallOpts ¶
type RecallOpts struct {
Limit int // max results, default 10
MinScore float32 // minimum relevance score, default 0.0
TimeRange *TimeRange // optional time filter
}
RecallOpts configures memory recall.
type SearchResult ¶
SearchResult is for key-based search.
type Store ¶
type Store interface {
// Observation storage (primary API)
RememberObservation(ctx context.Context, content, category, source string) (string, error) // returns ID
RememberFIL(ctx context.Context, findings, insights, lessons []string, source string) ([]string, error)
RetrieveByID(ctx context.Context, id string) (*ObservationItem, error)
RecallByCategory(ctx context.Context, query, category string, limit int) ([]string, error)
RecallFIL(ctx context.Context, query string, limitPerCategory int) (*FILResult, error)
// Generic recall (returns all categories mixed)
Recall(ctx context.Context, query string, opts RecallOpts) ([]MemoryResult, error)
// Key-value operations
Get(key string) (string, error)
Set(key, value string) error
List(prefix string) ([]string, error)
Search(query string) ([]SearchResult, error)
// Session consolidation
ConsolidateSession(ctx context.Context, sessionID string, transcript []Message) error
// Lifecycle
Close() error
}
Store is the interface for memory storage.
type ToolsAdapter ¶
type ToolsAdapter struct {
// contains filtered or unexported fields
}
ToolsAdapter adapts memory.Store to the tools.SemanticMemory interface.
func NewToolsAdapter ¶
func NewToolsAdapter(store Store) *ToolsAdapter
NewToolsAdapter creates a new adapter for the tools package.
func (*ToolsAdapter) Close ¶
func (a *ToolsAdapter) Close() error
Close closes the underlying store.
func (*ToolsAdapter) ConsolidateSession ¶
func (a *ToolsAdapter) ConsolidateSession(ctx context.Context, sessionID string, transcript []Message) error
ConsolidateSession wraps the store's consolidation.
func (*ToolsAdapter) Recall ¶
func (a *ToolsAdapter) Recall(ctx context.Context, query string, limit int) ([]ToolsMemoryResult, error)
Recall searches for relevant memories (all categories).
func (*ToolsAdapter) RecallFIL ¶
func (a *ToolsAdapter) RecallFIL(ctx context.Context, query string, limitPerCategory int) (*FILResult, error)
RecallFIL searches and returns results grouped as FIL.
func (*ToolsAdapter) RememberFIL ¶
func (a *ToolsAdapter) RememberFIL(ctx context.Context, findings, insights, lessons []string, source string) ([]string, error)
RememberFIL stores multiple observations and returns their IDs.
func (*ToolsAdapter) RetrieveByID ¶
func (a *ToolsAdapter) RetrieveByID(ctx context.Context, id string) (*ToolsObservationItem, error)
RetrieveByID gets a single observation by ID.
type ToolsMemoryResult ¶
type ToolsMemoryResult struct {
ID string `json:"id"`
Content string `json:"content"`
Category string `json:"category"` // "finding" | "insight" | "lesson"
Score float32 `json:"score"`
}
ToolsMemoryResult mirrors tools.SemanticMemoryResult
type ToolsObservationItem ¶
type ToolsObservationItem struct {
ID string `json:"id"`
Content string `json:"content"`
Category string `json:"category"`
}
ToolsObservationItem mirrors tools.ObservationItem