memory

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: MIT Purpose: text embedding via NVIDIA NIM. Uses nv-embed-v1 (or any OpenAI-compatible /v1/embeddings endpoint).

SPDX-License-Identifier: MIT Purpose: long-term project memory — bbolt-backed knowledge store with semantic search via NIM embeddings. Inspired by beads (gastownhall/beads).

SPDX-License-Identifier: MIT Purpose: semantic search, knowledge graph traversal, and prime-context injection for agents. All in-memory over the Store.

SPDX-License-Identifier: MIT Purpose: bbolt-backed Memory store with embeddings, links, and append-only audit log. Embeddings are cached in-memory by text hash.

Index

Constants

View Source
const NIMEmbedBaseURL = "https://integrate.api.nvidia.com/v1"
View Source
const NIMEmbedModel = "nvidia/nv-embed-v1"

Variables

View Source
var (
	ErrNotFound = errors.New("memory: not found")
)

Functions

func CosineSimilarity

func CosineSimilarity(a, b []float32) float64

func GenerateID

func GenerateID(insight string) string

func NoopEmbedding

func NoopEmbedding(text string) ([]float32, error)

NoopEmbedding returns an empty vector — used when no embedder is configured.

func NormalizeTags

func NormalizeTags(tags []string) []string

func SetEmbedder

func SetEmbedder(fn EmbeddingFunc, dim int)

func SetupNIMEmbedder

func SetupNIMEmbedder()

SetupNIMEmbedder registers the NIM embedder as the default.

Types

type EmbedRequest

type EmbedRequest struct {
	Input []string `json:"input"`
	Model string   `json:"model"`
}

type EmbedResponse

type EmbedResponse struct {
	Data []struct {
		Embedding []float32 `json:"embedding"`
		Index     int       `json:"index"`
	} `json:"data"`
	Usage struct {
		PromptTokens int `json:"prompt_tokens"`
		TotalTokens  int `json:"total_tokens"`
	} `json:"usage"`
}

type Embedder

type Embedder struct {
	BaseURL string
	Model   string
	APIKey  string
	HTTP    *http.Client
}

func NewNIMEmbedder

func NewNIMEmbedder() *Embedder

func (*Embedder) Embed

func (e *Embedder) Embed(ctx context.Context, texts []string) ([][]float32, error)

func (*Embedder) EmbedOne

func (e *Embedder) EmbedOne(ctx context.Context, text string) ([]float32, error)

type EmbeddingFunc

type EmbeddingFunc func(text string) ([]float32, error)

func GetEmbedder

func GetEmbedder() (EmbeddingFunc, int)
type Link struct {
	From    string    `json:"from"`
	To      string    `json:"to"`
	Rel     string    `json:"rel"`
	Created time.Time `json:"created"`
}

type LinkType

type LinkType string
const (
	LinkReferences  LinkType = "references"
	LinkSupports    LinkType = "supports"
	LinkContradicts LinkType = "contradicts"
	LinkExtends     LinkType = "extends"
	LinkCauses      LinkType = "causes"
)

func (LinkType) Valid

func (l LinkType) Valid() bool

type ListFilter

type ListFilter struct {
	Project string
	Tag     string
	TagsAny []string
	TagsAll []string
	Actor   string
	Search  string
	Limit   int
}

type Memory

type Memory struct {
	ID        string    `json:"id"`
	Insight   string    `json:"insight"`
	Project   string    `json:"project,omitempty"`
	Tags      []string  `json:"tags,omitempty"`
	Actor     string    `json:"actor,omitempty"`
	Created   time.Time `json:"created"`
	Updated   time.Time `json:"updated"`
	Embedding []float32 `json:"-"`
}

type ScoredMemory

type ScoredMemory struct {
	*Memory
	Score float64
}

type Store

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

func Open

func Open(path string) (*Store, error)

func (*Store) Add

func (s *Store) Add(m *Memory) error
func (s *Store) AddLink(l Link) error

func (*Store) Close

func (s *Store) Close() error

func (*Store) Delete

func (s *Store) Delete(id string, hard bool) error

func (*Store) EmbeddingStatus

func (s *Store) EmbeddingStatus() (bool, int)

func (*Store) Get

func (s *Store) Get(id string) (*Memory, error)
func (s *Store) GetLinks(id string) ([]Link, error)

func (*Store) Graph

func (s *Store) Graph(rootID string, maxDepth int) (map[string][]Link, error)

Graph traverses the knowledge graph from a starting node, returning all reachable nodes within maxDepth hops.

func (*Store) List

func (s *Store) List(f ListFilter) ([]*Memory, error)

func (*Store) Path

func (s *Store) Path() string

func (*Store) Prime

func (s *Store) Prime(query string, project string, topK int) (string, error)

Prime builds a context string with the top-K most relevant memories for the given query, formatted for injection into an LLM prompt.

func (s *Store) RemoveLink(from, to string) error

func (*Store) Search

func (s *Store) Search(query string, project string, limit int) ([]ScoredMemory, error)

Search returns memories ranked by similarity to query. If the embedder is configured and the query embeds, uses cosine similarity over stored embeddings. Falls back to substring search.

func (*Store) Stats

func (s *Store) Stats() (map[string]int, error)

Jump to

Keyboard shortcuts

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