SURREALQL
SurrealQL: one query, every model
The best way to understand SurrealQL is to see the payoff first. Consider a retrieval query for an AI agent that needs to find relevant knowledge base articles for a customer:
That single statement applies tenant isolation, temporal filtering, graph traversal through the customer's product relationships, and hybrid vector + full-text ranking. In a multi-system architecture, this would require four or five round-trips across independent databases with no transactional consistency between them. In SurrealQL, it is one query, one transaction, one consistent snapshot.
DATA MODELS
Composable by design
Graph relationships
Graph edges are native to the data model. Relationships are created with RELATE and traversed with arrow syntax. What makes SurrealDB's graph model distinct is that every edge is a full document - it can carry its own fields, metadata, embeddings, timestamps, and permissions.
Vector search
Vector similarity search is built into the query engine. You define an index on a field and query it with distance functions. The structured filter (category = 'tools') narrows the candidate set before the vector search runs - scope first, rank second.
Documents and record links
SurrealDB stores data as schemaless or schemafull documents. Record links replace foreign key joins with direct references that the engine resolves at query time, eliminating N+1 query patterns.
TEMPORAL AND SEARCH
Time-series, full-text, and real-time
Time-series and temporal queries
Native duration arithmetic, temporal aggregation functions, and point-in-time VERSION reads for time-travel queries without blocking writers.
Full-text search
BM25-scored full-text indexes with configurable analysers and the @@ match operator. Composes with every other model in the same query.
Live queries, events, and more
Geospatial queries work on native GeoJSON types with built-in distance, bearing, and containment functions. LIVE SELECT provides real-time subscriptions over WebSockets. DEFINE EVENT triggers server-side logic on data changes, and changefeeds provide ordered, durable mutation streams per table.
Every one of these models composes with every other. A single SurrealQL statement can combine a graph traversal with a vector search, scope it by a full-text match, filter by a temporal range, restrict by geospatial proximity, aggregate relationally, and stream the results to a live subscriber.
QUERY ENGINE
Specialised indexes, streaming execution
While the storage is unified KV, the indexing layer is purpose-built for each model: HNSW graphs for vector similarity, BM25-scored inverted indexes for full-text, B-tree derivatives for structured lookups, and the directional key structure itself for graph traversals.
SurrealDB 3.0 rearchitected the query engine around streaming execution, processing results without materialising full intermediate result sets - critical for graph traversals where intermediate sets can explode in size.
MORE CAPABILITIES
Beyond the core models
Geospatial queries
Native GeoJSON support with built-in distance, bearing, area, and containment functions. No PostGIS extension. Geospatial composes with everything else - find stores within 5km and traverse their inventory graph in one statement.
Surrealism: the extension system
A WebAssembly-based extension system. Write an extension in Rust, compile it to a .surli module, load it into a running database. Your functions become callable from SurrealQL, sandboxed in WASM, participating in ACID transactions. See surrealdb.com/platform/surrealdb/extensibility.
DEFINE API: custom endpoints in the database
DEFINE API creates custom HTTP endpoints directly inside SurrealDB - no external framework, no routing layer. The endpoint inherits ACID transactions, row-level permissions, and multi-model query capabilities. For agent-facing APIs and internal tools, this eliminates the entire API routing layer.
Single binary, runs everywhere
SurrealDB compiles to a single binary. It runs in the browser via WebAssembly, embedded in edge devices, as a serverless function, as a single-node server, or as a distributed SurrealDS cluster. The query engine, data model, and application code are identical across all environments - a prototype built embedded in a browser can move to a distributed cluster in production without rewriting a single query.
COMPARISON
How SurrealDB compares
| Feature | Postgres | Neo4j | Pinecone / Weaviate | SurrealDB |
|---|---|---|---|---|
| Data models | Relational + extensions | Graph + native vector index | Vector-first | Documents, graphs, vectors, time-series, geospatial, relational |
| Graph support | Recursive CTEs | Native (Cypher) | None | Native (arrow syntax, edges as documents) |
| Vector search | pgvector extension | Native vector index | Native ANN (specialised) | Native, composable with filters + graphs |
| Transactions | ACID, single model | ACID, graph | Tunable / eventual | ACID across every model |
| Agent memory | External middleware | External middleware | External middleware | Spectron (built on SurrealDB, ACID-consistent) |
| Storage | Coupled compute + storage | Coupled, cache-dependent | Managed service | Object-storage-backed, compute-storage separation |
| Extensibility | C extensions, PL/pgSQL | Java / APOC plugins | Limited | Surrealism (sandboxed WASM) |
SUMMARY
The full picture
SurrealDS provides distributed storage backed by S3-class object storage with quorum consensus, compute-storage separation, and scale-to-zero. SurrealDB provides the context layer: documents, graphs, vectors, time-series, geospatial, and relational structures as native primitives in one ACID transaction. Spectron provides persistent, structured agent memory that commits atomically alongside application data.
FREQUENTLY ASKED QUESTIONS
Frequently asked questions
GET STARTED
Start building with the context layer
Object storage to agent memory. A single stack, a single transaction, zero glue code.
SOC 2 Type 2
GDPR
Cyber Essentials Plus
ISO 27001