Documentation
¶
Index ¶
- func BlobToVector(buf []byte) []float32
- func CosineSimilarity(a, b []float32) float32
- func EuclideanDistance(a, b []float32) float32
- func VectorToBlob(v []float32) []byte
- type BySimilarity
- type EmbeddingGenerator
- type Memory
- type Store
- func (s *Store) Create(ctx context.Context, content string, importance float64, tags []string) (*Memory, error)
- func (s *Store) Delete(ctx context.Context, id string) error
- func (s *Store) Get(ctx context.Context, id string) (*Memory, error)
- func (s *Store) GetTopImportant(ctx context.Context, limit int) ([]*Memory, error)
- func (s *Store) GetWithoutEmbedding(ctx context.Context, limit int) ([]*Memory, error)
- func (s *Store) List(ctx context.Context, limit int) ([]*Memory, error)
- func (s *Store) SearchByVector(ctx context.Context, embedding []float32, limit int) ([]*Memory, error)
- func (s *Store) SearchRelevant(ctx context.Context, query string, limit int) ([]string, error)
- func (s *Store) SetEmbedder(e EmbeddingGenerator)
- func (s *Store) UpdateEmbedding(ctx context.Context, id string, embedding []float32) error
- type Vector
- type VectorMatch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlobToVector ¶
BlobToVector converts a binary blob back to float32 slice.
func CosineSimilarity ¶
CosineSimilarity computes the cosine similarity between two vectors. Returns a value between -1 and 1, where 1 means identical direction.
func EuclideanDistance ¶
EuclideanDistance computes the Euclidean distance between two vectors.
func VectorToBlob ¶
ToBlob converts a float32 slice to binary blob for SQLite storage.
Types ¶
type BySimilarity ¶
type BySimilarity []VectorMatch
BySimiliarity implements sort.Interface for sorting by similarity (descending).
func (BySimilarity) Len ¶
func (a BySimilarity) Len() int
func (BySimilarity) Less ¶
func (a BySimilarity) Less(i, j int) bool
func (BySimilarity) Swap ¶
func (a BySimilarity) Swap(i, j int)
type EmbeddingGenerator ¶
type EmbeddingGenerator interface {
GenerateEmbedding(ctx context.Context, text string) ([]float32, error)
}
EmbeddingGenerator generates vector embeddings for text content. This interface allows the memory store to request embeddings without depending directly on the AI service.
type Memory ¶
type Memory struct {
ID string `json:"id"`
Content string `json:"content"`
Importance float64 `json:"importance"`
Tags []string `json:"tags"`
CreatedAt time.Time `json:"created_at"`
LastAccessed time.Time `json:"last_accessed"`
AccessCount int `json:"access_count"`
}
Memory represents a stored memory
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store handles memory persistence
func (*Store) Create ¶
func (s *Store) Create(ctx context.Context, content string, importance float64, tags []string) (*Memory, error)
Create stores a new memory with optional embedding generation
func (*Store) GetTopImportant ¶
GetTopImportant returns the most important memories
func (*Store) GetWithoutEmbedding ¶
GetWithoutEmbedding returns memories that don't have embeddings yet. Used for backfilling embeddings.
func (*Store) SearchByVector ¶
func (s *Store) SearchByVector(ctx context.Context, embedding []float32, limit int) ([]*Memory, error)
SearchByVector searches using vector similarity (in-memory cosine similarity)
func (*Store) SearchRelevant ¶
SearchRelevant searches for relevant memories (simple keyword search)
func (*Store) SetEmbedder ¶
func (s *Store) SetEmbedder(e EmbeddingGenerator)
SetEmbedder sets the embedding generator for the store. When set, embeddings will be generated automatically when creating memories.
type Vector ¶
type Vector []float32
Vector represents a vector embedding for SQLite storage. Stored as binary BLOB (little-endian float32 array) for efficiency.
type VectorMatch ¶
VectorMatch represents a vector search result with similarity score.