SurrealDB
SurrealDB 是一個端到端的雲原生資料庫,專為現代應用程式設計,包括網路、行動、無伺服器、Jamstack、後端和傳統應用程式。 透過 SurrealDB,您可以簡化資料庫和 API 基礎架構、縮短開發時間,並以經濟高效的方式快速建置安全、高效能的應用程式。
SurrealDB 的主要功能包括:
- 縮短開發時間: SurrealDB 透過移除大多數伺服器端元件的需求,簡化了您的資料庫和 API 堆疊,讓您可以更快、更便宜地建置安全、高效能的應用程式。
- 即時協作 API 後端服務: SurrealDB 同時作為資料庫和 API 後端服務,實現即時協作。
- 支援多種查詢語言: SurrealDB 支援從客戶端裝置進行 SQL 查詢、GraphQL、ACID 交易、WebSocket 連線、結構化和非結構化資料、圖形查詢、全文索引和地理空間查詢。
- 細緻的存取控制: SurrealDB 提供基於列級權限的存取控制,讓您可以精確地管理資料存取。
這個筆記本展示了如何使用與 SurrealDBLoader
相關的功能。
概述
SurrealDB Document Loader 從 SurrealDB 資料庫傳回 Langchain 文件列表。
Document Loader 接受以下可選參數:
dburl
:連線到 WebSocket 端點的連線字串。 預設值:ws://127.0.0.1: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://127.0.0.1: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.'