From e53c10e546829e64b97a7bd0ef5f00bb0173f8e6 Mon Sep 17 00:00:00 2001 From: Collier King Date: Tue, 13 May 2025 15:18:27 -0500 Subject: [PATCH] docs: update Cloudflare examples for env references (#31205) - [ ] **Docs Update**: "langchain-cloudflare: add env var references in example notebooks" - We've updated our Cloudflare integration example notebooks with examples showing environmental variables to initialize the class instances. --- .../chat/cloudflare_workersai.ipynb | 6 +- .../text_embedding/cloudflare_workersai.ipynb | 77 ++- .../vectorstores/cloudflare_vectorize.ipynb | 533 ++++++++---------- 3 files changed, 286 insertions(+), 330 deletions(-) diff --git a/docs/docs/integrations/chat/cloudflare_workersai.ipynb b/docs/docs/integrations/chat/cloudflare_workersai.ipynb index ea45c57b5a1..d318d254223 100644 --- a/docs/docs/integrations/chat/cloudflare_workersai.ipynb +++ b/docs/docs/integrations/chat/cloudflare_workersai.ipynb @@ -41,7 +41,7 @@ "### Credentials\n", "\n", "\n", - "Head to https://www.cloudflare.com/developer-platform/products/workers-ai/ to sign up to CloudflareWorkersAI and generate an API key. Once you've done this set the CF_API_KEY environment variable and the CF_ACCOUNT_ID environment variable:" + "Head to https://www.cloudflare.com/developer-platform/products/workers-ai/ to sign up to CloudflareWorkersAI and generate an API key. Once you've done this set the CF_AI_API_KEY environment variable and the CF_ACCOUNT_ID environment variable:" ] }, { @@ -56,8 +56,8 @@ "import getpass\n", "import os\n", "\n", - "if not os.getenv(\"CF_API_KEY\"):\n", - " os.environ[\"CF_API_KEY\"] = getpass.getpass(\n", + "if not os.getenv(\"CF_AI_API_KEY\"):\n", + " os.environ[\"CF_AI_API_KEY\"] = getpass.getpass(\n", " \"Enter your CloudflareWorkersAI API key: \"\n", " )\n", "\n", diff --git a/docs/docs/integrations/text_embedding/cloudflare_workersai.ipynb b/docs/docs/integrations/text_embedding/cloudflare_workersai.ipynb index 71937e646ff..00cac7426c2 100644 --- a/docs/docs/integrations/text_embedding/cloudflare_workersai.ipynb +++ b/docs/docs/integrations/text_embedding/cloudflare_workersai.ipynb @@ -12,24 +12,36 @@ "\n", ">[Cloudflare Workers AI](https://developers.cloudflare.com/workers-ai/) allows you to run machine learning models, on the `Cloudflare` network, from your code via REST API.\n", "\n", - ">[Cloudflare AI document](https://developers.cloudflare.com/workers-ai/models/text-embeddings/) listed all text embeddings models available.\n", + ">[Workers AI Developer Docs](https://developers.cloudflare.com/workers-ai/models/text-embeddings/) lists all text embeddings models available.\n", "\n", "## Setting up\n", "\n", - "Both Cloudflare account ID and API token are required. Find how to obtain them from [this document](https://developers.cloudflare.com/workers-ai/get-started/rest-api/).\n" + "Both a Cloudflare Account ID and Workers AI API token are required. Find how to obtain them from [this document](https://developers.cloudflare.com/workers-ai/get-started/rest-api/).\n", + "\n", + "You can pass these parameters explicitly or define as environmental variables.\n" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "id": "f60023b8", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2025-05-13T06:00:30.121204Z", + "start_time": "2025-05-13T06:00:30.117936Z" + } + }, "outputs": [], "source": [ - "import getpass\n", + "import os\n", "\n", - "my_account_id = getpass.getpass(\"Enter your Cloudflare account ID:\\n\\n\")\n", - "my_api_token = getpass.getpass(\"Enter your Cloudflare API token:\\n\\n\")" + "from dotenv import load_dotenv\n", + "\n", + "load_dotenv(\".env\")\n", + "\n", + "cf_acct_id = os.getenv(\"CF_ACCOUNT_ID\")\n", + "\n", + "cf_ai_token = os.getenv(\"CF_AI_API_TOKEN\")" ] }, { @@ -42,9 +54,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 12, "id": "92c5b61e", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2025-05-13T06:00:31.224996Z", + "start_time": "2025-05-13T06:00:31.222981Z" + } + }, "outputs": [], "source": [ "from langchain_cloudflare.embeddings import (\n", @@ -54,25 +71,28 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 13, "id": "062547b9", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2025-05-13T06:00:32.515031Z", + "start_time": "2025-05-13T06:00:31.798590Z" + } + }, "outputs": [ { "data": { - "text/plain": [ - "(384, [-0.033627357333898544, 0.03982774540781975, 0.03559349477291107])" - ] + "text/plain": "(384, [-0.033660888671875, 0.039764404296875, 0.03558349609375])" }, - "execution_count": 3, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "embeddings = CloudflareWorkersAIEmbeddings(\n", - " account_id=my_account_id,\n", - " api_token=my_api_token,\n", + " account_id=cf_acct_id,\n", + " api_token=cf_ai_token,\n", " model_name=\"@cf/baai/bge-small-en-v1.5\",\n", ")\n", "# single string embeddings\n", @@ -82,17 +102,20 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 14, "id": "e1dcc4bd", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2025-05-13T06:00:33.106160Z", + "start_time": "2025-05-13T06:00:32.847232Z" + } + }, "outputs": [ { "data": { - "text/plain": [ - "(3, 384)" - ] + "text/plain": "(3, 384)" }, - "execution_count": 4, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -102,14 +125,6 @@ "batch_query_result = embeddings.embed_documents([\"test1\", \"test2\", \"test3\"])\n", "len(batch_query_result), len(batch_query_result[0])" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "52de8b88", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/docs/docs/integrations/vectorstores/cloudflare_vectorize.ipynb b/docs/docs/integrations/vectorstores/cloudflare_vectorize.ipynb index 8d0dc70cd57..52a3d06764a 100644 --- a/docs/docs/integrations/vectorstores/cloudflare_vectorize.ipynb +++ b/docs/docs/integrations/vectorstores/cloudflare_vectorize.ipynb @@ -40,16 +40,18 @@ "\n", "While you can create a single `api_token` with Edit privileges to all needed resources (WorkersAI, Vectorize & D1), you may want to follow the principle of \"least privilege access\" and create separate API tokens for each service\n", "\n", - "**Note:** These service-specific tokens (if provided) will take preference over a global token. You could provide these instead of a global token.\n" + "**Note:** These service-specific tokens (if provided) will take preference over a global token. You could provide these instead of a global token.\n", + "\n", + "You can also leave these parameters as environmental variables.\n" ] }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 7, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:47:40.057461Z", - "start_time": "2025-04-09T18:47:40.053778Z" + "end_time": "2025-05-13T05:36:42.486012Z", + "start_time": "2025-05-13T05:36:42.483123Z" }, "collapsed": false }, @@ -61,14 +63,14 @@ "\n", "load_dotenv(\".env\")\n", "\n", - "cf_acct_id = os.getenv(\"cf_acct_id\")\n", + "cf_acct_id = os.getenv(\"CF_ACCOUNT_ID\")\n", "\n", - "# single token with WorkersAI, Vectorize & D1\n", - "api_token = os.getenv(\"cf_ai_token\")\n", + "# single \"globally scoped\" token with WorkersAI, Vectorize & D1\n", + "api_token = os.getenv(\"CF_API_TOKEN\")\n", "\n", "# OR, separate tokens with access to each service\n", - "cf_vectorize_token = os.getenv(\"cf_vectorize_token\")\n", - "cf_d1_token = os.getenv(\"cf_d1_token\")" + "cf_vectorize_token = os.getenv(\"CF_VECTORIZE_API_TOKEN\")\n", + "cf_d1_token = os.getenv(\"CF_D1_API_TOKEN\")" ] }, { @@ -82,11 +84,11 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 9, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:08:51.876426Z", - "start_time": "2025-04-09T18:08:51.874212Z" + "end_time": "2025-05-13T05:36:50.644426Z", + "start_time": "2025-05-13T05:36:50.642087Z" }, "collapsed": false }, @@ -95,12 +97,35 @@ "import asyncio\n", "import json\n", "import uuid\n", + "import warnings\n", "\n", - "from langchain_cloudflare.embeddings import CloudflareWorkersAIEmbeddings\n", - "from langchain_cloudflare.vectorstores import CloudflareVectorize\n", + "from langchain_cloudflare.embeddings import (\n", + " CloudflareWorkersAIEmbeddings,\n", + ")\n", + "from langchain_cloudflare.vectorstores import (\n", + " CloudflareVectorize,\n", + ")\n", "from langchain_community.document_loaders import WikipediaLoader\n", "from langchain_core.documents import Document\n", - "from langchain_text_splitters import RecursiveCharacterTextSplitter" + "from langchain_text_splitters import RecursiveCharacterTextSplitter\n", + "\n", + "warnings.filterwarnings(\"ignore\")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "ExecuteTime": { + "end_time": "2025-05-13T05:36:52.026332Z", + "start_time": "2025-05-13T05:36:52.024503Z" + }, + "collapsed": false + }, + "outputs": [], + "source": [ + "# name your vectorize index\n", + "vectorize_index_name = f\"test-langchain-{uuid.uuid4().hex}\"" ] }, { @@ -118,11 +143,11 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 11, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:08:51.901475Z", - "start_time": "2025-04-09T18:08:51.900048Z" + "end_time": "2025-05-13T05:36:53.716159Z", + "start_time": "2025-05-13T05:36:53.714223Z" }, "collapsed": false }, @@ -133,18 +158,18 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 12, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:08:51.960856Z", - "start_time": "2025-04-09T18:08:51.959133Z" + "end_time": "2025-05-13T05:36:54.740315Z", + "start_time": "2025-05-13T05:36:54.738324Z" }, "collapsed": false }, "outputs": [], "source": [ "cf_ai_token = os.getenv(\n", - " \"cf_ai_token\"\n", + " \"CF_AI_API_TOKEN\"\n", ") # needed if you want to use workersAI for embeddings\n", "\n", "embedder = CloudflareWorkersAIEmbeddings(\n", @@ -169,18 +194,18 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 13, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:08:52.010301Z", - "start_time": "2025-04-09T18:08:52.008556Z" + "end_time": "2025-05-13T05:36:58.764589Z", + "start_time": "2025-05-13T05:36:58.762832Z" }, "collapsed": false }, "outputs": [], "source": [ "# provide the id of your D1 Database\n", - "d1_database_id = os.getenv(\"d1_database_id\")" + "d1_database_id = os.getenv(\"CF_D1_DATABASE_ID\")" ] }, { @@ -201,18 +226,16 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 14, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:08:52.030750Z", - "start_time": "2025-04-09T18:08:52.028905Z" + "end_time": "2025-05-13T05:37:00.814955Z", + "start_time": "2025-05-13T05:37:00.813043Z" }, "collapsed": false }, "outputs": [], "source": [ - "vectorize_index_name = f\"test-langchain-{uuid.uuid4().hex}\"\n", - "\n", "cfVect = CloudflareVectorize(\n", " embedding=embedder,\n", " account_id=cf_acct_id,\n", @@ -232,11 +255,11 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 15, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:08:56.018043Z", - "start_time": "2025-04-09T18:08:52.033871Z" + "end_time": "2025-05-13T05:37:04.023950Z", + "start_time": "2025-05-13T05:37:03.446897Z" } }, "outputs": [], @@ -259,9 +282,7 @@ "collapsed": false }, "source": [ - "### Gotchyas\n", - "\n", - "A few \"gotchyas\" are shown below for various missing token/parameter combinations" + "### Gotchyas" ] }, { @@ -275,11 +296,11 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 16, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:08:56.024043Z", - "start_time": "2025-04-09T18:08:56.019926Z" + "end_time": "2025-05-13T05:37:06.753333Z", + "start_time": "2025-05-13T05:37:06.751132Z" }, "collapsed": false }, @@ -313,42 +334,7 @@ "collapsed": false }, "source": [ - "No \"global\" `api_token` provided and either missing `ai_api_token` or `vectorize_api_token`" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": { - "ExecuteTime": { - "end_time": "2025-04-09T18:08:56.028549Z", - "start_time": "2025-04-09T18:08:56.025241Z" - }, - "collapsed": false - }, - "outputs": [], - "source": [ - "try:\n", - " cfVect = CloudflareVectorize(\n", - " embedding=embedder,\n", - " account_id=cf_acct_id,\n", - " # api_token=api_token, # (Optional if using service-specific token)\n", - " # ai_api_token=cf_ai_token, # (Optional if using global token)\n", - " d1_api_token=cf_d1_token, # (Optional if using global token)\n", - " vectorize_api_token=cf_vectorize_token, # (Optional if using global token)\n", - " d1_database_id=d1_database_id, # (Optional if not using D1)\n", - " )\n", - "except Exception as e:\n", - " print(str(e))" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": false - }, - "source": [ - "## Manage vector store\n", + "## Manage Vector Store\n", "\n", "### Creating an Index\n", "\n", @@ -357,11 +343,11 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 18, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:08:56.033461Z", - "start_time": "2025-04-09T18:08:56.029631Z" + "end_time": "2025-05-13T05:38:00.879772Z", + "start_time": "2025-05-13T05:38:00.877397Z" }, "collapsed": false }, @@ -375,13 +361,20 @@ " print(e)" ] }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": false + }, + "source": [] + }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 19, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:09:05.334526Z", - "start_time": "2025-04-09T18:08:56.034414Z" + "end_time": "2025-05-13T05:38:12.634512Z", + "start_time": "2025-05-13T05:38:03.195481Z" }, "collapsed": false }, @@ -390,12 +383,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'created_on': '2025-04-09T18:08:57.067099Z', 'modified_on': '2025-04-09T18:08:57.067099Z', 'name': 'test-langchain-b594da547de4463180a08b2117c4904d', 'description': '', 'config': {'dimensions': 1024, 'metric': 'cosine'}}\n" + "{'created_on': '2025-05-13T05:38:04.487284Z', 'modified_on': '2025-05-13T05:38:04.487284Z', 'name': 'test-langchain-5c177bb404f74d438c916462ad73d27a', 'description': 'A Test Vectorize Index', 'config': {'dimensions': 1024, 'metric': 'cosine'}}\n" ] } ], "source": [ - "r = cfVect.create_index(index_name=vectorize_index_name, wait=True)\n", + "r = cfVect.create_index(\n", + " index_name=vectorize_index_name, description=\"A Test Vectorize Index\", wait=True\n", + ")\n", "print(r)" ] }, @@ -412,11 +407,11 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 20, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:09:05.542544Z", - "start_time": "2025-04-09T18:09:05.335911Z" + "end_time": "2025-05-13T05:38:12.798392Z", + "start_time": "2025-05-13T05:38:12.635770Z" }, "collapsed": false }, @@ -425,7 +420,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[{'created_on': '2025-04-09T18:08:57.067099Z', 'modified_on': '2025-04-09T18:08:57.067099Z', 'name': 'test-langchain-b594da547de4463180a08b2117c4904d', 'description': '', 'config': {'dimensions': 1024, 'metric': 'cosine'}}]\n" + "[{'created_on': '2025-05-13T05:38:04.487284Z', 'modified_on': '2025-05-13T05:38:04.487284Z', 'name': 'test-langchain-5c177bb404f74d438c916462ad73d27a', 'description': 'A Test Vectorize Index', 'config': {'dimensions': 1024, 'metric': 'cosine'}}]\n" ] } ], @@ -449,11 +444,11 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 21, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:09:06.354051Z", - "start_time": "2025-04-09T18:09:05.543342Z" + "end_time": "2025-05-13T05:38:15.143529Z", + "start_time": "2025-05-13T05:38:14.890886Z" }, "collapsed": false }, @@ -486,11 +481,11 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 22, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:15:47.241516Z", - "start_time": "2025-04-09T18:09:06.355684Z" + "end_time": "2025-05-13T05:38:26.286211Z", + "start_time": "2025-05-13T05:38:17.940331Z" }, "collapsed": false }, @@ -499,7 +494,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'mutationId': '5e1895ff-a0f6-4fbc-aa93-58d2e181650d'}\n" + "{'mutationId': '7fc5f849-4d35-420c-bb3f-b950a79e48b6'}\n" ] } ], @@ -522,11 +517,11 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 23, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:15:47.534789Z", - "start_time": "2025-04-09T18:15:47.247760Z" + "end_time": "2025-05-13T05:38:26.457619Z", + "start_time": "2025-05-13T05:38:26.287551Z" } }, "outputs": [ @@ -534,7 +529,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[]\n" + "[{'propertyName': 'section', 'indexType': 'String'}]\n" ] } ], @@ -555,11 +550,11 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 24, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:15:50.905388Z", - "start_time": "2025-04-09T18:15:47.535643Z" + "end_time": "2025-05-13T05:38:36.596620Z", + "start_time": "2025-05-13T05:38:30.750758Z" }, "collapsed": false }, @@ -579,11 +574,11 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 25, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:15:50.930206Z", - "start_time": "2025-04-09T18:15:50.911209Z" + "end_time": "2025-05-13T05:38:36.601290Z", + "start_time": "2025-05-13T05:38:36.597784Z" }, "collapsed": false }, @@ -612,11 +607,11 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 26, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:15:50.933331Z", - "start_time": "2025-04-09T18:15:50.931155Z" + "end_time": "2025-05-13T05:38:36.604198Z", + "start_time": "2025-05-13T05:38:36.602147Z" }, "collapsed": false }, @@ -651,11 +646,11 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 27, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:21:58.065691Z", - "start_time": "2025-04-09T18:15:50.934011Z" + "end_time": "2025-05-13T05:39:10.554800Z", + "start_time": "2025-05-13T05:38:41.949203Z" }, "collapsed": false }, @@ -666,11 +661,11 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 28, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:21:58.071829Z", - "start_time": "2025-04-09T18:21:58.067043Z" + "end_time": "2025-05-13T05:39:10.557903Z", + "start_time": "2025-05-13T05:39:10.555869Z" }, "collapsed": false }, @@ -679,7 +674,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[\"58577244-247a-407e-8764-3c1a251c6855\", \"7f107458-a6e4-4571-867e-5a1c8a6eecc0\", \"6245c111-957c-48c0-9033-e5b0ce7a667b\", \"f5153123-5964-4126-affd-609e061cff5a\", \"68ceeb19-bf41-4c83-a1b4-c13894fd7157\", \"679e8b74-daf4-4d39-a49c-8a945557038d\", \"2cba8eed-2a83-4c42-bea3-3163a0ed9eea\", \"76e02c1a-a30c-4b2c\n" + "[\"433a614a-2253-4c54-951f-0e40379a52c4\", \"608a9cb6-ab71-4e5c-8831-ebedeb9749e8\", \"40a0eead-a781-46a7-a6a3-1940ec57c9ae\", \"64081e01-12d1-4760-9b3c-84ee1e4ba199\", \"af465fb9-9e3b-49a6-b00a-6a9eec4fc623\", \"2898e362-b667-46ab-ac20-651d8e13f2bf\", \"a2c0095b-2cbc-4724-bbcb-86cd702bfa84\", \"cc659763-37cb-42cb\n" ] } ], @@ -700,11 +695,11 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 29, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:22:02.729789Z", - "start_time": "2025-04-09T18:21:58.073959Z" + "end_time": "2025-05-13T05:39:15.044583Z", + "start_time": "2025-05-13T05:39:10.558566Z" }, "collapsed": false }, @@ -714,7 +709,7 @@ "output_type": "stream", "text": [ "55 results:\n", - "[Document(id='6d9f5eca-d664-42ff-a98e-4cec8d2a6418', metadata={}, page_content=\"In 2023, Cloudflare launched Workers AI, a framework allowing for use of Nvidia GPU's within\"), Document(id='ca1b3f52-b017-47bd-afb0-88e497842b8b', metadata={}, page_content='based on queries by leveraging Workers AI.Cloudflare announced plans in September 2024 to launch a'), Document(id='ef9318d7-498b-4411-81d7-e3c37453bb36', metadata={}, page_content='=== Artificial intelligence ===')]\n" + "[Document(id='24405ae0-c125-4177-a1c2-8b1849c13ab7', metadata={}, page_content=\"In 2023, Cloudflare launched Workers AI, a framework allowing for use of Nvidia GPU's within\"), Document(id='ca33b19e-4e28-4e1b-8ed7-94f133dbf8a7', metadata={}, page_content='based on queries by leveraging Workers AI.Cloudflare announced plans in September 2024 to launch a'), Document(id='14602058-73fe-4307-a1c2-95956d6392ad', metadata={}, page_content='=== Artificial intelligence ===')]\n" ] } ], @@ -749,11 +744,11 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 30, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:22:07.980455Z", - "start_time": "2025-04-09T18:22:02.733766Z" + "end_time": "2025-05-13T05:39:18.655452Z", + "start_time": "2025-05-13T05:39:15.046279Z" }, "collapsed": false }, @@ -789,11 +784,11 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 31, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:22:12.168269Z", - "start_time": "2025-04-09T18:22:07.981583Z" + "end_time": "2025-05-13T05:39:21.773498Z", + "start_time": "2025-05-13T05:39:18.656713Z" }, "collapsed": false }, @@ -803,7 +798,7 @@ "output_type": "stream", "text": [ "20 results:\n", - "(Document(id='6d9f5eca-d664-42ff-a98e-4cec8d2a6418', metadata={'section': 'Artificial intelligence'}, page_content=\"In 2023, Cloudflare launched Workers AI, a framework allowing for use of Nvidia GPU's within\"), 0.7851709)\n" + "(Document(id='24405ae0-c125-4177-a1c2-8b1849c13ab7', metadata={'section': 'Artificial intelligence'}, page_content=\"In 2023, Cloudflare launched Workers AI, a framework allowing for use of Nvidia GPU's within\"), 0.7851709)\n" ] } ], @@ -823,23 +818,23 @@ "collapsed": false }, "source": [ - "## Usage for retrieval-augmented generation\n", - "\n", "### Including D1 for \"Raw Values\"\n", "All of the `add` and `search` methods on CloudflareVectorize support a `include_d1` parameter (default=True).\n", "\n", "This is to configure whether you want to store/retrieve raw values.\n", "\n", - "If you do not want to use D1 for this, you can set this to `include=False`. This will return documents with an empty `page_content` field." + "If you do not want to use D1 for this, you can set this to `include=False`. This will return documents with an empty `page_content` field.\n", + "\n", + "**Note:** Your D1 table name MUST MATCH your vectorize index name! If you run 'create_index' and include_d1=True or cfVect(d1_database=...,) this D1 table will be created along with your Vectorize Index." ] }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 32, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:22:13.165602Z", - "start_time": "2025-04-09T18:22:12.174967Z" + "end_time": "2025-05-13T05:39:36.857527Z", + "start_time": "2025-05-13T05:39:21.774272Z" }, "collapsed": false }, @@ -849,7 +844,7 @@ "output_type": "stream", "text": [ "20 results:\n", - "(Document(id='f5153123-5964-4126-affd-609e061cff5a', metadata={'section': 'Introduction'}, page_content=''), 0.60426825)\n" + "(Document(id='64081e01-12d1-4760-9b3c-84ee1e4ba199', metadata={'section': 'Introduction'}, page_content=''), 0.60426825)\n" ] } ], @@ -877,11 +872,11 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 33, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:22:14.370032Z", - "start_time": "2025-04-09T18:22:13.169353Z" + "end_time": "2025-05-13T05:39:41.018102Z", + "start_time": "2025-05-13T05:39:36.858445Z" }, "collapsed": false }, @@ -909,11 +904,11 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": 34, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:22:16.266640Z", - "start_time": "2025-04-09T18:22:14.372586Z" + "end_time": "2025-05-13T05:39:52.954655Z", + "start_time": "2025-05-13T05:39:41.018945Z" }, "collapsed": false }, @@ -923,7 +918,7 @@ "output_type": "stream", "text": [ "6 results:\n", - " - [(Document(id='f5153123-5964-4126-affd-609e061cff5a', metadata={'section': 'Introduction'}, page_content=\"and other services. Cloudflare's headquarters are in San Francisco, California. According to\"), 0.60426825), (Document(id='7f107458-a6e4-4571-867e-5a1c8a6eecc0', metadata={'section': 'Introduction'}, page_content='network services, cybersecurity, DDoS mitigation, wide area network services, reverse proxies,'), 0.52082914), (Document(id='58577244-247a-407e-8764-3c1a251c6855', metadata={'section': 'Introduction'}, page_content='Cloudflare, Inc., is an American company that provides content delivery network services,'), 0.50490546)]\n" + " - [(Document(id='64081e01-12d1-4760-9b3c-84ee1e4ba199', metadata={'section': 'Introduction'}, page_content=\"and other services. Cloudflare's headquarters are in San Francisco, California. According to\"), 0.60426825), (Document(id='608a9cb6-ab71-4e5c-8831-ebedeb9749e8', metadata={'section': 'Introduction'}, page_content='network services, cybersecurity, DDoS mitigation, wide area network services, reverse proxies,'), 0.52082914), (Document(id='433a614a-2253-4c54-951f-0e40379a52c4', metadata={'section': 'Introduction'}, page_content='Cloudflare, Inc., is an American company that provides content delivery network services,'), 0.50490546)]\n" ] } ], @@ -949,11 +944,11 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 35, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:22:17.714962Z", - "start_time": "2025-04-09T18:22:16.271523Z" + "end_time": "2025-05-13T05:39:55.615643Z", + "start_time": "2025-05-13T05:39:52.955740Z" } }, "outputs": [ @@ -962,7 +957,7 @@ "output_type": "stream", "text": [ "20 results:\n", - " - [(Document(id='354f6e61-9a45-46fd-b9b9-2182a7b3e8da', metadata={}, page_content='== Products =='), 0.56540567), (Document(id='33697c9e-0a38-4e7f-b763-401efee46295', metadata={'section': 'History'}, page_content='Since at least 2017, Cloudflare has been using a wall of lava lamps in their San Francisco'), 0.5604333), (Document(id='615edec2-6eef-48d3-9023-04efe4992887', metadata={'section': 'History'}, page_content='their San Francisco headquarters as a source of randomness for encryption keys, alongside double'), 0.55573463)]\n" + " - [(Document(id='daeb7891-ec00-4c09-aa73-fc8e9a226ca8', metadata={}, page_content='== Products =='), 0.56540567), (Document(id='8c91ed93-d306-4cf9-ad1e-157e90a01ddf', metadata={'section': 'History'}, page_content='Since at least 2017, Cloudflare has been using a wall of lava lamps in their San Francisco'), 0.5604333), (Document(id='1400609f-0937-4700-acde-6e770d2dbd12', metadata={'section': 'History'}, page_content='their San Francisco headquarters as a source of randomness for encryption keys, alongside double'), 0.55573463)]\n" ] } ], @@ -979,11 +974,11 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 36, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:22:19.606691Z", - "start_time": "2025-04-09T18:22:17.716576Z" + "end_time": "2025-05-13T05:40:04.151104Z", + "start_time": "2025-05-13T05:39:55.618316Z" } }, "outputs": [ @@ -992,7 +987,7 @@ "output_type": "stream", "text": [ "20 results:\n", - " - [(Document(id='520e5786-1ffd-4fe7-82c0-00ce53846454', metadata={'section': 'Products'}, page_content='protocols such as DNS over HTTPS, SMTP, and HTTP/2 with support for HTTP/2 Server Push. As of 2023,'), 0.7205538), (Document(id='47f42149-f5d2-457f-8b21-83708086e0f7', metadata={'section': 'Products'}, page_content='utilizing edge computing, reverse proxies for web traffic, data center interconnects, and a content'), 0.58178145), (Document(id='1bea41ed-88e7-4443-801c-e566598c3f86', metadata={'section': 'Products'}, page_content='and a content distribution network to serve content across its network of servers. It supports'), 0.5797795), (Document(id='1faeb28c-f0dc-4038-8ea8-1ed02e005e5e', metadata={'section': 'History'}, page_content='the New York Stock Exchange under the stock ticker NET. It opened for public trading on September'), 0.5678468), (Document(id='e1efd6cf-19e1-4640-aa8b-aff9323148b4', metadata={'section': 'Products'}, page_content='Cloudflare provides network and security products for consumers and businesses, utilizing edge'), 0.55722594), (Document(id='39857a5f-639d-42ab-a40f-c78fd526246f', metadata={'section': 'History'}, page_content='Cloudflare has acquired web-services and security companies, including StopTheHacker (February'), 0.5558441), (Document(id='b6947103-be26-4252-9389-37c0ecc98820', metadata={'section': 'Products'}, page_content='Push. As of 2023, Cloudflare handles an average of 45 million HTTP requests per second.'), 0.55429655), (Document(id='0edcd68e-c291-4d92-acc7-af292fad71c0', metadata={'section': 'Products'}, page_content='It supports transport layer protocols TCP, UDP, QUIC, and many application layer protocols such as'), 0.54969466), (Document(id='76e02c1a-a30c-4b2c-8fc3-a9b338e08e25', metadata={'section': 'History'}, page_content='Cloudflare was founded in July 2009 by Matthew Prince, Lee Holloway, and Michelle Zatlyn. Prince'), 0.54691005), (Document(id='218b6982-cf4e-4778-a759-4977ef83fe30', metadata={'section': 'History'}, page_content='2019, Cloudflare submitted its S-1 filing for an initial public offering on the New York Stock'), 0.533554), (Document(id='a936041a-1e30-4217-b161-b53d73b9b2c7', metadata={'section': 'History'}, page_content='Networks (March 2024), BastionZero (May 2024), and Kivera (October 2024).'), 0.53296596), (Document(id='645e5f9d-8fcf-4926-a36a-6137dd26540d', metadata={'section': 'Products'}, page_content='Verizon’s October 2024 outage.'), 0.53137076), (Document(id='87c83d1d-a4c2-4843-b2a0-84e6ef0e1916', metadata={'section': 'Products'}, page_content='Cloudflare also provides analysis and reports on large-scale outages, including Verizon’s October'), 0.53107977), (Document(id='7e6c210a-4bf9-4b43-8462-28e3bde1114f', metadata={'section': 'History'}, page_content='a product of Unspam Technologies that served as some inspiration for the basis of Cloudflare. From'), 0.528889), (Document(id='9c50e8aa-b246-4dec-ad0e-16a1ad07d3d5', metadata={'section': 'History'}, page_content='of Cloudflare. From 2009, the company was venture-capital funded. On August 15, 2019, Cloudflare'), 0.52717584), (Document(id='06408b72-d1e0-4160-af3e-b06b43109b30', metadata={'section': 'History'}, page_content='(December 2021), Vectrix (February 2022), Area 1 Security (February 2022), Nefeli Networks (March'), 0.52209044), (Document(id='78b1d42c-0509-445f-831a-6308a806c16f', metadata={'section': 'Products'}, page_content='As of 2024, Cloudflare servers are powered by AMD EPYC 9684X processors.'), 0.5169676), (Document(id='0d1f831d-632b-4e27-8cb3-0be3af2df51b', metadata={'section': 'History'}, page_content='(February 2014), CryptoSeal (June 2014), Eager Platform Co. (December 2016), Neumob (November'), 0.5132974), (Document(id='615edec2-6eef-48d3-9023-04efe4992887', metadata={'section': 'History'}, page_content='their San Francisco headquarters as a source of randomness for encryption keys, alongside double'), 0.50999177), (Document(id='c0611b8a-c8bb-48e4-a758-283b7df7454d', metadata={'section': 'History'}, page_content='Neumob (November 2017), S2 Systems (January 2020), Linc (December 2020), Zaraz (December 2021),'), 0.5092492)]\n" + " - [(Document(id='253a0987-1118-4ab2-a444-b8a50f0b4a63', metadata={'section': 'Products'}, page_content='protocols such as DNS over HTTPS, SMTP, and HTTP/2 with support for HTTP/2 Server Push. As of 2023,'), 0.7205538), (Document(id='112b61d1-6c34-41d6-a22f-7871bf1cca7b', metadata={'section': 'Products'}, page_content='utilizing edge computing, reverse proxies for web traffic, data center interconnects, and a content'), 0.58178145), (Document(id='36929a30-32a9-482a-add7-6c109bbf8f82', metadata={'section': 'Products'}, page_content='and a content distribution network to serve content across its network of servers. It supports'), 0.5797795), (Document(id='485ac8dc-c2ad-443a-90fc-8be9e004eaee', metadata={'section': 'History'}, page_content='the New York Stock Exchange under the stock ticker NET. It opened for public trading on September'), 0.5678468), (Document(id='1c7581d5-0b06-45d6-874c-554907f4f7f7', metadata={'section': 'Products'}, page_content='Cloudflare provides network and security products for consumers and businesses, utilizing edge'), 0.55722594), (Document(id='f2fd02ac-3bab-4565-a6e2-14d9963e8fd9', metadata={'section': 'History'}, page_content='Cloudflare has acquired web-services and security companies, including StopTheHacker (February'), 0.5558441), (Document(id='1315a8ff-6509-4350-ae84-21e11da282b3', metadata={'section': 'Products'}, page_content='Push. As of 2023, Cloudflare handles an average of 45 million HTTP requests per second.'), 0.55429655), (Document(id='f5b0c9d0-89c2-43ec-a9b7-5a5b376a5a85', metadata={'section': 'Products'}, page_content='It supports transport layer protocols TCP, UDP, QUIC, and many application layer protocols such as'), 0.54969466), (Document(id='cc659763-37cb-42cb-bf09-465df1b5bc1a', metadata={'section': 'History'}, page_content='Cloudflare was founded in July 2009 by Matthew Prince, Lee Holloway, and Michelle Zatlyn. Prince'), 0.54691005), (Document(id='b467348b-9a9b-4bf1-9104-27570891c9e4', metadata={'section': 'History'}, page_content='2019, Cloudflare submitted its S-1 filing for an initial public offering on the New York Stock'), 0.533554), (Document(id='7966591b-ff56-4346-aca8-341daece01fc', metadata={'section': 'History'}, page_content='Networks (March 2024), BastionZero (May 2024), and Kivera (October 2024).'), 0.53296596), (Document(id='c7657276-c631-4331-98ec-af308387ea49', metadata={'section': 'Products'}, page_content='Verizon’s October 2024 outage.'), 0.53137076), (Document(id='9418e10c-426b-45fa-a1a4-672074310890', metadata={'section': 'Products'}, page_content='Cloudflare also provides analysis and reports on large-scale outages, including Verizon’s October'), 0.53107977), (Document(id='db5507e2-0103-4275-a9f8-466f977255c0', metadata={'section': 'History'}, page_content='a product of Unspam Technologies that served as some inspiration for the basis of Cloudflare. From'), 0.528889), (Document(id='9d840318-be0e-4cf7-8a60-eaab50d45c9e', metadata={'section': 'History'}, page_content='of Cloudflare. From 2009, the company was venture-capital funded. On August 15, 2019, Cloudflare'), 0.52717584), (Document(id='db9137cc-051b-4b20-8d49-8a32bb2b99a7', metadata={'section': 'History'}, page_content='(December 2021), Vectrix (February 2022), Area 1 Security (February 2022), Nefeli Networks (March'), 0.52209044), (Document(id='dfaffd2f-4492-444d-accf-180b1f841463', metadata={'section': 'Products'}, page_content='As of 2024, Cloudflare servers are powered by AMD EPYC 9684X processors.'), 0.5169676), (Document(id='65bbd754-22d1-435a-860a-9259f6cf7dea', metadata={'section': 'History'}, page_content='(February 2014), CryptoSeal (June 2014), Eager Platform Co. (December 2016), Neumob (November'), 0.5132974), (Document(id='1400609f-0937-4700-acde-6e770d2dbd12', metadata={'section': 'History'}, page_content='their San Francisco headquarters as a source of randomness for encryption keys, alongside double'), 0.50999177), (Document(id='b77cef8b-1140-4d92-891b-0048ea70ae3a', metadata={'section': 'History'}, page_content='Neumob (November 2017), S2 Systems (January 2020), Linc (December 2020), Zaraz (December 2021),'), 0.5092492)]\n" ] } ], @@ -1019,11 +1014,11 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 37, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:29:28.208975Z", - "start_time": "2025-04-09T18:22:19.610724Z" + "end_time": "2025-05-13T05:40:34.317910Z", + "start_time": "2025-05-13T05:40:04.152057Z" } }, "outputs": [], @@ -1051,11 +1046,11 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 38, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:29:31.470144Z", - "start_time": "2025-04-09T18:29:28.210494Z" + "end_time": "2025-05-13T05:40:40.686003Z", + "start_time": "2025-05-13T05:40:34.318561Z" } }, "outputs": [ @@ -1064,7 +1059,7 @@ "output_type": "stream", "text": [ "2 results:\n", - " - [Document(id='6c9ab453-bf69-42aa-910d-e148c9c638d0', metadata={'section': 'Namespace Test2', '_namespace': 'test-namespace-e85040f0'}, page_content='This is another namespace specific document!'), Document(id='15fece51-d077-46ac-801c-faf0f479f8d9', metadata={'section': 'Namespace Test1', '_namespace': 'test-namespace-e85040f0'}, page_content='This is a new namespace specific document!')]\n" + " - [Document(id='65c4f7f4-aa4f-46b4-85ba-c90ea18dc7ed', metadata={'section': 'Namespace Test2', '_namespace': 'test-namespace-9cc13b96'}, page_content='This is another namespace specific document!'), Document(id='96350f98-7053-41c7-b6bb-5acdd3ab67bd', metadata={'section': 'Namespace Test1', '_namespace': 'test-namespace-9cc13b96'}, page_content='This is a new namespace specific document!')]\n" ] } ], @@ -1092,11 +1087,11 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 39, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:29:31.472282Z", - "start_time": "2025-04-09T18:29:31.470813Z" + "end_time": "2025-05-13T05:40:40.694068Z", + "start_time": "2025-05-13T05:40:40.688290Z" } }, "outputs": [], @@ -1106,11 +1101,11 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 40, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:29:31.474260Z", - "start_time": "2025-04-09T18:29:31.472946Z" + "end_time": "2025-05-13T05:40:40.705385Z", + "start_time": "2025-05-13T05:40:40.698526Z" } }, "outputs": [], @@ -1120,11 +1115,11 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": 41, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:29:33.982385Z", - "start_time": "2025-04-09T18:29:31.475049Z" + "end_time": "2025-05-13T05:40:45.557475Z", + "start_time": "2025-05-13T05:40:40.707940Z" }, "collapsed": false }, @@ -1133,7 +1128,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[Document(id='6c9ab453-bf69-42aa-910d-e148c9c638d0', metadata={'section': 'Namespace Test2', '_namespace': 'test-namespace-e85040f0', '_values': [-0.0005841255, 0.014480591, 0.040771484, 0.005218506, 0.015579224, 0.0007543564, -0.005138397, -0.022720337, 0.021835327, 0.038970947, 0.017456055, 0.022705078, 0.013450623, -0.015686035, -0.019119263, -0.01512146, -0.017471313, -0.007183075, -0.054382324, -0.01914978, 0.0005302429, 0.018600464, -0.083740234, -0.006462097, 0.0005598068, 0.024230957, -0\n" + "[Document(id='65c4f7f4-aa4f-46b4-85ba-c90ea18dc7ed', metadata={'section': 'Namespace Test2', '_namespace': 'test-namespace-9cc13b96', '_values': [-0.0005841255, 0.014480591, 0.040771484, 0.005218506, 0.015579224, 0.0007543564, -0.005138397, -0.022720337, 0.021835327, 0.038970947, 0.017456055, 0.022705078, 0.013450623, -0.015686035, -0.019119263, -0.01512146, -0.017471313, -0.007183075, -0.054382324, -0.01914978, 0.0005302429, 0.018600464, -0.083740234, -0.006462097, 0.0005598068, 0.024230957, -0\n" ] } ], @@ -1170,11 +1165,11 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 42, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:29:33.985741Z", - "start_time": "2025-04-09T18:29:33.983345Z" + "end_time": "2025-05-13T05:40:45.562390Z", + "start_time": "2025-05-13T05:40:45.558685Z" } }, "outputs": [ @@ -1193,11 +1188,11 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 43, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:29:33.988862Z", - "start_time": "2025-04-09T18:29:33.986649Z" + "end_time": "2025-05-13T05:40:45.569145Z", + "start_time": "2025-05-13T05:40:45.564029Z" } }, "outputs": [], @@ -1212,11 +1207,11 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 44, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:35:28.126792Z", - "start_time": "2025-04-09T18:29:33.989518Z" + "end_time": "2025-05-13T05:41:04.904425Z", + "start_time": "2025-05-13T05:40:45.570865Z" } }, "outputs": [], @@ -1231,11 +1226,11 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 45, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:35:32.063291Z", - "start_time": "2025-04-09T18:35:28.130531Z" + "end_time": "2025-05-13T05:41:06.539749Z", + "start_time": "2025-05-13T05:41:04.905714Z" } }, "outputs": [], @@ -1245,11 +1240,11 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 46, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:35:32.078271Z", - "start_time": "2025-04-09T18:35:32.065646Z" + "end_time": "2025-05-13T05:41:06.542927Z", + "start_time": "2025-05-13T05:41:06.540660Z" } }, "outputs": [ @@ -1281,11 +1276,11 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 47, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:41:02.396233Z", - "start_time": "2025-04-09T18:35:32.080078Z" + "end_time": "2025-05-13T05:41:29.181103Z", + "start_time": "2025-05-13T05:41:06.543465Z" }, "collapsed": false }, @@ -1314,11 +1309,11 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 49, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:41:04.395895Z", - "start_time": "2025-04-09T18:41:02.401169Z" + "end_time": "2025-05-13T05:43:17.713812Z", + "start_time": "2025-05-13T05:43:10.741675Z" }, "collapsed": false }, @@ -1340,11 +1335,11 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 50, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:41:04.400595Z", - "start_time": "2025-04-09T18:41:04.397288Z" + "end_time": "2025-05-13T05:43:22.078653Z", + "start_time": "2025-05-13T05:43:22.075918Z" }, "collapsed": false }, @@ -1355,11 +1350,11 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 51, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:46:53.345978Z", - "start_time": "2025-04-09T18:41:04.402435Z" + "end_time": "2025-05-13T05:46:32.961234Z", + "start_time": "2025-05-13T05:43:22.582050Z" }, "collapsed": false }, @@ -1379,11 +1374,11 @@ }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 52, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:46:57.243780Z", - "start_time": "2025-04-09T18:46:53.349338Z" + "end_time": "2025-05-13T05:46:36.767953Z", + "start_time": "2025-05-13T05:46:32.962142Z" }, "collapsed": false }, @@ -1428,27 +1423,26 @@ }, { "cell_type": "code", - "execution_count": 124, + "execution_count": 55, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:52:48.010687Z", - "start_time": "2025-04-09T18:52:48.008676Z" + "end_time": "2025-05-13T05:47:46.258496Z", + "start_time": "2025-05-13T05:47:46.256052Z" } }, "outputs": [], "source": [ "vectorize_index_name1 = f\"test-langchain-{uuid.uuid4().hex}\"\n", - "vectorize_index_name2 = f\"test-langchain-{uuid.uuid4().hex}\"\n", - "vectorize_index_name3 = f\"test-langchain-{uuid.uuid4().hex}\"" + "vectorize_index_name2 = f\"test-langchain-{uuid.uuid4().hex}\"" ] }, { "cell_type": "code", - "execution_count": 125, + "execution_count": 56, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:52:53.477345Z", - "start_time": "2025-04-09T18:52:48.595183Z" + "end_time": "2025-05-13T05:47:52.533905Z", + "start_time": "2025-05-13T05:47:48.054530Z" }, "collapsed": false }, @@ -1461,7 +1455,6 @@ "async_requests = [\n", " cfVect.acreate_index(index_name=vectorize_index_name1),\n", " cfVect.acreate_index(index_name=vectorize_index_name2),\n", - " cfVect.acreate_index(index_name=vectorize_index_name3),\n", "]\n", "\n", "res = await asyncio.gather(*async_requests);" @@ -1478,11 +1471,11 @@ }, { "cell_type": "code", - "execution_count": 126, + "execution_count": 57, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T18:57:49.148816Z", - "start_time": "2025-04-09T18:53:00.253125Z" + "end_time": "2025-05-13T05:48:10.542021Z", + "start_time": "2025-05-13T05:47:55.284495Z" }, "collapsed": false }, @@ -1501,12 +1494,6 @@ " index_name=vectorize_index_name2,\n", " wait=True,\n", " ),\n", - " cfVect.acreate_metadata_index(\n", - " property_name=\"section\",\n", - " index_type=\"string\",\n", - " index_name=vectorize_index_name3,\n", - " wait=True,\n", - " ),\n", "]\n", "\n", "await asyncio.gather(*async_requests);" @@ -1523,11 +1510,11 @@ }, { "cell_type": "code", - "execution_count": 127, + "execution_count": 58, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T19:04:16.026672Z", - "start_time": "2025-04-09T18:57:49.149486Z" + "end_time": "2025-05-13T05:48:50.706158Z", + "start_time": "2025-05-13T05:48:17.442185Z" } }, "outputs": [], @@ -1535,7 +1522,6 @@ "async_requests = [\n", " cfVect.aadd_documents(index_name=vectorize_index_name1, documents=texts, wait=True),\n", " cfVect.aadd_documents(index_name=vectorize_index_name2, documents=texts, wait=True),\n", - " cfVect.aadd_documents(index_name=vectorize_index_name3, documents=texts, wait=True),\n", "]\n", "\n", "await asyncio.gather(*async_requests);" @@ -1552,11 +1538,11 @@ }, { "cell_type": "code", - "execution_count": 128, + "execution_count": 59, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T19:04:20.526829Z", - "start_time": "2025-04-09T19:04:16.030438Z" + "end_time": "2025-05-13T05:48:56.430401Z", + "start_time": "2025-05-13T05:48:50.706851Z" } }, "outputs": [], @@ -1564,7 +1550,6 @@ "async_requests = [\n", " cfVect.asimilarity_search(index_name=vectorize_index_name1, query=\"Workers AI\"),\n", " cfVect.asimilarity_search(index_name=vectorize_index_name2, query=\"Edge Computing\"),\n", - " cfVect.asimilarity_search(index_name=vectorize_index_name3, query=\"SASE\"),\n", "]\n", "\n", "async_results = await asyncio.gather(*async_requests);" @@ -1572,11 +1557,11 @@ }, { "cell_type": "code", - "execution_count": 129, + "execution_count": 60, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T19:04:20.544176Z", - "start_time": "2025-04-09T19:04:20.529296Z" + "end_time": "2025-05-13T05:48:56.433621Z", + "start_time": "2025-05-13T05:48:56.431425Z" } }, "outputs": [ @@ -1587,16 +1572,13 @@ "20 results:\n", "page_content='In 2023, Cloudflare launched Workers AI, a framework allowing for use of Nvidia GPU's within'\n", "20 results:\n", - "page_content='utilizing edge computing, reverse proxies for web traffic, data center interconnects, and a content'\n", - "20 results:\n", - "page_content='== Products =='\n" + "page_content='utilizing edge computing, reverse proxies for web traffic, data center interconnects, and a content'\n" ] } ], "source": [ "print(f\"{len(async_results[0])} results:\\n{str(async_results[0][0])[:300]}\")\n", - "print(f\"{len(async_results[1])} results:\\n{str(async_results[1][0])[:300]}\")\n", - "print(f\"{len(async_results[1])} results:\\n{str(async_results[2][0])[:300]}\")" + "print(f\"{len(async_results[1])} results:\\n{str(async_results[1][0])[:300]}\")" ] }, { @@ -1610,11 +1592,11 @@ }, { "cell_type": "code", - "execution_count": 130, + "execution_count": 62, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T19:04:25.193066Z", - "start_time": "2025-04-09T19:04:20.546405Z" + "end_time": "2025-05-13T05:49:13.545276Z", + "start_time": "2025-05-13T05:49:11.373856Z" } }, "outputs": [], @@ -1632,12 +1614,6 @@ " return_values=True,\n", " return_metadata=\"all\",\n", " ),\n", - " cfVect.asimilarity_search(\n", - " index_name=vectorize_index_name3,\n", - " query=\"California\",\n", - " return_values=True,\n", - " return_metadata=\"all\",\n", - " ),\n", "]\n", "\n", "async_results = await asyncio.gather(*async_requests);" @@ -1645,11 +1621,11 @@ }, { "cell_type": "code", - "execution_count": 131, + "execution_count": 63, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T19:04:25.215003Z", - "start_time": "2025-04-09T19:04:25.197020Z" + "end_time": "2025-05-13T05:49:13.548757Z", + "start_time": "2025-05-13T05:49:13.546263Z" } }, "outputs": [ @@ -1657,8 +1633,6 @@ "name": "stdout", "output_type": "stream", "text": [ - "20 results:\n", - "page_content='and other services. Cloudflare's headquarters are in San Francisco, California. According to' metadata={'section': 'Introduction', '_values': [-0.031219482, -0.018295288, -0.006000519, 0.017532349, 0.016403198, -0.029922485, -0.007133484, 0.004447937, 0.04559326, -0.011405945, 0.034820\n", "20 results:\n", "page_content='and other services. Cloudflare's headquarters are in San Francisco, California. According to' metadata={'section': 'Introduction', '_values': [-0.031219482, -0.018295288, -0.006000519, 0.017532349, 0.016403198, -0.029922485, -0.007133484, 0.004447937, 0.04559326, -0.011405945, 0.034820\n", "20 results:\n", @@ -1668,8 +1642,7 @@ ], "source": [ "print(f\"{len(async_results[0])} results:\\n{str(async_results[0][0])[:300]}\")\n", - "print(f\"{len(async_results[1])} results:\\n{str(async_results[1][0])[:300]}\")\n", - "print(f\"{len(async_results[1])} results:\\n{str(async_results[2][0])[:300]}\")" + "print(f\"{len(async_results[1])} results:\\n{str(async_results[1][0])[:300]}\")" ] }, { @@ -1681,11 +1654,11 @@ }, { "cell_type": "code", - "execution_count": 132, + "execution_count": 64, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T19:04:29.199053Z", - "start_time": "2025-04-09T19:04:25.216813Z" + "end_time": "2025-05-13T05:49:51.760893Z", + "start_time": "2025-05-13T05:49:48.661638Z" } }, "outputs": [], @@ -1707,14 +1680,6 @@ " return_metadata=\"all\",\n", " # return_values=True\n", " ),\n", - " cfVect.asimilarity_search(\n", - " index_name=vectorize_index_name3,\n", - " query=\"Cloudflare services\",\n", - " k=2,\n", - " md_filter={\"section\": \"Products\"},\n", - " return_metadata=\"all\",\n", - " # return_values=True\n", - " ),\n", "]\n", "\n", "async_results = await asyncio.gather(*async_requests);" @@ -1722,34 +1687,11 @@ }, { "cell_type": "code", - "execution_count": 133, + "execution_count": 66, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T19:04:29.219704Z", - "start_time": "2025-04-09T19:04:29.202339Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": "[True, True]" - }, - "execution_count": 133, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "[doc.metadata[\"section\"] == \"Products\" for doc in async_results[0]]" - ] - }, - { - "cell_type": "code", - "execution_count": 134, - "metadata": { - "ExecuteTime": { - "end_time": "2025-04-09T19:04:29.225644Z", - "start_time": "2025-04-09T19:04:29.221100Z" + "end_time": "2025-05-13T05:49:55.359884Z", + "start_time": "2025-05-13T05:49:55.357763Z" } }, "outputs": [ @@ -1757,19 +1699,16 @@ "name": "stdout", "output_type": "stream", "text": [ - "2 results:\n", - "page_content='Cloudflare also provides analysis and reports on large-scale outages, including Verizon’s October' metadata={'section': 'Products'}\n", - "2 results:\n", - "page_content='Cloudflare provides network and security products for consumers and businesses, utilizing edge' metadata={'section': 'Products'}\n", - "2 results:\n", + "9 results:\n", + "page_content='It supports transport layer protocols TCP, UDP, QUIC, and many application layer protocols such as' metadata={'section': 'Products'}\n", + "9 results:\n", "page_content='Cloudflare provides network and security products for consumers and businesses, utilizing edge' metadata={'section': 'Products'}\n" ] } ], "source": [ "print(f\"{len(async_results[0])} results:\\n{str(async_results[0][-1])[:300]}\")\n", - "print(f\"{len(async_results[1])} results:\\n{str(async_results[1][0])[:300]}\")\n", - "print(f\"{len(async_results[1])} results:\\n{str(async_results[2][0])[:300]}\")" + "print(f\"{len(async_results[1])} results:\\n{str(async_results[1][0])[:300]}\")" ] }, { @@ -1782,11 +1721,11 @@ }, { "cell_type": "code", - "execution_count": 135, + "execution_count": 67, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T19:04:29.467086Z", - "start_time": "2025-04-09T19:04:29.227549Z" + "end_time": "2025-05-13T05:50:07.381737Z", + "start_time": "2025-05-13T05:50:05.330842Z" } }, "outputs": [], @@ -1797,11 +1736,11 @@ }, { "cell_type": "code", - "execution_count": 136, + "execution_count": 68, "metadata": { "ExecuteTime": { - "end_time": "2025-04-09T19:04:31.759851Z", - "start_time": "2025-04-09T19:04:29.467922Z" + "end_time": "2025-05-13T05:50:10.440360Z", + "start_time": "2025-05-13T05:50:07.382653Z" }, "collapsed": false }, @@ -1816,7 +1755,9 @@ { "cell_type": "markdown", "metadata": {}, - "source": "## API reference\n" + "source": [ + "## API Reference\n" + ] }, { "cell_type": "markdown",