Skip to main content

An integration package connecting SurrealDB and LangChain

Project description

The official SurrealDB components for LangChain


       

  X (formerly Twitter) Follow    

langchain-surrealdb

This package contains the LangChain integration with SurrealDB

SurrealDB is a unified, multi-model database purpose-built for AI systems. It combines structured and unstructured data (including vector search, graph traversal, relational queries, full-text search, document storage, and time-series data) into a single ACID-compliant engine, scaling from a 3 MB edge binary to petabyte-scale clusters in the cloud. By eliminating the need for multiple specialized stores, SurrealDB simplifies architectures, reduces latency, and ensures consistency for AI workloads.

Why SurrealDB Matters for GenAI Systems

  • One engine for storage and memory: Combine durable storage and fast, agent-friendly memory in a single system, providing all the data your agent needs and removing the need to sync multiple systems.
  • One-hop memory for agents: Run vector search, graph traversal, semantic joins, and transactional writes in a single query, giving LLM agents fast, consistent memory access without stitching relational, graph and vector databases together.
  • In-place inference and real-time updates: SurrealDB enables agents to run inference next to data and receive millisecond-fresh updates, critical for real-time reasoning and collaboration.
  • Versioned, durable context: SurrealDB supports time-travel queries and versioned records, letting agents audit or “replay” past states for consistent, explainable reasoning.
  • Plug-and-play agent memory: Expose AI memory as a native concept, making it easy to use SurrealDB as a drop-in backend for AI frameworks.

Installation

Python 3.10+ is required.

# -- Using pip
pip install -U langchain-surrealdb surrealdb
# -- Using uv (preferred for contributors)
uv add langchain-surrealdb surrealdb

Graph QA extra

Experimental graph QA helpers depend on langchain-classic. Install the extra if you plan to use them:

pip install -U "langchain-surrealdb[graph-qa]"

Local development with uv

# install all dependency groups and extras
uv sync --all-groups --all-extras
# run the test suite
uv run pytest
# run formatting + lint checks
make lint

To exercise the included examples:

  • cd examples/basic && uv sync && uv run python main.py
  • cd examples/graph && uv sync && uv run python graph.py

Requirements

You can run SurrealDB locally or start with a free SurrealDB cloud account.

For local, two options:

  1. Install SurrealDB and run SurrealDB. Run in-memory with:
surreal start -u root -p root
  1. Run with Docker.
docker run --rm --pull always -p 8000:8000 surrealdb/surrealdb:latest start

Simple example

from langchain_core.documents import Document
from langchain_surrealdb.vectorstores import SurrealDBVectorStore
from langchain_ollama import OllamaEmbeddings
from surrealdb import Surreal

conn = Surreal("ws://localhost:8000/rpc")
conn.signin({"username": "root", "password": "root"})
conn.use("langchain", "demo")
vector_store = SurrealDBVectorStore(OllamaEmbeddings(model="llama3.2"), conn)

doc_1 = Document(page_content="foo", metadata={"source": "https://surrealdb.com"})
doc_2 = Document(page_content="SurrealDB", metadata={"source": "https://surrealdb.com"})

vector_store.add_documents(documents=[doc_1, doc_2], ids=["1", "2"])

results = vector_store.similarity_search_with_score(
    query="surreal", k=1, custom_filter={"source": "https://surrealdb.com"}
)
for doc, score in results:
    print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")

Next steps

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_surrealdb-0.2.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_surrealdb-0.2.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file langchain_surrealdb-0.2.0.tar.gz.

File metadata

  • Download URL: langchain_surrealdb-0.2.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for langchain_surrealdb-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8d4e9ac8a8e5e573f36980b9e73e2d0348671346eaefd36915548ba5b5074135
MD5 40da77ad48870a1085e8f8b6e2732d8e
BLAKE2b-256 aede76399a40ae091d20934f14fc4c550b1ccd9e2470fd103d756d2ae3aa3aeb

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_surrealdb-0.2.0.tar.gz:

Publisher: release.yml on surrealdb/langchain-surrealdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_surrealdb-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_surrealdb-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a430a4a641f9aadfde590206e98c98ea1e715db2a93c664aaef58a4109b2d3aa
MD5 f1cf304d2f9e77ae31c935ba6fd2359b
BLAKE2b-256 e9950ca6e4db3b310313bc2738c8c28425578126aaa0120bd32f04e231724fd4

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_surrealdb-0.2.0-py3-none-any.whl:

Publisher: release.yml on surrealdb/langchain-surrealdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page