> For the complete documentation index, see [llms.txt](https://docs.codna.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.codna.ai/concepts/memory.md). Agents can also search and read this documentation through its [MCP server](https://docs.codna.ai/~gitbook/mcp).

# Code Memory

Codna's on-device code memory. A local semantic index of your repository, powered by the bundled Telys kernel. Offline and zero-configuration after a one-time free \`codna login\`.

Codna keeps a local semantic index of your repository so it, and any AI client connected through [MCP](https://docs.codna.ai/guides/mcp.md), can recall the most relevant symbols for a query without re-reading the codebase. It is powered by Telys, Codna's memory kernel, bundled in the wheel.

{% hint style="success" %}
Memory runs fully offline with zero configuration after a one-time free `codna login` — device authorization (free community license), which also installs the signed on-device memory runtime. The Telys license ships in the wheel, so there is no license file to manage.
{% endhint %}

## The store

Codna builds a per-repository index in `.codna-memory/` at the repo root:

| File                  | Purpose                                                           |
| --------------------- | ----------------------------------------------------------------- |
| `codna_memory.json`   | Index-run record: commit SHA, branch, timestamp, vector-space id. |
| `content_hashes.json` | Per-symbol content hashes for incremental re-indexing.            |
| `repo_symbols/`       | The Telys collection (the vector index).                          |

The index persists across runs and refreshes when `HEAD` moves, re-embedding only changed symbols. Add `.codna-memory/` to `.gitignore`.

{% hint style="info" %}
As an [MCP server](https://docs.codna.ai/guides/mcp.md), Codna stores recall indexes outside your checkout, under `~/.codna/telys-memory/mcp/` (override with `CODNA_TELYS_MEMORY_ROOT`).
{% endhint %}

### Repository identity

Per-repository recall state (`episodes/`, `lexcache/`) is filed under an identity derived from the **canonical absolute path** — for example `codna-ide-936efa2fccd5`. The readable prefix is the folder name; the suffix is a hash of the path.

The suffix is what keeps two different checkouts apart. A folder name alone is not an identity: `~/work/notes` and `~/oss/notes` are different projects, and filing both under `notes` let one project's stored history be recalled as the other's. Episodes also record the identity they were written for, and a record naming a different repository is refused rather than surfaced.

{% hint style="warning" %}
Upgrading re-keys existing indexes, so the first recall after an upgrade rebuilds from the working tree (a one-time cost per repository). Old `lexcache/` and `episodes/` directories from a previous version are left on disk untouched and are no longer read — code is re-indexed automatically, but historical episodes are not re-derivable. Delete the stale directories when you no longer want them.
{% endhint %}

## Recall

The `codna_recall` MCP tool returns the most relevant symbols for a query:

| Parameter  | Default      | Meaning                            |
| ---------- | ------------ | ---------------------------------- |
| `repo`     | `"."`        | Repository path.                   |
| `query`    | *(required)* | What you are looking for.          |
| `service`  | `""`         | Optional service/partition filter. |
| `language` | `""`         | Optional language filter.          |
| `final_k`  | `8`          | Symbols to return.                 |

It returns `symbols` (each with `id`, `score`, `symbol_type`, `path`), an `explain` breakdown, and `candidate_count`. It builds the index on first call if empty.

Ranking blends lexical and semantic signals (default `alpha 0.7`), down-weighting test symbols for non-test queries. The semantic reranker ships in the `memory` extra (`pip install "codna[memory]"`); without it, recall ranks lexically.

## Export

`codna memory export PATH` writes the index as a small read-only serve artifact, about 4x smaller than the full index, that any device can open. It indexes first when the memory is empty and refreshes when stale. See the [CLI Reference](https://docs.codna.ai/reference/cli.md).

## Tuning

| Variable                       | Default  | Effect                                                     |
| ------------------------------ | -------- | ---------------------------------------------------------- |
| `CODNA_MEMORY_RERANK`          | `blend`  | `blend` \| `wordllama` \| `lexical`/`off`.                 |
| `CODNA_MEMORY_RERANK_ALPHA`    | `0.7`    | Lexical vs. semantic weight (0–1).                         |
| `CODNA_MEMORY_RERANK_K`        | `40`     | Size of the reordered candidate pool.                      |
| `CODNA_MEMORY_TEST_DOWNWEIGHT` | `0.85`   | Test-symbol multiplier for non-test queries (`1.0` = off). |
| `CODNA_MEMORY_EMBED`           | *(auto)* | `local` forces the in-process embedder.                    |
| `CODNA_MEMORY_EMBED_MODEL`     | *(auto)* | Override the embedding model id.                           |
| `CODNA_MEMORY_EMBED_DIM`       | `1024`   | Embedding dimension.                                       |

## Next steps

* [Language support](https://docs.codna.ai/concepts/languages.md) — which languages the extractor indexes.
* [MCP Server](https://docs.codna.ai/guides/mcp.md) — expose `codna_recall` to a client.
* [Installation](https://docs.codna.ai/getting-started/installation.md) — the `codna[memory]` extras.
