Documentation
¶
Overview ¶
Package mneme gives an AI agent persistent, searchable long-term memory.
You feed it conversation messages with Add; it uses an LLM to extract durable, self-contained facts, embeds and deduplicates them, and stores them in a per-scope vector index. Later you call Search to retrieve the facts most relevant to a query within the same scope.
mneme is library-first and self-contained: it carries its own OpenAI-compatible LLM/embedding client (provider/openai) and its own storage (store/sqlite, pure-Go, no cgo). Construct a Memory with New:
m, err := mneme.New() // builds providers + store from MNEME_* env vars
if err != nil { ... }
defer m.Close()
scope := mneme.Scope{UserID: "alice"}
m.Add(ctx, []mneme.Message{{Role: "user", Content: "I drive a Ferrari 488 GTB"}}, scope)
hits, _ := m.Search(ctx, "what car does the user own?", scope, 5)
The pipeline is additive: facts accumulate and are deduped by hash and by the extractor's own awareness of existing memories; there is no update/delete LLM pass in v1. See PLAN.md for the full design.
Example ¶
Example shows the full library surface: construct a Memory, Add a conversation, then Search it back. It uses offline fakes so it runs as part of the test suite; a real consumer would call mneme.New() to build providers from MNEME_* env vars instead.
package main
import (
"context"
"fmt"
"github.com/AccursedGalaxy/mneme"
"github.com/AccursedGalaxy/mneme/provider/fake"
"github.com/AccursedGalaxy/mneme/store/sqlite"
)
func main() {
st, _ := sqlite.Open(":memory:")
m, err := mneme.New(
mneme.WithStore(st),
mneme.WithLLM(&fake.LLM{Responses: []string{
fake.JSON("Alice drives a Ferrari 488 GTB"),
}}),
mneme.WithEmbedder(&fake.Embedder{}),
)
if err != nil {
panic(err)
}
defer m.Close()
ctx := context.Background()
scope := mneme.Scope{UserID: "alice"}
written, _ := m.Add(ctx, []mneme.Message{
{Role: "user", Content: "I drive a Ferrari 488 GTB"},
}, scope)
fmt.Printf("wrote %d fact(s)\n", len(written))
hits, _ := m.Search(ctx, "what Ferrari does Alice drive?", scope, 1)
for _, h := range hits {
fmt.Println(h.Text)
}
}
Output: wrote 1 fact(s) Alice drives a Ferrari 488 GTB
Index ¶
Examples ¶
Constants ¶
const DefaultExtractionTopK = 10
DefaultExtractionTopK is how many existing memories are shown to the extractor for dedup/linking when WithExtractionTopK is not set.
const DefaultPromptVersion = "v1"
DefaultPromptVersion is the prompt version New uses unless WithPromptVersion overrides it.
Variables ¶
This section is empty.
Functions ¶
func PromptVersions ¶
func PromptVersions() []string
PromptVersions returns the registered prompt version names (unordered).
Types ¶
type Fact ¶
Public value types are defined once in the leaf package types and re-exported here as aliases, so consumers use mneme.Message / mneme.Scope / mneme.Fact while the store package can share the same types without an import cycle.
type Memory ¶
type Memory interface {
// Add ingests messages, extracts durable facts, dedups, and stores them.
// It returns the facts that were newly written (after dedup).
Add(ctx context.Context, msgs []Message, scope Scope) ([]Fact, error)
// Search returns the top-k facts most relevant to query within scope,
// with Score populated, highest first.
Search(ctx context.Context, query string, scope Scope, k int) ([]Fact, error)
// Get returns one fact by id.
Get(ctx context.Context, id string) (Fact, error)
// Delete removes one fact by id.
Delete(ctx context.Context, id string) error
// Close releases resources (the DB handle).
Close() error
}
Memory is the top-level handle an agent holds. It is safe for concurrent use to the extent its underlying store, LLM and embedder are.
type Message ¶
Public value types are defined once in the leaf package types and re-exported here as aliases, so consumers use mneme.Message / mneme.Scope / mneme.Fact while the store package can share the same types without an import cycle.
type Option ¶
type Option func(*memory)
Option configures New. Options are applied in order; later ones win.
func WithEmbedder ¶
WithEmbedder sets the embedder. Without it, New builds an OpenAI-compatible client from MNEME_EMBED_* env vars.
func WithExtractionTopK ¶
WithExtractionTopK sets how many existing memories are shown to the extractor.
func WithLLM ¶
WithLLM sets the extraction LLM. Without it, New builds an OpenAI-compatible client from MNEME_LLM_* env vars.
func WithPromptVersion ¶
WithPromptVersion selects the extraction prompt version (see PromptVersions).
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
eval
command
Command eval runs mneme's prompt-evaluation harness against a live LLM and prints a per-metric table plus an aggregate score per prompt version.
|
Command eval runs mneme's prompt-evaluation harness against a live LLM and prints a per-metric table plus an aggregate score per prompt version. |
|
Package eval is mneme's prompt evaluation harness.
|
Package eval is mneme's prompt evaluation harness. |
|
examples
|
|
|
basic
command
Command basic is a runnable end-to-end dogfood of the mneme library against a real OpenAI-compatible endpoint.
|
Command basic is a runnable end-to-end dogfood of the mneme library against a real OpenAI-compatible endpoint. |
|
Package provider defines the LLM and embedding interfaces mneme depends on, plus implementations (an OpenAI-compatible HTTP client in provider/openai and deterministic fakes in provider/fake).
|
Package provider defines the LLM and embedding interfaces mneme depends on, plus implementations (an OpenAI-compatible HTTP client in provider/openai and deterministic fakes in provider/fake). |
|
fake
Package fake provides deterministic, offline implementations of provider.LLM and provider.Embedder for unit tests.
|
Package fake provides deterministic, offline implementations of provider.LLM and provider.Embedder for unit tests. |
|
openai
Package openai is a minimal OpenAI-compatible HTTP client implementing provider.LLM and provider.Embedder over net/http with no SDK dependency.
|
Package openai is a minimal OpenAI-compatible HTTP client implementing provider.LLM and provider.Embedder over net/http with no SDK dependency. |
|
Package store defines the persistence interface for mneme facts and ships a pure-Go SQLite implementation (store/sqlite).
|
Package store defines the persistence interface for mneme facts and ships a pure-Go SQLite implementation (store/sqlite). |
|
sqlite
Package sqlite is the pure-Go (modernc.org/sqlite, no cgo) default Store for mneme.
|
Package sqlite is the pure-Go (modernc.org/sqlite, no cgo) default Store for mneme. |
|
Package types holds the small value types shared across mneme's packages.
|
Package types holds the small value types shared across mneme's packages. |