Agent Memory
SurrealDB
SuperOptiX
Multi-Framework

Building Agent Memory on SurrealDB Across Modern Agent Frameworks with SuperOptiX

March 6, 2026
18 min read
By Shashi Jagtap
Building Agent Memory on SurrealDB Across Modern Agent Frameworks with SuperOptiX

One database. Multiple retrieval modes. Eight agent frameworks.

Agent Memory is one of the hot topics in the Agentic AI space as everyone tries to solve this for once. AI agents usually end up with a fragmented memory stack. One system stores embeddings. Another stores structured records. A third handles graph relationships. A cache keeps short-lived context. Then application code has to stitch all of it together, keep it consistent, and explain to the agent framework where each piece of memory lives.

We tried many vector databases and explored the pros and cons of each. Every database has its own unique strengths and weaknesses - but when Agent Memory is the topic, SurrealDB is one you cannot ignore.

In this post, we will do three things:

  1. 1.Get a real SurrealDB-backed agent running end to end.
  2. 2.Show how the same SurrealDB backend works across multiple frameworks through SuperOptiX.
  3. 3.Map SurrealDB 3.0's newest agent-memory story to what SuperOptiX supports today.

Full companion docs: SuperOptiX SurrealDB guide

What SurrealDB 3.0 Changes for Agent Memory

SurrealDB is a multi-model database that brings together documents, graph traversal, vector search, full-text retrieval, and live queries in one engine. SurrealDB 3.0 makes the case even stronger for AI systems: agent memory, richer indexing, extensions, file support, record references, live data, and more expressive ways to connect application logic to data.

That matters because agent memory is not just semantic search. A real memory layer often needs:

Semantic retrieval over embeddings
Exact lexical retrieval for tokens and identifiers
Relationships between entities, tools, and tasks
Durable state that changes over time
Live subscriptions for coordination
Safe access patterns for external runtimes

SurrealDB 3.0 highlights

  • Vector, graph, and SQL retrieval in a unified model
  • Better indexing and performance
  • Improved in-memory engine
  • Extensions via Surrealism
  • File storage support
  • Client-side transactions
  • Custom API endpoints
  • Record references
  • Live data patterns and richer multi-model traversal

What SuperOptiX Adds

SuperOptiX is the integration and runtime layer. Its useful property here is that SurrealDB can sit behind one shared runtime and the same behaviour becomes available across DSPy, OpenAI, Claude SDK, Microsoft, PydanticAI, CrewAI, Google ADK, and DeepAgents - without rebuilding the integration eight times.

One Agent Spec & Runtime

Single declarative model drives all framework adapters

Shared RAG Layer

Vector, hybrid, graph, and multi retrieval in one place

Shared Memory Layer

Temporal memory with version history and live subscriptions

Shared Tool Layer

Read-only SurrealDB query tool wired across frameworks

Shared runtime covers today:

  • Vector RAG
  • Hybrid retrieval
  • GraphRAG
  • Multi retrieval (hybrid + graph expansion)
  • Temporal memory with version history
  • Server-side embedding path with client fallback
  • Live memory utility using LIVE SELECT
  • A read-only SurrealDB query tool
  • Capability detection and graceful fallback

Architecture in One View

SurrealDB support in SuperOptiX is not implemented as isolated framework-specific integrations. It lives in the shared runtime layer, so the same backend behaviour is exercised across all frameworks.

SuperOptiX Playbook
Framework Adapter

DSPy · OpenAI · Claude · PydanticAI · CrewAI · ADK · DeepAgents

Shared Runtime Layer
RAG Runtime

vector · hybrid · graph · multi

Memory Backend

key-value · temporal

Built-in Tool

read-only surrealdb_query

Live Utility

LIVE SELECT subscriptions

Feature Detector

RELATE · fn::embed · gating

SurrealDB

Every framework adapter talks to the same Shared Runtime - SurrealDB is wired in once, available everywhere.

Recommended Quick Start - Cloud Models

The easiest path is Google Gemini for inference and SurrealDB for retrieval and memory. This avoids local model setup. Only the runtime flags change - everything else stays the same.

1Install SuperOptiX with SurrealDB support

With uv:

Shell
uv pip install "superoptix[surrealdb]"

With pip:

Shell
pip install "superoptix[surrealdb]"

2Set your Google API key

