{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "source": [ "## Cookbook for using ChromaDB with Embedchain" ], "metadata": { "id": "b02n_zJ_hl3d" } }, { "cell_type": "markdown", "source": [ "### Step-1: Install embedchain package" ], "metadata": { "id": "gyJ6ui2vhtMY" } }, { "cell_type": "code", "source": [ "!pip install embedchain" ], "metadata": { "id": "-NbXjAdlh0vJ" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "### Step-2: Set OpenAI environment variables\n", "\n", "You can find this env variable on your [OpenAI dashboard](https://platform.openai.com/account/api-keys)." ], "metadata": { "id": "nGnpSYAAh2bQ" } }, { "cell_type": "code", "source": [ "import os\n", "from embedchain import App\n", "\n", "os.environ[\"OPENAI_API_KEY\"] = \"sk-xxx\"" ], "metadata": { "id": "0fBdQ9GAiRvK" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "### Step-3: Define your Vector Database config" ], "metadata": { "id": "Ns6RhPfbiitr" } }, { "cell_type": "code", "source": [ "config = \"\"\"\n", "vectordb:\n", " provider: chroma\n", " config:\n", " collection_name: 'my-collection'\n", " # CHANGE THE BELOW TWO LINES!\n", " # pass remote database variables - host and port\n", " host: your-chromadb-url.com\n", " port: 5200\n", " allow_reset: true\n", "\"\"\"\n", "\n", "# Write the multi-line string to a YAML file\n", "with open('chromadb.yaml', 'w') as file:\n", " file.write(config)" ], "metadata": { "id": "S9CkxVjriotB" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "### Step-4 Create embedchain app based on the config" ], "metadata": { "id": "PGt6uPLIi1CS" } }, { "cell_type": "code", "source": [ "app = App.from_config(yaml_path=\"chromadb.yaml\")" ], "metadata": { "id": "Amzxk3m-i3tD" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "### Step-5: Add data sources to your app" ], "metadata": { "id": "XNXv4yZwi7ef" } }, { "cell_type": "code", "source": [ "app.add(\"https://www.forbes.com/profile/elon-musk\")" ], "metadata": { "id": "Sn_0rx9QjIY9" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "### Step-6: All set. Now start asking questions related to your data" ], "metadata": { "id": "_7W6fDeAjMAP" } }, { "cell_type": "code", "source": [ "while(True):\n", " question = input(\"Enter question: \")\n", " if question in ['q', 'exit', 'quit']:\n", " break\n", " answer = app.query(question)\n", " print(answer)" ], "metadata": { "id": "cvIK7dWRjN_f" }, "execution_count": null, "outputs": [] } ] }