Examples
With the Walrus Memory SDK, you store a memory with remember(), wait for completion with waitForRememberJob(), and recall it with recall(). Advanced patterns cover manual registration with pre-computed vectors, fact extraction with analyze(), AI middleware with withMemWal, and structured memory for research apps.
Store and recall a memory
The shortest working Walrus Memory example using the default relayer-backed SDK.
Source: sdk/examples.mdimport { MemWal } from "@mysten-incubation/memwal";
const memwal = MemWal.create({
key: process.env.MEMWAL_PRIVATE_KEY!,
accountId: process.env.MEMWAL_ACCOUNT_ID!,
serverUrl: process.env.MEMWAL_SERVER_URL,
namespace: "demo",
});
await memwal.health();
const accepted = await memwal.remember(
"User prefers dark mode and works in TypeScript."
);
const stored = await memwal.waitForRememberJob(accepted.job_id);
const recalled = await memwal.recall({
query: "What do we know about this user?",
limit: 5,
});
console.log(stored.blob_id);
console.log(recalled.results);
What you should see:
health()succeedsremember()returns ajob_idimmediatelywaitForRememberJob()returns ablob_idrecall()returns plaintext results for the same namespace
Manual registration
Use rememberManual() when you already have an encrypted payload plus vector, and recallManual()
when you already have a query vector. On the MemWal client, recallManual() returns hits that contain only blob_id and distance, with no decrypted text, so you fetch and decrypt the blobs yourself. For all options and return values, see Manual remember and recall parameters.
Extract facts from text
Use analyze() when you want the relayer to extract facts from longer text and store them as
memories.
const analyzed = await memwal.analyze(
"I live in Hanoi, prefer dark mode, and usually work late at night."
);
console.log(analyzed.facts, analyzed.job_ids);
AI middleware
Use withMemWal when you want recall before generation and optional auto-save after generation.
See AI Integration for the full setup.
Research app pattern
Use this when you want to store structured research findings and recall them in later sessions.
- Submit a structured summary with
remember()and wait for completion when immediate recall is needed - Generate targeted queries later
- Use
recall()with aqueryandlimit, as in the basic example, to pull plaintext results for the same namespace back into context
Structured summaries usually recall better than raw transcripts because they keep the signal high.
Manual remember and recall parameters
rememberManual({ encryptedData, vector, namespace? }) accepts these options:
encryptedData: Base64-encoded Seal-encrypted bytes. The relayer uploads them to Walrus.vector: The embedding vector you already generated, asnumber[].namespace: Optional. Defaults to the config namespace ordefault.
It returns id, blob_id, owner, and namespace.
recallManual({ vector, limit?, namespace? }) accepts a pre-computed query embedding vector, an optional limit (default 10, must be a positive integer), and an optional namespace. It returns hits that contain only blob_id and distance, with no decrypted text, so you fetch and decrypt the blobs yourself.
To generate an embedding vector without storing anything, call embed(text).