recall

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Recall

Shared, typed memory for agents.

Recall lets agents share facts, preferences, and project context across processes and sessions. One agent can record a preference, another can update it, and both can read the current value and its history.

Use it through Go, Python, or MCP, with Polign as the storage backend. Go applications can also supply their own backend.

Choose an integration

Integration Get started
Python Follow the quickstart below, then see the client guide.
Go Run go get github.com/Polign/recall and follow the Go client guide.
MCP Connect an agent to tools for remembering, recalling, and forgetting facts.

The Claude Code plugin is a ready-made MCP integration for memory across coding sessions.

Quickstart

You'll need Python 3.10+ and Polign v0.6.4 or later, with both polign and polign-server on your PATH. The Python client launches a local polign mcp process that connects to your database. This example needs no model or embedding API key.

Start the database in a terminal and leave it running:

polign-server -store "fs:$HOME/.local/share/recall/data"

In another terminal, from a checkout of this repository, install the Python client and select a collection for the example:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install ./python
export POLIGN_URL=http://127.0.0.1:23000
export POLIGN_COLLECTION=recall_demo

One process saves an editor preference and then changes it:

python - <<'PY'
from polign_recall import Client

with Client() as memory:
    memory.remember("user", "prefers_editor", "vim")
    memory.remember("user", "prefers_editor", "neovim")
PY

Run a second process in the same terminal. It reads the saved preference and the earlier statements:

python - <<'PY'
from polign_recall import Client

with Client() as memory:
    current = memory.recall("user", "prefers_editor")
    print(current[0].value)  # neovim
    print([event.value for event in memory.history("user", "prefers_editor")])
    # On a fresh collection: ['vim', 'neovim']
PY

Each process closes its client when it exits; the memories remain in the database. Agents on other machines can use the same server URL and collection, with POLIGN_API_KEY set when authentication is required.

For examples covering historical reads and forgetting, see the Python session example or Go session example.

How memory works

A memory has a subject, a predicate, and a typed value:

Subject Predicate Value
user prefers_editor neovim
recall-demo prefers_test_framework pytest
recall-demo uses_technology Go

The registry defines which predicates an application accepts, their value types, and whether they hold one value or several. Recall includes 15 predicates for preferences, identity, and project facts. You can extend the registry for your application.

For a single-valued predicate such as prefers_editor, a new assertion replaces the current value. A multi-valued predicate such as uses_technology can hold both Python and Go. Corrections preserve earlier statements, so you can read current values, inspect their history, or query what was known at an earlier time.

Forgetting records a withdrawal and removes the affected fact from current answers. It does not permanently delete the record.

An agent can also propose facts from text. Recall validates those proposals against the registry before writing them.

Recall provides memory rules, validation, and history; the backend provides persistence and access to the data. Agents share memory by using the same backend, collection, and namespace, with compatible Recall versions and memory definitions. Search also requires compatible embedding methods.

Concurrent reads and writes follow the backend's consistency guarantees. Recall does not add transaction isolation or replication. Go applications can implement the Put, List, and Search backend contract to use another storage system.

The Go library has no external module dependencies. Its built-in lexical embedder supports word-overlap search; applications can supply a model-based embedder for semantic search. See the embedding guide.

Repository layout

Path Contents
recall.go, doc.go Public Go API at github.com/Polign/recall
internal/engine/ Memory implementation and unit tests
polign/ Go backend adapter
python/ Python package and tests
cmd/ Command-line tools, including recall-audit
examples/ Runnable Go and Python examples
docs/ Guides and API reference
testdata/ Shared audit fixtures

See the development guide for the implementation map and test commands.

Documentation

Developer reference · Caching memory reads · Exporting and replaying history

License

Apache 2.0.

Documentation

Overview

Package recall is the typed agent-memory layer: a closed registry of predicates, an append-only event log per subject, and the fold that turns that log into what the agent believes, now or at any past instant.

The central decision is that a belief is derived, never mutated. An earlier design flipped a record's status to "superseded" in a second write after storing its replacement, which left two live beliefs for a single-valued predicate whenever a process died between the two. Here the log is the truth and Fold deterministically interprets the events visible to a reader. This does not serialize concurrent writers or establish a read snapshot. Current and historical beliefs use the same fold with a different ceiling.

