Skip to content

Commit

Permalink
Merge pull request #144 from vanna-ai/marqo
Browse files Browse the repository at this point in the history
Add Marqo as a vector storage option
  • Loading branch information
zainhoda committed Jan 8, 2024
2 parents 99d5ba5 + ff468ed commit 8871564
Show file tree
Hide file tree
Showing 103 changed files with 268 additions and 76 deletions.
2 changes: 1 addition & 1 deletion notebooks/bigquery-mistral-chromadb.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions notebooks/bigquery-mistral-marqo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells": [{"id": "fda9bc52-4501-5569-953e-0f1ebff8b5eb", "cell_type": "markdown", "execution_count": null, "metadata": {}, "outputs": [], "source": "# Generating SQL for BigQuery using Mistral via Mistral API, Marqo\nThis notebook runs through the process of using the `vanna` Python package to generate SQL using AI (RAG + LLMs) including connecting to a database and training. If you're not ready to train on your own database, you can still try it using a sample [SQLite database](getting-started.html)."}, {"id": "ba570f08-fcb8-5fa8-967b-7c3e400d610d", "cell_type": "markdown", "execution_count": null, "metadata": {}, "outputs": [], "source": "\n<h3 class=\"mb-5 text-lg font-medium text-gray-900 dark:text-white\">Which LLM do you want to use?</h3>\n<ul class=\"grid w-full gap-6 md:grid-cols-2\">\n \n <li>\n <a href=\"bigquery-openai-vanna-vannadb.html\" class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 peer-checked:border-blue-600 peer-checked:text-blue-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300 dark:peer-checked:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\">OpenAI via Vanna.AI (Recommended)</div>\n <small class=\"w-full\">Use Vanna.AI for free to generate your queries</small>\n </div>\n </a>\n </li>\n \n <li>\n <a href=\"bigquery-openai-standard-marqo.html\" class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 peer-checked:border-blue-600 peer-checked:text-blue-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300 dark:peer-checked:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\">OpenAI</div>\n <small class=\"w-full\">Use OpenAI with your own API key</small>\n </div>\n </a>\n </li>\n \n <li>\n <a href=\"bigquery-openai-azure-marqo.html\" class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 peer-checked:border-blue-600 peer-checked:text-blue-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300 dark:peer-checked:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\">Azure OpenAI</div>\n <small class=\"w-full\">If you have OpenAI models deployed on Azure</small>\n </div>\n </a>\n </li>\n \n <li>\n <span class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border bg-white p-5 border-blue-600 text-blue-600 dark:bg-gray-800 dark:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\"><span class=\"hidden\">[Selected]</span> Mistral via Mistral API</div>\n <small class=\"w-full\">If you have a Mistral API key</small>\n </div>\n </span>\n </li>\n \n <li>\n <a href=\"bigquery-other-llm-marqo.html\" class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 peer-checked:border-blue-600 peer-checked:text-blue-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300 dark:peer-checked:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\">Other LLM</div>\n <small class=\"w-full\">If you have a different LLM model</small>\n </div>\n </a>\n </li>\n \n</ul>\n "}, {"id": "0ef5320d-f0cc-57b8-993e-f938ff50b6ba", "cell_type": "markdown", "execution_count": null, "metadata": {}, "outputs": [], "source": "\n<h3 class=\"mb-5 text-lg font-medium text-gray-900 dark:text-white\">Where do you want to store the 'training' data?</h3>\n<ul class=\"grid w-full gap-6 md:grid-cols-2\">\n \n <li>\n <a href=\"bigquery-mistral-vannadb.html\" class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 peer-checked:border-blue-600 peer-checked:text-blue-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300 dark:peer-checked:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\">Vanna Hosted Vector DB (Recommended)</div>\n <small class=\"w-full\">Use Vanna.AIs hosted vector database (pgvector) for free. This is usable across machines with no additional setup.</small>\n </div>\n </a>\n </li>\n \n <li>\n <a href=\"bigquery-mistral-chromadb.html\" class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 peer-checked:border-blue-600 peer-checked:text-blue-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300 dark:peer-checked:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\">ChromaDB</div>\n <small class=\"w-full\">Use ChromaDBs open-source vector database for free locally. No additional setup is necessary -- all database files will be created and stored locally.</small>\n </div>\n </a>\n </li>\n \n <li>\n <span class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border bg-white p-5 border-blue-600 text-blue-600 dark:bg-gray-800 dark:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\"><span class=\"hidden\">[Selected]</span> Marqo</div>\n <small class=\"w-full\">Use Marqo locally for free. Requires additional setup. Or use their hosted option.</small>\n </div>\n </span>\n </li>\n \n <li>\n <a href=\"bigquery-mistral-other-vectordb.html\" class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 peer-checked:border-blue-600 peer-checked:text-blue-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300 dark:peer-checked:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\">Other VectorDB</div>\n <small class=\"w-full\">Use any other vector database. Requires additional setup.</small>\n </div>\n </a>\n </li>\n \n</ul>\n "}, {"id": "ee059407-58ac-50fa-843a-7b876328df13", "cell_type": "markdown", "execution_count": null, "metadata": {}, "outputs": [], "source": "## Setup"}, {"id": "fedb304d-43d5-5d20-9a58-9967908a4dc5", "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "%pip install 'vanna[marqo,mistralai,bigquery]'"}, {"id": "696e9c9c-d724-56db-9a06-10a66dc15b0a", "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "from vanna.marqo.marqo import Marqo\nfrom vanna.mistral.mistral import Mistral\n"}, {"id": "de83d46a-6116-5978-8b9a-f0f586a583bd", "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "\n\n\nclass MyVanna(Marqo, Mistral):\n def __init__(self, config=None):\n Marqo.__init__(self, config={'marqo_url': MARQO_URL, 'marqo_model': MARQO_MODEL})\n Mistral.__init__(self, config={'api_key': MISTRAL_API_KEY, 'model': 'mistral-tiny'})\n\nvn = MyVanna()\n"}, {"id": "15b5737f-f7ff-5f9e-89fb-c06431c6a802", "cell_type": "markdown", "execution_count": null, "metadata": {}, "outputs": [], "source": "\n<h3 class=\"mb-5 text-lg font-medium text-gray-900 dark:text-white\">Which database do you want to query?</h3>\n<ul class=\"grid w-full gap-6 md:grid-cols-2\">\n \n <li>\n <a href=\"sqlite-mistral-marqo.html\" class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 peer-checked:border-blue-600 peer-checked:text-blue-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300 dark:peer-checked:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\">SQLite</div>\n <small class=\"w-full\"></small>\n </div>\n </a>\n </li>\n \n <li>\n <a href=\"snowflake-mistral-marqo.html\" class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 peer-checked:border-blue-600 peer-checked:text-blue-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300 dark:peer-checked:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\">Snowflake</div>\n <small class=\"w-full\"></small>\n </div>\n </a>\n </li>\n \n <li>\n <span class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border bg-white p-5 border-blue-600 text-blue-600 dark:bg-gray-800 dark:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\"><span class=\"hidden\">[Selected]</span> BigQuery</div>\n <small class=\"w-full\"></small>\n </div>\n </span>\n </li>\n \n <li>\n <a href=\"postgres-mistral-marqo.html\" class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 peer-checked:border-blue-600 peer-checked:text-blue-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300 dark:peer-checked:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\">Postgres</div>\n <small class=\"w-full\"></small>\n </div>\n </a>\n </li>\n \n <li>\n <a href=\"other-database-mistral-marqo.html\" class=\"inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 peer-checked:border-blue-600 peer-checked:text-blue-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300 dark:peer-checked:text-blue-500\">\n <div class=\"block\">\n <div class=\"w-full text-lg font-semibold\">Other Database</div>\n <small class=\"w-full\">Use Vanna to generate queries for any SQL database</small>\n </div>\n </a>\n </li>\n \n</ul>\n "}, {"id": "45b52fa3-74ea-5bb0-82e5-518731dbe674", "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "vn.connect_to_bigquery(project_id='my-project')"}, {"id": "f06c0e89-83f7-5ad1-8f6e-a64cf5bd8e60", "cell_type": "markdown", "execution_count": null, "metadata": {}, "outputs": [], "source": "## Training\nYou only need to train once. Do not train again unless you want to add more training data."}, {"id": "5d321d01-d66f-5c5e-a3f3-e2d3d4330344", "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "\n# The information schema query may need some tweaking depending on your database. This is a good starting point.\ndf_information_schema = vn.run_sql(\"SELECT * FROM INFORMATION_SCHEMA.COLUMNS\")\n\n# This will break up the information schema into bite-sized chunks that can be referenced by the LLM\nplan = vn.get_training_plan_generic(df_information_schema)\nplan\n\n# If you like the plan, then uncomment this and run it to train\n# vn.train(plan=plan)\n\n"}, {"id": "7c421f88-42ea-567c-8581-3dcac96c36a3", "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "\n# The following are methods for adding training data. Make sure you modify the examples to match your database.\n\n# DDL statements are powerful because they specify table names, colume names, types, and potentially relationships\nvn.train(ddl=\"\"\"\n CREATE TABLE IF NOT EXISTS my-table (\n id INT PRIMARY KEY,\n name VARCHAR(100),\n age INT\n )\n\"\"\")\n\n# Sometimes you may want to add documentation about your business terminology or definitions.\nvn.train(documentation=\"Our business defines OTIF score as the percentage of orders that are delivered on time and in full\")\n\n# You can also add SQL queries to your training data. This is useful if you have some queries already laying around. You can just copy and paste those from your editor to begin generating new SQL.\nvn.train(sql=\"SELECT * FROM my-table WHERE name = 'John Doe'\")\n"}, {"id": "59fcb3b1-4434-583d-82be-ed8e9b04d699", "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "# At any time you can inspect what training data the package is able to reference\ntraining_data = vn.get_training_data()\ntraining_data"}, {"id": "0dd237e6-ab36-5dd4-9234-e2d25168d50f", "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "# You can remove training data if there's obsolete/incorrect information. \nvn.remove_training_data(id='1-ddl')"}, {"id": "bf2fc121-a3ab-5a2e-95b0-383271e82d5f", "cell_type": "markdown", "execution_count": null, "metadata": {}, "outputs": [], "source": "## Asking the AI\nWhenever you ask a new question, it will find the 10 most relevant pieces of training data and use it as part of the LLM prompt to generate the SQL."}, {"id": "edb6679e-a102-5efc-b890-81babca8f500", "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "vn.ask(question=...)"}, {"id": "644da41f-f753-5456-81d9-329a3ead11fe", "cell_type": "markdown", "execution_count": null, "metadata": {}, "outputs": [], "source": "## Next Steps\nUsing Vanna via Jupyter notebooks is great for getting started but check out additional interfaces like the \n- [Streamlit app](https://github.com/vanna-ai/vanna-streamlit)\n- [Flask app](https://github.com/vanna-ai/vanna-flask)\n- [Slackbot](https://github.com/vanna-ai/vanna-slack)\n- [Vanna Hosted Web App](https://app.vanna.ai)"}], "metadata": {"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.8.5"}}, "nbformat": 4, "nbformat_minor": 5}
Loading

0 comments on commit 8871564

Please sign in to comment.