SurrealDB
SurrealDB 是一款面向现代应用程序(包括 Web、移动、无服务器、Jamstack、后端和传统应用程序)的端到端云原生数据库。借助 SurrealDB,您可以简化数据库和 API 基础架构,缩短开发时间,并以经济高效的方式快速构建安全、高性能的应用程序。
SurrealDB 的主要特点包括:
- 缩短开发时间: SurrealDB 通过消除大多数服务器端组件的需求,简化了您的数据库和 API 堆栈,使您能够更快、更经济地构建安全、高性能的应用程序。
- 实时协作 API 后端服务: SurrealDB 同时充当数据库和 API 后端服务,支持实时协作。
- 支持多种查询语言: SurrealDB 支持来自客户端设备的 SQL 查询、GraphQL、ACID 事务、WebSocket 连接、结构化和非结构化数据、图查询、全文索引和地理空间查询。
- 精细的访问控制: SurrealDB 提供基于行级权限的访问控制,使您能够精确地管理数据访问。
本 Notebook 展示了如何使用与 SurrealDBLoader 相关的功能。
概述
SurrealDB Document Loader 从 SurrealDB 数据库返回一系列 Langchain Documents。
Document Loader 接受以下可选参数:
dburl: 连接到 websocket 端点的连接字符串。默认值:ws://localhost:8000/rpcns: 命名空间的名称。默认值:langchaindb: 数据库的名称。默认值:databasetable: 表的名称。默认值:documentsdb_user: 如果需要,提供 SurrealDB 凭证:数据库用户名。db_pass: 如果需要,提供 SurrealDB 凭证:数据库密码。filter_criteria: 用于构造WHERE子句的字典,用于过滤表中的结果。
输出的 Document 具有以下形状:
Document(
page_content=<包含结果文档的 json 编码字符串>,
metadata={
'id': <文档 ID>,
'ns': <命名空间名称>,
'db': <数据库名称>,
'table': <表名称>,
... <文档元数据属性中的其他字段>
}
)
设置
取消注释下面的单元格以安装 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 Reference: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.'
Related
- Document loader conceptual guide
- Document loader how-to guides