diff --git "a/scripts/07_Reranking.ipynb" "b/scripts/07_Reranking.ipynb" new file mode 100644--- /dev/null +++ "b/scripts/07_Reranking.ipynb" @@ -0,0 +1,9309 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "jThylW3TKQ5t" + }, + "source": [ + "# Optimise Query" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "fNjMa3DlKPIM", + "outputId": "0d5196dc-ec5c-48c7-ee7a-8091c9e798b8" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/67.3 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.3/67.3 kB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", + " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", + " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m81.9/81.9 kB\u001b[0m \u001b[31m6.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m42.9/42.9 kB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m455.6/455.6 kB\u001b[0m \u001b[31m31.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m56.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m481.1/481.1 kB\u001b[0m \u001b[31m27.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m602.1/602.1 kB\u001b[0m \u001b[31m35.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m259.5/259.5 kB\u001b[0m \u001b[31m19.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m81.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m284.2/284.2 kB\u001b[0m \u001b[31m22.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m91.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m74.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.6/7.6 MB\u001b[0m \u001b[31m116.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m266.8/266.8 kB\u001b[0m \u001b[31m20.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.0/41.0 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━��━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m101.6/101.6 kB\u001b[0m \u001b[31m8.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m16.4/16.4 MB\u001b[0m \u001b[31m99.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m65.8/65.8 kB\u001b[0m \u001b[31m5.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m55.7/55.7 kB\u001b[0m \u001b[31m4.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m196.2/196.2 kB\u001b[0m \u001b[31m15.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m118.5/118.5 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.5/4.5 MB\u001b[0m \u001b[31m99.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m103.4/103.4 kB\u001b[0m \u001b[31m7.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m186.1/186.1 kB\u001b[0m \u001b[31m13.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m459.8/459.8 kB\u001b[0m \u001b[31m30.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m374.1/374.1 kB\u001b[0m \u001b[31m25.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m304.2/304.2 kB\u001b[0m \u001b[31m22.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m363.4/363.4 MB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.8/13.8 MB\u001b[0m \u001b[31m105.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m24.6/24.6 MB\u001b[0m \u001b[31m87.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m883.7/883.7 kB\u001b[0m \u001b[31m48.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m664.8/664.8 MB\u001b[0m \u001b[31m2.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m211.5/211.5 MB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.3/56.3 MB\u001b[0m \u001b[31m35.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m127.9/127.9 MB\u001b[0m \u001b[31m18.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m207.5/207.5 MB\u001b[0m \u001b[31m3.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m21.1/21.1 MB\u001b[0m \u001b[31m91.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.0/4.0 MB\u001b[0m \u001b[31m97.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m453.1/453.1 kB\u001b[0m \u001b[31m30.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.0/46.0 kB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m207.4/207.4 kB\u001b[0m \u001b[31m16.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m86.8/86.8 kB\u001b[0m \u001b[31m7.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.9/50.9 kB\u001b[0m \u001b[31m3.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m115.4/115.4 kB\u001b[0m \u001b[31m8.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m129.3/129.3 kB\u001b[0m \u001b[31m10.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h Building wheel for pypika (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", + "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", + "ipython 7.34.0 requires jedi>=0.16, which is not installed.\u001b[0m\u001b[31m\n", + "\u001b[0m" + ] + } + ], + "source": [ + "# Install requirements\n", + "\n", + "!pip install -q llama-index==0.12.21 openai==1.59.8 tiktoken==0.8.0 huggingface-hub==0.30 chromadb==0.6.0 llama-index-vector-stores-chroma==0.4.1 llama-index-llms-gemini==0.4.1 llama-index-finetuning==0.3.2 llama-index-postprocessor-cohere-rerank==0.3.0 llama-index-embeddings-huggingface==0.5.4 llama-index-embeddings-cohere==0.5.0 cohere==5.15.0" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "QNcwfYyDT2Sk" + }, + "outputs": [], + "source": [ + "import os\n", + "\n", + "# Set the following API Keys in the Python environment. Will be used later.\n", + "\n", + "from google.colab import userdata\n", + "os.environ[\"OPENAI_API_KEY\"] = userdata.get('openai_api_key')\n", + "os.environ[\"GOOGLE_API_KEY\"] = userdata.get('google_api_key')\n", + "os.environ[\"CO_API_KEY\"] = userdata.get('co_api_key')\n", + "cohere_key = userdata.get('co_api_key')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "oTf1T6BLXwOo" + }, + "outputs": [], + "source": [ + "# Allows running asyncio in environments with an existing event loop, like Jupyter notebooks.\n", + "\n", + "import nest_asyncio\n", + "\n", + "nest_asyncio.apply()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "O813m1RzX4C9" + }, + "source": [ + "# Load model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 163, + "referenced_widgets": [ + "46070b9a58d94617a9bb47c2f66c36eb", + "3461f5ecbcd1476c9738ecfe91b79be0", + "7a322d1a11744eb285f7d73bedb8a5d2", + "1a31f92ac41d46feb208296398337a11", + "5cc5fa132d9b4488810b8a4edb1505af", + "300e76964dca48f8bca8877e51ec74c7", + "50eb694b42fd4e80bba9814152f3578f", + "742de565b5d74b76a90dc50cc2969366", + "572e37c547514ff78d062ee170d9a636", + "e14d4a8fb0234811b9ebf3fed4ac5968", + "e811456e95c94c439bff7824d0f9b218", + "83becfcc0e0049d09e2ee671140e5f7f", + "2dd4cabc00b943928c8e6269f89ca070", + "db7e0e81851c444aa5268e5e5282633b", + "06ade2a995a04c25bf44a9f8bdfb6aca", + "40476e00dfb24dc8a15df7afcef60f70", + "fcd3aaf0875f441e830a1937e9f8659c", + "82ee1c5b89d64d49957f62afadcb3900", + "b8fc9a18907944f59490b5d5392cc13b", + "0a713bbc6ff1412781f27140934db31b", + "ce63d00c153641d88230ea3f645fa5e5", + "5322c67f55754abdb5231c479f1bc14c", + "43a547ed2bc740869dd84c2d9d488124", + "e4c01ddf132147e5b9ee6234449f04f5", + "886734788c444c4c956e4818a9a7fe8b", + "e25ac3c4ba0446e5b61f672672af1726", + "5b4e345c61224f0a9f091fbb3ddef5e5", + "379190df9b7e4f3382b93babf117f198", + "30d0e9c578bf429a8651d071d0b20bde", + "efccf42241dc4f5ab2bd123de27ee803", + "392397607328485ca1b14c3d9b71052f", + "2ff2779fa731456ca1188713abd04249", + "6fa8e19022b44c629a256bcb844cfae5", + "64b40c91e6cf4142b2ebb31ac6a1416f", + "443ce789b3ff4239828ed162450d4dec", + "8d748de6c1fe43709f147af356ca5395", + "78f4ef666ea649659addabcb5bcb08b1", + "c9939ee4c6eb4281a469921b61a94d3c", + "906052a1f2b4407591c6a79dc8fc1d37", + "50327e85818f46619afdcbdff53fb58a", + "54f2c0839bf04806a3a46ca2c5507d7d", + "eb0643c12151461c9c5d7000b72ac0da", + "702a373fb4ed48b1acd893f61f5df639", + "74a3794498e94e5e91f51c43d2a1f24a" + ] + }, + "id": "b9_zcPPBCPvg", + "outputId": "cd3a3902-e39f-43c2-8772-c2053a385f3f" + }, + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Fetching 3 files: 0%| | 0/3 [00:00: RelatedNodeInfo(node_id='3325b42b-9e6f-54c7-8882-b5078237e102', node_type='4', metadata={'url': 'https://learn.microsoft.com/en-us/azure/architecture/networking/guide/spoke-to-spoke-networking', 'title': 'Patterns for inter-spoke networking - Azure Architecture Center | Microsoft Learn', 'tokens': 6417, 'retrieve_doc': True, 'source': 'azure-architecture'}, hash='b05298929d6f54c578805a0974e4584ef23bc187cf5ca95fa02ca9bfe0484bfe'), : RelatedNodeInfo(node_id='7f07f313-6e53-4ccf-98a1-73d136d619df', node_type='1', metadata={'url': 'https://learn.microsoft.com/en-us/azure/architecture/networking/guide/spoke-to-spoke-networking', 'title': 'Patterns for inter-spoke networking - Azure Architecture Center | Microsoft Learn', 'tokens': 6417, 'retrieve_doc': True, 'source': 'azure-architecture'}, hash='caad23bb6b5c5008fb5f6030b2bf67f336b13ec33638cf8b05a5f7f8a8df6444'), : RelatedNodeInfo(node_id='a6ed1991-f396-47a4-a63b-c0c4772d69e0', node_type='1', metadata={}, hash='ff66dda2b720ade30a171d63f555d0db27f53247f12047319b543a517ac354f4')}, metadata_template='{key}: {value}', metadata_separator='\\n', text=\"The most common networking design patterns in Azure involve creating hub-and-spoke virtual network topologies in one or multiple Azure regions, optionally connected to on-premises networks via Azure ExpressRoute or site-to-site virtual private network (VPN) tunnels over the public internet.\\n\\nMost design guides focus on application traffic to those virtual networks from users either in internal, on-premises networks or from the internet (what the industry typically designates _north-south traffic_, because it's often represented by vertical lines in network diagrams). This article focuses on various patterns that are available for _east-west traffic_. That is, communication flows among workloads deployed in Azure virtual networks, either within one region or in different regions.\\n\\nMaking sure that your network design satisfies requirements for east-west traffic is critical to providing performance, scalability, and resiliency to your applications that run in Azure.\\n\\n[Section titled: Potential use cases](https://learn.microsoft.com/en-us/azure/architecture/networking/guide/spoke-to-spoke-networking#potential-use-cases)\\n\\n## Potential use cases\\n\\nSpoke-to-spoke traffic can be important in several scenarios:\\n\\n- Different tiers of a single application are in separate virtual networks. For example, perimeter network servers (also known as _DMZ servers_) in a perimeter virtual network communicate with application services in an internal virtual network.\\n- Application workloads in different environments (Development, Staging, Production) must replicate data among each other.\\n- Different applications or microservices need to communicate with each other.\\n- Databases need to replicate data across regions to guarantee business continuity in the case of a disaster.\\n- Users are inside Azure virtual networks. For example, they use Azure Virtual Desktop.\\n\\n[Section titled: Patterns and topologies for inter-spoke communication](https://learn.microsoft.com/en-us/azure/architecture/networking/guide/spoke-to-spoke-networking#patterns-and-topologies-for-inter-spoke-communication)\\n\\n## Patterns and topologies for inter-spoke communication\\n\\nThere are two main topologies that you can use in Azure designs that cross multiple virtual networks: [traditional hub and spoke](https://learn.microsoft.com/en-us/azure/architecture/reference-architectures/hybrid-networking/hub-spoke) and [Azure Virtual WAN](https://learn.microsoft.com/en-us/azure/virtual-wan/virtual-wan-about). In a Virtual WAN environment, Microsoft manages the hub virtual network and everything inside it. In a traditional hub-and-spoke environment, you manage the hub virtual network.\\n\\nVirtual WAN and hub-and-spoke topologies are both examples of architectures in which the workloads run in spoke virtual networks and connectivity to on-premises is centralized in a hub virtual network. So many of the concepts explained in this article apply to both hub-and-spoke and Virtual WAN designs.\\n\\nThere are two main patterns for connecting spoke virtual networks to each other:\\n\\n- **Spokes directly connected to each other.** Virtual network peerings or VPN tunnels are created between the spoke virtual networks to provide direct connectivity without traversing the hub virtual network.\\n- **Spokes communicate over a network appliance.** Each spoke virtual network has a peering to Virtual WAN or to a hub virtual network. An appliance routes traffic from spoke to spoke. The appliance can be managed by Microsoft (as with Virtual WAN) or by you.\\n\\nIntroduction to the main networking patterns in Azure, focusing on east-west traffic in hub-and-spoke and Virtual WAN topologies.\", mimetype='text/plain', start_char_idx=2342, end_char_idx=5861, metadata_seperator='\\n', text_template='{metadata_str}\\n\\n{content}'), score=0.9875683), NodeWithScore(node=TextNode(id_='4e331c95-193b-4a0f-b3f1-e16c406b9309', embedding=None, metadata={'url': 'https://learn.microsoft.com/en-us/azure/architecture/patterns/', 'title': 'Cloud Design Patterns - Azure Architecture Center | Microsoft Learn', 'tokens': 2857, 'retrieve_doc': True, 'source': 'azure-architecture'}, excluded_embed_metadata_keys=['url', 'tokens', 'retrieve_doc', 'source', 'context_added'], excluded_llm_metadata_keys=['title', 'tokens', 'retrieve_doc', 'source', 'context_added'], relationships={: RelatedNodeInfo(node_id='2fe86fce-4a2d-595f-b758-cec6c8416922', node_type='4', metadata={'url': 'https://learn.microsoft.com/en-us/azure/architecture/patterns/', 'title': 'Cloud Design Patterns - Azure Architecture Center | Microsoft Learn', 'tokens': 2857, 'retrieve_doc': True, 'source': 'azure-architecture'}, hash='781989c18ad3a780d0cd6f48ab8e50854b5d75ffdeb24d97bc75fe05985b097a'), : RelatedNodeInfo(node_id='13a9c825-fed2-4cf8-8125-c1cc06d68c1b', node_type='1', metadata={'url': 'https://learn.microsoft.com/en-us/azure/architecture/patterns/', 'title': 'Cloud Design Patterns - Azure Architecture Center | Microsoft Learn', 'tokens': 2857, 'retrieve_doc': True, 'source': 'azure-architecture'}, hash='d850ebbe00173e66e769038a13ecfdd67325fd016ff2575ad07b68ee6ba76aed'), : RelatedNodeInfo(node_id='1c7f3271-d46c-4e70-a5d4-d5a0c5ada0f5', node_type='1', metadata={}, hash='fcaa18c64b7f842299d199bbc3005027007d19b361e6cabb91815de3afa11dff')}, metadata_template='{key}: {value}', metadata_separator='\\n', text='| \\\\- Operational\\xa0Excellence
\\\\- Performance\\xa0Efficiency |\\n| [Circuit Breaker](https://learn.microsoft.com/en-us/azure/architecture/patterns/circuit-breaker) | Handle faults that might take a variable amount of time to fix when an application connects to a remote service or resource. | \\\\- Reliability
\\\\- Performance\\xa0Efficiency |\\n| [Claim Check](https://learn.microsoft.com/en-us/azure/architecture/patterns/claim-check) | Split a large message into a claim check and a payload to avoid overwhelming a message bus. | \\\\- Reliability
\\\\- Security
\\\\- Cost Optimization
\\\\- Performance\\xa0Efficiency |\\n| [Compensating Transaction](https://learn.microsoft.com/en-us/azure/architecture/patterns/compensating-transaction) | Undo the work performed by a sequence of steps that collectively form an eventually consistent operation. | \\\\- Reliability |\\n| [Competing Consumers](https://learn.microsoft.com/en-us/azure/architecture/patterns/competing-consumers) | Enable multiple concurrent consumers to process messages that they receive on the same messaging channel. | \\\\- Reliability
\\\\- Cost Optimization
\\\\- Performance\\xa0Efficiency |\\n| [Compute Resource Consolidation](https://learn.microsoft.com/en-us/azure/architecture/patterns/compute-resource-consolidation) | Consolidate multiple tasks or operations into a single computational unit. | \\\\- Cost Optimization
\\\\- Operational\\xa0Excellence
\\\\- Performance\\xa0Efficiency |\\n| [CQRS](https://learn.microsoft.com/en-us/azure/architecture/patterns/cqrs) | Separate operations that read data from those that update data by using distinct interfaces. | \\\\- Performance\\xa0Efficiency |\\n| [Deployment Stamps](https://learn.microsoft.com/en-us/azure/architecture/patterns/deployment-stamp) | Deploy multiple independent copies of application components, including data stores. | \\\\- Operational\\xa0Excellence
\\\\- Performance\\xa0Efficiency |\\n| [Event Sourcing](https://learn.microsoft.com/en-us/azure/architecture/patterns/event-sourcing) | Use an append-only store to record a full series of events that describe actions taken on data in a domain. | \\\\- Reliability
\\\\- Performance\\xa0Efficiency |\\n| [External Configuration Store](https://learn.microsoft.com/en-us/azure/architecture/patterns/external-configuration-store) | Move configuration information out of an application deployment package to a centralized location. | \\\\- Operational\\xa0Excellence |\\n| [Federated Identity](https://learn.microsoft.com/en-us/azure/architecture/patterns/federated-identity) | Delegate authentication to an external identity provider. | \\\\- Reliability
\\\\- Security
\\\\- Performance\\xa0Efficiency |\\n| [Gateway Aggregation](https://learn.microsoft.com/en-us/azure/architecture/patterns/gateway-aggregation) | Use a gateway to aggregate multiple individual requests into a single request. | \\\\- Reliability
\\\\- Security
\\\\- Operational\\xa0Excellence
\\\\- Performance\\xa0Efficiency |\\n| [Gateway Offloading](https://learn.microsoft.com/en-us/azure/architecture/patterns/gateway-offloading) | Offload shared or specialized service functionality to a gateway proxy. | \\\\- Reliability
\\\\- Security
\\\\- Cost Optimization
\\\\- Operational\\xa0Excellence
\\\\- Performance\\xa0Efficiency |\\n| [Gateway Routing](https://learn.microsoft.com/en-us/azure/architecture/patterns/gateway-routing) | Route requests to multiple services by using a single endpoint.\\n\\nPart listing specific cloud design patterns, their descriptions, and the pillars of the Well-Architected Framework they support.', mimetype='text/plain', start_char_idx=6421, end_char_idx=9774, metadata_seperator='\\n', text_template='{metadata_str}\\n\\n{content}'), score=0.98282325)]\n" + ] + } + ], + "source": [ + "# Define the ServiceCotext object to tie the LLM for generating final answer,\n", + "# and the embedding model to help with retrieving related nodes.\n", + "# The `node_postprocessors` function will be applied to the retrieved nodes.\n", + "query_engine = index.as_query_engine(\n", + " similarity_top_k=400, node_postprocessors=[cohere_rerank3]\n", + ")\n", + "\n", + "#res = query_engine.query(\"When to use Azure Functions instead of App Service?\")\n", + "res = query_engine.query(\"list the most known patterns from azure architecture. Explain with details. Use only the context provided\")\n", + "res.response\n", + "\n", + "print(res.source_nodes)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "G5h5uTaiZaTC" + }, + "source": [ + "# Evaluate Cohere rerank" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 49, + "referenced_widgets": [ + "fcec89d18ee84986826bc7b058281945", + "5bd19d6f0c7f40c99173759c6e1ae76e", + "4e7ee74ed5f648459f58da7a06022ed4", + "9411dab67a184d78b9b5f3484b423f08", + "123b88e9b10245c8b3e023e868d23249", + "dc45b45a92404beeb9184de907eb680a", + "4f82e877b4b54046aa4edb9de2390e39", + "944a53c4bed144b09d5e1c24106effeb", + "0c3bdb82155a4453b10521f5e7c2eda5", + "d988efbf3dbe4eedae21861766ff1b83", + "055e38159eba414a9a2c0747e3a7b7e5" + ] + }, + "id": "AtCV641nZb7G", + "outputId": "5d2b4f21-5975-441d-91b6-7e323307678b" + }, + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/plain": [ + "rag_eval_dataset2.json: 0%| | 0.00/27.8M [00:00