Shell
export GEMINI_API_KEY=your_key_here
# or
export GOOGLE_API_KEY=your_key_here

3Start SurrealDB

Shell
docker run --rm -p 8000:8000 --name surrealdb-demo surrealdb/surrealdb:latest \
    start --log info --user root --pass secret memory

4Seed the demo data

Shell
python -m superoptix.agents.demo.setup_surrealdb_seed
python -m superoptix.agents.demo.setup_surrealdb_seed --graph

Look for in output:

  • SurrealDB seed complete
  • Inserted: 8
  • GraphRAG seeding:
  • Edges created: > 0

5Create a SuperOptiX project

Shell
super init memory-demo
cd memory-demo

6Run basic RAG with DSPy and Gemini

Shell
super agent pull rag_surrealdb_dspy_demo
super agent compile rag_surrealdb_dspy_demo --framework dspy
super agent run rag_surrealdb_dspy_demo \
  --framework dspy \
  --cloud \
  --provider google-genai \
  --model gemini-2.5-flash \
  --goal "What is NEON-FOX-742?"

Verify:

  • RAG retrieval enabled
  • Validation Status: PASSED
  • Answer mentions NEON-FOX-742 - confirms retrieval from SurrealDB, not hallucination

7Run GraphRAG with DSPy and Gemini

Shell
super agent pull graphrag_surrealdb_dspy_demo
super agent compile graphrag_surrealdb_dspy_demo --framework dspy
super agent run graphrag_surrealdb_dspy_demo \
  --framework dspy \
  --cloud \
  --provider google-genai \
  --model gemini-2.5-flash \
  --goal "What capabilities does SurrealDB provide?"

Verify:

  • Run does not fall back from graph mode to vector mode
  • Answer includes SurrealDB capabilities from graph-connected records

Quick Start - Local Models

You need Python, Docker, and a terminal with uv or pip. For the local model path, also install Ollama.

Shell
# Install with uv
uv pip install "superoptix[surrealdb]"
ollama pull llama3.1:8b

# Or with pip
pip install "superoptix[surrealdb]"
ollama pull llama3.1:8b

Open Terminal A - start Ollama:

Terminal A
ollama serve

Then start SurrealDB, seed the data, create a SuperOptiX project, and pull agents from the marketplace.

Shell
super agent pull rag_surrealdb_dspy_demo
super agent compile rag_surrealdb_dspy_demo --framework dspy
super agent run rag_surrealdb_dspy_demo \
  --framework dspy \
  --goal "What is NEON-FOX-742?"
Why NEON-FOX-742? That token is part of the seeded dataset. A correct answer confirms the agent is retrieving from SurrealDB rather than guessing from the model's prior training.

Moving from RAG to GraphRAG

Seed graph-enabled data

Shell
python -m superoptix.agents.demo.setup_surrealdb_seed --graph
If Edges created: is zero or the command warns that RELATE is unsupported, GraphRAG is not active yet.

Run the GraphRAG demo

Shell
super agent pull graphrag_surrealdb_dspy_demo
super agent compile graphrag_surrealdb_dspy_demo --framework dspy
super agent run graphrag_surrealdb_dspy_demo \
  --framework dspy \
  --goal "What capabilities does SurrealDB provide?"

Run GraphRAG with Gemini

Shell
super agent pull graphrag_surrealdb_dspy_demo
super agent compile graphrag_surrealdb_dspy_demo --framework dspy
super agent run graphrag_surrealdb_dspy_demo \
  --framework dspy \
  --cloud \
  --provider google-genai \
  --model gemini-2.5-flash \
  --goal "What capabilities does SurrealDB provide?"

At this point the core integration is working: vector retrieval, graph expansion, and framework-managed agent execution.

Watch Demo

See the SurrealDB integration in action - RAG, GraphRAG, and temporal memory running across agent frameworks with SuperOptiX.

How the Data is Modeled

The default SurrealDB RAG table is rag_documents. A typical row looks like this:

JSON
{
  "content": "document text",
  "embedding": [0.123, -0.456, 0.789],
  "metadata": {
    "seed_id": "seed-001",
    "source": "superoptix_surreal_seed_v1",
    "topic": "retrieval"
  }
}

For GraphRAG, SuperOptiX creates graph-oriented records using deterministic IDs:

