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.Get a real SurrealDB-backed agent running end to end.
- 2.Show how the same SurrealDB backend works across multiple frameworks through SuperOptiX.
- 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:
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.
DSPy · OpenAI · Claude · PydanticAI · CrewAI · ADK · DeepAgents
vector · hybrid · graph · multi
key-value · temporal
read-only surrealdb_query
LIVE SELECT subscriptions
RELATE · fn::embed · gating
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:
uv pip install "superoptix[surrealdb]"With pip:
pip install "superoptix[surrealdb]"2Set your Google API key
export GEMINI_API_KEY=your_key_here
# or
export GOOGLE_API_KEY=your_key_here3Start SurrealDB
docker run --rm -p 8000:8000 --name surrealdb-demo surrealdb/surrealdb:latest \
start --log info --user root --pass secret memory4Seed the demo data
python -m superoptix.agents.demo.setup_surrealdb_seed
python -m superoptix.agents.demo.setup_surrealdb_seed --graphLook for in output:
- SurrealDB seed complete
- Inserted: 8
- GraphRAG seeding:
- Edges created: > 0
5Create a SuperOptiX project
super init memory-demo
cd memory-demo6Run basic RAG with DSPy and Gemini
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
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.
# Install with uv
uv pip install "superoptix[surrealdb]"
ollama pull llama3.1:8b
# Or with pip
pip install "superoptix[surrealdb]"
ollama pull llama3.1:8bOpen Terminal A - start Ollama:
ollama serveThen start SurrealDB, seed the data, create a SuperOptiX project, and pull agents from the marketplace.
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?"Moving from RAG to GraphRAG
Seed graph-enabled data
python -m superoptix.agents.demo.setup_surrealdb_seed --graphEdges created: is zero or the command warns that RELATE is unsupported, GraphRAG is not active yet.Run the GraphRAG demo
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
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:
{
"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:
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.
Vector Retrieval
Standard semantic retrieval. SuperOptiX creates a query embedding and ranks rows by cosine similarity over the embedding field.
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.
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.
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.
| Framework | Basic RAG demo | GraphRAG demo |
|---|---|---|
| DSPy | rag_surrealdb_dspy_demo | graphrag_surrealdb_dspy_demo |
| OpenAI | rag_surrealdb_openai_demo | graphrag_surrealdb_openai_demo |
| Claude SDK | rag_surrealdb_claude_sdk_demo | graphrag_surrealdb_claude_sdk_demo |
| Microsoft | rag_surrealdb_microsoft_demo | graphrag_surrealdb_microsoft_demo |
| PydanticAI | rag_surrealdb_pydanticai_demo | graphrag_surrealdb_pydanticai_demo |
| CrewAI | rag_surrealdb_crewai_demo | graphrag_surrealdb_crewai_demo |
| Google ADK | rag_surrealdb_adk_demo | graphrag_surrealdb_adk_demo |
| DeepAgents | rag_surrealdb_deepagents_demo | graphrag_surrealdb_deepagents_demo |
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, andRETURN - 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.
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: secretMapping 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
| Capability | Status |
|---|---|
| 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
| Capability | Current state |
|---|---|
| SurrealMCP | SuperOptiX has a read-only query tool, but not full official SurrealMCP integration |
| Surrealism / extensions | Touched through the fn::embed path, not exposed as a general extension model |
Not implemented yet
| Capability | Current state |
|---|---|
| Record references with <~ | Not yet exposed |
| File buckets / file storage workflows | Not yet exposed |
| Client-side transactions | Not yet exposed |
| Custom API endpoints | Not in scope today |
| Full record-reference lifecycle examples | Not yet exposed |
| Full SurrealMCP deployment integration | Not 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
