Development - Retinue

Table of Contents

<- Back to index

1. Architecture

Retinue uses:

model2vec
Static embedding model (minishlab/potion-multilingual-128M, ~540 MB download on first use, then offline; the repo's unused ~512 MB ONNX export is skipped). Understands meaning across languages.
sqlite-vec
SQLite extension for vector similarity search. No server, no daemon, no port.
Unified store
All memories share one table. Each memory has a content string, a timestamp, and an auto-generated embedding.

1.1. Database layout

Retinue stores all data in a single SQLite virtual table under the active Hermes home:

$HERMES_HOME/retinue_memory.db

"memories" virtual table:

Column Type Meaning
rowid INTEGER Auto-increment primary key. Stable ID used for deletion.
embedding float[MODEL_DIM] The model2vec embedding vector for content.
content TEXT The full text of the memory/fact.
created TEXT ISO 8601 UTC timestamp when the row was inserted.

MODEL_DIM depends on the model (hardcoded to minishlab/potion-multilingual-128M). The table is created with sqlite-vec and supports KNN vector search by L2 distance (the vec0 default).

Why a virtual table? In SQLite, a virtual table is created with CREATE VIRTUAL TABLE ... USING vec0(...). The vec0 module from sqlite-vec provides the storage and indexing logic for the embedding column, which enables the embedding MATCH ? vector similarity query. The table is still persisted in the same SQLite .db file; “virtual” only means SQLite delegates the table engine to the sqlite-vec extension.

2. Project structure

Retinue/
├── Documentation/
│   ├── index.org             # Public user documentation
│   └── Development/index.org # This file
├── Install Retinue           # Deploy into the active Hermes plugin directory
├── plugin.yaml               # Hermes plugin metadata
├── __init__.py               # Plugin entry point: register(ctx)
├── src/                      # Plugin source package
│   └── retinue/
│       ├── __init__.py       # Package init
│       ├── memory.py         # Memory engine: embeddings + sqlite-vec
│       ├── provider.py       # MemoryProvider subclass
│       ├── cli.py            # Debug CLI behind "Show Retinue memory contents"
│       ├── import_holographic.py  # Holographic memory_store.db importer
│       └── system_prompt_block.txt # Injected into the Hermes system prompt
├── test/
│   └── test_standalone.py    # End-to-end MemoryStore + provider tests
├── Tools/                    # Development helpers (desktop scripts)
│   ├── lib/common.sh         # Shared bash helpers: RETINUE_PY resolution
│   ├── Run tests            # Standalone smoke test runner
│   ├── Show Retinue memory contents  # Debug CLI: dump/search all memories
│   ├── Import Holographic memories   # Migrate facts from Holographic memory_store.db
│   ├── Open with IntelliJ IDEA
│   └── Update web site      # Export Documentation/*.org to HTML + publish
└── $HERMES_HOME/retinue_memory.db    # Created at runtime: SQLite + sqlite-vec

3. What the installer does

Install Retinue is the deployment bridge between the Retinue workspace and the active Hermes home. It is intended for iterative development: edit the source tree, run the script, and test inside Hermes immediately.

The script is idempotent, so you can run it after every code change. It preserves runtime artifacts (the database, virtual environments, and caches) while replacing the plugin source code.

What it does, in order:

  1. Detects the active Hermes home from the HERMES_HOME environment variable, or falls back to $HOME/.hermes.
  2. Creates $HERMES_HOME/plugins/retinue/ and its .hf-cache/ subdirectory if they do not exist.
  3. Removes every previously deployed item in the plugin directory except the PRESERVE list (.venv, .hf-cache), so stale code cannot linger.
  4. Copies the whitelist (plugin.yaml __init__.py src) from the workspace into the plugin directory with cp.
  5. Resolves the Python interpreter that Hermes actually runs under (via the PYTHON environment variable, common venv layouts, or the hermes launcher shebang) and installs any missing sqlite-vec / model2vec dependencies into it, trying in order: pip, ensurepip-bootstrapped pip, then uv pip install --python (uv is probed on PATH and at $HERMES_HOME/bin/uv — Hermes bundles it there). The chain exists because the Hermes runtime venv is created by uv venv and ships without pip.
  6. Pre-downloads the embedding model into .hf-cache/ by calling retinue.memory.get_model() with the Hermes Python — the same code path the plugin uses at runtime. The snapshot download skips the repo's unused ~512 MB ONNX export (ignore_patterns["onnx/*"]=) and loads from the returned local path, so the cache is ~540 MB and the first Hermes session does not stall. Failure here is non-fatal: a warning is printed and the model simply downloads on first use instead.
  7. Sets memory.provider: retinue with hermes config set if the CLI is available.
  8. Enables the memory toolset for the CLI platform with hermes tools enable --platform cli memory. Clean "Blank Slate" Hermes installs list memory in agent.disabled_toolsets and exclude it from platform_toolsets.cli, which makes Hermes withhold the retinue_memory_* tools and the system-prompt block from the model even with the provider selected; this step lifts both gates. Other platforms need their own --platform <name> run.
  9. Runs a lightweight import check to confirm the plugin loads.

Every fallible step captures its combined output into a temp directory (cleaned by an EXIT trap) and prints an excerpt on failure — stderr is never discarded silently.

To target a specific Hermes profile or home directory:

HERMES_HOME="$HOME/.hermes/profiles/coder" bash "Install Retinue"

4. Tools exposed to Hermes

When Retinue is the active memory provider, Hermes can call these tools natively. The exact names and schemas are defined in get_tool_schemas() and dispatched through handle_tool_call().

4.1. retinue_memory_add

Store a memory with content.

{
  "name": "retinue_memory_add",
  "description": "Store a semantic memory in Retinue.",
  "parameters": {
    "type": "object",
    "properties": {
      "content": {"type": "string", "description": "The memory content"}
    },
    "required": ["content"]
  }
}

Read more: How memory save works.

4.3. retinue_memory_delete

Delete a memory by ID.

4.4. retinue_memory_stats

Returns facts about the store itself — not the memories. Takes no parameters; the LLM calls it with an empty object:

retinue_memory_stats({})

and gets back a single object: total (number of stored memories), latest_id (the rowid assigned to the most recent memory — the next memory gets latest_id + 1, and ids up to it are valid delete candidates even after deletions), db_path (which database file is in use), model (embedding model name), and dim (embedding vector dimension):

{"success": true, "result": {"total": 2418, "latest_id": 2675,
  "db_path": "/home/john/.hermes/retinue_memory.db",
  "model": "minishlab/potion-multilingual-128M", "dim": 256}}

5. How memory save works

  1. LLM decides something is worth remembering it issues the call:

    retinue_memory_add({"content": "ProjectX is hosted on our primary server"})
    

    Alternative trigger: LLM instead calls Hermes' built-in memory tool. Hermes then calls Retinue's on_memory_write hook, which feeds the same text into the same chain at step 2. Both triggers produce one identical memory in the same single store — one memory system, two ways to trigger a save.

  2. Hermes routes it to handle_tool_call("retinue_memory_add", args).
  3. Text is embedded with model2vec into a float32 vector packed as bytes. On the first call in a process, memory.py resolves the model snapshot with snapshot_download(MODEL, ignore_patterns["onnx/*"])= (skipping the repo's unused ~512 MB ONNX export) and loads StaticModel from the returned local path — loading from a local path is what prevents re-fetching the skipped files on every load;
  4. Resulting vector with original text is written into database

    INSERT INTO memories (embedding, content, created)
    
  5. JSON string is then returned back to the LLM:

    {"success": true, "result": {"id": 1, "content": "ProjectX is hosted on our primary server"}}
    

6. How memory retrieval works

Retrieval has two paths that read the same memories table: automatic recall through the prefetch hook (below) and the explicit retinue_memory_search tool. The tool path returns what the LLM asks for; the automatic path returns only memories this session has not seen yet.

The step-by-step mechanics of the explicit path:

  1. The LLM is notified the tool exists. At session start Hermes calls get_tool_schemas() and places all four retinue_memory_* schemas into the LLM's tool list next to the built-in tools. The retinue_memory_search schema declares three parameters: query (required string), limit (optional integer, default 30), and include_seen (optional boolean, default false — when true, memories already returned in this session are included again). Separately, the text of src/retinue/system_prompt_block.txt is injected into the system prompt, instructing the LLM to run retinue_memory_search before acting on a task.
  2. The LLM invokes it with a natural-language query. Example call: retinue_memory_search({"query": "coworker", "limit": 2}).
  3. Retinue embeds the query and runs a vector query. The query text is embedded with the same model2vec model used at write time, then MemoryStore.search() executes a sqlite-vec KNN query: WHERE embedding MATCH ? AND k = <limit> against the memories virtual table.
  4. Result count is limited by count only. The k parameter is a hard top-N cap: sqlite-vec returns at most limit nearest rows, with no similarity threshold. Even a nonsense query ("zzzzqqq nonexistent") returns exactly limit rows. Filtering weak matches is left to the LLM reading the scores.
  5. Results are sorted best-first. sqlite-vec orders KNN results by ascending distance, so the most similar memory is always results[0]. Ordering is deterministic; ties can occur (two different memories scored 0.458 on the same query).
  6. The tool returns a JSON string — the result of json.dumps({"success": True, "result": [...]}). Each element has four fields: id (the rowid, for retinue_memory_delete), content (full stored text), created (ISO 8601 UTC timestamp), and similarity. The similarity is computed in provider.py from the raw sqlite-vec distance as 1 / (1 + distance) — higher is better, 1.0 means identical vectors. The stored embeddings are unit-length (model2vec normalizes them), so the raw distance is plain L2 and cosine similarity is 1 - distance^2 / 2; 1 / (1 + distance) compresses that into roughly 0.40–0.50 for everything in a real store. Treat it as a relative ranking signal only.

    {"success": true, "result": [
      {"id": 2, "content": "Coworker John reads Spanish",
       "created": "2026-07-17T20:33:43.081952+00:00", "similarity": 0.4626},
      {"id": 1, "content": "ProjectX is hosted on our serverY",
       "created": "2026-07-17T20:33:40.987271+00:00", "similarity": 0.4357}
    ]}
    

    (Captured verbatim from handle_tool_call("retinue_memory_search", {"query": "coworker", "limit": 2}) against a store holding exactly those two memories; similarity values shortened for print.)

  1. The LLM reads the JSON and decides. Weak-looking results (all scores near the noise floor) mean the store has nothing relevant; the LLM proceeds without memory context.

6.1. Automatic recall (prefetch)

  1. Before every non-trivial turn Hermes calls the provider with the current user message and the session id:

    prefetch("Why does it filter already returned ids?", session_id="20261023_101500_ab12cd")
    

    Nothing else from the conversation is passed in.

  2. Retinue builds the embedding query from the current message plus a rolling topic recorded by sync_turn() on previous turns: the two previous user messages (200 characters each) and the first 200 characters of the last assistant reply. The current message is capped at 600 characters. This is what gives a short follow-up ("and the second one?") a subject to search for.
  3. MemoryStore.search() runs the same vec0 KNN query as the tool with a fixed budget of 30 rows (PREFETCH_LIMIT in provider.py). There is no similarity threshold and no character cap.
  4. Ids already returned during this session are dropped from those 30 rows. The surviving ids are recorded as returned for the session.
  5. If nothing survives, prefetch() returns an empty string and Hermes injects nothing on that turn. Otherwise the block is appended to the user message and persisted with it:

    Retinue recall (2 fresh):
    [123] Retinue project: deployed with "Install Retinue" into ~/.hermes/plugins/retinue.
    [456] Retinue stores everything in retinue_memory.db (single SQLite file).
    
  6. The returned-set is per session and lives in RAM (_seen in provider.py). It is cleared by on_session_switch() (/new, /resume, /branch, /reset) and by on_pre_compress(), because compression may summarize the injected block away and the memory would otherwise stay invisible for the rest of the session.
  7. The set is not persisted. After a restart the first turn of the next session injects its best matches again.
  8. The explicit retinue_memory_search tool applies the same filter; include_seen: true returns already-recalled memories anyway.

The net effect: a memory enters the conversation at most once per session. With a stable topic the injected block shrinks turn by turn and eventually returns nothing; when the subject changes, the new top 30 contains fresh ids and recall resumes.

7. Development and testing workflow

Retinue is developed in its own source tree and deployed into the active Hermes home with Install Retinue. This makes iteration fast and safe: the runtime data/ directory lives in Hermes, while the source code lives in the workspace.

7.1. Iterative development loop

  1. Edit source files in the Retinue workspace.
  2. Run the installer to copy the latest code into Hermes:

    cd /path/to/retinue
    bash "Install Retinue"
    
  3. Verify the plugin loads:

    hermes memory status
    
  4. Test through a Hermes session:

    hermes chat -q "Remember that my default shell is fish."
    hermes chat -q "What shell do I use?"
    
  5. Repeat from step 1.

7.2. Standalone testing

You can also test Retinue without installing it into Hermes. The project includes a standalone test runner:

cd /path/to/retinue
"Tools/Run tests"

This uses a project-local .venv and caches downloaded models in .hf-cache, both of which are excluded from deployment by the installer.

7.3. Inspecting the memory store

For debugging, the Show Retinue memory contents script dumps every stored memory to the terminal without going through Hermes:

cd /path/to/retinue
"Tools/Show Retinue memory contents"                                  # dump all memories
"Tools/Show Retinue memory contents" --search "deployment"            # semantic search
"Tools/Show Retinue memory contents" --home ~/.hermes/profiles/coder  # other Hermes home
"Tools/Show Retinue memory contents" --json                           # machine-readable output

It resolves the database from --db, --home, $HERMES_HOME, or by auto-detecting a single profile database under ~/.hermes/profiles/. Plain listing never loads the embedding model, so it works offline and starts instantly; only --search loads it (~540 MB into .hf-cache on first use). The implementation lives in src/retinue/cli.py and is not deployed by the installer — it is a development-only tool.

Created: 2026-10-23 pe 17:02

Validate