跳到主要內容

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)

此頁面是否有幫助?