From eaa579602092ade1e403e4e3905370fe022869f7 Mon Sep 17 00:00:00 2001 From: valerioarvizzigno Date: Mon, 31 Mar 2025 23:31:37 +0200 Subject: [PATCH] VertexAI grounding integration - Updated templates with the right ELSER template + minor fixes (#435) --- .../search-templates/generic_kNN_search.json | 1 + ...search_with_custom_dense_vector_model.json | 6 +- ...search_with_ELSER_sparse_vector_model.json | 57 ++++++++++--------- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/supporting-blog-content/Cloud-Vertex-AI/search-templates/generic_kNN_search.json b/supporting-blog-content/Cloud-Vertex-AI/search-templates/generic_kNN_search.json index e1b76078e..e99e88baa 100644 --- a/supporting-blog-content/Cloud-Vertex-AI/search-templates/generic_kNN_search.json +++ b/supporting-blog-content/Cloud-Vertex-AI/search-templates/generic_kNN_search.json @@ -1,3 +1,4 @@ +kNN search with VertexAI's embeddings models configured via Elastic's Inference API PUT _scripts/google-template-knn-multioutput { "script": { diff --git a/supporting-blog-content/Cloud-Vertex-AI/search-templates/semantic_kNN_search_with_custom_dense_vector_model.json b/supporting-blog-content/Cloud-Vertex-AI/search-templates/semantic_kNN_search_with_custom_dense_vector_model.json index 5a9306e16..4dedcf3c4 100644 --- a/supporting-blog-content/Cloud-Vertex-AI/search-templates/semantic_kNN_search_with_custom_dense_vector_model.json +++ b/supporting-blog-content/Cloud-Vertex-AI/search-templates/semantic_kNN_search_with_custom_dense_vector_model.json @@ -1,4 +1,4 @@ -#knn template +#knn template with custom multilingual dense model (chunked) PUT _scripts/google-template-knn { "script": { @@ -36,8 +36,8 @@ GET nqdataset-simplified-clean-semantictext-e5/_search/template { "id": "google-template-knn", "params": { - "query": "italian food", - "index_name": "nqdataset-simplified-clean-semantictext-e5", + "query": "What's the most famous food in Italian cousine?", + "index_name": "", "num_hits": 1 } } diff --git a/supporting-blog-content/Cloud-Vertex-AI/search-templates/semantic_search_with_ELSER_sparse_vector_model.json b/supporting-blog-content/Cloud-Vertex-AI/search-templates/semantic_search_with_ELSER_sparse_vector_model.json index 528a192e0..3686a8a91 100644 --- a/supporting-blog-content/Cloud-Vertex-AI/search-templates/semantic_search_with_ELSER_sparse_vector_model.json +++ b/supporting-blog-content/Cloud-Vertex-AI/search-templates/semantic_search_with_ELSER_sparse_vector_model.json @@ -1,38 +1,39 @@ -PUT _scripts/google-template-knn-multioutput +#ELSER sparse_vector search template with ELSER (chunked) +PUT _scripts/google-template-elser { "script": { "lang": "mustache", "source": { - "_source": { - "excludes": [ "title_embedding", "description_embedding", "images"] - }, + "_source": false, "size": "{{num_hits}}", - "knn" : [ - { - "field": "description_embedding", - "k": 5, - "num_candidates": 10, - "query_vector_builder": { - "text_embedding": { - "model_id": "googlevertexai_embeddings_004", - "model_text": "{{query}}" + "query": { + "nested": { + "path": "document_text.inference.chunks", + "query":{ + "sparse_vector":{ + "field": "document_text.inference.chunks.embeddings", + "inference_id":".elser-2-elasticsearch", + "query":"{{query}}" } }, - "boost": 0.4 - }, - { - "field": "title_embedding", - "k": 5, - "num_candidates": 10, - "query_vector_builder": { - "text_embedding": { - "model_id": "googlevertexai_embeddings_004", - "model_text": "{{query}}" - } - }, - "boost": 0.6 + "inner_hits": { + "size": 1, + "name": "{{index_name}}.document_text", + "_source": "*.text" } - ] + } + } } } -} \ No newline at end of file +} + +#Run the ELSER chunked templated search - chunks returned, not full documents +GET nqdataset-simplified-clean-semantictext/_search/template +{ + "id": "google-template-elser", + "params": { + "query": "What's the most famous food in Italian cousine?", + "index_name": "", + "num_hits": 10 + } +}