Guides

Per-user knowledge

Ingest documents and conversations into per-user graphs and answer questions across both.

Per-user knowledge

For agents that need to combine private user context (preferences, history) with shared knowledge (a customer account, a product manual), the pattern is to write to both a per-user graph and a group graph, then read from both in a single query.

Set up the graphs

import { MemoryClient } from "@memhq/sdk";
const memhq = new MemoryClient();

// Per-user graph is implicit — the first add() call creates it.
// Group graph needs to exist and have the user as a member.
await memhq.groups.create({
  groupId: "acct_acme",
  name: "Acme Corp account",
  memberUserIds: ["user_42", "user_7"],
});

Ingest

// Personal preference → user graph
await memhq.add({
  userId: "user_42",
  messages: [
    { role: "user", content: "I'm in PST and prefer morning syncs." },
  ],
});

// Account-wide fact → group graph (every Acme user sees it)
await memhq.add({
  groupId: "acct_acme",
  messages: [
    {
      role: "system",
      content:
        "Acme's procurement requires POs above $5k. POs are issued by [email protected].",
    },
  ],
});

Query both at once

const answer = await memhq.ask({
  userId: "user_42",
  groupId: "acct_acme",
  question:
    "Schedule a kickoff with the user and tell them about the PO process.",
});

console.log(answer.text);
// → "Schedule a morning kickoff (user is in PST). Mention POs above
//    $5k require a Acme PO from [email protected]."

When both userId and groupId are passed, MemHQ retrieves from both graphs and lets the synthesizer weigh them together. Citations in the response identify which graph each source came from.

Coming soon — full guide

This page covers the basic pattern. A deeper walkthrough — document ingestion, ontology customization for domain-specific entities, and multi-group fan-out — is in progress.