Give AI agents persistent memory, rich context, and semantic understanding across structured, unstructured, and graph data using a unified, expressive query language.
What AI Agents need to operate reliably
AI agents need a unified foundation to reason, act, and adapt in real time. To perform reliably in production, they require consistent access to context, state, tools, and governance - the core elements that shape scalable agentic systems.
Unified memory
Agents need a single, persistent source of truth for context and history. Fragmented memory across systems leads to lost context and unreliable reasoning.
Fast data access
Agents need a single, persistent source of truth for context and history. Fragmented memory across systems leads to lost context and unreliable reasoning.
Reliable execution
Agents need deterministic, ACID-safe operations so updates and actions remain consistent. Without this, they risk duplicating work or corrupting shared state.
Strong governance
Agents need fine-grained permissions, audit trails, and secure boundaries to safely interact with sensitive or operational data.
The challenge with legacy backends
Fragmented architectures
Traditional backends rely on multiple disconnected data stores - creating fragile integrations and inconsistent state.
Loss of context
When embeddings, documents, and metadata flow between separate systems, agents lose context, reducing reasoning quality and reliability.
Operational overhead
Legacy stacks require teams to manage many specialised services, increasing maintenance, complexity, and operational risk.
Cost and latency spikes
Multi-system pipelines introduce latency and higher infrastructure costs, especially under vector-heavy or multi-agent workloads.
The SurrealDB solution for AI Agents
Unified data and memory
SurrealDB stores structured data, documents, vectors, and graphs in one place, giving agents a single source of context and state.
Multi-model reasoning
A unified query layer lets agents combine relational, graph, and vector operations in one request for faster, more accurate decisions.
Real-time reactivity
Subscriptions and event triggers let agents react instantly to changing data, enabling more adaptive behaviour.
Access and permissions
Role-based access control, permissions, encryption, and auditing provide clear oversight of agent activity, ensuring safer, compliant AI workflows.
Multi-model querying for richer context
SurrealDB enables graphs, vectors, documents and relational data in one language. Blend connections, facts, and semantics in a single round trip.
1-- Example: Find products similar to a user's last purchase 2 3-- Get the last user's purchase info by datetime 4LET$last_purchase = user:one->purchased.at.last(); 5 6-- And the most recently purchased product from that 7LET$last_product = ( 8user:one->purchased[WHEREat=$last_purchase]->product 9)[0]; 10 11-- Then get the most similar products 12-- $last_product will show up as most similar so slice starting at index 1 13( 14SELECT 15id, 16vector, 17vector::similarity::cosine($last_product.vector, vector) ASsimilarity 18FROMproduct 19ORDERBYsimilarityDESC 20LIMIT3 21)[1..];
1-- Example: Find siblings (i.e., documents that share a tag) and calculate vector (semantic) similarity 2 3SELECTVALUE ( 4SELECT *, 5vector::similarity::cosine(embedding, $parent.embedding) ASsimilarity 6FROMarray::distinct(->tagged_with->$tag<-tagged_with<-document) 7) ASsiblings 8FROMONLY$record 9FETCHsiblings;
RAG, Graph RAG and unified memory
Retrieval-Augmented Generation thrives on fresh, structured context. This content is usually stored in memory, but can also be saved to disk for persistent storage. Toolkits in languages including Rust, Python and JavaScript make this easy.
As an example, let's see how a simple Graph RAG looks like using LangChain. We will use SurrealDB for the vector and graph stores, and Ollama to generate the embeddings.
1# DB connection 2conn=Surreal(url) 3conn.signin({"username": user,"password": password}) 4conn.use(ns,db) 5 6# Vector Store 7vector_store=SurrealDBVectorStore( 8OllamaEmbeddings(model="llama3.2"), 9conn 10) 11 12# Graph Store 13graph_store=SurrealDBGraph(conn)
1documents.append(Document(page_content=chunk,metadata=...)) 2 3# This calculates the embeddings and inserts the documents into the DB 4vector_store.add_documents(documents)
1# Find nodes and edges (Product -> tagged_with -> Tag) 2tag_node=Node(id=tag.name,type="Tag",properties=asdict(tag)) 3product_node=Node(id=product.id,type="Product",properties=addict(product) 4 5# Edges 6relationships.append( 7Relationship(source=product_node,target=symptom_node,type="tagged_with") 8) 9graph_documents.append( 10GraphDocument(nodes=nodes,relationships=relationships,source=doc) 11) 12 13# Store the graph 14graph_store.add_graph_documents(graph_documents,include_source=True)
Governance and security
Meet regulatory requirements without wrapping your database in yet another proxy.
RBAC & record-based access
On every part of your database schema.
Rate limiting
By disallowing arbitrary queries, requiring low-access users to use defined API endpoints with middleware such as timeouts instead.
Encrypted in flight
With TLS and on-disk encryption.
Audit trails
Use env vars to record logs and traces to file with automatic rotation.
Business impact
Lower total cost of ownership
One tool to replace multiple databases (structured and unstructured, graph, vector), blob store, queue, and function compute.
Reduced complexity
Replace multiple specialised systems for memory, vectors, and relationships with a single, unified SurrealDB platform that's easier to build, operate, and scale.
Stronger governance
Centralised policies and audit across structured, unstructured, and AI data.
Scale as you need
Go from embedded, to single-node server, to a to a highly scalable distributed cluster.
Powering innovation across industries
Unlocking insights with knowledge graphs
Samsung uses SurrealDB to power a knowledge graph for real-time audience insights and ad targeting in its ad division.