Files
langchain/docs/versioned_docs/version-0.2.x/integrations/retrievers/dria_index.ipynb
Jacob Lee aff771923a Jacob/new docs (#20570)
Use docusaurus versioning with a callout, merged master as well

@hwchase17 @baskaryan

---------

Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Rahul Tripathi <rauhl.psit.ec@gmail.com>
Co-authored-by: Leonid Ganeline <leo.gan.57@gmail.com>
Co-authored-by: Leonid Kuligin <lkuligin@yandex.ru>
Co-authored-by: Averi Kitsch <akitsch@google.com>
Co-authored-by: Erick Friis <erick@langchain.dev>
Co-authored-by: Nuno Campos <nuno@langchain.dev>
Co-authored-by: Nuno Campos <nuno@boringbits.io>
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Martín Gotelli Ferenaz <martingotelliferenaz@gmail.com>
Co-authored-by: Fayfox <admin@fayfox.com>
Co-authored-by: Eugene Yurtsev <eugene@langchain.dev>
Co-authored-by: Dawson Bauer <105886620+djbauer2@users.noreply.github.com>
Co-authored-by: Ravindu Somawansa <ravindu.somawansa@gmail.com>
Co-authored-by: Dhruv Chawla <43818888+Dominastorm@users.noreply.github.com>
Co-authored-by: ccurme <chester.curme@gmail.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
Co-authored-by: WeichenXu <weichen.xu@databricks.com>
Co-authored-by: Benito Geordie <89472452+benitoThree@users.noreply.github.com>
Co-authored-by: kartikTAI <129414343+kartikTAI@users.noreply.github.com>
Co-authored-by: Kartik Sarangmath <kartik@thirdai.com>
Co-authored-by: Sevin F. Varoglu <sfvaroglu@octoml.ai>
Co-authored-by: MacanPN <martin.triska@gmail.com>
Co-authored-by: Prashanth Rao <35005448+prrao87@users.noreply.github.com>
Co-authored-by: Hyeongchan Kim <kozistr@gmail.com>
Co-authored-by: sdan <git@sdan.io>
Co-authored-by: Guangdong Liu <liugddx@gmail.com>
Co-authored-by: Rahul Triptahi <rahul.psit.ec@gmail.com>
Co-authored-by: Rahul Tripathi <rauhl.psit.ec@gmail.com>
Co-authored-by: pjb157 <84070455+pjb157@users.noreply.github.com>
Co-authored-by: Eun Hye Kim <ehkim1440@gmail.com>
Co-authored-by: kaijietti <43436010+kaijietti@users.noreply.github.com>
Co-authored-by: Pengcheng Liu <pcliu.fd@gmail.com>
Co-authored-by: Tomer Cagan <tomer@tomercagan.com>
Co-authored-by: Christophe Bornet <cbornet@hotmail.com>
2024-04-18 11:10:55 -07:00

191 lines
3.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "UYyFIEKEkmHb"
},
"source": [
"# Dria\n",
"\n",
"Dria is a hub of public RAG models for developers to both contribute and utilize a shared embedding lake. This notebook demonstrates how to use the Dria API for data retrieval tasks."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "VNTFUgK9kmHd"
},
"source": [
"# Installation\n",
"\n",
"Ensure you have the `dria` package installed. You can install it using pip:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "X--1A8EEkmHd"
},
"outputs": [],
"source": [
"%pip install --upgrade --quiet dria"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "xRbRL0SgkmHe"
},
"source": [
"# Configure API Key\n",
"\n",
"Set up your Dria API key for access."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "hGqOByNMkmHe"
},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.environ[\"DRIA_API_KEY\"] = \"DRIA_API_KEY\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "nDfAEqQtkmHe"
},
"source": [
"# Initialize Dria Retriever\n",
"\n",
"Create an instance of `DriaRetriever`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "vlyorgCckmHe"
},
"outputs": [],
"source": [
"from langchain.retrievers import DriaRetriever\n",
"\n",
"api_key = os.getenv(\"DRIA_API_KEY\")\n",
"retriever = DriaRetriever(api_key=api_key)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "j7WUY5jBOLQd"
},
"source": [
"# **Create Knowledge Base**\n",
"\n",
"Create a knowledge on [Dria's Knowledge Hub](https://dria.co/knowledge)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "L5ER81eWOKnt"
},
"outputs": [],
"source": [
"contract_id = retriever.create_knowledge_base(\n",
" name=\"France's AI Development\",\n",
" embedding=DriaRetriever.models.jina_embeddings_v2_base_en.value,\n",
" category=\"Artificial Intelligence\",\n",
" description=\"Explore the growth and contributions of France in the field of Artificial Intelligence.\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9VCTzSFpkmHe"
},
"source": [
"# Add Data\n",
"\n",
"Load data into your Dria knowledge base."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xeTMafIekmHf"
},
"outputs": [],
"source": [
"texts = [\n",
" \"The first text to add to Dria.\",\n",
" \"Another piece of information to store.\",\n",
" \"More data to include in the Dria knowledge base.\",\n",
"]\n",
"\n",
"ids = retriever.add_texts(texts)\n",
"print(\"Data added with IDs:\", ids)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dy1UlvLCkmHf"
},
"source": [
"# Retrieve Data\n",
"\n",
"Use the retriever to find relevant documents given a query."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "9y3msv9tkmHf"
},
"outputs": [],
"source": [
"query = \"Find information about Dria.\"\n",
"result = retriever.get_relevant_documents(query)\n",
"for doc in result:\n",
" print(doc)"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.x"
}
},
"nbformat": 4,
"nbformat_minor": 0
}