memory

package
v0.0.0-...-e41016f Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRecallK is the default limit of memory nodes injected into prompts or tool responses.
	DefaultRecallK = 5

	// DefaultHookTimeout caps how long recall operations can take.
	DefaultHookTimeout = 8 * time.Second
)

Variables

This section is empty.

Functions

func Close

func Close() error

Close tears down the default process-wide memory service.

func DefaultDBPath

func DefaultDBPath() (string, error)

DefaultDBPath returns the standard SQLite vector database file location.

func DefaultModelPath

func DefaultModelPath() (string, error)

DefaultModelPath returns the standard local embedding model GGUF location.

func FormatRecallContext

func FormatRecallContext(hits []RecallHit, heading string) string

FormatRecallContext formats vector search hits into a numbered markdown list under heading.

func Index

func Index(ctx context.Context, cwd, text string) error

Index embeds and saves a text memory using the default service.

func IsOpen

func IsOpen() bool

IsOpen reports whether the default process-wide memory service is open.

func MemoryIndexTool

func MemoryIndexTool(cwd string, requestApproval func(ctx context.Context, name string, params map[string]any) *fantasy.ToolResponse) fantasy.AgentTool

MemoryIndexTool returns the fantasy AgentTool for storing text in vector memory.

func Open

func Open(opts Options) error

Open initializes the default process-wide memory service.

func PromptContext

func PromptContext(ctx context.Context, cwd, prompt string) string

PromptContext returns the per-turn memory recall block matching the user prompt.

func SerializeVector

func SerializeVector(vec []float32) []byte

SerializeVector converts a float32 slice to the byte representation expected by sqlite-vec.

func SetDefault

func SetDefault(s *Service)

SetDefault replaces the default global Service instance.

func Sweep

func Sweep(ctx context.Context) error

Sweep triggers maintenance on the default service.

func SystemBlock

func SystemBlock(ctx context.Context, cwd string) string

SystemBlock returns the session-start project context memory block.

func WrapFileTools

func WrapFileTools(tools []fantasy.AgentTool, cwd string) []fantasy.AgentTool

WrapFileTools decorates read, edit, and write tools with memory recall.

Types

type Embedder

type Embedder interface {
	Embed(text string) ([]float32, error)
	EmbdSize() int
	Close()
}

Embedder represents a model capable of generating vector embeddings for text.

type EmbeddingModel

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

EmbeddingModel manages an in-memory llama.cpp embedding model instance.

func LoadEmbeddingModel

func LoadEmbeddingModel(path string) (*EmbeddingModel, error)

LoadEmbeddingModel initializes the llama.cpp backend and loads the GGUF model from path.

func (*EmbeddingModel) Close

func (m *EmbeddingModel) Close()

Close releases the llama context and model resources.

func (*EmbeddingModel) EmbdSize

func (m *EmbeddingModel) EmbdSize() int

EmbdSize returns the embedding dimension of the model.

func (*EmbeddingModel) Embed

func (m *EmbeddingModel) Embed(text string) ([]float32, error)

Embed generates an embedding vector for the provided text.

type MemoryAwareTool

type MemoryAwareTool struct {
	fantasy.AgentTool
	Cwd string
}

MemoryAwareTool decorates a file tool (read / edit / write) so the tool output carries relevant memory recall context for the touched file path.

func (*MemoryAwareTool) Run

Run executes the underlying tool and appends file-specific memory recall when available.

type Options

type Options struct {
	DBPath    string
	ModelPath string
	Embedder  Embedder
}

Options configures the initialization of the Memory Service.

type RecallHit

type RecallHit struct {
	ID         int64     `json:"id"`
	ProjectID  string    `json:"project_id"`
	Text       string    `json:"text"`
	Distance   float32   `json:"distance"`
	LastRecall time.Time `json:"last_recall"`
}

RecallHit represents a matched memory entry from vector search.

func Recall

func Recall(ctx context.Context, cwd, prompt string, k int) ([]RecallHit, error)

Recall queries the default memory service for relevant hits.

type Service

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

Service manages vector memory persistence and retrieval.

func Default

func Default() *Service

Default returns the default global Service instance.

func NewService

func NewService(opts Options) (*Service, error)

NewService initializes a SQLite-vec memory service with the specified options.

func (*Service) Close

func (s *Service) Close() error

Close releases the database and embedding model.

func (*Service) Index

func (s *Service) Index(ctx context.Context, cwd, text string) error

Index embeds and saves a text memory associated with the given working directory.

func (*Service) IsOpen

func (s *Service) IsOpen() bool

IsOpen reports whether the memory service is initialized and open.

func (*Service) Recall

func (s *Service) Recall(ctx context.Context, cwd, prompt string, k int) ([]RecallHit, error)

Recall performs vector cosine similarity search for the given prompt in the project context.

func (*Service) Sweep

func (s *Service) Sweep(ctx context.Context) error

Sweep prunes memory records older than 30 days.

Jump to

Keyboard shortcuts

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