Skip to main content

Dria

Dria 是一个公共RAG模型的中心,供开发者贡献和利用共享的嵌入湖。本笔记本演示了如何使用 Dria API 进行数据检索任务。

安装

确保您已安装 dria 包。您可以使用pip进行安装:

%pip install --upgrade --quiet dria

配置 API 密钥

设置您的 Dria API 密钥以进行访问。

import os

os.environ["DRIA_API_KEY"] = "DRIA_API_KEY"

初始化 Dria 检索器

创建 DriaRetriever 的实例。

<!--IMPORTS:[{"imported": "DriaRetriever", "source": "langchain_community.retrievers", "docs": "https://python.langchain.com/api_reference/community/retrievers/langchain_community.retrievers.dria_index.DriaRetriever.html", "title": "Dria"}]-->
from langchain_community.retrievers import DriaRetriever

api_key = os.getenv("DRIA_API_KEY")
retriever = DriaRetriever(api_key=api_key)

创建知识库

Dria 的知识中心 创建知识

contract_id = retriever.create_knowledge_base(
name="France's AI Development",
embedding=DriaRetriever.models.jina_embeddings_v2_base_en.value,
category="Artificial Intelligence",
description="Explore the growth and contributions of France in the field of Artificial Intelligence.",
)

添加数据

将数据加载到您的 Dria 知识库中。

texts = [
"The first text to add to Dria.",
"Another piece of information to store.",
"More data to include in the Dria knowledge base.",
]

ids = retriever.add_texts(texts)
print("Data added with IDs:", ids)

检索数据

使用检索器根据查询查找相关文档。

query = "Find information about Dria."
result = retriever.invoke(query)
for doc in result:
print(doc)

相关


Was this page helpful?


You can also leave detailed feedback on GitHub.

扫我,入群扫我,找书