Skip to main content

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.md
import { 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() succeeds
  • remember() returns a job_id immediately
  • waitForRememberJob() returns a blob_id
  • recall() 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.

Source: sdk/examples.md
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.

  1. Submit a structured summary with remember() and wait for completion when immediate recall is needed
  2. Generate targeted queries later
  3. Use recall() with a query and limit, 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, as number[].
  • namespace: Optional. Defaults to the config namespace or default.

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).