Skip to main content
Open In ColabOpen on GitHub

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.

本笔记本展示了如何使用与SurrealDBLoader相关的功能。

概览

SurrealDB 文档加载器从 SurrealDB 数据库返回一个 LangChain 文档列表。

文档加载器接受以下可选参数:

  • dburl:WebSocket 端点的连接字符串。默认值:ws://localhost:8000/rpc
  • ns:命名空间的名称。默认值:langchain
  • db: 数据库名称。默认值:database
  • table: 表名。默认值:documents
  • db_user:如需 SurrealDB 凭据:数据库用户名。
  • db_pass: 如需 SurrealDB 凭据:数据库密码。
  • filter_criteria: 用于构建 WHERE 子句的字典,以便从表中过滤结果。

输出 Document 采用以下形状:

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>
}
)

设置

取消注释以下单元格以安装 surrealdb 和 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 参考:SurrealDBLoader
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.'