Multi-model RAG with SurrealDB & LangChain
Watch on-demand

Run data, logic, and AI everywhere your application lives - no extra services needed

SurrealDB brings database power to the outermost edge: phones, browsers, IoT gateways, retail kiosks, and anything in between. Deploy the same engine you use in the cloud as a lightweight binary or WebAssembly module.

The challenge

Latency and battery drain

Pushing every read or write to the cloud introduces latency, drains batteries, and fails when connectivity is patchy.

Fragmented stores

Traditional embedded stores solve a slice of the problem but force developers to manage separate replication and access-control stacks.

Network dependency

Edge services fail when connectivity drops, breaking user experience and critical operations.

Complex sync logic

Hand-rolling bespoke stores, replication layers, and API wrappers creates operational overhead.

Surrealism

Same multi-model database, everywhere

Embedded runtime

Embed SurrealDB in-process with the Rust crate for native apps and services, or connect from edge runtimes over HTTP/WebSocket.

Offline-first sync

Design offline flows with local storage and app-managed synchronization. Use history/versioning to aid conflict detection and reconciliation.

Unified queries

Mix document, graph, and time-series reads in a single statement to power complex edge applications.

Persistent engine

Use SurrealKV (file-backed) for crash-safe local storage, or in-memory for ephemeral workloads.

use surrealdb::{engine::local::{File, Mem}, Surreal}; // In-memory (ephemeral) let db = Surreal::new::<Mem>(()).await?; // Or file-backed (persistent) let db = Surreal::new::<File>("/var/lib/myapp/edge.db").await?;
-- Write logic once DEFINE TABLE reading SCHEMALESS PERMISSIONS FOR create, select WHERE $auth.id = device; INSERT reading CONTENT { device: $auth.id, ts: time::now(), value: fn::get_device_input($auth.id) };

Real-world scenarios

From industrial IoT to mobile field apps, SurrealDB powers edge applications across industries.

-- Industrial IoT: Aggregate sensor data and run safety rules LET $sensor_data = ( SELECT value, ts FROM sensors WHERE device = $device AND ts > time::now() - 1h ); LET $anomaly_score = fn::edge_inference($sensor_data); IF $anomaly_score > 0.8 THEN INSERT INTO alerts { device: $device, severity: "critical", score: $anomaly_score }; END;

Retail point-of-sale resilience

Keep checkout lines moving when the store’s WAN link is saturated.

-- Each register runs SurrealDB locally with file-backed storage -- Transactions post locally; application syncs to peers or central when online BEGIN TRANSACTION; INSERT INTO transactions { register: $register_id, items: $cart_items, total: $total_amount, timestamp: time::now() }; -- App-managed sync via HTTP/WebSocket when connectivity is available COMMIT;

Mobile field applications

Field technicians record inspections and photos in remote areas with offline-first functionality.

-- Store forms, images (as references), and graph links locally INSERT INTO inspections { technician: $user_id, asset: $asset_id, photos: $photo_files, notes: $inspection_notes, location: $gps_coords, timestamp: time::now() }; -- Graph links to assets for relationship queries RELATE inspections:$inspection_id ->inspected-> assets:$asset_id; -- App feels native offline; updates are sent by the app when connectivity returns

Connected vehicles

Vehicles stream telemetry, require local classification, and must pass compliance audits.

-- SurrealDB runs locally, logging time-series data INSERT INTO telemetry { vehicle: $vehicle_id, speed: $current_speed, engine_temp: $engine_temp, location: $gps_coords, timestamp: time::now() }; -- Optional: call a defined function for local inference or classification LET $classification = fn::vehicle_ai_analysis($telemetry_data); UPDATE telemetry SET classification = $classification WHERE id = $telemetry_id;

Security and governance built-in

Meet regulatory requirements without wrapping your DB in yet another proxy.

Transport security

Use TLS for data-in-transit security between edge nodes and services. Manage keys and secrets with your platform of choice.

Fine-grained access

Row- and record-level permissions, roles, and authentication (incl. JWT) are defined in schema and enforced consistently.

Built-in history

With SurrealKV, query historical versions of data for auditing and troubleshooting without external changelog systems.

Data locality

Keep sensitive data local and sync only the fields you choose. Implement redaction or aggregation in application logic.

Business impact

Lower latency

Process reads and writes locally to minimize round trips and improve UX.

Reduced bandwidth

Reduce network usage with local aggregation and selective synchronization.

Extended battery life

Fewer network calls can reduce power consumption on mobile devices.

Fewer components

Consolidate data, queries, and access control to simplify your stack.

Faster delivery

Iterate on schema and edge logic together with a single query language.

Single governance

Use one permission model from edge to core, with optional historical queries for audits.

Ready to build and
deploy to the edge?

Start building intelligent applications for the edge with realtime, on-device decision making in one database.

Start for free
Learn more
Trusted & Certified for Enterprise Security Learn more
SOC 2 Type 2
GDPR
Cyber Essentials Plus
ISO 27001