Retraction is likewise an event, not a deletion. Forgetting a fact on Wednesday must not change what the agent believed on Tuesday, and a log that erases its own history cannot answer that.

Index

Constants

View Source
const (
	PointerGitRef   = engine.PointerGitRef
	PointerObject   = engine.PointerObject
	PointerEnv      = engine.PointerEnv
	PointerExternal = engine.PointerExternal
	PointerProcess  = engine.PointerProcess
)

Pointer types.

View Source
const AuditVersion = engine.AuditVersion

AuditVersion identifies the bundle envelope and its canonical checksum.

View Source
const DefaultSubject = engine.DefaultSubject

DefaultSubject is who a note is about when the text yielded no proposal to take a subject from.

View Source
const EventVersion = engine.EventVersion

EventVersion identifies the typed Event fields recorded in a bundle.

View Source
const FoldVersion = engine.FoldVersion

FoldVersion identifies observation-time ordering and the current single and multi-value fold rules. Incompatible changes need a new replay path.

v2 orders a retraction after the assertion it withdraws when the two share an instant. v1 ordered that tie on the event id, so the same log can fold differently under the two, and a v1 bundle must not be replayed here as though nothing had changed.

View Source
const LexicalSpace = engine.LexicalSpace
View Source
const MaxCandidateEvents = engine.MaxCandidateEvents

MaxCandidateEvents bounds event discovery for broad exact queries. A query for one explicit subject/predicate uses MaxHistoryEvents instead.

View Source
const MaxExport = engine.MaxExport

MaxExport bounds an unbounded export, so that asking for everything cannot turn into an unbounded scan by accident.

View Source
const MaxHistoryEvents = engine.MaxHistoryEvents

MaxHistoryEvents bounds a complete subject-and-predicate history. Histories beyond this bound fail explicitly; a partial fold could revive a retraction.

View Source
const MaxRecall = engine.MaxRecall

MaxRecall bounds the number of beliefs a query can request. Candidate discovery and result allocations are bounded independently of caller input.

View Source
const Multi = engine.Multi

Multi means values accumulate: an agent may like many languages.

View Source
const NotePredicate = engine.NotePredicate

NotePredicate is where a statement goes when no registered predicate fits it. Every client and store registers it, so "nothing matched" always has a place to be written instead of being dropped. A note is multi-valued free text: it never supersedes anything, and recall ranks it after typed beliefs.

View Source
const Single = engine.Single

Single means a newer value replaces the older one: an agent has one preferred editor.

Variables

View Source
var (
	ErrLeaseHeld        = engine.ErrLeaseHeld
	ErrLeaseLost        = engine.ErrLeaseLost
	ErrLeaseUnsupported = engine.ErrLeaseUnsupported
	ErrAgentClosed      = engine.ErrAgentClosed
	ErrLeaseNotHeld     = engine.ErrLeaseNotHeld
)
View Source
var ErrDigestMismatch = engine.ErrDigestMismatch

ErrDigestMismatch means validated content differs from its checksum.

View Source
var ErrEmbedderRequired = engine.ErrEmbedderRequired

ErrEmbedderRequired means an operation needs vectors but no embedder was configured.

View Source
var ErrIncompleteCandidates = engine.ErrIncompleteCandidates

ErrIncompleteCandidates means a broad exact query could not discover enough matching beliefs or prove it exhausted the candidate set. No partial answer is returned; callers can narrow the query to an explicit subject/predicate.

View Source
var ErrIncompleteHistory = engine.ErrIncompleteHistory

ErrIncompleteHistory means the backend could not supply a complete exact log. No belief or write may be derived from such a log.

View Source
var ErrInvalidAudit = engine.ErrInvalidAudit

ErrInvalidAudit marks unsupported versions or invalid bundle inputs.

View Source
var ErrInvalidEvent = engine.ErrInvalidEvent

ErrInvalidEvent means a stored record cannot safely participate in a fold.