rag_documents:superoptixrag_documents:surrealdbrag_documents:vector_search

Indexes the seeder defines:

  • HNSW vector index on the embedding field
  • BM25 full-text index on the content field
  • Index on metadata.entity_id

Aligns with SurrealDB's own vector model guidance, where HNSW is the recommended pattern.

Retrieval Modes in SuperOptiX

This is where SurrealDB becomes more than a plain vector store.

1

Vector Retrieval

Standard semantic retrieval. SuperOptiX creates a query embedding and ranks rows by cosine similarity over the embedding field.

2

Hybrid Retrieval

Combines vector similarity with lexical relevance from full-text search. Matters when exact terms matter - product names, identifiers, error strings. Controlled by retrieval_mode: hybrid and hybrid_alpha.

3

GraphRAG

A two-step flow: retrieve the best seed records with vector search, then expand by traversing configured RELATE edges. Turns SurrealDB into a graph-aware retrieval backend.

4

Multi Retrieval

Starts with hybrid retrieval, then expands results via graph traversal. Use it when the question mixes semantic meaning, exact tokens, and relationships.

SurrealDB Across Modern Agent Frameworks

The same SurrealDB backend is exercised across all frameworks. The seed data, retrieval behaviour, and Gemini model stay the same - only the demo ID and --framework flag change.

Click any framework name in the table below to jump directly to its step-by-step implementation in the docs.

FrameworkBasic RAG demoGraphRAG demo
DSPyrag_surrealdb_dspy_demographrag_surrealdb_dspy_demo
OpenAIrag_surrealdb_openai_demographrag_surrealdb_openai_demo
Claude SDKrag_surrealdb_claude_sdk_demographrag_surrealdb_claude_sdk_demo
Microsoftrag_surrealdb_microsoft_demographrag_surrealdb_microsoft_demo
PydanticAIrag_surrealdb_pydanticai_demographrag_surrealdb_pydanticai_demo
CrewAIrag_surrealdb_crewai_demographrag_surrealdb_crewai_demo
Google ADKrag_surrealdb_adk_demographrag_surrealdb_adk_demo
DeepAgentsrag_surrealdb_deepagents_demographrag_surrealdb_deepagents_demo
Shell - same pattern for every framework
super agent pull <demo_id>
super agent compile <demo_id> --framework <framework>
super agent run <demo_id> --framework <framework> --goal "<question>"

# Basic RAG: "What is NEON-FOX-742?"
# GraphRAG:  "What capabilities does SurrealDB provide?"

Agent Memory Beyond Retrieval

SurrealDB 3.0 is not only about vector search. SuperOptiX already exposes several pieces of its broader agent memory story.

Temporal Memory

The SurrealDB memory backend supports temporal versioning - turning memory into a journal rather than a simple overwrite store.

  • Primary table stores the latest value for a key
  • Companion versions table stores all historical writes
  • retrieve() returns the current value
  • history() returns prior versions
  • retrieve_at() returns the value at a point in time

Example playbook: temporal_memory_surrealdb_demo

Live Memory Utility

SurrealDB's LIVE SELECT is a good fit for real-time memory and coordination. SuperOptiX includes a LiveMemorySubscriber utility that subscribes to changes over WebSocket-based SurrealDB connections. It is not auto-wired into every agent runtime path - which is the right choice. Live coordination is useful but operationally different from basic retrieval.

Server-side Embeddings

The RAG runtime can try a server-side embedding path through fn::embed. If available, the query is embedded inside SurrealDB. If not, SuperOptiX automatically falls back to the client-side sentence-transformer path.

MCP-style Query Access

SuperOptiX includes a read-only SurrealDB query tool, surrealdb_query, intentionally restricted for safety:

  • Only SELECT, INFO, and RETURN
  • Row limit injection when missing
  • Timeout protection

Not the same as full SurrealMCP - this is a focused, built-in read-only query tool.

A Practical SuperOptiX Configuration

One SurrealDB deployment backing RAG, multi retrieval, temporal memory, and read-only query access - all in one SuperSpec YAML.

