Skip to content

Reference

JavaScript SDK reference

The @surrealdb/memory package is the JavaScript and TypeScript client for SurrealDB Agent Memory. This page covers installing it and configuring a client.

ItemValue
npm package@surrealdb/memory
Sourcesurrealdb.js/packages/memory
OpenAPI inputpackages/memory/spec/openapi.json
npm install @surrealdb/memory
import { AgentMemory } from "@surrealdb/memory";

const client = new AgentMemory({
  endpoint: process.env.AGENT_MEMORY_ENDPOINT!,
  context: "acme-prod",
  apiKey: process.env.AGENT_MEMORY_API_KEY!,
  timeoutMs: 30000,
  maxRetries: 3,
});

timeoutMs defaults to 30000 and maxRetries to 3. The older timeout option is deprecated and is ignored when timeoutMs is also set.

Uses Authorization: Bearer header authentication.

MethodHTTP
remember(...)POST /api/v1/{ctx}/facts
rememberMany(...)POST /api/v1/{ctx}/facts/batch
recall(...)POST /api/v1/{ctx}/query
forget(...)POST /api/v1/{ctx}/forget
chat(...)POST /api/v1/{ctx}/chat (SSE when stream: true)
consolidate(...)POST /api/v1/{ctx}/consolidate
reflect(...)POST /api/v1/{ctx}/reflect
elaborate(...)POST /api/v1/{ctx}/elaborate
context(...)POST /api/v1/{ctx}/context
inspect(...)GET /api/v1/{ctx}/inspect
state()GET /api/v1/{ctx}/state
profile()GET /api/v1/{ctx}/profile
audit(...)GET /api/v1/{ctx}/audit
fsck(...)POST /api/v1/{ctx}/fsck
lookup(...)POST /api/v1/{ctx}/lookup
whoami()GET /api/v1/{ctx}/me
health()GET /api/v1/health

Python names query_context as context here.

onBehalfOf(principalId) returns a client that sends every request with the X-Spectron-On-Behalf-Of delegation header. The original client is left unchanged.

NamespaceHighlights
documentsupload, get, delete, list, query, raw, reprocess, recomputeLinks, chunks, keywords.*
sessionscreate → Session with .turns(), .context(), .close()
entitieslist, get, history, delete
factsattributes, relations, actions, with allAttributes, allRelations, allActions and allEdgesOf to walk every page
uncertaintylist, listAll, count, resolve
keyscreate, list, listAll, delete, rotate (self-service keys for the caller's own principal)
scopesregister, list, delete, forget
principalslist, get, effective, grant, revoke
traceslist, get, stats
lifecycledecay, expire
ClassTypical cause
AgentMemoryErrorBase
AuthError401
ScopeError403
NotFoundError404
ValidationError400 / 422
RateLimitError429 (retryAfter when provided)
ServerError5xx
ConnectionErrorNetwork / timeout
StreamErrorA streamed response failed part of the way through
CancelledErrorThe caller aborted the request through its signal

→ Errors and retries

npm install @surrealdb/agent-memory-vercel-ai

→ Vercel AI SDK

→ JavaScript and TypeScript SDK

Was this page helpful?