memory: per-session semantic memory (strata-memory crate, Qdrant Edge + BGE-M3)

remember/recall/forget agent tools, one-way opt-in latch with embedder gate, fail-open Store-authoritative design, keyword fallback, model-id rebuild, GUI toggle + i18n; docs updated; split-debuginfo=unpacked
This commit is contained in:
adm committed 2026-11-30 11:37:48 +01:00
1 parent 6898cdf113
commit f74d53e446
24 files changed
+4853 -67

No files matched your search

+64 -46
View File
@@ -201,17 +201,20 @@ advanced settings to grow on top.
**Framework root.** All persistent state lives under `~/.strata-ctl/` (the Linux
user's home; override with `workspace_root`), separated by content type:
`sessions/<name>/` (agent workspace folders), `data/` (the SQLite database),
`uploads/` (uploaded files). A legacy DB at `~/.config/strata-ctl/sessions.db` is
`uploads/` (uploaded files), `memory/` (the rebuildable semantic index). A legacy
DB at `~/.config/strata-ctl/sessions.db` is
copied into `data/` once on first run (the original is left in place).
## Agent mode
The GUI model can **act**, not just chat. Tools are **always on** — there is no
toggle, because the framework could not function without them. The agent's tool
The GUI model can **act**, not just chat. The core tools are **always on** — there
is no toggle, because the framework could not function without them. The agent's tool
surface is small and deliberate: **`shell_exec`** (a shell is universal: file ops,
programs, system inspection, web via curl, git, …), **`notepad`** (agent-curated
persistent memory, see below) and **`share_file`** (hand the user a download link
for a file on its filesystem, see below). A bounded server-side loop drives
for a file on its filesystem, see below). A session that opts into **semantic
memory** additionally gets `remember` / `recall` / `forget` (see **Semantic vector
memory** below). A bounded server-side loop drives
`model → shell_exec → result → model → … → final answer`, persisting the whole
trajectory and streaming progress events — `delta` (the model's thinking and final
answer, token by token), `tool_call` / `tool_result` (every command and its output
@@ -264,6 +267,12 @@ shared JSON config ──► InklingFormatter ──► Engine supervisor ──
per-turn `[SPEAKER]` provenance (prompt-only).
- `render` — server-side Markdown → sanitized HTML with LaTeX → native MathML
(`pulldown-cmark` + `pulldown-latex`) for assistant replies.
- `agent` — the bounded server-side tool loop: `shell_exec`, `notepad`,
`share_file`, MCP connectors and the per-session memory tools.
- `memory` — the semantic memory service: the authoritative `Store` plus a
rebuildable vector index, kept in step and fail-open. Backed by the
**`strata-memory`** workspace crate (swappable `Embedder` trait, HTTP BGE-M3
client, embedded Qdrant Edge index).
## Building and running
@@ -290,8 +299,9 @@ The config is the same JSON the other Strata tools use. Keys acted on here inclu
`max_new` (default generation budget, see below), `sampling`, `api_key`,
`allowed_hosts`, `db_path` (GUI session database), `workspace_root` (framework
root), `system_prompt` (general default), `language` (UI/prompt catalog, default
`it`), and the optional `startup_timeout_secs` / `silence_timeout_secs`. Everything
else (`arch`, `mcp_servers`, `cors_origins`, …) is preserved untouched and reported
`it`), `memory_embedder_url` (semantic-memory embedder endpoint, default the free
Altair instance), and the optional `startup_timeout_secs` / `silence_timeout_secs`.
Everything else (`arch`, `mcp_servers`, `cors_origins`, …) is preserved untouched and reported
as ignored — unknown keys never break startup.
**Generation budget (`max_new`).** When neither the request nor the session sets
@@ -318,7 +328,8 @@ later adaptation round.
## Status
Working and tested (191 tests, plus 3 real-file tests run on demand). Text, images,
Working and tested (238 tests passing; 6 ignored tests exercise the real engine,
embedder or files and run on demand). Text, images,
the full client-side tool loop, the Anthropic endpoint, the web GUI (session
context, streaming, stats, **file/image upload**, **file download** (`share_file`
→ containment-checked attachment endpoint), assistant **Markdown/LaTeX
@@ -330,7 +341,10 @@ verified against the real chat template. A per-session **notepad** (agent-curate
`<NOTEPAD>` entries via the `notepad` tool) and a **sliding DIALOG window**
(message-count main area + buffer headroom, stepped KV-cache-friendly eviction at
turn boundaries, `window_start` persisted per session, full history never deleted)
are implemented and dogfooded live. A best-effort **cache pre-warm** (`GEN 0` over
are implemented and dogfooded live. Per-session **semantic memory**
(`remember` / `recall` / `forget` over an embedded Qdrant Edge index with BGE-M3
embeddings) is implemented and validated live against the Altair embedder. A
best-effort **cache pre-warm** (`GEN 0` over
the next turn's shared prefix during idle GPU time) hides the re-prefill on a
pending window rotation **or a notepad change** (pre-warm-on-change: the model
always sees a fresh notepad, no frozen header, no schema migration). The joint
@@ -365,22 +379,41 @@ routing, images via Vision) work. Per-tool host/container sandboxing was
## Roadmap
**Important TODO (suspended) — semantic vector memory.** A Qoder-style vector
database giving the agent long-term, cross-session semantic recall, useful well
beyond coding: embed and index conversation chunks, session notes, uploaded
documents and learned facts, then retrieve by similarity to inject the relevant
context into a turn, plus explicit *remember* / *semantic search* tools.
**Suspended on purpose** while we refine what already ships: the embedder/store
choice is costly to reverse, the leading candidate (vetta / BGE-M3) emits extra
modalities this application may not use and its suitability is unverified — so
the decision stays open rather than rushed.
### Semantic vector memory — implemented
Decided so far — requirements, not products:
The agent has long-term **semantic memory**: explicit `remember` / `recall` /
`forget` tools backed by dense-vector search, shipped as the `strata-memory`
workspace crate plus the control-layer seam (`src/memory.rs`). The ratified
choices:
- **One general engine + one general embedder.** A single multilingual,
domain-agnostic embedding model and a single vector engine must decently cover
any need; specialization lives *above* the index, never in a second engine or
model.
- **Embedder: BGE-M3 dense (1024-d)** via the team's `vetta-embedder` over HTTP
(`memory_embedder_url`, default the free Altair instance at
`http://192.168.50.18:8091`; C++/ggml, no Python/ONNX, no model bundled). The
`Embedder` trait keeps the backend swappable — an in-process embedder can
replace HTTP later without touching callers. Chosen after a live **fitness
probe** (representative memory corpus, labeled positive/negative queries:
top-1 20/20, MRR 1.000, clean positive/negative separation), which also
calibrated the default recall threshold to **0.45** cosine.
- **Index: Qdrant Edge** (`qdrant-edge`, embedded in-process — no server, single
binary preserved) under `~/.strata-ctl/memory/`. The SQLite `Store` stays
**authoritative**: the shard is a disposable semantic layer, rebuilt from the
Store whenever the persisted model-id sidecar (`strata_model.json`) mismatches
the current embedder — swapping embedders never mixes incompatible vectors.
- **Fail-open.** `remember` persists to the Store first; if the embedder is
unreachable, indexing is deferred and reconciled on the next open. `recall`
falls back to a keyword scan of the Store, so memory stays useful offline.
Vectors never leave the service — the model sees text + score only.
- **Per-session, one-way opt-in.** Memory is off by default (casual chat needs
none); each session's memories are **scoped to its id** — recall and forget
never cross sessions. Enabling it (GUI checkbox or `PATCH /api/sessions/{id}`)
is an **irreversible latch** like `name_locked`, so indexed memories are never
silently orphaned, and it requires the embedder to be reachable. The memory
tools are declared to the model only on memory-enabled sessions.
Still on the roadmap for memory:
- **Common / cross-session memory.** A shared scope on top of the per-session
one, when the isolation model has proven itself in use.
- **Layered directives.** An always-on **common core** (knowledge lifecycle:
recall when relevant, record durable lessons, verify against current evidence,
one topic per memory, prune duplicates) plus **enable-able domain guideline
@@ -389,28 +422,13 @@ Decided so far — requirements, not products:
carries structured config (categories/tags, chunking strategy, retrieval
filters/boosts, exposed tools) so the same general engine serves specialized
retrieval. Packs integrate with the per-session settings (copy-on-create) and
never override the core (core > pack).
- **Per-session, one-way opt-in.** Vector memory is off by default (casual chat
needs none); enabling it for a session is **irreversible** (a latch like
`name_locked`), so indexed memories are never silently orphaned by a later
disable. Enabling requires the embedder to be reachable.
Candidates under evaluation — the concrete engine / embedder / store choice is
**still open**, to be settled against the requirements above when we implement:
- **Embedder candidate: the team's `vetta-embedder`** (BGE-M3 dense 1024-d +
learned-sparse + ColBERT + a BGE-Reranker-v2-m3 cross-encoder sidecar), repo
`vetta-semantics`, already deployed on Linux hosts at `:8091` (C++/ggml, Vulkan
with CPU fallback, no Python/ONNX). Probed live: `/embed` and `/rerank` behave
correctly and multilingually; it would be reached over HTTP like the engine, so
no model is bundled. A strong candidate, **not yet chosen**. Alternative: a
small bundled multilingual embedder (ONNX/candle) if zero external services is
ever required.
- **Store candidate: sqlite-vec** inside the existing SQLite behind the `Store`
trait (dense KNN + metadata columns; recall → rerank → inject), keeping memory
co-located and transactional with sessions (single binary). Alternates behind
the same seam: the team's Qdrant (used by Iris) and the planned ArangoDB
(documents + vectors + search).
never override the core (core > pack). For now the tool guidance lives in the
tool declarations themselves; a dedicated prompt section will follow the
model's own feedback from real use.
- **One general engine + one general embedder** stays the rule: a single
multilingual, domain-agnostic embedding model and a single vector engine must
decently cover any need; specialization lives *above* the index, never in a
second engine or model.
### Sliding context window + per-session notepad
@@ -481,8 +499,8 @@ policy ships first), common/cross-session memories, a working-memory reference a
recap is out of scope**: summarizing what slides out needs an autonomous background
agent, whereas strata-ctl is reactive — the agent-curated notepad plus deterministic
truncation cover the resume anchor without a curator. The deep-retrieval complement
is the suspended semantic vector memory above; a simpler lexical recall over the
retained SQLite history can come first.
is the semantic vector memory above (implemented); a simpler lexical recall over
the retained SQLite history can still come as a lighter addition.
### Client surfaces (under consideration, not scheduled)