From a8e248969aa7c3f5df2e9d32a1eefc780fa43b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Thu, 31 Oct 2024 13:07:17 +0100 Subject: [PATCH 1/5] [DOCS] Adds examples to inference processor docs. --- .../ingest/processors/inference.asciidoc | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/docs/reference/ingest/processors/inference.asciidoc b/docs/reference/ingest/processors/inference.asciidoc index 9c6f0592a1d91..b4f5e9720c9c5 100644 --- a/docs/reference/ingest/processors/inference.asciidoc +++ b/docs/reference/ingest/processors/inference.asciidoc @@ -735,3 +735,64 @@ You can also specify the target field as follows: In this case, {feat-imp} is exposed in the `my_field.foo.feature_importance` field. + + +[discrete] +[[inference-processor-examples]] +==== {infer-cap} processor examples + +The following examples uses an <> in an {infer} processor with the name of `query_helper_pipeline` to perform a chat completion task. + + +[source,console] +-------------------------------------------------- +PUT _ingest/pipeline/query_helper_pipeline +{ + "processors": [ + { + "script": { + "source": "ctx.prompt = 'Please generate an elasticsearch search query on index `articles_index` for the following natural language query. Dates are in the field `@timestamp`, document types are in the field `type` (options are `news`, `publication`), categories in the field `category` and can be multiple (options are `medicine`, `pharmaceuticals`, `technology`), and document names are in the field `title` which should use a fuzzy match. Ignore fields which cannot be determined from the natural language query context: ' + ctx.content" <1> + } + }, + { + "inference": { + "model_id": "openai_chat_completions", <2> + "input_output": { + "input_field": "prompt", + "output_field": "query" + } + } + }, + { + "remove": { + "field": "prompt" + } + } + ] +} +-------------------------------------------------- +// NOTCONSOLE +<1> The `prompt` field contains the prompt for the chat completion task. +<2> + + +[source,console] +-------------------------------------------------- +POST _ingest/pipeline/query_helper_pipeline/_simulate +{ + "docs": [ + { + "_source": { + "content": "artificial intelligence in medicine articles published in the last 12 months" + } + } + ] +} +-------------------------------------------------- +// NOTCONSOLE + +[discrete] +[[infer-proc-readings]] +==== Further readings + +* https://www.elastic.co/search-labs/blog/openwebcrawler-llms-semantic-text-resume-job-search[Which job is the best for you? Using LLMs and semantic_text to match resumes to jobs] \ No newline at end of file From dae75440306fe1551fe81aae72ca1a0caa6af123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Thu, 31 Oct 2024 14:59:11 +0100 Subject: [PATCH 2/5] [DOCS] More edits. --- docs/reference/ingest/processors/inference.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/ingest/processors/inference.asciidoc b/docs/reference/ingest/processors/inference.asciidoc index b4f5e9720c9c5..bf6fbf62aab96 100644 --- a/docs/reference/ingest/processors/inference.asciidoc +++ b/docs/reference/ingest/processors/inference.asciidoc @@ -772,8 +772,8 @@ PUT _ingest/pipeline/query_helper_pipeline } -------------------------------------------------- // NOTCONSOLE -<1> The `prompt` field contains the prompt for the chat completion task. -<2> +<1> The `prompt` field contains the prompt for the completion task. +<2> The ID of the {infer} endpoint created upfront that uses the <> with the `completion` task type. [source,console] From 0bfc24220d1da4e3064e6d09bd18a7bcf9731a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Thu, 31 Oct 2024 15:32:14 +0100 Subject: [PATCH 3/5] [DOCS] Adds explanation to the example. --- docs/reference/ingest/processors/inference.asciidoc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/reference/ingest/processors/inference.asciidoc b/docs/reference/ingest/processors/inference.asciidoc index bf6fbf62aab96..cad84608e8c07 100644 --- a/docs/reference/ingest/processors/inference.asciidoc +++ b/docs/reference/ingest/processors/inference.asciidoc @@ -771,8 +771,10 @@ PUT _ingest/pipeline/query_helper_pipeline ] } -------------------------------------------------- -// NOTCONSOLE +// TEST[skip: An inference endpoint is required.] <1> The `prompt` field contains the prompt for the completion task. +We use <> to construct the prompt. +With `+ ctx.content`, we append the natural language input as part of the generated prompt. <2> The ID of the {infer} endpoint created upfront that uses the <> with the `completion` task type. @@ -783,13 +785,15 @@ POST _ingest/pipeline/query_helper_pipeline/_simulate "docs": [ { "_source": { - "content": "artificial intelligence in medicine articles published in the last 12 months" + "content": "artificial intelligence in medicine articles published in the last 12 months" <1> } } ] } -------------------------------------------------- -// NOTCONSOLE +// TEST[skip: An inference processor with an inference endpoint is required.] +<1> The natural language query to be used to generate an {es} query as part of the prompt scripted in the {infer} processor. + [discrete] [[infer-proc-readings]] From aed013ba906356f656fb433b273d3da39c2869e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Thu, 31 Oct 2024 15:40:53 +0100 Subject: [PATCH 4/5] [DOCS] Fine-tunes content. --- docs/reference/ingest/processors/inference.asciidoc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/reference/ingest/processors/inference.asciidoc b/docs/reference/ingest/processors/inference.asciidoc index cad84608e8c07..2294dd6187f56 100644 --- a/docs/reference/ingest/processors/inference.asciidoc +++ b/docs/reference/ingest/processors/inference.asciidoc @@ -741,7 +741,8 @@ In this case, {feat-imp} is exposed in the [[inference-processor-examples]] ==== {infer-cap} processor examples -The following examples uses an <> in an {infer} processor with the name of `query_helper_pipeline` to perform a chat completion task. +The following example uses an <> in an {infer} processor named `query_helper_pipeline` to perform a chat completion task. +The processor generates an {es} query from natural language input using a prompt designed for a completion task type. [source,console] @@ -772,11 +773,11 @@ PUT _ingest/pipeline/query_helper_pipeline } -------------------------------------------------- // TEST[skip: An inference endpoint is required.] -<1> The `prompt` field contains the prompt for the completion task. -We use <> to construct the prompt. -With `+ ctx.content`, we append the natural language input as part of the generated prompt. -<2> The ID of the {infer} endpoint created upfront that uses the <> with the `completion` task type. +<1> The `prompt` field contains the prompt used for the completion task, created with <>. +`+ ctx.content` appends the natural language input to the prompt. +<2> The ID of the pre-configured {infer} endpoint, which utilizes the <> with the `completion` task type. +The following API request will simulate running a document through the ingest pipeline created previously: [source,console] -------------------------------------------------- @@ -792,7 +793,7 @@ POST _ingest/pipeline/query_helper_pipeline/_simulate } -------------------------------------------------- // TEST[skip: An inference processor with an inference endpoint is required.] -<1> The natural language query to be used to generate an {es} query as part of the prompt scripted in the {infer} processor. +<1> The natural language query used to generate an {es} query within the prompt created by the {infer} processor. [discrete] From 2b7e8cc3ec3142821318cf7725108480f859678a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Thu, 5 Dec 2024 16:55:52 +0100 Subject: [PATCH 5/5] [DOCS] Adds link to service list. --- docs/reference/ingest/processors/inference.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference/ingest/processors/inference.asciidoc b/docs/reference/ingest/processors/inference.asciidoc index 2294dd6187f56..e079b9d665290 100644 --- a/docs/reference/ingest/processors/inference.asciidoc +++ b/docs/reference/ingest/processors/inference.asciidoc @@ -743,6 +743,7 @@ In this case, {feat-imp} is exposed in the The following example uses an <> in an {infer} processor named `query_helper_pipeline` to perform a chat completion task. The processor generates an {es} query from natural language input using a prompt designed for a completion task type. +Refer to <> for the {infer} service you use and check the corresponding examples of setting up an endpoint with the chat completion task type. [source,console]