Ari’s Space*   est. 2026
Skip to content
ari*s space[ a. ]
← Librarymemory / 2026-05-23

I gave my LLM a Cortex

A brain-inspired memory layer that gives any LLM persistent, self-organising, auto-recalled context.

7 parts / Hover to explore. Click to read.

A brain-inspired memory layer that gives any LLM persistent, self-organising, auto-recalled context.

Canonical source files
          | index
          v
   rebuildable Cortex
          | retrieve
          v
      model context
          | trace claim
          v
   retained source files
This design puts authority in retained files and connections in a derived index. A retrieval score selects material; it does not establish that the material answers the question.
Cortex: a memory layer between your files and any modelThree stacked System 7 windows. Top window YOUR FILES holds notes, transcripts and outputs and is labelled canonical. A downward arrow labelled index leads to the middle window THE CORTEX, a derived index of brain regions and strengthening edges. A second downward arrow labelled retrieve and inject at session start leads to the bottom window ANY MODEL, listing Claude, Codex, Gemini and local.YOUR FILESnotes · transcripts · decisions · outputsbriefs · ship reports · past workcanonical. the brain never owns this.index: chunk · embed · tagTHE CORTEXlanguagevisionepisodicidentityedges strengthen when chunks fire togetherSQLite + vectors · rebuildable · nothing destroyedretrieve + inject at session startANY MODELClaude Codex Gemini localvia injected context · adapter · MCP server

A new session can know very little about the work that came before it. Meanwhile, the notes, transcripts, decisions and finished files are sitting in the workspace, waiting to be useful again.

I kept having to explain things we'd already established. Instead of making the opening prompt longer every time, I built Cortex: a memory layer between the files and the model using them.

Files own the truth. The brain owns the connections.

Make previous work available again

The goal was continuity. A capable model is still starting cold if it can't find the decisions, references and results that matter to this job.

Most working setups already produce that material. What's missing is a way to organise it and retrieve a useful part when a session begins.

A large context window can hold what you give it now. Durable memory has another job: preserve the source across sessions and make the right material available to the next one. I wanted that layer to survive a change of model or interface.

Keep five rules visible

Files remain canonical. Notes and other source files are the authority. Cortex builds a derived index over them. Rebuilding that index should not require reconstructing your knowledge from memory; keeping the necessary source material is part of the contract.

Decay changes ranking, not the existence of a record. Older material can become less prominent without being destroyed. A retained item must still lead back to its source.

Use events to keep the system useful. Retrieve at session start and re-index when a source file changes. The ordinary path should work without me remembering a special command every time.

Index the thinking. Keep useful reasoning, decisions, prompts and outputs. Mechanical logs and tool noise stay out of the memory index.

Keep the model replaceable. The memory contract belongs to the system around the model. A different model should be able to receive the same retrieved material through an appropriate interface.

The system around the AI is the intelligence.

Use structure to make recall more useful

The brain analogy gives the software an organising scheme. It isn't a claim that a vector index behaves like a human brain.

Regions give material a place

Language comprehension, language production, vision, episodic events, spatial or project structure, and identity map to regions. Results can then arrive in meaningful groups instead of one undifferentiated list.

CORTEX REGION MAP
Select a region to see what memory lives there.

Connections give you another route in

Typed edges connect related material. Some relationships are known: a prompt and its answer, an image and its description, or every item connected to every other item in the same project.

Other edges form through co-activation. If two memories keep being retrieved together, the system creates a permanent edge between them. Its weight can decay when the connection goes unused, but the edge remains. The retained records and their source paths remain available even as their retrieval prominence changes.

Consolidation makes a smaller working layer

Raw capture is noisy and expensive to load repeatedly. The consolidation path moves from raw sessions to session digests, then daily summaries, longer-lived signal and promoted facts.

The figure used in this design is roughly 37-fold compression of a year's raw thinking into a smaller queryable layer. It isn't a guarantee for every corpus. The essential requirement is keeping lineage back to the original material, so compression doesn't become the only surviving account of what happened.

CONSOLIDATION COMPRESSOR
22.0M
TOKENS / YEAR
RawSessionDailyWeeklyFact
Raw

Illustrative stages and token counts, not measured storage or a guaranteed runtime pipeline.