View Source
var ErrWatermarkUnsupported = engine.ErrWatermarkUnsupported

Functions

func Digest added in v0.2.0

func Digest(events []Event) string

Digest is the legacy stable checksum over a log. It uses case-insensitive value identity, so it does not detect changes only to string capitalization. Use DigestV2 for exact typed values or ExportAudit for reproducible bundles.

A separately trusted digest lets two parties compare logs without exchanging them. A checksum alone does not authenticate an exporter or prove completeness. The input is each event's canonical fields in a fixed order, so the digest depends on the content of the log and not on how it was serialised, paged, or which node answered.

func DigestV2 added in v0.3.0

func DigestV2(events []Event) (string, error)

DigestV2 hashes exact typed event fields, including case-sensitive strings and the IEEE-754 bits of finite numbers (so -0 and +0 differ). Instants are canonical UTC timestamps. It rejects invalid events and duplicate IDs. Digest remains the legacy, case-insensitive checksum for existing exports.

func SortEvents added in v0.2.0

func SortEvents(events []Event)

SortEvents orders a log oldest first, breaking ties on id so that two exports of the same events are byte-identical.

func ValueKey

func ValueKey(v any) string

ValueKey renders a value in the canonical form used to tell two values apart. Strings fold case, so "Neovim" stated twice with different capitals is one belief rather than two; the event keeps whatever form was written, and only identity is case-insensitive. Numbers render without exponent drift so that 8000 and 8000.0 are one value rather than two.

func VerifyDigest added in v0.3.0

func VerifyDigest(events []Event, expected string) error

VerifyDigest verifies either a legacy sha256: digest or a sha256:v2: digest. Legacy verification intentionally retains its original identity semantics.

Types

type Agent added in v0.6.0

type Agent = engine.Agent

Agent is a resumed agent: it holds the agent's lease and writes its working state, pointers, turns and outputs. Obtain one from Client.Resume.

type AuditBundle added in v0.3.0

type AuditBundle = engine.AuditBundle

AuditBundle records the inputs needed to reproduce exact beliefs offline. The digest covers every field except Digest itself, independent of event or registry iteration order. It is a checksum, not a signature or proof that the exporter supplied every event. Retain its digest through a trusted channel.

type AuditRequest added in v0.3.0

type AuditRequest = engine.AuditRequest

AuditRequest selects histories and the instant at which to replay them. A zero AsOf captures the store's current time once, before reading events.

type AuditScope added in v0.3.0

type AuditScope = engine.AuditScope

AuditScope selects complete histories. Empty fields match all subjects or predicates. Unlike Export, this scope cannot request a truncated event subset.

type Backend added in v0.3.0

type Backend = engine.Backend

Backend is the context-aware storage contract used by Client. Implementations must be safe for concurrent calls. List must obey VectorDB's exact totals, internal pagination, and stable ordered-prefix contract.

type Belief

type Belief = engine.Belief

Belief is a statement that holds at some instant: the result of folding a log, not a stored row.

func Fold

func Fold(events []Event, card Cardinality, asOf time.Time) []Belief

Fold reduces one subject-and-predicate's events to the beliefs that hold at asOf. A zero asOf means now.

Events may arrive in any order and may repeat; the fold is defined by the log's content alone, so a partially applied write, a retried write, or a clock that stepped backwards changes the answer only in so far as it changed the log.

type Cardinality

type Cardinality = engine.Cardinality

Cardinality decides what a second value for the same subject and predicate means.

type Client added in v0.3.0

type Client = engine.Client

Client is a context-aware memory client. Configuration is immutable, and operations have independent request state. Concurrent writes still follow the backend's consistency guarantees; Client does not promise serializable writes.

func NewClient added in v0.3.0

func NewClient(cfg Config) (*Client, error)

NewClient validates configuration and copies the registry.

type Config added in v0.3.0

type Config = engine.Config

Config configures an immutable Client. Embedder is optional for exact reads, histories, and exports; writes and semantic recall require it.

type EmbedFunc added in v0.3.0

type EmbedFunc = engine.EmbedFunc

EmbedFunc adapts a function to Embedder.

