The CGI web UI, the library path (MEMORYD_HOME, MEMORYDIR still accepted), one repository on the first write with a commit per add/update/delete, and every MCP tool with its arguments and defaults (memory_list 20, general scope). Code: git.kropa.tech.
132 lines
5.4 KiB
Markdown
132 lines
5.4 KiB
Markdown
# memoryd
|
|
|
|
What an agent remembered, searchable by meaning.
|
|
|
|
One fact per file, one embedding per fact, and a search that answers "how was it with the
|
|
frost protection" with the note that says "coolant down to -25 °C" — even though the word
|
|
frost never appears in it. Served over MCP, like `tasksd` and `skilld`; a CGI web UI,
|
|
`memoryd-http`, shows the same store in a browser.
|
|
|
|
Code: https://git.kropa.tech/hiddenbox/memoryd
|
|
|
|
```sh
|
|
memoryd # stdio, JSON-RPC per line
|
|
memoryd --http 8795 # Streamable HTTP on all addresses, so every host uses the same store
|
|
memoryd --http 127.0.0.1:8795 # Streamable HTTP on loopback only
|
|
```
|
|
|
|
## Storage
|
|
|
|
One JSON file per memory under `$MEMORYD_HOME` (the older name `$MEMORYDIR` still works;
|
|
default `$XDG_DATA_HOME/memoryd`, else `~/.local/share/memoryd`):
|
|
|
|
```json
|
|
{
|
|
"id": "m00001",
|
|
"scope": "van/technik",
|
|
"text": "Der Frostschutz steht auf -25 Grad, aufgefüllt wird G12+ blau.",
|
|
"tags": "kühlmittel",
|
|
"source": "konrad",
|
|
"model": "nomic-embed-text",
|
|
"created": 1794147600,
|
|
"embedding": [0.0428, 0.0418, ...]
|
|
}
|
|
```
|
|
|
|
Readable, diffable, backupable without a database. A `scope` is a free string and selects
|
|
itself plus its children, so `van` covers `van/technik` — the same rule as tasksd. A memory
|
|
stored without a scope lands in `general`.
|
|
|
|
**History through git.** If `git` is installed, the store becomes a repository on the first
|
|
write, and every `memory_add`, `memory_update` and `memory_delete` is committed with the
|
|
memory's id as message (`memory_update m00001`). A wrong memory deleted today can still be
|
|
recovered tomorrow. Without git everything works, just without history.
|
|
|
|
## Tools
|
|
|
|
| tool | what it is for |
|
|
|---|---|
|
|
| `memory_add` | store one fact: `text` (required), `scope` (default `general`), `tags`, `source` |
|
|
| `memory_search` | meaning-based search with scores: `query` (required), `scope`, `limit` (default 5, at most 50) |
|
|
| `memory_list` | what exists in a scope, newest first: `scope`, `limit` (default 20) |
|
|
| `memory_get` | one memory in full: `id` |
|
|
| `memory_update` | correct a fact: `id`, plus new `text` (re-embedded), `tags` or `scope` |
|
|
| `memory_delete` | remove what is wrong or obsolete: `id` |
|
|
| `memory_scopes` | which scopes exist, how many memories each |
|
|
|
|
Knowledge bases (`kb_*`) used to live here; they moved to their own service, wikid.
|
|
|
|
## The embedder
|
|
|
|
OpenAI-compatible `/v1/embeddings`, called through `curl`:
|
|
|
|
| variable | default |
|
|
|---|---|
|
|
| `EMBED_URL` | `http://127.0.0.1:8091/v1/embeddings` |
|
|
| `EMBED_MODEL` | `nomic-embed-text` (768 dimensions) |
|
|
| `EMBED_TIMEOUT_S` | `180` seconds per request |
|
|
|
|
The timeout is generous because long texts embedded in chunks through a proxy take tens of
|
|
seconds, and a vector that is missing once stays missing.
|
|
|
|
**It is not required to run.** If it does not answer, the memory is stored without a
|
|
vector and the tool says so (`WITHOUT embedding`); search then falls back to a
|
|
case-insensitive substring match and labels the result `substring match`. A store that
|
|
silently pretends to understand meaning is worse than one that admits it is matching
|
|
letters.
|
|
|
|
## What does not belong here
|
|
|
|
Secrets, keys, passwords, long transcripts. The text is the conclusion, not the raw
|
|
material — one paragraph that still makes sense to an agent who was not there. A store
|
|
that keeps everything makes every search worse.
|
|
|
|
## Build, test, install
|
|
|
|
```sh
|
|
make # memoryd and memoryd-http; C99 + POSIX, libc and libm
|
|
make test # tests/run.sh (17 checks, HTTP + stdio) and tests/test-http.sh (the CGI)
|
|
sudo make install # /usr/local/bin/memoryd, /usr/local/lib/cgi-bin/memoryd-http
|
|
```
|
|
|
|
At runtime memoryd needs `curl` for the embedder and, optionally, `git` for the history.
|
|
The tests need `python3` and `curl`; they start their own memoryd on a free port and an
|
|
embedder stub with deterministic vectors, so they do not depend on a model being loaded on
|
|
this machine. `PREFIX`, `CGIDIR` and `DESTDIR` move the install paths.
|
|
|
|
`packaging/memoryd.service` is a systemd unit: store in `/var/lib/memoryd`, listening on
|
|
`127.0.0.1:8795`.
|
|
|
|
## Web UI (CGI)
|
|
|
|
`memoryd-http` is a C99 CGI program: HTML 4.01, no JavaScript, no auth. It never reads
|
|
the memory files itself — every list, search, read, add, update and delete is a
|
|
`tools/call` against memoryd (`MEMORYD_URL`, default `http://127.0.0.1:8795/mcp`). The
|
|
browser and the agents therefore share one store.
|
|
|
|
Addresses are relative to the script (`/cgi-bin/memoryd-http` under busybox httpd):
|
|
|
|
| Address | Effect |
|
|
|---|---|
|
|
| `/` | memories, filter with `?scope=…&limit=…` (default 50, at most 200) |
|
|
| `/search?q=…` | semantic search, optional `&scope=…`, up to 20 hits |
|
|
| `/scopes` | scopes with counts |
|
|
| `/new` | add a memory |
|
|
| `/m/<id>` | one memory with created/source |
|
|
| `/m/<id>/edit` | edit text, tags, scope |
|
|
| `/m/<id>/delete` | POST only |
|
|
|
|
With busybox httpd (the four fleet CGIs — wikid-http, memoryd-http, skilld-http,
|
|
tasksd-http — share the navigation when installed side by side):
|
|
|
|
```sh
|
|
install -d /srv/www/cgi-bin
|
|
install -m 0755 memoryd-http /srv/www/cgi-bin/
|
|
MEMORYD_URL=http://127.0.0.1:8795/mcp \
|
|
busybox httpd -f -p 0.0.0.0:8798 -h /srv/www
|
|
```
|
|
|
|
`vendor/cgi/cgi.h` is the shared CGI helper (the same file lives in wikid, skilld and
|
|
tasksd): environment, HTML shell, Markdown, form parameters and the MCP call.
|
|
`vendor/libmcp/mcp.h` is the MCP library both programs are built on.
|