ClawQL’s memory architecture — OKF vault, vector recall, and optional Onyx — and how they compose into persistent, auditable, sovereign agent intelligence. 8.0 correction: PageIndex and CodeGraph are no longer product layers.
This pairs with Git-native agent memory (vault backend, auto-commit, R2/Arweave durability), the Enterprise Ontology (entity instances as vault knowledge), and twelve layers of LLM cost. OKF serialization: docs/memory/okf.md. Token-efficiency layers: docs.clawql.com/architecture/token-efficiency. Migration: migrate-to-8.0.
Format note: the vault ships OKF-compatible Markdown by default — memory_ingest writes .md with the required type field. .cqk is the ClawQL Knowledge extension for the same frontmatter contract (ADR 0010). Examples below use .cqk; treat .md with the same fields as the Day-1 path.
The Tax Nobody Measures
Every AI coding session opens with the same overhead. The developer types something like “continue working on the authentication refactor.” The agent asks what the authentication refactor is.
It has no idea. The decision to use JWT over sessions last week is gone. The three hours spent benchmarking argon2 against bcrypt — gone. Organizational knowledge — the reasoning behind decisions, the approaches that were tried and rejected — doesn’t survive the context window boundary at all.
This isn’t a model failure. Models demonstrate within-session memory just fine. The problem is architectural: nothing persists between sessions.
What Agents Actually Need to Remember
“Memory” covers at least five distinct categories, each requiring different storage and retrieval:
- Decisions — why JWT instead of sessions; why the current architecture rather than the alternatives.
- Domain entities — typed, relationship-aware facts (contracts, customers, assets). See the Enterprise Ontology post.
- Session context — what was in progress, what was blocked, what the next step was.
- Team knowledge — decisions and patterns shared across the swarm.
- Codebase structure — which files exist, how they relate. Agents still rediscover this with
grep/read_aroundtoday; a structural index may return later (see Removed in 8.0).
Standard AI tooling handles zero of these persistently. ClawQL’s memory stack addresses the first four today; codebase structure stays on working grep until graded evidence clears a revival bar.
The Live Stack (8.0)
Layer 3: Onyx — Semantic enterprise knowledge (opt-in hybrid / explicit sources)
Layer 2: Vector Recall — Semantic similarity search over vault entries
Layer 1: OKF Vault (.cqk / OKF .md) — Durable, auditable, structured knowledge
+ in-process lexical scoring (corpus IDF × log-saturated TF)
Default memory_recall (omit sources): vault keyword + wikilinks, plus vector KNN. That is the whole default path.
Onyx joins the default set only when CLAWQL_MEMORY_RECALL_HYBRID_ONYX=1, or when the caller passes explicit sources: [...]. Hybrid defaults are gated on measured task-completion gains — not on “more layers look better.”
By default,
memory_recallqueries the OKF vault (keyword + wikilinks) and vector KNN. Onyx is available viasourcesor a hybrid env flag. ClawQL’s heading-tree PageIndex tools and hybrid PageIndex recall, and its structural CodeGraph tools, were removed in 8.0 after graded evals failed the ship bar; a Vectify-style redesign (LLM node summaries + strong tree nav) may return later as a new PageIndex experiment on a fresh hard set, and CodeGraph may be revisited on a large-monorepo cohort or with a local model — neither is a revival of the purged surface.
Layer 1: The OKF Vault
Every memory entry ClawQL stores is OKF-compatible: Markdown body, YAML frontmatter, file path as concept identity, wikilinks between concepts. The .cqk extension is the ClawQL Knowledge promotion of the same format, carrying additional provenance fields.
The Open Knowledge Format establishes just enough convention to make different producers and consumers interoperable. Required type field. Optional resource, description, tags. Catalog in index.md. Changelog in log.md. ClawQL adds worm_ref, correlation_id, agent_id, verdict, and confidence_score — fields that tie every entry to the WORM audit trail.
---
type: decision
title: "Authentication: JWT over sessions"
description: "JWT chosen for stateless auth rather than server-side sessions"
tags: auth, jwt, security, performance
timestamp: 2026-07-14T14:32:00Z
confidence_score: 0.94
agent_id: agent-daniel-dev-01
correlation_id: sess-8821-tool-047
worm_ref: sha256:a1b2c3d4e5f6...
verdict: passed
session_id: sess-8821
project: clawql-auth-refactor
---
## Decision
JWT over server-side sessions for the authentication layer.
## Reasoning
Server-side sessions require a shared session store that becomes a single point of failure
and complicates horizontal scaling. JWT tokens are stateless — the server validates
cryptographically without any external lookup.
## Related
[[Authentication: argon2 over bcrypt]]
[[Authentication: 15-minute access token TTL]]
The wikilinks create a traversable knowledge graph. memory_recall can follow them the way a human would navigate a wiki — start at one decision, follow links to related ones, build a coherent picture of a decision cluster rather than a single isolated answer.
The worm_ref field links the knowledge entry to its WORM audit record, which captures the session ID, agent ID, full prompt context, and Evaluator verdict at the moment of ingestion. The entry is auditable: you can prove when it was created, by which agent, during which session.
Vault Directory Structure
~/.ClawQL/
vault/
index.md # OKF catalog — first thing read on recall
log.md # append-only changelog of every ingest
decisions/
auth-jwt-over-sessions.cqk
auth-argon2-over-bcrypt.cqk
context/ # type: context — cross-session bridges
session-2026-07-14-end.cqk
entity_instances/ # type: entity_instance
contracts/
contract-abc123.cqk
task_results/
weekly-summary-2026-07-14.cqk
errors/ # failure patterns + solutions
jwt-validation-timeout.cqk
patterns/
retry-with-exponential-backoff.cqk
ontology/ # schema definitions — Git-tracked separately
entities/
Contract.cqe
The vault lives in S3/R2. Schemas (.cqe, .cqm) live in Git. These have different lifecycles: schemas change through PRs and deployments, knowledge accumulates continuously and should never require a deployment to persist. clawql sync handles R2 push/pull across edge nodes.
Lexical Scoring (Not FTS5 BM25)
Lexical scoring on the vault path is corpus IDF × log-saturated TF — in-process, not SQLite FTS5 / Okapi BM25. BM25 (length normalization) was evaluated as a candidate and washed vs IDF — it is not the default.
The OKF Index
The index.md is what makes the vault scale past a few dozen entries:
# ClawQL Agent Memory Vault
## Decisions (47 entries)
- [[auth-jwt-over-sessions]] — Authentication token strategy
- [[arch-effect-ts-migration]] — TypeScript error handling architecture
...
## Errors (23 entries)
- [[jwt-validation-timeout]] — JWT validation latency spike — RESOLVED
...
memory_recall reads index.md first. Scanning the catalog costs about 500 tokens. Loading the index plus the five most relevant full entries costs about 3,000 tokens. Loading every entry in a large vault would cost 50,000–200,000 tokens. The index-first pattern is what keeps recall economical as the vault grows.
The log.md
An append-only record of every memory_ingest event:
## 2026-07-14T14:35:22Z — sess-8821
**Ingested:** decision/auth-jwt-over-sessions
**Agent:** agent-daniel-dev-01
**Summary:** JWT chosen over sessions. Reasoning: stateless, horizontal scaling.
**WORM:** sha256:a1b2c3d4...
At the start of a new session, memory_recall reads log.md filtered to the last N days and the current project. The agent sees what was worked on recently without loading any full entries — the fastest possible session continuity mechanism.
Layer 2: Vector Recall
When memory_ingest creates an entry, it can also generate an embedding and store it in the derived index (memory.db / optional pgvector). On edge gateways this stays local with zero network latency. In the Virtual Gateway, Postgres/pgvector handles team scale.
The recall pipeline surveys the index, runs vault lexical scoring, runs vector similarity when configured, follows wikilinks from high-scoring seeds, and returns normalized hits[] with source attribution. Embedding failures fail open — the lexical vault path still works. The cache is an optimization, never a gate.
Cache hits are flagged with cache_hit: true. The --exclude-cache-hits flag on Flywheel export removes them from training data — training on cached responses instead of model outputs degrades training quality.
OpenBench tooling WINs prove the tools work; they are not claims of retrieval superiority over every alternative stack.
Layer 3: Onyx (Optional)
The vault captures what agents learned. Onyx surfaces what the organization already knew — Confluence, Notion, Slack, Google Drive, GitHub, Jira, and other connectors — with citation-backed, permission-aware results that tell the agent not just what was found but where and why.
An agent working on the authentication refactor might query both:
- OKF vault: “what authentication decisions did we make in previous sessions?” → typed decision entries
- Onyx: “what does the security documentation say about token handling?” → Confluence pages, Slack threads, GitHub issues
Wire it with CLAWQL_ENABLE_ONYX=1 and either CLAWQL_MEMORY_RECALL_HYBRID_ONYX=1 or explicit sources: ["vault", "vector", "onyx"].
Removed in 8.0 (Not Layer 3 / 4)
Do not list PageIndex or CodeGraph as live layers in the current ClawQL stack. Hybrid defaults earn their place only when graded task completion moves; both failed that bar.
PageIndex — Purged
7.x shipped deterministic heading-tree tools (pageindex_build_tree / traverse / synthesize). They were vectorless hierarchical retrieval over Markdown structure — not an LLM category router. Earlier LLM category-routing sketches (page_index_path / page_index_categories) never shipped as product.
Graded evidence: hybrid PageIndex as a merge was harmful (−7.8 pts; 13/13 displaced). Track A fair test tied Net=4 → no Vectify port. The ClawQL PageIndex surface — tools, hybrid flags, and pageindex.db.json sync — is gone in 8.0. Do not set CLAWQL_ENABLE_PAGEINDEX or teach pageindex_* as operator guidance.
Any future hierarchical index work is post-8.0 Vectify backlog (LLM node summaries + strong tree nav on a fresh hard set), not a present-tense product layer.
CodeGraph — Purged
Structural CodeGraph (codegraph_*, Graphify import/sync, the clawql-codegraph package) was removed after a strong-model Track B retest tied Net=0 vs working grep + read_around → tie_purge. Do not list CodeGraph as a live stack layer or teach CLAWQL_ENABLE_CODEGRAPH / codegraph_* as operator guidance.
Revival conditions (large-monorepo cohort / local model): post-8.0 CodeGraph backlog.
Purge inventory: 8.0.0-purge-inventory-spec.
How the Layers Compose (8.0)
// Default (omit sources): vault + vector only
await memory_recall({ query: 'why JWT over sessions?' });
// Explicit enterprise peer
await memory_recall({
query: 'token handling policy',
sources: ['vault', 'vector', 'onyx'],
});
The agent receives normalized hits[] plus specialist followUps when needed. Source is recorded per hit. There is no default fan-out across purged PageIndex/CodeGraph layers — and Onyx is not in the omit-sources default unless the hybrid env flag is set.
Team Memory
Individual developer memory is valuable. When every developer’s agent shares knowledge through the Virtual Gateway, the swarm collectively knows more than any individual agent.
Namespace Model
s3://clawql-org-vault/
personal/{developer_id}/vault/ # private to the developer
team/{team_id}/vault/ # shared across the team, ATRClaims scoped
org/vault/ # shared across the organization
memory_recall queries all three namespaces the agent is authorized for. memory_ingest routes to the appropriate namespace based on knowledge type. Personal decisions stay personal. Architectural decisions shared with the team. Organizational standards go to the org namespace.
In the Agentic Fabric, the Virtual Gateway’s NATS JetStream propagates recall requests across the swarm when a local cache misses. Team vault answers don’t require every edge node to hold the full team vault locally.
Connection to the Token Efficiency Stack
The memory stack connects to multiple layers in the twelve-layer efficiency architecture:
Layer 3 (Redundant static context): The vault index.md is stable between sessions. The system prefix including the index survey is cacheable at the provider layer.
Layer 5 (Semantic cache): Recall queries are themselves cached. The same query in a different session returns the cached result.
Layer 6 (Undistilled history): When session history grows long, ClawQL distills it into a type: context vault entry. The transcript is gone; the semantic content persists.
Layer 7 (Cross-session rediscovery): The next session recalls the context entry rather than re-establishing project state from scratch. Code exploration still uses grep / read_around until a structural index clears the ship bar.
Layer 12 (Flywheel): Every memory_ingest with verdict: passed is a training example. Verdict-filtered Flywheel export still turns good sessions into training data — that loop does not depend on PageIndex or CodeGraph.
WORM Audit
Every memory operation can write a WORM entry:
'MEMORY_INGEST'; // new entry created
'MEMORY_RECALL'; // query + entries returned
'MEMORY_CACHE_HIT'; // recall returned cached result
'MEMORY_UPDATE'; // existing entry modified
'MEMORY_ARCHIVE'; // entry moved to cold storage
'MEMORY_SYNC_PUSH'; // entry synced to R2
'MEMORY_SYNC_PULL'; // entry pulled to edge
'ONYX_SOURCE_INDEXED'; // Onyx connector indexed new content
Compliance queries that no other memory system supports:
“Show me every decision created by agent X in the last 90 days” — WORM query on MEMORY_INGEST filtered by agent_id and type: decision.
“Prove that HIPAA-sensitive patient data was not accessed by the agent during this session” — WORM query on MEMORY_RECALL events filtered by pii_classification: PHI. If no PHI entries appear in recall events, the agent didn’t access them.
The negative proof is what regulated industries need. Not just what the agent remembered, but what it provably didn’t access.
What Alternatives Are Missing
Plain Obsidian vault: The knowledge structure is right. Agent access is manual. No memory_ingest automation, no vector recall, no WORM audit, no team sync.
MemoryGraph and similar MCP servers: Graph-based relational memory works conceptually. Missing: OKF compatibility, Onyx enterprise connectors, WORM trail, team sharing, hot/cold tiering, Flywheel export.
Claude Projects: Persistent context within Claude’s platform. Missing: portability to other tools, independent auditability, data ownership. The memories belong to Anthropic’s platform.
Naive RAG over documentation: A retrieval system for static documentation. Missing: structured knowledge format, cross-session capture, WORM audit, team sharing. New knowledge never enters the index.
Vector databases directly: Storage infrastructure. They’re Layer 2 of the live stack, not the stack itself. Missing: OKF catalog for token-efficient index survey, IDF+log-TF lexical path, Onyx connectors, WORM trail, provenance fields.
Getting Started (8.0)
Day 1: OKF Vault
export CLAWQL_OBSIDIAN_VAULT_PATH=~/.ClawQL/vault
clawql inference serve --port 8080
# Connect IDE: http://localhost:8080/mcp
# "Remember that we chose JWT over sessions — stateless, horizontal scaling"
Week 1: Vector Recall
export CLAWQL_EMBEDDING_MODEL=text-embedding-3-small
# or a local embedding model
export CLAWQL_MEMORY_VECTOR_RECALL=1
export CLAWQL_MEMORY_CACHE_THRESHOLD=0.92
When You Need Enterprise Search
export CLAWQL_ENABLE_ONYX=1
export CLAWQL_ONYX_URL=http://onyx:3000
export CLAWQL_ONYX_API_KEY=...
export CLAWQL_MEMORY_RECALL_HYBRID_ONYX=1 # optional default join
Team Sync
clawql sync init --provider r2 --bucket org-vault
clawql sync pull
clawql sync push
Do not set CLAWQL_ENABLE_PAGEINDEX or CLAWQL_ENABLE_CODEGRAPH — those flags and tools are deleted in 8.0.
The Moat
The memory stack compounds. The longer it runs, the more the vault knows. The richer the vault, the better each session. The better each session, the more high-quality data enters the Flywheel. The Flywheel produces a fine-tuned model that’s better at recall for this organization’s specific domain.
A competitor building an identical stack starting today begins from zero. Your stack has months or years of organizational knowledge, your domain’s patterns, your team’s accumulated decisions. None of that transfers.
Hybrid layers earn their place only when graded task completion moves — PageIndex and CodeGraph did not clear that bar in 8.0, so they are out of the default product surface until new evidence says otherwise.
The WORM audit trail adds a compliance dimension that no other memory system provides: not just “we remember” but provable records of what was remembered, when, by whom, and against what quality standard. For regulated industries, that proof is the difference between production deployment and indefinite evaluation.
OKF vault serialization and memory_ingest / memory_recall behavior: docs/memory/okf.md. Migration: migrate-to-8.0. Purge inventory: 8.0.0-purge-inventory-spec. Git backend: Git-native agent memory. Related essay: Memory Finds. Ontology Decides.. Enterprise Ontology: docs.clawql.com/architecture/enterprise-ontology.