YAML - SuperSpec
spec:
  target_framework: dspy

  language_model:
    location: cloud
    provider: google-genai
    model: gemini-2.5-flash

  memory:
    enabled: true
    backend:
      type: surrealdb
      config:
        url: ws://localhost:8000
        namespace: superoptix
        database: agents
        username: root
        password: secret
        table_name: superoptix_memory
    temporal:
      enabled: true
      max_versions_per_key: 50

  rag:
    enabled: true
    retriever_type: surrealdb
    config:
      top_k: 5
      retrieval_mode: multi
      hybrid_alpha: 0.7
      graph_depth: 2
      graph_relations:
        - integrates_with
        - provides
        - supports
        - enables
      embedding_mode: client
    vector_store:
      url: ws://localhost:8000
      namespace: superoptix
      database: knowledge
      username: root
      password: secret
      table_name: rag_documents
      vector_field: embedding
      content_field: content
      metadata_field: metadata
      embedding_model: sentence-transformers/all-MiniLM-L6-v2

  tools:
    built_in_tools:
      - name: surrealdb_query
        config:
          url: ws://localhost:8000
          namespace: superoptix
          database: knowledge
          username: root
          password: secret

Mapping SurrealDB 3.0 to Current SuperOptiX Coverage

Explicit about what is covered well, what is partial, and what is not implemented yet.

Covered well today

CapabilityStatus
Vector retrieval
Supported
Hybrid retrieval
Supported
GraphRAG via RELATE traversal
Supported
Multi retrieval (hybrid + graph)
Supported
Temporal memory
Supported
LIVE SELECT utility
Supported
Server-side embedding via fn::embed with fallback
Supported
Multi-framework demos
Supported across 8 frameworks
Runtime capability detection and fallback
Supported

Covered partially

CapabilityCurrent state
SurrealMCPSuperOptiX has a read-only query tool, but not full official SurrealMCP integration
Surrealism / extensionsTouched through the fn::embed path, not exposed as a general extension model

Not implemented yet

CapabilityCurrent state
Record references with <~Not yet exposed
File buckets / file storage workflowsNot yet exposed
Client-side transactionsNot yet exposed
Custom API endpointsNot in scope today
Full record-reference lifecycle examplesNot yet exposed
Full SurrealMCP deployment integrationNot yet exposed

The integration is already strong where it matters most for agent retrieval and memory, while being honest about what is still future work.

Production Notes

Use the right connection mode

SuperOptiX works with ws:// or wss:// for server mode and live subscriptions, or embedded transports like memory / surrealkv:// for local development.

Verify indexes explicitly

The demo seeder attempts to define indexes automatically, but production environments should not rely only on that. Explicitly verify vector indexing on embeddings, full-text indexing on content, and stable record identifiers for graph-oriented data.

Treat GraphRAG as a capability, not an assumption

If your server does not support the graph behavior SuperOptiX expects, GraphRAG degrades gracefully. Check the logs and seed output instead of assuming graph traversal is active.

Keep security boundaries tight

If you expose query access to agents, keep it read-only. The built-in surrealdb_query tool is intentionally conservative for that reason.

Why This Combination Matters

A lot of agent stacks still assume a single memory primitive - usually vector search. That is not enough.

Real agents need semantic retrieval, exact lookup, relations, state over time, safe data access, and a clean way to use all of the above across different runtimes.

SurrealDB 3.0 brings those primitives closer together. SuperOptiX gives us one place to test, run, and compare those behaviors across modern agent frameworks. One backend, multiple retrieval styles, multiple frameworks, one shared runtime model.

SuperOptiX Optimization - What's Coming

SuperOptiX is an agent optimization framework and we have not yet applied optimization techniques to the SurrealDB integration.

When all the SurrealDB RAG queries, memories, and prompts get optimized by GEPA and suitable optimizers, that will be the super powerful feature of this combination. We will cover that in the next post.

Conclusion

SurrealDB 3.0 makes a serious case for being more than a vector database in an agent stack. Its direction is clearly about agent memory, unified retrieval, richer indexing, and bringing more intelligence closer to the data layer.

SuperOptiX makes that story concrete. Today you can run SurrealDB-backed vector RAG, hybrid retrieval, GraphRAG, multi-retrieval, temporal memory, live memory utility, and read-only query tooling across modern agent frameworks - not just one.

Next layer of work:

  • Deeper use of record references
  • Richer SurrealMCP integration
  • File-backed multimodal memory patterns
  • Transaction-aware agent workflows
  • Optimisation and evaluation of RAG and Memory