Skip to main content
Open In Colab在 GitHub 上打开

NucliaDB 数据库

您可以使用本地 NucliaDB 实例或使用 Nuclia Cloud

使用本地实例时,您需要一个 Nuclia Understanding API 密钥,以便您的文本得到适当的矢量化和索引。您可以通过在 https://nuclia.cloud 上创建免费账户来获取密钥,然后创建 NUA 密钥

%pip install --upgrade --quiet  langchain langchain-community nuclia

与 nuclia.cloud 一起使用

from langchain_community.vectorstores.nucliadb import NucliaDB

API_KEY = "YOUR_API_KEY"

ndb = NucliaDB(knowledge_box="YOUR_KB_ID", local=False, api_key=API_KEY)
API 参考:NucliaDB

与本地实例的用法

注意:默认情况下backend设置为http://localhost:8080.

from langchain_community.vectorstores.nucliadb import NucliaDB

ndb = NucliaDB(knowledge_box="YOUR_KB_ID", local=True, backend="http://my-local-server")
API 参考:NucliaDB

向 Knowledge Box 添加和删除文本

ids = ndb.add_texts(["This is a new test", "This is a second test"])
ndb.delete(ids=ids)

在您的知识框中搜索

results = ndb.similarity_search("Who was inspired by Ada Lovelace?")
print(results[0].page_content)