Documentation
¶
Index ¶
- Constants
- func Categorize(content string) string
- func ExpandQueryAdvanced(query string) string
- func ExpandQueryForFTS(keywords []string) string
- func ExtractKeywords(query string) []string
- func Migrate(db *sql.DB) error
- func NormalizeAccents(s string) string
- func SplitOnPunctuation(text string) []string
- func TruncateAtBoundary(s string, maxBytes int) string
- func VectorNorm(v []float32) float64
- type DeleteScopeOptions
- type EmbeddingCache
- type EmbeddingProvider
- type EntityDetector
- type EntityDetectorConfig
- type FastTokenizer
- type HybridSearchConfig
- type HybridSearcher
- type ImportRecord
- type ListOptions
- type Memory
- type MemoryIndexer
- type MemoryMetadata
- type ONNXEmbedder
- type ONNXPaths
- type QuantizedEmbedding
- func (q QuantizedEmbedding) CosineSimilarity(query []float32, queryNorm float64) float64
- func (q QuantizedEmbedding) Dequantize() []float32
- func (q QuantizedEmbedding) DotProduct(query []float32) float64
- func (q QuantizedEmbedding) MarshalBinary() ([]byte, error)
- func (q *QuantizedEmbedding) UnmarshalBinary(data []byte) error
- type SQLiteStore
- func (s *SQLiteStore) BackfillContentHash(ctx context.Context) (int, error)
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) CountWithoutEmbedding(ctx context.Context) (int, error)
- func (s *SQLiteStore) CreateImport(id, source, path string) error
- func (s *SQLiteStore) DB() *sql.DB
- func (s *SQLiteStore) Delete(ctx context.Context, id string) error
- func (s *SQLiteStore) DeleteByScope(ctx context.Context, opts DeleteScopeOptions) (int, error)
- func (s *SQLiteStore) FindByContentHash(ctx context.Context, hash string, projectID *string) (*Memory, error)
- func (s *SQLiteStore) Get(ctx context.Context, id string) (*Memory, error)
- func (s *SQLiteStore) GetLastImport(source string) (*ImportRecord, error)
- func (s *SQLiteStore) List(ctx context.Context, opts ListOptions) ([]Memory, error)
- func (s *SQLiteStore) ListWithoutEmbedding(ctx context.Context, limit int) ([]Memory, error)
- func (s *SQLiteStore) Save(ctx context.Context, m Memory) error
- func (s *SQLiteStore) Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)
- func (s *SQLiteStore) SoftDelete(ctx context.Context, id string) error
- func (s *SQLiteStore) Stats(ctx context.Context) (*StoreStats, error)
- func (s *SQLiteStore) Update(ctx context.Context, id string, content string, category string) error
- func (s *SQLiteStore) UpdateEmbedding(ctx context.Context, id string, embedding []float32) error
- func (s *SQLiteStore) UpdateImport(id, status string, memoriesImported int, errMsg string) error
- func (s *SQLiteStore) VectorCache() *VectorCache
- type Sanitizer
- type SaveOptions
- type SearchOptions
- type SearchResult
- type Service
- func (s *Service) BackfillContentHash(ctx context.Context) (int, error)
- func (s *Service) BackfillEmbeddings(ctx context.Context, batchSize int) (int, error)
- func (s *Service) Close()
- func (s *Service) Forget(ctx context.Context, id string) error
- func (s *Service) ForgetByScope(ctx context.Context, projectID, category, source string, hard bool) (int, error)
- func (s *Service) Get(ctx context.Context, id string) (*Memory, error)
- func (s *Service) List(ctx context.Context, opts ListOptions) ([]Memory, error)
- func (s *Service) ResolveProject(cwd string) string
- func (s *Service) Save(ctx context.Context, content, category, source string, cwd string) (*Memory, error)
- func (s *Service) SaveMemory(ctx context.Context, content, category, source string, cwd string) error
- func (s *Service) SaveRaw(ctx context.Context, content, category, source string, cwd string) error
- func (s *Service) SaveRawNoEmbed(ctx context.Context, content, category, source string, cwd string) error
- func (s *Service) SaveWithOptions(ctx context.Context, opts SaveOptions) (*Memory, error)
- func (s *Service) Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)
- func (s *Service) SetKGExtractor(extractor *kg.PatternExtractor)
- func (s *Service) SoftForget(ctx context.Context, id string) error
- func (s *Service) Stats(ctx context.Context) (*StoreStats, error)
- func (s *Service) StoreDB() *sql.DB
- func (s *Service) Update(ctx context.Context, id, content, category string) (*Memory, error)
- func (s *Service) VectorCache() *VectorCache
- type Store
- type StoreStats
- type Tokenizer
- type TopicChangeDetector
- type VectorCache
- type WordPieceTokenizer
Constants ¶
const LegacyModelName = "all-MiniLM-L6-v2"
Variables ¶
This section is empty.
Functions ¶
func Categorize ¶
func ExpandQueryAdvanced ¶ added in v0.2.0
ExpandQueryAdvanced takes a raw user query and produces an FTS5-compatible query string. It handles:
- Quoted phrases: "exact phrase" → preserved as FTS5 phrase
- NEAR operator: word1 NEAR/5 word2 → preserved
- Standalone words: prefix expansion (word*) + synonym expansion
- Accent normalization before FTS5 generation
func ExpandQueryForFTS ¶
func ExtractKeywords ¶
func NormalizeAccents ¶ added in v0.2.0
func SplitOnPunctuation ¶
func TruncateAtBoundary ¶
func VectorNorm ¶
Types ¶
type DeleteScopeOptions ¶ added in v0.2.0
type EmbeddingCache ¶
type EmbeddingCache struct {
// contains filtered or unexported fields
}
func NewEmbeddingCache ¶
func NewEmbeddingCache(db *sql.DB, logger *slog.Logger) *EmbeddingCache
func (*EmbeddingCache) MigrateFromLegacy ¶ added in v0.2.0
func (c *EmbeddingCache) MigrateFromLegacy(currentModel string) int64
type EmbeddingProvider ¶
type EntityDetector ¶ added in v0.2.0
type EntityDetector struct {
// contains filtered or unexported fields
}
func NewEntityDetector ¶ added in v0.2.0
func NewEntityDetector(db *sql.DB, cfg EntityDetectorConfig, logger *slog.Logger) *EntityDetector
func (*EntityDetector) Detect ¶ added in v0.2.0
func (d *EntityDetector) Detect(text string) []string
type EntityDetectorConfig ¶ added in v0.2.0
func DefaultEntityDetectorConfig ¶ added in v0.2.0
func DefaultEntityDetectorConfig() EntityDetectorConfig
type FastTokenizer ¶ added in v0.2.0
type FastTokenizer struct {
// contains filtered or unexported fields
}
FastTokenizer parses HuggingFace tokenizer.json and produces ONNX-compatible input_ids matching Python transformers output.
func NewFastTokenizer ¶ added in v0.2.0
func NewFastTokenizer(tokenizerPath string, maxLen int) (*FastTokenizer, error)
NewFastTokenizer loads a HuggingFace tokenizer.json and builds a FastTokenizer.
func (*FastTokenizer) Tokenize ¶ added in v0.2.0
func (ft *FastTokenizer) Tokenize(text string) (inputIDs, attentionMask, tokenTypeIDs []int64)
type HybridSearchConfig ¶
type HybridSearchConfig struct {
VectorWeight float64
BM25Weight float64
MaxResults int
MinScore float64
MMREnabled bool
MMRLambda float64
TemporalDecayEnabled bool
TemporalDecayHalfLifeDays int
}
func DefaultHybridSearchConfig ¶
func DefaultHybridSearchConfig() HybridSearchConfig
type HybridSearcher ¶
type HybridSearcher struct {
// contains filtered or unexported fields
}
func NewHybridSearcher ¶
func NewHybridSearcher(store Store, embedder EmbeddingProvider, cache *EmbeddingCache, vectorCache *VectorCache, cfg HybridSearchConfig, entityDetector *EntityDetector, topicChangeDetector *TopicChangeDetector, logger *slog.Logger) *HybridSearcher
func (*HybridSearcher) Search ¶
func (h *HybridSearcher) Search(ctx context.Context, query string, opts ...SearchOptions) ([]SearchResult, error)
type ImportRecord ¶ added in v0.2.0
type ListOptions ¶
type Memory ¶
type Memory struct {
ID string `json:"id"`
ProjectID *string `json:"project_id,omitempty"`
Category string `json:"category"`
Content string `json:"content"`
ContentHash string `json:"content_hash,omitempty"`
Keywords []string `json:"keywords,omitempty"`
Embedding []float32 `json:"embedding,omitempty"`
Source string `json:"source"`
SourceID *string `json:"source_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"deleted_at,omitempty"`
AccessCount int `json:"access_count"`
LastAccessed *time.Time `json:"last_accessed,omitempty"`
Metadata any `json:"metadata,omitempty"`
}
type MemoryIndexer ¶ added in v0.2.0
type MemoryIndexer struct {
// contains filtered or unexported fields
}
MemoryIndexer watches directories and incrementally indexes markdown/jsonl files. It uses polling (os.Stat) instead of filesystem events to avoid external dependencies.
func NewMemoryIndexer ¶ added in v0.2.0
func NewMemoryIndexer(svc *Service, paths []string, logger *slog.Logger) *MemoryIndexer
func (*MemoryIndexer) IndexNow ¶ added in v0.2.0
func (idx *MemoryIndexer) IndexNow(path string) error
IndexNow triggers immediate indexing of a specific file or directory.
func (*MemoryIndexer) SetInterval ¶ added in v0.2.0
func (idx *MemoryIndexer) SetInterval(d time.Duration)
SetInterval changes the polling interval. Must be called before Start.
func (*MemoryIndexer) Start ¶ added in v0.2.0
func (idx *MemoryIndexer) Start()
Start performs initial indexing of all watched paths, then starts a background goroutine that polls for changes.
func (*MemoryIndexer) Stop ¶ added in v0.2.0
func (idx *MemoryIndexer) Stop()
Stop terminates the background polling goroutine.
type MemoryMetadata ¶ added in v0.2.0
type MemoryMetadata struct {
Source string `json:"source,omitempty"` // "user", "auto_capture", "dream", "import", "precompact"
SessionID string `json:"session_id,omitempty"` // Source session that created this memory
Consolidated []string `json:"consolidated,omitempty"` // IDs of memories merged into this one
DreamVersion string `json:"dream_version,omitempty"` // Dream run ID that processed this
CaptureReason string `json:"capture_reason,omitempty"` // Why this was captured
QualityScore float64 `json:"quality_score,omitempty"` // Auto-capture quality score
}
MemoryMetadata provides structured metadata for memories. Stored as JSON in the Memory.Metadata field (which is `any` for backward compat).
func ParseMetadata ¶ added in v0.2.0
func ParseMetadata(v any) MemoryMetadata
ParseMetadata parses an `any` (from Memory.Metadata) into MemoryMetadata. Returns zero-value MemoryMetadata if input is nil or unparseable.
func (MemoryMetadata) MarshalJSON ¶ added in v0.2.0
func (m MemoryMetadata) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler using an alias to avoid infinite recursion.
func (MemoryMetadata) ToAny ¶ added in v0.2.0
func (m MemoryMetadata) ToAny() any
ToAny converts MemoryMetadata to the `any` type expected by Memory.Metadata.
type ONNXEmbedder ¶
type ONNXEmbedder struct {
// contains filtered or unexported fields
}
func NewONNXEmbedder ¶
func NewONNXEmbedder(modelDir string, logger *slog.Logger) (*ONNXEmbedder, error)
func (*ONNXEmbedder) Close ¶
func (e *ONNXEmbedder) Close() error
func (*ONNXEmbedder) Dimensions ¶
func (e *ONNXEmbedder) Dimensions() int
func (*ONNXEmbedder) Model ¶
func (e *ONNXEmbedder) Model() string
func (*ONNXEmbedder) Name ¶
func (e *ONNXEmbedder) Name() string
type QuantizedEmbedding ¶
func QuantizeFloat32 ¶
func QuantizeFloat32(vec []float32) QuantizedEmbedding
func (QuantizedEmbedding) CosineSimilarity ¶
func (q QuantizedEmbedding) CosineSimilarity(query []float32, queryNorm float64) float64
func (QuantizedEmbedding) Dequantize ¶
func (q QuantizedEmbedding) Dequantize() []float32
func (QuantizedEmbedding) DotProduct ¶
func (q QuantizedEmbedding) DotProduct(query []float32) float64
func (QuantizedEmbedding) MarshalBinary ¶
func (q QuantizedEmbedding) MarshalBinary() ([]byte, error)
func (*QuantizedEmbedding) UnmarshalBinary ¶
func (q *QuantizedEmbedding) UnmarshalBinary(data []byte) error
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
func NewSQLiteStore ¶
func NewSQLiteStore(dbPath string, logger *slog.Logger) (*SQLiteStore, error)
func (*SQLiteStore) BackfillContentHash ¶ added in v0.2.0
func (s *SQLiteStore) BackfillContentHash(ctx context.Context) (int, error)
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
func (*SQLiteStore) CountWithoutEmbedding ¶ added in v0.2.0
func (s *SQLiteStore) CountWithoutEmbedding(ctx context.Context) (int, error)
func (*SQLiteStore) CreateImport ¶ added in v0.2.0
func (s *SQLiteStore) CreateImport(id, source, path string) error
func (*SQLiteStore) DB ¶
func (s *SQLiteStore) DB() *sql.DB
func (*SQLiteStore) DeleteByScope ¶ added in v0.2.0
func (s *SQLiteStore) DeleteByScope(ctx context.Context, opts DeleteScopeOptions) (int, error)
func (*SQLiteStore) FindByContentHash ¶ added in v0.2.0
func (*SQLiteStore) GetLastImport ¶ added in v0.2.0
func (s *SQLiteStore) GetLastImport(source string) (*ImportRecord, error)
func (*SQLiteStore) List ¶
func (s *SQLiteStore) List(ctx context.Context, opts ListOptions) ([]Memory, error)
func (*SQLiteStore) ListWithoutEmbedding ¶ added in v0.2.0
func (*SQLiteStore) Search ¶
func (s *SQLiteStore) Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)
func (*SQLiteStore) SoftDelete ¶ added in v0.2.0
func (s *SQLiteStore) SoftDelete(ctx context.Context, id string) error
func (*SQLiteStore) Stats ¶
func (s *SQLiteStore) Stats(ctx context.Context) (*StoreStats, error)
func (*SQLiteStore) UpdateEmbedding ¶ added in v0.2.0
func (*SQLiteStore) UpdateImport ¶ added in v0.2.0
func (s *SQLiteStore) UpdateImport(id, status string, memoriesImported int, errMsg string) error
func (*SQLiteStore) VectorCache ¶ added in v0.2.0
func (s *SQLiteStore) VectorCache() *VectorCache
type Sanitizer ¶
type Sanitizer struct {
// contains filtered or unexported fields
}
func NewSanitizer ¶
type SaveOptions ¶ added in v0.2.0
type SearchOptions ¶
type SearchResult ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) BackfillContentHash ¶ added in v0.2.0
func (*Service) BackfillEmbeddings ¶ added in v0.2.0
func (*Service) ForgetByScope ¶ added in v0.2.0
func (*Service) ResolveProject ¶ added in v0.2.0
ResolveProject returns the project ID for a given working directory, or empty string if none.
func (*Service) SaveMemory ¶ added in v0.1.1
func (*Service) SaveRawNoEmbed ¶ added in v0.2.0
func (*Service) SaveWithOptions ¶ added in v0.2.0
func (*Service) Search ¶
func (s *Service) Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)
func (*Service) SetKGExtractor ¶ added in v0.2.0
func (s *Service) SetKGExtractor(extractor *kg.PatternExtractor)
func (*Service) SoftForget ¶ added in v0.2.0
func (*Service) VectorCache ¶ added in v0.2.0
func (s *Service) VectorCache() *VectorCache
type Store ¶
type Store interface {
Save(ctx context.Context, m Memory) error
Get(ctx context.Context, id string) (*Memory, error)
Update(ctx context.Context, id, content, category string) error
Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)
Delete(ctx context.Context, id string) error
SoftDelete(ctx context.Context, id string) error
DeleteByScope(ctx context.Context, opts DeleteScopeOptions) (int, error)
List(ctx context.Context, opts ListOptions) ([]Memory, error)
Stats(ctx context.Context) (*StoreStats, error)
UpdateEmbedding(ctx context.Context, id string, embedding []float32) error
ListWithoutEmbedding(ctx context.Context, limit int) ([]Memory, error)
FindByContentHash(ctx context.Context, hash string, projectID *string) (*Memory, error)
BackfillContentHash(ctx context.Context) (int, error)
DB() *sql.DB
VectorCache() *VectorCache
Close() error
}
type StoreStats ¶
type TopicChangeDetector ¶ added in v0.2.0
type TopicChangeDetector struct {
// contains filtered or unexported fields
}
func NewTopicChangeDetector ¶ added in v0.2.0
func NewTopicChangeDetector(embedder EmbeddingProvider, entityDetector *EntityDetector) *TopicChangeDetector
func (*TopicChangeDetector) Reset ¶ added in v0.2.0
func (d *TopicChangeDetector) Reset()
type VectorCache ¶ added in v0.2.0
type VectorCache struct {
// contains filtered or unexported fields
}
VectorCache is a thread-safe in-memory cache of memory embeddings keyed by memory ID.
func NewVectorCache ¶ added in v0.2.0
func NewVectorCache(logger *slog.Logger) *VectorCache
func (*VectorCache) All ¶ added in v0.2.0
func (c *VectorCache) All() map[string][]float32
func (*VectorCache) Len ¶ added in v0.2.0
func (c *VectorCache) Len() int
func (*VectorCache) Put ¶ added in v0.2.0
func (c *VectorCache) Put(id string, embedding []float32)
func (*VectorCache) Remove ¶ added in v0.2.0
func (c *VectorCache) Remove(id string)
type WordPieceTokenizer ¶
type WordPieceTokenizer struct {
// contains filtered or unexported fields
}
func NewWordPieceTokenizer ¶
func NewWordPieceTokenizer(vocabPath string, maxLen int) (*WordPieceTokenizer, error)
func (*WordPieceTokenizer) Tokenize ¶
func (t *WordPieceTokenizer) Tokenize(text string) (inputIDs, attentionMask, tokenTypeIDs []int64)
Source Files
¶
- categorizer.go
- embedding_cache.go
- embeddings.go
- embeddings_onnx.go
- entity_detector.go
- hybrid_search.go
- indexer.go
- metadata.go
- quantized.go
- query_expansion.go
- sanitizer.go
- service.go
- sqlite_migrations.go
- sqlite_schema.go
- sqlite_store.go
- store.go
- text_util.go
- tokenizer.go
- tokenizer_fast.go
- topic_change_detector.go
- vector_cache.go