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/spectron
OpenAPI inputpackages/spectron/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!,
  timeout: 30000,
  maxRetries: 3,
});

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
health()GET /api/v1/health

Python names query_context as context here. Python exposes whoami() and keys.*; the JavaScript client does not include those methods - use REST for those endpoints.

NamespaceHighlights
documentsupload, get, delete, list, query, raw, reprocess, recomputeLinks, chunks, keywords.*
sessionscreateSession with .turns(), .context(), .close()
entitieslist, get, history, delete
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

Errors and retries

npm install @surrealdb/spectron-vercel-ai

Vercel AI SDK

JavaScript and TypeScript SDK

Was this page helpful?