SurrealDB
SurrealDB 是一个为现代应用设计的端到端云原生数据库,包括网络、移动、无服务器、Jamstack、后端和传统应用。借助 SurrealDB,您可以简化您的数据库和 API 基础设施,减少开发时间,并快速经济地构建安全高效的应用程序。
SurrealDB 的主要功能包括:
- 减少开发时间: SurrealDB 通过消除大多数服务器端组件简化了您的数据库和API堆栈,使您能够更快、更便宜地构建安全高效的应用程序。
- 实时协作API后端服务: SurrealDB 既作为数据库也作为API后端服务,支持实时协作。
- 支持多种查询语言: SurrealDB 支持客户端设备的 SQL 查询、GraphQL、ACID 事务、WebSocket 连接、结构化和非结构化数据、图查询、全文索引以及地理空间查询。
- 细粒度访问控制: SurrealDB 提供基于行级权限的访问控制,使您能够精确管理数据访问。
这个笔记本展示了如何使用与SurrealDBLoader相关的功能。
概览
The SurrealDB 文档加载器会从 SurrealDB 数据库返回一个 Langchain 文档列表。
The Document Loader 可接受以下可选参数:
dburl: 连接字符串,用于websocket端点。默认值:ws://localhost:8000/rpcns: 空间命名的名称。默认:langchaindb: 数据库名称。默认值:databasetable: 表格的名称。默认:documentsdb_user: 如果需要,SurrealDB凭据:数据库用户名。db_pass: 若需要,SurrealDB凭证:数据库密码。filter_criteria: 构造从表格中过滤结果的WHERE子句的字典。
The output 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.'