Langchain
LangChain is a framework for developing applications powered by large language models (LLMs). SurrealDB is an excellent database choice for LangChain projects primarily because of its multi-model capabilities, which streamline data management by requiring only a single database.
This unified system adeptly handles structured and unstructured data, incorporating vector search, graph traversal, relational queries, full-text search, document storage, and time-series data all within one ACID-compliant engine.
For LangChain applications, which often juggle diverse data types for tasks like context retrieval and complex data interactions, SurrealDB's ability to consolidate these needs into one platform simplifies architecture, reduces latency, and ensures data consistency, making it a highly efficient and powerful backend solution.
In this guide, we'll walk through how to use SurrealDB as a vector store for LangChain.
Setup
You can run SurrealDB locally or start with a free SurrealDB Cloud account.
For local, two options:
Install SurrealDB and run SurrealDB. Run in-memory with:
Install dependencies
surrealdb→ SurrealDB Python SDKlangchain-surrealdb→ housesSurrealDBVectorStorelangchain_ollama,langchain-openai(or HF, Cohere, etc.) → embeddings
Quick start
Create a vector store, and documents with embeddings, and do a similarity search.
Under the hood the helper will:
Create table
documents(if it doesn’t exist).Add an M-Tree index with the correct dimensionality.
Insert each text with its freshly generated embedding.
Similarity search
If you want to get the score with the results, use similarity_search_with_score instead.
You can also transform the vector store into a retriever for easier usage in your chains.
Next steps
Now that you have a basic understanding of how to use SurrealDB with LangChain, let's explore some additional resources to help you dive deeper and build more sophisticated applications.
To help you get started quickly, we provide several example implementations:
A basic example with a ready-to-use Dockerfile - perfect for your first steps
A more advanced graph example showcasing graph capabilities
An interactive Jupyter notebook for hands-on learning
Further reading and resources
For a deeper understanding of the technology stack:
Explore the SurrealDB vector-search reference for detailed technical information
Check out the LangChain API docs for
SurrealDBStorefor comprehensive API documentationBrowse Awesome SurrealDB for a curated collection of resources, tools, and applications
That’s it – you now have a fully-featured LangChain vector store powered by SurrealDB, no boilerplate required. 🚀