Skip to main content
你可以使用本地 NucliaDB 实例,也可以使用 Nuclia Cloud 使用本地实例时,你需要一个 Nuclia Understanding API 密钥,以便对文本进行正确的向量化和索引处理。你可以在 https://nuclia.cloud 注册免费账户来获取密钥,然后创建一个 NUA 密钥
pip install -qU  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)

使用本地实例

注意:默认情况下,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")

向知识库中添加和删除文本

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)