MemLibMemLib

store()

Store memories with optional LLM-powered fact extraction

Signature

mem.store(options: StoreOptions): Promise<StoreResult>

Smart Store (Default)

By default, store() uses the smart store pipeline — the API extracts atomic facts from your content, deduplicates against existing memories, and resolves conflicts automatically.

const result = await mem.store({
  content: "I switched from VS Code to Cursor. Love the AI features.",
  source: "conversation",
  tags: ["preference"],
});

console.log(result.memories);
// [
//   { content: "Uses Cursor as primary editor", category: "preference", event: "ADD" },
//   { content: "Switched from VS Code to Cursor", category: "preference", event: "REPLACE" },
// ]

console.log(result.skipped);   // 0 — no duplicates
console.log(result.conflicts); // 1 — resolved VS Code → Cursor

What Happens

  1. Extract — LLM parses your text into atomic facts with importance scores and categories
  2. Embed — each fact is converted to a vector embedding
  3. Deduplicate — each fact is compared against existing memories (cosine similarity > 0.98 → skip)
  4. Resolve conflicts — facts with 0.65–0.98 similarity are resolved via LLM (merge, replace, keep, or contradict)
  5. Store — new and resolved facts are inserted into your database

Raw Store

Skip LLM inference and store the content exactly as provided:

const result = await mem.store({
  content: "Exact fact to store verbatim",
  infer: false,
});

Raw store still performs basic deduplication (similarity > 0.98 check) but makes zero LLM calls.


Options

OptionTypeRequiredDefaultDescription
contentstringText to store
namespacestringconstructor defaultOverride namespace
entitystringconstructor defaultOverride entity
inferbooleantrueUse smart store with LLM extraction
tagsstring[]Tags for categorization
metadataRecord<string, unknown>Arbitrary key-value metadata
sourcestringOrigin identifier (e.g., "conversation", "api", "import")
ttlnumberTime-to-live in seconds. Memory expires after this duration.

Return Type

interface StoreResult {
  /** Array of stored/updated memories with their resolution event */
  memories: (Memory & { event: string })[];
  /** Count of duplicate facts that were skipped */
  skipped: number;
  /** Count of conflicts detected and resolved */
  conflicts: number;
}

Event Types

EventMeaning
ADDNew memory inserted
MERGECombined with an existing memory
REPLACESuperseded an existing memory
KEEP_EXISTINGExisting memory kept, new fact skipped
SKIP_DUPLICATEExact duplicate, skipped entirely

Examples

Store with metadata and tags

await mem.store({
  content: "Meeting with design team moved to Thursdays at 3pm",
  tags: ["meeting", "schedule"],
  metadata: { updatedBy: "calendar-sync" },
  source: "calendar",
});

Store with TTL (auto-expiration)

await mem.store({
  content: "User is currently browsing the pricing page",
  ttl: 3600,  // expire after 1 hour
  source: "analytics",
});

Store to a different entity

await mem.store({
  content: "Prefers email over Slack for async communication",
  entity: "user-456",  // override constructor default
});

On this page