type Embedder added in v0.3.0

type Embedder = engine.Embedder

Embedder supplies compatible document and query vectors. Implementations must honor cancellation and be safe for concurrent calls.

type Event

type Event = engine.Event

Event is one durable statement about a subject, or the retraction of one. Events are immutable once written: a correction is a later event, never an edit of an earlier one.

func DecodeEvent added in v0.3.0

func DecodeEvent(id string, m map[string]any) (Event, error)

DecodeEvent validates typed event metadata before returning it. Store reads use this strict decoder so a malformed correction or retraction cannot be silently skipped. EventFromMetadata remains available as a permissive decoder. Missing retraction denotes a legacy assertion; observed_ms is optional because observed_at is the authoritative timestamp.

func EventFromMetadata

func EventFromMetadata(id string, m map[string]any) Event

EventFromMetadata decodes without validation, retaining its legacy behavior. Invalid fields become their zero values. Use DecodeEvent before deriving beliefs from stored metadata; Store uses that strict decoder internally.

type Export added in v0.2.0

type Export = engine.Export

Export selects part of the log for audit. An empty field means "every one of these": zero Export exports everything the store holds.

type ExtractionResult added in v0.3.0

type ExtractionResult = engine.ExtractionResult

type Extractor added in v0.3.0

type Extractor = engine.Extractor

type ForgetRequest added in v0.3.0

type ForgetRequest = engine.ForgetRequest

ForgetRequest selects exactly one typed Value or All=true. False and numeric zero are values; an omitted value never implicitly withdraws everything.

type Hit

type Hit = engine.Hit

Hit is one search result.

type LeaseBackend added in v0.6.0

type LeaseBackend = engine.LeaseBackend

LeaseBackend optionally grants per-agent leases. Resume requires it unless ResumeRequest.Unleased is set.

type LeaseGrant added in v0.6.0

type LeaseGrant = engine.LeaseGrant

LeaseGrant is one held lease epoch; the epoch is the fencing token.

type LeaseHeldError added in v0.6.0

type LeaseHeldError = engine.LeaseHeldError

LeaseHeldError names who holds a lease that could not be taken.

type LexicalEmbedder added in v0.3.0

type LexicalEmbedder = engine.LexicalEmbedder

LexicalEmbedder is a dependency-free signed feature-hashing fallback. It retrieves overlapping words, not semantic synonyms. Use a dedicated collection for this versioned 256-dimensional space; never mix it with model embeddings.

type Materialization added in v0.3.0

type Materialization = engine.Materialization

Materialization is a bounded, process-local derived belief view owned by one client. The durable event log remains authoritative. Restart rebuilds the view.

type Output added in v0.6.0

type Output = engine.Output

Output is a large tool result, kept whole and fetched by reference.

type OutputRef added in v0.6.0

type OutputRef = engine.OutputRef

OutputRef describes a stored output without its content.

type Pointer added in v0.6.0

type Pointer = engine.Pointer

Pointer is a typed reference to where some of an agent's work lives.

type Predicate

type Predicate = engine.Predicate

Predicate is one registry entry. Cardinality decides what a second value for the same subject means: "single" makes a newer value supersede the old one, "multi" makes it an additional fact. ValueType decides what a value IS: a string, a number, or a boolean. Values are stored with that type, so a number compares numerically in recall filters instead of lexically.

type PromoteRequest added in v0.5.0

type PromoteRequest = engine.PromoteRequest

PromoteRequest files a note under a typed predicate. Note is the note's value exactly as recall returned it; the remaining fields are the typed statement it becomes, with RememberRequest's defaults.

type Proposal added in v0.3.0

type Proposal = engine.Proposal

Proposal is an untrusted model suggestion, never a belief until Remember validates and folds it. Evidence must be an exact excerpt from the input.

type ProposedStatements added in v0.3.0

type ProposedStatements = engine.ProposedStatements

ProposedStatements adapts proposals made by the calling agent. This lets an MCP host use its own model for extraction without another model service. RememberText still treats every proposal as untrusted and validates the batch.

type Query

type Query = engine.Query

