diff --git a/README.md b/README.md index 9113711..e451f58 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,21 @@ 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`. +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, so every host uses the same store +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 `$MEMORYDIR` (default `$XDG_DATA_HOME/memoryd`, else `~/.local/share/memoryd`): +One JSON file per memory under `$MEMORYD_HOME` (the older name `$MEMORYDIR` still works; +default `$XDG_DATA_HOME/memoryd`, else `~/.local/share/memoryd`): ```json { @@ -29,57 +34,40 @@ One JSON file per memory under `$MEMORYDIR` (default `$XDG_DATA_HOME/memoryd`, e ``` 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. +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, tags, source | -| `memory_search` | meaning-based search with scores; scope and limit optional | -| `memory_list` | what exists in a scope, newest first | -| `memory_get` | one memory in full | -| `memory_update` | correct a fact (re-embeds the new text) | -| `memory_delete` | remove what is wrong or obsolete | +| `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 — a wiki next to the memories - -A knowledge base is a named collection of pages. Same mechanics as a memory (title, text, -embedding, searchable by meaning), different purpose: memories are what an agent picked up -along the way, a knowledge base is what a human wrote down to be read again. - -``` -$MEMORYDIR/kb//kb.json {"name","slug","description","created"} -$MEMORYDIR/kb//e00001.json {"id","title","text","tags","source", - "created","updated","model","embedding", - "history":[{"text","updated"}]} -``` - -| tool | what it is for | -|---|---| -| `kb_create` | a base per subject area (`olivia-technik`, `fleet-junction`); `"Olivia Technik"` becomes the slug `olivia-technik` | -| `kb_list` | which bases exist, how many pages, what they are for | -| `kb_write` | a page; **the same title updates it** instead of duplicating | -| `kb_read` | one page in full, optionally with its earlier versions | -| `kb_search` | by meaning; without `kb` it searches all bases and ranks globally | -| `kb_entries` | what a base already covers | -| `kb_delete` | one page | -| `kb_drop` | a whole base — needs `confirm="yes"`, otherwise it only says what would be lost | - -Two decisions that matter: - -- **Same title = update, with history.** The previous text moves into `history` (five - versions), and the answer says `updated … earlier version kept in history`. A wiki that - silently overwrites is not a wiki. -- **Search ranks globally** across bases unless one is named — the best page wins, not the - best page per base. +Knowledge bases (`kb_*`) used to live here; they moved to their own service, wikid. ## The embedder -OpenAI-compatible `/v1/embeddings`, `EMBED_URL` (default -`http://127.0.0.1:8091/v1/embeddings`), `EMBED_MODEL` (default `nomic-embed-text`, 768 -dimensions). +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 @@ -93,16 +81,21 @@ Secrets, keys, passwords, long transcripts. The text is the conclusion, not the material — one paragraph that still makes sense to an agent who was not there. A store that keeps everything makes every search worse. -## Build and test +## Build, test, install ```sh -make # C99 + POSIX, no dependency beyond libc, libm, and curl at runtime -make test # 16 checks against the running service (HTTP + stdio), stub embedder -sudo make install +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 ``` -The suite starts its own embedder stub with deterministic vectors, so it does not depend -on a model being loaded on this machine. +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) @@ -111,23 +104,20 @@ the memory files itself — every list, search, read, add, update and delete is `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=…` | -| `/search?q=…` | semantic search, optional `&scope=…` | +| `/` | 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/` | one memory with created/source | | `/m//edit` | edit text, tags, scope | | `/m//delete` | POST only | -```sh -make # memoryd and memoryd-http -sudo make install # /usr/local/bin/memoryd, /usr/local/lib/cgi-bin/memoryd-http -``` - -With busybox httpd (the four fleet CGIs share the navigation when installed side by -side): +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 @@ -138,3 +128,4 @@ MEMORYD_URL=http://127.0.0.1:8795/mcp \ `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.