memory

package
v0.0.1-beta1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

FAISS disabled stub

Unified Vector Memory Store - FAISS HNSW + SQLite + Local/OpenAI Embeddings

Index

Constants

This section is empty.

Variables

View Source
var EMBEDDING_DIMENSIONS = map[string]int{
	"text-embedding-3-small": 1536,
	"text-embedding-3-large": 3072,
	"text-embedding-ada-002": 1024,
}

Model dimension

View Source
var MEMORY_CATEGORIES = []string{"preference", "decision", "fact", "entity", "other"}

Categories compatible with OpenClaw

Functions

func DetectCategory

func DetectCategory(text string) string

Category detection

func FAISSVersion

func FAISSVersion() string

func IsFAISSAvailable

func IsFAISSAvailable() bool

Types

type Config

type Config struct {
	ApiKey          string  // OpenAI API Key (or ${OPENAI_API_KEY})
	EmbeddingModel  string  // OpenAI model: text-embedding-3-small/large
	EmbeddingServer string  // Local embedding service URL
	EmbeddingDim    int     // Embedding dimension (auto-detected)
	MaxResults      int     // Max results (default 5)
	MinScore        float32 // Minimum similarity score (default 0.7)
	HNSWPath        string  // HNSW index file path
	HybridEnabled   bool    // Enable hybrid search (default true)
	VectorWeight    float32 // Vector weight (default 0.7)
	TextWeight      float32 // Keyword weight (default 0.3)
	CandidateMult   int     // Candidate multiplier (default 4)
}

Config

type EmbeddingProvider

type EmbeddingProvider interface {
	Embed(text string) ([]float32, error)
	Dim() int
	Name() string
}

Embedding provider interface

type HNSWConfig

type HNSWConfig struct {
	Dim         int
	M           int
	EfSearch    int
	EfConstruct int
	Distance    string
	StoragePath string
}

HNSW index config (kept in sync with the FAISS build)

type HNSWIndex

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

HNSWIndex placeholder when FAISS build tag is missing. Used to compile and automatically fall back to SQLite search. Note: all methods return unavailable or empty results.

func NewHNSWIndex

func NewHNSWIndex(cfg HNSWConfig) (*HNSWIndex, error)

func (*HNSWIndex) Add

func (idx *HNSWIndex) Add(vectors [][]float32) error

func (*HNSWIndex) Close

func (idx *HNSWIndex) Close() error

func (*HNSWIndex) Config

func (idx *HNSWIndex) Config() HNSWConfig

func (*HNSWIndex) Count

func (idx *HNSWIndex) Count() int64

func (*HNSWIndex) Dim

func (idx *HNSWIndex) Dim() int

func (*HNSWIndex) Load

func (idx *HNSWIndex) Load(path string) error

func (*HNSWIndex) Loaded

func (idx *HNSWIndex) Loaded() bool

func (*HNSWIndex) Metric

func (idx *HNSWIndex) Metric() string

func (*HNSWIndex) Save

func (idx *HNSWIndex) Save(path string) error

func (*HNSWIndex) Search

func (idx *HNSWIndex) Search(query []float32, k int) ([]float32, []int64, error)

func (*HNSWIndex) SearchWithScores

func (idx *HNSWIndex) SearchWithScores(query []float32, k int) ([]float32, []int64, error)

type LocalProvider

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

Local embedding (llama.cpp server)

func NewLocalProvider

func NewLocalProvider(serverURL string, dim int) (*LocalProvider, error)

func (*LocalProvider) Dim

func (p *LocalProvider) Dim() int

func (*LocalProvider) Embed

func (p *LocalProvider) Embed(text string) ([]float32, error)

func (*LocalProvider) Name

func (p *LocalProvider) Name() string

type MemoryEntry

type MemoryEntry struct {
	ID         string
	Text       string
	Vector     []float32
	Importance float64
	Category   string
	Source     string
	CreatedAt  int64
	UpdatedAt  int64
}

Memory entry

type MemoryResult

type MemoryResult struct {
	Entry   MemoryEntry
	Score   float32 // Similarity score (0-1)
	Matched bool    // Whether matched
}

Search result (with similarity score)

type OpenAIProvider

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

OpenAI embedding

func NewOpenAIProvider

func NewOpenAIProvider(apiKey, model string) (*OpenAIProvider, error)

func (*OpenAIProvider) Dim

func (p *OpenAIProvider) Dim() int

func (*OpenAIProvider) Embed

func (p *OpenAIProvider) Embed(text string) ([]float32, error)

func (*OpenAIProvider) Name

func (p *OpenAIProvider) Name() string

type VectorMemoryStore

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

Vector memory store - unified architecture

func NewVectorMemoryStore

func NewVectorMemoryStore(dbPath string, cfg Config) (*VectorMemoryStore, error)

func (*VectorMemoryStore) Close

func (s *VectorMemoryStore) Close() error

func (*VectorMemoryStore) Count

func (s *VectorMemoryStore) Count() (int, error)

func (*VectorMemoryStore) Delete

func (s *VectorMemoryStore) Delete(id string) (bool, error)

func (*VectorMemoryStore) Get

func (s *VectorMemoryStore) Get(id string) (MemoryEntry, error)

Get memory entry (exposed to tools)

func (*VectorMemoryStore) Search

func (s *VectorMemoryStore) Search(query string, limit int, minScore float32) ([]MemoryResult, error)

Search - with similarity scores

func (*VectorMemoryStore) Store

func (s *VectorMemoryStore) Store(text string, category string, importance float64) (string, error)

func (*VectorMemoryStore) StoreWithSource

func (s *VectorMemoryStore) StoreWithSource(text string, category string, importance float64, source string) (string, error)

func (*VectorMemoryStore) Update

func (s *VectorMemoryStore) Update(id string, text string, category string, importance float64) (bool, error)

Update existing memory (re-embed on text change)

Jump to

Keyboard shortcuts

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