diff --git a/supporting-blog-content/vector-search-implementation-guide-api/vector_search_implementation_guide_api.ipynb b/supporting-blog-content/vector-search-implementation-guide-api/vector_search_implementation_guide_api.ipynb index 3a7c2636..7734915d 100644 --- a/supporting-blog-content/vector-search-implementation-guide-api/vector_search_implementation_guide_api.ipynb +++ b/supporting-blog-content/vector-search-implementation-guide-api/vector_search_implementation_guide_api.ipynb @@ -90,29 +90,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "SL47BJNyl3-r", - "outputId": "43588d08-9dfb-4b13-9c42-58e071cf3526" + "outputId": "fa707db7-b6ec-47b4-c802-2d14c346e7bd" }, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ "{'acknowledged': True}\n" ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - ":44: DeprecationWarning: The 'body' parameter is deprecated and will be removed in a future version. Instead use individual parameters.\n", - " response = es.ingest.put_pipeline(id=pipeline_id, body=pipeline)\n" - ] } ], "source": [ @@ -169,68 +161,56 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "zNqjEiPZl36N", - "outputId": "55130ac4-042f-4d65-bc4b-08c6527d85d4" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'acknowledged': True}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - ":34: ElasticsearchWarning: Legacy index templates are deprecated in favor of composable templates.\n", - " response = es.indices.put_template(name=\"my_vector_index\",\n" - ] - } - ], "source": [ "index_patterns = [\"my_vector_index-*\"]\n", "\n", - "order = 1\n", + "priority = 1\n", "\n", "settings = {\n", - " \"number_of_shards\": 1,\n", - " \"number_of_replicas\": 1,\n", " \"index.default_pipeline\": pipeline_id,\n", "}\n", "\n", "mappings = {\n", " \"properties\": {\n", - " \"my_vector\": {\n", - " \"type\": \"dense_vector\",\n", - " \"dims\": 768,\n", - " \"index\": True,\n", - " \"similarity\": \"dot_product\",\n", - " },\n", + " \"my_vector\": {\"type\": \"dense_vector\", \"dims\": 768},\n", " \"my_text\": {\"type\": \"text\"},\n", " },\n", " \"_source\": {\"excludes\": [\"my_vector\"]},\n", "}\n", "\n", + "# Exclude `my_vector` from `_source` explicitly\n", + "source_exclusions = {\"_source\": {\"excludes\": [\"my_vector\"]}}\n", "\n", - "# Create the index template\n", - "response = es.indices.put_template(\n", - " name=\"my_vector_index\",\n", + "# Create the index template using put_index_template\n", + "response = es.indices.put_index_template(\n", + " name=\"my_vector_index_template\", # Template name\n", " index_patterns=index_patterns,\n", - " order=order,\n", - " settings=settings,\n", - " mappings=mappings,\n", + " priority=priority,\n", + " template={\n", + " \"settings\": settings,\n", + " \"mappings\": mappings,\n", + " },\n", ")\n", "\n", - "\n", "# Print the response\n", "print(response)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "I5F6DR8jroEM", + "outputId": "f1222091-cd17-4d8a-d811-2ac8e55d944e" + }, + "execution_count": 49, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "{'acknowledged': True}\n" + ] + } ] }, { @@ -244,7 +224,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": { "id": "XbapSs1c-hkd" }, @@ -255,24 +235,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "bSIJ-AngVmUi", - "outputId": "49074d6e-1d30-44e1-d565-edac0251eae1" + "outputId": "c5cdd475-132d-4410-83e8-3557f4e05bb5" }, "outputs": [ { + "output_type": "execute_result", "data": { "text/plain": [ "ObjectApiResponse({'_shards': {'total': 2, 'successful': 1, 'failed': 0}})" ] }, - "execution_count": 14, "metadata": {}, - "output_type": "execute_result" + "execution_count": 51 } ], "source": [ @@ -328,22 +308,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "xl76_rM4l3iC", - "outputId": "9a796cf1-4beb-4405-91b9-c323db756d36" + "outputId": "5d3b4c44-ff3c-4489-b850-e2e1bfc4880a" }, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ - "[{'_id': 'UO5Y3IoB3ljSe18vZY6D',\n", + "[{'_id': 'PoHEcpIB5JwEUwVjEs6E',\n", " '_index': 'my_vector_index-01',\n", - " '_score': 0.78170115,\n", + " '_score': 0.7825787,\n", " '_source': {'ml': {'inference': {}},\n", " 'my_metadata': 'The Dude',\n", " 'my_text': \"Hey, careful, man, there's a beverage here!\"}}]\n" @@ -379,27 +359,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "wLY8Q6tEmk06", - "outputId": "dc4dd649-3a66-4084-cba1-2e0e51984037" + "outputId": "3f1cc630-6e65-42b8-82eb-b83222fd43ce" }, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ - "[{'_id': 'U-5Y3IoB3ljSe18vZY6D',\n", + "[{'_id': 'QYHEcpIB5JwEUwVjEs6E',\n", " '_index': 'my_vector_index-01',\n", - " '_score': 1.8080788,\n", + " '_score': 1.8082356,\n", " 'fields': {'my_metadata': ['Walter Sobchak'],\n", " 'my_text': ['What do you mean brought it bowling, Dude?']}},\n", - " {'_id': 'VO5Y3IoB3ljSe18vZY6D',\n", + " {'_id': 'QoHEcpIB5JwEUwVjEs6E',\n", " '_index': 'my_vector_index-01',\n", - " '_score': 1.2358729,\n", + " '_score': 1.2366624,\n", " 'fields': {'my_metadata': ['Walter Sobchak'],\n", " 'my_text': ['Donny was a good bowler, and a good man. He was one '\n", " 'of us. He was a man who loved the outdoors... and '\n", @@ -447,22 +427,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "yVDMHuM3mla7", - "outputId": "ebd848da-8ecc-4683-cb81-719f5a12f815" + "outputId": "b39c13de-a97b-4112-b733-a246cdc7f364" }, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ - "[{'_id': 'UO5Y3IoB3ljSe18vZY6D',\n", + "[{'_id': 'PoHEcpIB5JwEUwVjEs6E',\n", " '_index': 'my_vector_index-01',\n", - " '_score': 0.59285694,\n", + " '_score': 0.59394693,\n", " 'fields': {'my_metadata': ['The Dude'],\n", " 'my_text': [\"Hey, careful, man, there's a beverage here!\"]}}]\n" ] @@ -479,7 +459,7 @@ " \"model_text\": \"Did you bring the dog?\",\n", " }\n", " },\n", - " \"filter\": {\"term\": {\"my_metadata\": \"The Dude\"}},\n", + " \"filter\": {\"term\": {\"my_metadata.keyword\": \"The Dude\"}},\n", "}\n", "\n", "fields = [\"my_text\", \"my_metadata\"]\n", @@ -501,27 +481,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "jbwinE0fm5-I", - "outputId": "e8b02f4b-8a89-417f-a892-2e676a812a2d" + "outputId": "7ae0af99-3260-475b-98fe-2b5d8d165645" }, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ - "[{'_id': 'U-5Y3IoB3ljSe18vZY6D',\n", + "[{'_id': 'QYHEcpIB5JwEUwVjEs6E',\n", " '_index': 'my_vector_index-01',\n", - " '_score': 0.74352247,\n", + " '_score': 0.7433834,\n", " 'fields': {'my_metadata': ['Walter Sobchak'],\n", " 'my_text': ['What do you mean brought it bowling, Dude?']}},\n", - " {'_id': 'UO5Y3IoB3ljSe18vZY6D',\n", + " {'_id': 'PoHEcpIB5JwEUwVjEs6E',\n", " '_index': 'my_vector_index-01',\n", - " '_score': 0.6010935,\n", + " '_score': 0.6028075,\n", " 'fields': {'my_metadata': ['The Dude'],\n", " 'my_text': [\"Hey, careful, man, there's a beverage here!\"]}}]\n" ] @@ -540,7 +520,7 @@ " },\n", "}\n", "\n", - "aggs = {\"metadata\": {\"terms\": {\"field\": \"my_metadata\"}}}\n", + "aggs = {\"metadata\": {\"terms\": {\"field\": \"my_metadata.keyword\"}}}\n", "\n", "fields = [\"my_text\", \"my_metadata\"]\n", "\n", @@ -565,4 +545,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file