跳到主要內容
Open In ColabOpen on GitHub

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 的實例。

from langchain_community.retrievers import DriaRetriever

api_key = os.getenv("DRIA_API_KEY")
retriever = DriaRetriever(api_key=api_key)
API 參考:DriaRetriever

建立知識庫

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)

此頁面是否對您有幫助?