คลังความจํา
mem
A memory service for agents that is really just a wiki: markdown pages on disk are the source of truth, a derived SQLite index makes them searchable, and every agent can write.
go + sqlite markdown files no embeddings loopback by default
ปัญหาที่แก้ · the problem
An agent that starts empty re-learns the same facts
Every new session begins by rediscovering the host, the ports, the command that almost worked. Notes and transcripts both fail the same way: the fact is in there somewhere, and the agent cannot find it in time to use it.
mem holds those facts where an agent can write them in one call and read them back instantly. The first attempt here, minimem, proved the shape of the problem: search was easy, keeping a store worth reading was not. The second attempt, mem v1, over-corrected with a review gate and a graph. This version goes back to the plain thing that works, a wiki.
the store
Markdown files, one page per topic
~/mem-wiki/*.md · derived SQLite index
-
Pages
One file per topic,
slug.md, with a small frontmatter header: title, tags, created, updated, updated_by. The rest of the file is free-form markdown. -
Facts
New knowledge is appended under a
## Factsheading as a dated bullet: the fact body, then the writer and date. A fact whose body is already on the page updates it instead of piling up a duplicate. -
Index
SQLite FTS5, derived from the files and rebuildable at any time with
mem reindex. The server also rescans the directory every 5 minutes, so a hand edit shows up on its own. -
Trash
Deleting a page moves the file to
trash/. Nothing is erased; the organizer rotates the trash only after its retention window.
Markdown is the interface, not an export. Any agent with filesystem access can read or append a page directly, with the same result as the HTTP API, and the file on disk is always the thing that is true.
writing
Every agent writes, the writer is provenance
v1 routed agent writes through a steward and an inbox, and the inbox was the whole problem: nothing an agent wrote was real until a human accepted it. v2 has no gate. A valid token writes immediately; the identity it carries is recorded next to the fact, not enforced on top of it.
| Call | Result |
|---|---|
POST /v1/memory/nodes |
append a fact line to the page for its topic, active at once |
POST /v1/memory/extract |
the same append, for a remembered blob |
POST /v1/wiki/pages |
create or upsert a page |
PUT /v1/wiki/pages/<slug> |
replace a page body |
DELETE /v1/wiki/pages/<slug> |
move the page to the trash |
The compat endpoints from v1 still answer, so older clients keep working:
inbox is always empty and
promote / reject answer
noop, because there is no queue left to move through.
search
Substring search that survives Thai
The index tokenizer is trigram, not a word tokenizer. That is the whole
trick: ระบบความจํา has no spaces, so a word tokenizer would file
it as one long unknown term, while a trigram index matches it by substring, the same way
it matches postmarketOS. Queries of three characters or more
run as an FTS match; shorter queries and zero-hit results fall back to a plain
LIKE scan. No tokenizer to tune, no embedding provider, and
nothing to fall back from.
# find the page, then read it back
mem search "salt backup"
mem show "mem service"
http api
The whole surface
base url http://127.0.0.1:3200
| Endpoint | Method | Purpose |
|---|---|---|
| /health | GET | liveness, no auth |
| /v1/wiki/pages | GET, POST | list pages, or create and upsert one |
| /v1/wiki/pages/<slug> | GET, PUT, DELETE | read, replace or trash a page |
| /v1/wiki/reindex | POST | rebuild the index from the files |
| /v1/memory/nodes | GET, POST | list pages as nodes, or append a fact |
| /v1/memory/search | GET, POST | trigram search with a LIKE fallback |
| /v1/memory/context | GET, POST | search results joined into one block for a prompt |
| /v1/memory/extract | POST | append a remembered blob as a fact |
| /v1/memory/stats | GET | page and fact counts |
| /v1/memory/brief | GET | a short digest of recent pages |
| /v1/memory/inbox | GET | always empty; kept for old clients |
| /v1/memory/backup | GET | the wiki as one gzipped tar (index excluded) |
| /v1/memory/restore | POST | replace the pages from that tar, then rescan |
| / | GET | the web UI (basic auth) |
surfaces
A terminal, a browser, and an MCP shim
-
Terminal UI
Running
memon a terminal opens a small browser: a page list, live full-text search, a scrollable reader and page creation. Built with Bubble Tea, on the same data as everything else. -
CLI
mem list,search,showandadd. Output is styled with Lip Gloss and Glamour on a terminal and stays plain text when piped, so a script reads exactly what it always did. -
Web UI
A single page at
:3200, in the same paper-pop skin as this site: search, read, edit, create, trash. Mobile first, with the page list in a drawer on a phone. - MCP shim A small stdio server that fronts the REST API, so an agent framework that speaks MCP gets search, add, context and stats as tools with no code of its own.
# the whole store in one file, then back again
mem backup --file /var/backups/mem-$(date +%F).tar.gz
mem backup --file - | ssh other-host mem restore --file -
running it
One binary, loopback by default
- No database to run. SQLite is embedded (modernc.org/sqlite, pure Go), so there is no PostgreSQL to provision, no extension to install and no service dependency. One static binary is the whole thing.
-
It refuses a public bind. A non-loopback listen address is rejected
unless
MEM_API_TOKENis set. The lab exposes the port on the LAN address only, proxied to loopback bysystemd-socket-proxyd. -
Config lives in one file.
/etc/mem/mem.envat mode 0600 holdsMEM_WIKI_DIR,MEM_LISTEN_ADDR,MEM_API_TOKEN,MEM_UI_USERandMEM_UI_PASSWORD. -
The unit is hardened. The systemd service runs as an unprivileged user
with
UMask=0077,ProtectSystem=fullandPrivateTmp. - A nightly organizer tidies. On a timer it drops exact duplicate fact lines, reports cross-page duplicates for a human to merge, and rotates the trash after its retention window. It never rewrites meaning.
- Backups are the files. The wiki directory is a tar archive, and the index is left out on purpose: it is derived and rebuilds on restore. Here it is sealed with everything else on an off-host schedule.
ข้อจํากัด · known limits
What it will not do
- No embeddings. Search is a trigram substring match, on purpose. If the query is about meaning rather than text, this is the wrong store.
- One wiki, no tenancy. All agents share one namespace. There is no per-agent memory separation, which is the point at this scale and the limit as it grows.
- One token, full access. Any valid token reads and writes; there are no per-identity permissions. Provenance is recorded, not enforced.
- Trigram search needs three characters. One and two character queries drop to a plain substring scan, which for non-ASCII is case-sensitive.
- Dedupe is substring-based. A short fact that is a substring of another line on the same page is suppressed. Consolidating meaning is still a writer's job.
- The wiki is a secret. Memories accumulate hostnames, ports and configuration. Treat a copy the way you treat a key.