MemorySync
SDKs · Node.js

Node.js Memory Client

Build against the 35 public promise-based memory methods, their exported TypeScript types, and explicit project and end-user scope.

Configure the client

client.ts
import { MemorySyncClient } from "memorysync-sdk";
const client = new MemorySyncClient({
apiKey: process.env.MEMORYSYNC_API_KEY!,
baseUrl: "https://api.memorysync.io",
projectId: process.env.MEMORYSYNC_PROJECT_ID!,
endUserId: "usr_7f3a9c2e",
});
FieldRequiredPurpose
apiKeyYesServer-side memory API credential.
baseUrlYesMemorySync HTTPS base URL.
projectIdBy application scopeSelects the trusted project context.
endUserIdFor user-scoped memory callsStable opaque application-user identifier.
timeoutMsNoRequest timeout in milliseconds; defaults to 30000.
fetchNoInject a compatible fetch implementation when required.

All memory methods

MethodReturnsUse
add(request)Promise<AddResponse>Store one memory candidate.
bulkAdd(items, options?)Promise<BulkAddResponse>Submit 1–50 items and inspect each outcome.
query(request)Promise<QueryResponse>Retrieve a result window.
get(memoryId)Promise<MemoryRecord>Read one known record.
update(memoryId, request)Promise<MemoryRecord>Replace supported descriptive fields.
forget(memoryIds, reason?)Promise<number[]>Remove selected records and inspect confirmed IDs.
summarize(request)Promise<MemoryRecord>Create a summary record.
compose(request)Promise<ComposeResponse>Receive a composed prompt and usage fields.
exportAll()Promise<ExportResponse>Read the authenticated principal export.
createImport(request)Promise<Record<string, unknown>>Upload a payload and start an import job.
getImport(jobId)Promise<Record<string, unknown>>Poll one job’s status and counters.
listImports(opts?)Promise<Record<string, unknown>>Recent import jobs, newest first.
cancelImport(jobId)Promise<Record<string, unknown>>Ask the worker to stop between batches.
createRelation(fromId, request)Promise<RelationRecord>Create a documented record relationship.
addTurn(request)Promise<Record<string, unknown>>Store one conversational turn verbatim (episodic ingestion).
recall(request)Promise<Record<string, unknown>>Build a prompt-ready context block for an LLM call.
listMemories(request)Promise<Record<string, unknown>>Page through a specific end user’s memories.
retrieve(request)Promise<QueryResponse>Alias of query against /memory/retrieve — identical semantics.
searchRouted(request)Promise<Record<string, unknown>>Route a question to the best knowledge source and answer from it.
synthesize(request)Promise<Record<string, unknown>>Compose an answer across several memories, with citations.
upload(file, options)Promise<AddResponse>Ingest a document and store the memories extracted from its text.
batchUpdate(items)Promise<BatchUpdateResponse>Apply up to 100 metadata edits in one request.
refresh()Promise<Record<string, unknown>>Re-embed this end user’s memories; returns immediately (202).
status(memoryId)Promise<Record<string, unknown>>Async ingestion status for one memory.
history(memoryId, opts?)Promise<HistoryResponse>Recorded changes to one memory, oldest first.
feedback(memoryId, signal, comment?)Promise<FeedbackResponse>Tell MemorySync whether a memory was useful; tunes ranking.
graph(opts?)Promise<Record<string, unknown>>Nodes and typed edges for this end user’s memory graph.
clusters(opts?)Promise<Record<string, unknown>>Semantic clusters over this end user’s memories.
decisions(opts?)Promise<Record<string, unknown>>Contradictions and open decisions detected across memories.
resolveDecision(request)Promise<Record<string, unknown>>Record which side of a contradiction wins.
intelligence(opts)Promise<Record<string, unknown>>The intelligence report: themes, entities, patterns.
knowledgeStats()Promise<Record<string, unknown>>Counts and coverage for the knowledge base.
getOntology()Promise<Ontology>The memory vocabulary in effect for this organization.
updateOntology(request)Promise<Ontology>Replace this organization’s additions to the vocabulary.
purgeUser()always throwsGuard method: account erasure lives in the Control Plane SDK, never here.

Narrow AddResponse

add-memory.ts
const result = await client.add({
text: "The user prefers dark mode.",
source: "settings",
metadata: { screen: "appearance" },
});
if ("status" in result && result.status === "skipped") {
console.log("not created", result.reason);
} else {
console.log("created", result.id, result.text);
}

Reconcile every bulk item

bulk-add.ts
const response = await client.bulkAdd([
{ text: "The launch is Friday.", tags: ["plan"] },
{ text: "The release needs legal approval.", tags: ["constraint"] },
]);
for (const item of response.results) {
console.log(item.index, item.status, item.memoryIds, item.reason);
}

Retrieve and maintain records

retrieve-and-update.ts
const response = await client.query({
query: "What constraints apply to the launch?",
k: 5,
filters: { tags: ["constraint"] },
});
for (const memory of response.memories) {
const current = await client.get(memory.id);
const updated = await client.update(current.id, {
tags: ["constraint", "reviewed"],
});
console.log(updated.id, updated.tags);
}

Authorize destructive operations

forget.ts
const requestedIds = [101, 102];
const deletedIds = await client.forget(requestedIds, "user_request");
const confirmedIds = new Set(deletedIds);
if (requestedIds.some((id) => !confirmedIds.has(id))) {
console.log("Reconcile the IDs that were not confirmed");
}

Reference and safety

Was this page helpful?