Query is one read. With Text set the read is semantic (the text is embedded and searched); without it it is an exact filtered read. Both modes answer with beliefs folded from the same log, so semantic recall can never return something exact recall would say is no longer believed.

type Registry

type Registry = engine.Registry

Registry is the closed set of predicates the store accepts. A write with an unregistered predicate is rejected, so an agent cannot invent near-duplicate predicates ("editor_preference" beside "prefers_editor") and split one fact across two names that never meet.

func DefaultRegistry added in v0.3.0

func DefaultRegistry() Registry

DefaultRegistry returns an independent starter vocabulary. Applications may extend the returned map before constructing a Client.

func LoadRegistry

func LoadRegistry(raw []byte) (Registry, error)

LoadRegistry parses and validates a registry document.

type RememberRequest added in v0.3.0

type RememberRequest = engine.RememberRequest

RememberRequest records a typed value (string, float64, or bool). Kind defaults to fact and Source to user_stated. Nil Confidence defaults to 1; a pointer to zero records zero confidence rather than selecting the default.

type RememberResult

type RememberResult = engine.RememberResult

RememberResult is what a write reports back: the assertion stored or found, whether it already held, and anything it displaced.

type ResumeContext added in v0.6.0

type ResumeContext = engine.ResumeContext

ResumeContext is the context a resumed agent starts from. Its Briefing is one message a harness can hand the model as its starting context.

type ResumeRequest added in v0.6.0

type ResumeRequest = engine.ResumeRequest

ResumeRequest names the agent to resume and how to build its context.

type Store

type Store = engine.Store

Store turns writes into durable, typed events and reads into beliefs. It derives each answer from the log returned by its backend at read time. Consistency across concurrent operations depends on that backend.

func NewStore

func NewStore(db VectorDB, collection string, registry Registry, embed func(string) []float32) *Store

NewStore returns a store over one collection.

An invalid registry is recorded rather than returned, because this constructor has never had an error to return. Every operation reports it, so a bad cardinality surfaces at the first call instead of silently folding a multi-valued predicate as single-valued and appearing much later as a malformed audit.

type StoredVector

type StoredVector = engine.StoredVector

StoredVector is one record as the database returns it.

type Turn added in v0.6.0

type Turn = engine.Turn

Turn is one message of an agent's run, kept verbatim.

type VectorDB

type VectorDB = engine.VectorDB

VectorDB is the database surface the store needs. Keeping it an interface is what lets the memory layer live outside the database it usually runs against, and lets tests exercise the semantics without one.

type WatermarkBackend added in v0.3.0

type WatermarkBackend = engine.WatermarkBackend

WatermarkBackend optionally supplies an opaque revision of the complete collection visible to this reader. It must change on every visible mutation, including overwritten IDs, deletes, late arrivals, restores, and route changes. It is not an observation timestamp or a maximum event ID. Equality is the only meaningful operation; replicas need not expose the same revision.

A revision must never be reused once it has changed. A counter that resets on restart lets a revision repeat, and a repeat silently revalidates a cached fold that the log has since moved past. Entries also expire after 30 seconds so that a backend which under-reports bounds, rather than keeps, the staleness it causes.

type WorkingState added in v0.6.0

type WorkingState = engine.WorkingState

WorkingState is an agent's handoff note to its next instance.

Directories

Path Synopsis
cmd
recall-audit command
recall-audit verifies a JSON audit bundle from stdin and prints its replayed beliefs.
recall-audit verifies a JSON audit bundle from stdin and prints its replayed beliefs.
examples
resume command
resume shows an agent surviving a crash without a snapshot.
resume shows an agent surviving a crash without a snapshot.
sessions command
sessions demonstrates exact memory across separate client processes.
sessions demonstrates exact memory across separate client processes.
internal
engine
Package engine implements Recall's typed memory, event histories, and audit replay.
Package engine implements Recall's typed memory, event histories, and audit replay.
Package polign implements Recall's context-aware Backend over the Polign HTTP API.
Package polign implements Recall's context-aware Backend over the Polign HTTP API.

Jump to

Keyboard shortcuts

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