Every session captured as-is. Maximum fidelity, maximum noise.

Modes change the ranking stance

Creative work, deep reasoning and fast recall don't need identical retrieval weights. A mode changes how the same memory is searched and ranked. It doesn't create a different source of truth.

Rank useful context rather than pretending to know the answer

At session start, the query comes from the situation: the current project, recently touched material and the task. The user doesn't have to write a separate search query on the ordinary boot path.

The system retrieves candidates by meaning, then combines several signals:

  • Region and layer: identity and core rules are exempt from decay; episodic material is sensitive to recency.
  • Importance: less useful older material fades in rank while durable facts remain easier to reach.
  • Co-activation: items previously retrieved together receive a connection-based boost.
  • Graph walk: follow edges to supporting material, such as the decision reached from a note or the caption attached to an image.

The selected mode reweights these signals. A token budget caps the material inserted into the session, and results remain grouped by region.

How Cortex ranks and pulls contextA vertical System 7 pipeline. WHERE YOU ARE (your current project, recent files and task) becomes the query and flows into CANDIDATES, ranked by meaning. Those flow into RE-RANK, which stacks four signals: region and layer, importance decay, co-activation, and graph walk. A MODE callout on the left reweights the RE-RANK stage. The result passes through a TOKEN BUDGET cap and arrives as INJECTED CONTEXT grouped by region.WHERE YOU AREproject · recent files · the task at handthis is the query. you never type it.CANDIDATESeverything, ranked by meaning (vectors)RE-RANKregion + layer · core stays, recent ranksimportance · decays over timeco-activation · fire together = boostgraph walk · follow the edges outwardMODEreweights thewhole stackTOKEN BUDGETcap it. never flood the window.INJECTED CONTEXTdropped into turn onegrouped the way the brain organises it

Cortex supplies the best-ranked context it can find. The model still has to use it, and the result still needs checking. A retrieval score is a selection signal, not proof that the selected material answers the question.

Assemble a small implementation

The components in this pattern can be swapped. Local defaults can run offline without a paid API; the actual adapter needs to fit the tool you're connecting.

your files/            # canonical: notes, transcripts, decisions, outputs
index.db             # derived: SQLite + a vector extension

hooks/
session-start        # run retrieval, inject top-k context into turn 1
on-change            # re-index a file the moment it is edited

jobs/
nightly              # consolidate raw -> digests -> facts (the "sleep")

adapters/
injected-context     # default: drop context into the prompt preamble
mcp-server           # for tools that speak Model Context Protocol

Build it in seven moves:

  1. Keep the notes, transcripts and other source files authoritative.
  2. Create a derived index, for example SQLite with a vector extension. Chunk the files, embed the chunks, and tag their region and memory layer.
  3. Add known edges: prompt to answer, image to caption, and every item to every other item in the same project.
  4. Create permanent edges when chunks are repeatedly retrieved together. Let unused edge weights fade while retaining the edges.
  5. Add a session-start hook that retrieves a bounded set of results and inserts them into the first turn, grouped by region.
  6. Re-index on file changes and run consolidation as a scheduled job, such as the nightly pass shown above.
  7. Expose the result through injected context, a thin adapter or an MCP server so the memory is not tied to one model provider.

Check the rebuild path as well as the retrieval path. If the index is meant to be derived, you need the source material and any durable inputs required to reconstruct it. The phrase “rebuildable” is a property to establish, not a label that does the work for you.

What changes at the start of a session

The intended difference is a session that begins with relevant prior work already available: the core rules, a recent decision, the useful connection you might not have remembered to search for.

Repeated use can improve the associations the system ranks. Consolidation gives the next session a smaller working layer while retaining a route to the raw source. The model can change without requiring the whole knowledge base to be rewritten for it.

SESSION START
BLINDBRAIN
No memory of you. Starting from zero.

The illustration shows that contrast. It doesn't mean a memory layer guarantees perfect recall or that every future model connects without an adapter.

Start with one project and a few sources you understand. Open a fresh session and inspect what the hook supplies. Can you identify why each item is there? Can you reach the original? Does it actually help with the job?

That's the practical test. The model may be replaceable. The useful memory is the material and the connections you can still carry into the next session.

[ comments ]

guests welcome. members show first in the list

no comments yet. start the thread_

1 / 9