Guides
Memory
On-device encrypted vector memory in QTSQ, local embeddings, recall, and opt-in remote adapters.
On this page8 sections
sofuu.memory is the on-device vector memory surface, backed by QTSQ containers (.qtsq). A container stores records with vectors, text, timestamps, and roles, and it is encrypted by default.
Open a container
const brain = sofuu.memory.open("./brain.qtsq", 768);
open(path, vecDim, options?) opens an encrypted QTSQ container. An object form ({ path, dim, space }) is also accepted. The third positional argument can carry open modes such as { readonly: true }, { verifyFull: true }, or { plaintext: true }.
| Method | Behavior |
|---|---|
open(path, vecDim, options?) | Opens a container and returns a handle. |
remember(vectorOrText, text?, role?, turn?) | Stores a record with a vector, timestamp, and text. A plain string is embedded automatically. |
recall(queryVectorOrText, k) | Returns the top k nearest records, including distance (0 is an exact match) and similarity. |
count() / stats() | Total records, active segments, and capacity metrics. |
flush() | Persists pending writes to the container. |
forget(index) | Removes a record by its index. |
list(options?) | Returns records, with optional tier, role, entity, text, min_strength, offset, and limit filters. |
export() | Produces an export of the container. Exported copies are not encrypted. |
close() | Releases the handle. |
Open containers are also addressable by a small handle object, which is what the C funnel uses. Close a container with close() when you are done with it.
Remember and recall
const text = "Sofuu embeds a JavaScript runtime in one native binary.";
brain.remember(sofuu.ai.embedLocal(text), text, "user");
const hits = brain.recall(sofuu.ai.embedLocal("single binary"), 3);
for (const hit of hits) {
console.log(hit.text, hit.distance, hit.similarity);
}
brain.flush();
brain.close();
Keep one embedding space per container. A write from a different space is refused with a typed error rather than silently corrupting recall.
Embedding spaces
| Space | Dimensions | Notes |
|---|---|---|
hash-768 | 768 | Default for sofuu.ai.embedLocal() and for the brain. A character-trigram hash with zero parameters. |
sem1-64 | 64 | Opt-in learned space. |
sem2-64 | 64 | Opt-in learned space, and the default for sofuu.ai.embed(). |
img1-64 | 64 | Image projector, compatible with sem2-64 text geometry. |
The spaces are tagged by model and dimension. img1-64 is the one documented exception: it is jointly trained with sem2-64 text geometry, so text queries can retrieve images. Every other index uses one space.
Encryption and keys
QTSQ containers use AES-256-GCM with a machine-local key. The key resolution order is:
SOFUU_BRAIN_KEY, supplied as 64 hex characters (32 bytes).~/.sofuu/brain.key, 32 random bytes written as hex with mode0600and created on first use.- If no usable key exists, a process-local random key is used and the reason is printed. Brains written in that process will not reopen.
The key is read once per process and cached. Losing the key file means the brain file is unreadable; there is no recovery path in the runtime. Copy the key if the brain matters. A brain copied to another machine will refuse to open unless the key moves with it.
This is at-rest protection, not a sandbox. Anything running as your user can read the key and decrypt the brain, and a compromised machine has the same access.
Plaintext mode is explicit: sofuu.memory.open("./notes.qtsq", 768, { plaintext: true }). It is useful for inspection and tests, not for data you would not put in a plain file. Logs and external providers have their own data handling, separate from the brain.
Working memory
A session working set holds records that are not yet durable. It uses the same vector shape as the main store.
brain.rememberWorking(vec, "candidate fact", "user");
brain.promoteWorking([id]); // move selected records into the durable store
brain.clearWorking();
| Method | Behavior |
|---|---|
rememberWorking(vec, text, role?) | Adds a record to the session working set. |
promoteWorking(ids) | Promotes the selected records into the durable store. |
clearWorking() | Drops the working set without promoting it. |
These methods are available through JavaScript and the C funnel (memory.rememberWorking, memory.promoteWorking, memory.clearWorking).
Remote adapters
Remote vector backends are opt-in. They are not the default path, and they require network access plus a reachable service.
const remote = sofuu.memory.open("https://qdrant.example.com", {
adapter: "qdrant", // qdrant | pinecone | pgvector | custom
dimensions: 768,
collection: "notes",
apiKeyEnv: "QDRANT_API_KEY",
});
await remote.remember("hello", { tags: ["note"] });
const hits = await remote.recall({ query: "hello", limit: 5 });
The adapter keeps the same remember / recall contract, but its calls are asynchronous. apiKeyEnv names an environment variable rather than passing the key in the call. A custom adapter object with remember and recall methods is also accepted. Keep a remote index on one space, as you would a local container.
Related storage
sofuu.storage.open(path) opens a structured store with .messages, .traces, and a key-value facade at .kv. Use it for message records and run traces; use sofuu.memory for vector recall. The two are separate files with separate lifecycles.