diff --git a/docs/indexes/local.ipynb b/docs/indexes/local.ipynb index 4df940ff..822752d9 100644 --- a/docs/indexes/local.ipynb +++ b/docs/indexes/local.ipynb @@ -9,18 +9,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/jamesbriggs/opt/anaconda3/envs/decision-layer/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - } - ], + "outputs": [], "source": [ "from semantic_router import Route\n", "\n", @@ -55,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -67,7 +58,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -78,26 +69,26 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-02-14 03:08:45 INFO semantic_router.utils.logger local\u001b[0m\n" + "2025-01-07 12:08:10 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" ] } ], "source": [ - "from semantic_router.layer import RouteLayer\n", + "from semantic_router.routers import SemanticRouter\n", "\n", - "local_rl = RouteLayer(encoder=encoder, routes=routes, index=local_index)" + "local_rl = SemanticRouter(encoder=encoder, routes=routes, index=local_index, auto_sync=\"local\")" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -106,7 +97,7 @@ "['politics', 'chitchat']" ] }, - "execution_count": 5, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -117,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -126,7 +117,7 @@ "'politics'" ] }, - "execution_count": 6, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -137,7 +128,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -146,7 +137,7 @@ "'chitchat'" ] }, - "execution_count": 7, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -157,7 +148,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -173,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -182,7 +173,7 @@ "10" ] }, - "execution_count": 9, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -193,16 +184,26 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 17, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-07 12:08:29 - semantic_router.utils.logger - WARNING - base.py:172 - _read_config() - This method should be implemented by subclasses.\n", + "2025-01-07 12:08:29 - semantic_router.utils.logger - WARNING - base.py:172 - _read_config() - This method should be implemented by subclasses.\n", + "2025-01-07 12:08:29 - semantic_router.utils.logger - WARNING - base.py:823 - delete() - Route `chitchat` not found in SemanticRouter\n", + "2025-01-07 12:08:29 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" + ] + }, { "data": { "text/plain": [ "5" ] }, - "execution_count": 10, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -214,7 +215,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -223,7 +224,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -232,7 +233,7 @@ "{'type': 'local', 'dimensions': 384, 'vectors': 5}" ] }, - "execution_count": 12, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -258,7 +259,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.12.7" } }, "nbformat": 4, diff --git a/docs/indexes/pinecone.ipynb b/docs/indexes/pinecone.ipynb index 8236c155..ac938ed0 100644 --- a/docs/indexes/pinecone.ipynb +++ b/docs/indexes/pinecone.ipynb @@ -6,23 +6,14 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -qU \"semantic-router[pinecone]==0.0.22\"" + "!pip install -qU \"semantic-router[pinecone]==0.1.0.dev3\"" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/jamesbriggs/opt/anaconda3/envs/decision-layer/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - } - ], + "outputs": [], "source": [ "from semantic_router import Route\n", "\n", @@ -57,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -74,9 +65,21 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-07 12:10:29 - pinecone_plugin_interface.logging - INFO - discover_namespace_packages.py:12 - discover_subpackages() - Discovering subpackages in _NamespacePath(['c:\\\\Users\\\\Joshu\\\\OneDrive\\\\Documents\\\\Aurelio\\\\agents-course\\\\07-pratical-ai\\\\.venv\\\\Lib\\\\site-packages\\\\pinecone_plugins'])\n", + "2025-01-07 12:10:29 - pinecone_plugin_interface.logging - INFO - discover_plugins.py:9 - discover_plugins() - Looking for plugins in pinecone_plugins.inference\n", + "2025-01-07 12:10:29 - pinecone_plugin_interface.logging - INFO - installation.py:10 - install_plugins() - Installing plugin inference into Pinecone\n", + "2025-01-07 12:10:31 - pinecone_plugin_interface.logging - INFO - discover_namespace_packages.py:12 - discover_subpackages() - Discovering subpackages in _NamespacePath(['c:\\\\Users\\\\Joshu\\\\OneDrive\\\\Documents\\\\Aurelio\\\\agents-course\\\\07-pratical-ai\\\\.venv\\\\Lib\\\\site-packages\\\\pinecone_plugins'])\n", + "2025-01-07 12:10:31 - pinecone_plugin_interface.logging - INFO - discover_plugins.py:9 - discover_plugins() - Looking for plugins in pinecone_plugins.inference\n" + ] + } + ], "source": [ "from semantic_router.index.pinecone import PineconeIndex\n", "\n", @@ -89,21 +92,23 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-02-14 01:40:22 INFO semantic_router.utils.logger local\u001b[0m\n" + "2025-01-07 12:11:05 - pinecone_plugin_interface.logging - INFO - discover_namespace_packages.py:12 - discover_subpackages() - Discovering subpackages in _NamespacePath(['c:\\\\Users\\\\Joshu\\\\OneDrive\\\\Documents\\\\Aurelio\\\\agents-course\\\\07-pratical-ai\\\\.venv\\\\Lib\\\\site-packages\\\\pinecone_plugins'])\n", + "2025-01-07 12:11:05 - pinecone_plugin_interface.logging - INFO - discover_plugins.py:9 - discover_plugins() - Looking for plugins in pinecone_plugins.inference\n", + "2025-01-07 12:11:08 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" ] } ], "source": [ - "from semantic_router.layer import RouteLayer\n", + "from semantic_router.routers import SemanticRouter\n", "\n", - "rl = RouteLayer(encoder=encoder, routes=routes, index=pc_index)" + "rl = SemanticRouter(encoder=encoder, routes=routes, index=pc_index, auto_sync=\"local\")" ] }, { @@ -115,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -124,7 +129,7 @@ "['politics', 'chitchat']" ] }, - "execution_count": 5, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -135,16 +140,16 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "5" + "10" ] }, - "execution_count": 6, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -162,28 +167,20 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'vectors': [{'id': 'politics#1c4e5a74a2cb693bd51dd4fe0d8deb41'}, {'id': 'politics#3f95e1e2c26aa109d7a6b352bd1da93e'}, {'id': 'politics#461468866b9123c5ef111b72040c20d8'}, {'id': 'politics#e9120cb91dcc3ff76e7d2ce0740e009c'}, {'id': 'politics#f798c13e0a6d8a9926fc35a0f10f880b'}], 'pagination': {'next': 'eyJza2lwX3Bhc3QiOiJwb2xpdGljcyNmNzk4YzEzZTBhNmQ4YTk5MjZmYzM1YTBmMTBmODgwYiIsInByZWZpeCI6InBvbGl0aWNzIn0='}, 'namespace': '', 'usage': {'readUnits': 1}}\n", - "{'vectors': [], 'namespace': '', 'usage': {'readUnits': 1}}\n" - ] - }, { "data": { "text/plain": [ - "['politics#1c4e5a74a2cb693bd51dd4fe0d8deb41',\n", - " 'politics#3f95e1e2c26aa109d7a6b352bd1da93e',\n", - " 'politics#461468866b9123c5ef111b72040c20d8',\n", - " 'politics#e9120cb91dcc3ff76e7d2ce0740e009c',\n", - " 'politics#f798c13e0a6d8a9926fc35a0f10f880b']" + "['politics#64069085d9d6e98e5a80915f69fabe82bac6c742f801bc305c5001dce88f0d19',\n", + " 'politics#af8b76111f260cf44fb34f04fcf82927dcbe08e8f47c30f4d571379c1512fac8',\n", + " 'politics#d1bb40236c3d95b9c695bfa86b314b6da4eb87e136699563fccae47fccea23e2',\n", + " 'politics#ed0f3dd7bd5dea12e55b1953bcd2c562a5ab19f501f6d5ff8c8927652c3904b8',\n", + " 'politics#fc6d15f9e6075e6de82b3fbef6722b64353e4eadc8d663b7312a4ed60c43e6f6']" ] }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -201,16 +198,23 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-07 12:11:37 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "'politics'" ] }, - "execution_count": 8, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -221,16 +225,23 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-07 12:11:43 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "'chitchat'" ] }, - "execution_count": 9, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -241,9 +252,17 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-07 12:11:46 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + } + ], "source": [ "rl(\"I'm interested in learning about llama 2\").name" ] @@ -257,7 +276,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -266,7 +285,7 @@ "10" ] }, - "execution_count": 11, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -277,14 +296,14 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": {}, "outputs": [ { - "name": "stdout", + "name": "stderr", "output_type": "stream", "text": [ - "{'vectors': [{'id': 'chitchat#1e01e2c7f411d4dfcc43fe7a3de2fb67'}, {'id': 'chitchat#34fd10a3b6d1436b49759d9c67068a7e'}, {'id': 'chitchat#74cfdf22939f052ea9be158d77bc6bda'}, {'id': 'chitchat#bc13a8bc005f437d2bdeacbb9e741b8b'}, {'id': 'chitchat#fca33e294c0c4bb08ed95e1e3fd944c0'}], 'namespace': '', 'usage': {'readUnits': 1}}\n" + "2025-01-07 12:11:57 - semantic_router.utils.logger - WARNING - pinecone.py:431 - _read_config() - Configuration for sr_lock parameter not found in index.\n" ] }, { @@ -293,7 +312,7 @@ "5" ] }, - "execution_count": 12, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -308,37 +327,33 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-07 12:12:01 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + } + ], "source": [ "rl(\"how's the weather today?\").name" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "metadata": {}, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'vectors': [{'id': 'politics#1c4e5a74a2cb693bd51dd4fe0d8deb41'}, {'id': 'politics#3f95e1e2c26aa109d7a6b352bd1da93e'}, {'id': 'politics#461468866b9123c5ef111b72040c20d8'}, {'id': 'politics#e9120cb91dcc3ff76e7d2ce0740e009c'}, {'id': 'politics#f798c13e0a6d8a9926fc35a0f10f880b'}], 'namespace': '', 'usage': {'readUnits': 1}}\n" - ] - }, { "data": { "text/plain": [ - "[('politics', \"they're going to destroy this country!\"),\n", - " ('politics',\n", - " \"don't you just love the presidentdon't you just hate the president\"),\n", - " ('politics', \"isn't politics the best thing ever\"),\n", - " ('politics', \"why don't you tell me about your political opinions\"),\n", - " ('politics', 'they will save the country!')]" + "[Route(name='politics', utterances=[\"they're going to destroy this country!\", 'they will save the country!', \"don't you just love the presidentdon't you just hate the president\", \"isn't politics the best thing ever\", \"why don't you tell me about your political opinions\"], description=None, function_schemas=None, llm=None, score_threshold=None, metadata={})]" ] }, - "execution_count": 14, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -349,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -358,7 +373,7 @@ "{'type': 'pinecone', 'dimensions': 1536, 'vectors': 5}" ] }, - "execution_count": 15, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -384,7 +399,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.12.7" } }, "nbformat": 4,