Skip to main content

SurrealDB

SurrealDB is an end-to-end cloud-native database designed for modern applications, including web, mobile, serverless, Jamstack, backend, and traditional applications. With SurrealDB, you can simplify your database and API infrastructure, reduce development time, and build secure, performant apps quickly and cost-effectively.

Key features of SurrealDB include:

  • Reduces development time: SurrealDB simplifies your database and API stack by removing the need for most server-side components, allowing you to build secure, performant apps faster and cheaper.
  • Real-time collaborative API backend service: SurrealDB functions as both a database and an API backend service, enabling real-time collaboration.
  • Support for multiple querying languages: SurrealDB supports SQL querying from client devices, GraphQL, ACID transactions, WebSocket connections, structured and unstructured data, graph querying, full-text indexing, and geospatial querying.
  • Granular access control: SurrealDB provides row-level permissions-based access control, giving you the ability to manage data access with precision.

View the features, the latest releases, and documentation.

This notebook shows how to use functionality related to the SurrealDBLoader.

Overview

The SurrealDB Document Loader returns a list of Langchain Documents from a SurrealDB database.

The Document Loader takes the following optional parameters:

  • dburl: connection string to the websocket endpoint. default: ws://localhost:8000/rpc
  • ns: name of the namespace. default: langchain
  • db: name of the database. default: database
  • table: name of the table. default: documents
  • db_user: SurrealDB credentials if needed: db username.
  • db_pass: SurrealDB credentails if needed: db password.
  • filter_criteria: dictionary to construct the WHERE clause for filtering results from table.

The output Document takes the following shape:

Document(
page_content=<json encoded string containing the result document>,
metadata={
'id': <document id>,
'ns': <namespace name>,
'db': <database_name>,
'table': <table name>,
... <additional fields from metadata property of the document>
}
)

Setup

Uncomment the below cells to install surrealdb and langchain.

# %pip install --upgrade --quiet  surrealdb langchain langchain-community
# add this import for running in jupyter notebook
import nest_asyncio

nest_asyncio.apply()
import json

from langchain_community.document_loaders.surrealdb import SurrealDBLoader

API Reference:

loader = SurrealDBLoader(
dburl="ws://localhost:8000/rpc",
ns="langchain",
db="database",
table="documents",
db_user="root",
db_pass="root",
filter_criteria={},
)
docs = loader.load()
len(docs)
42
doc = docs[-1]
doc.metadata
{'id': 'documents:zzz434sa584xl3b4ohvk',
'source': '../../how_to/state_of_the_union.txt',
'ns': 'langchain',
'db': 'database',
'table': 'documents'}
len(doc.page_content)
18078
page_content = json.loads(doc.page_content)
page_content["text"]
'When we use taxpayer dollars to rebuild America – we are going to Buy American: buy American products to support American jobs. \n\nThe federal government spends about $600 Billion a year to keep the country safe and secure. \n\nThere’s been a law on the books for almost a century \nto make sure taxpayers’ dollars support American jobs and businesses. \n\nEvery Administration says they’ll do it, but we are actually doing it. \n\nWe will buy American to make sure everything from the deck of an aircraft carrier to the steel on highway guardrails are made in America. \n\nBut to compete for the best jobs of the future, we also need to level the playing field with China and other competitors. \n\nThat’s why it is so important to pass the Bipartisan Innovation Act sitting in Congress that will make record investments in emerging technologies and American manufacturing. \n\nLet me give you one example of why it’s so important to pass it.'

Was this page helpful?


You can leave detailed feedback on GitHub.