Skip to content

Commit

Permalink
Changes model_id path parameter to inference_id in openAI and Cohere …
Browse files Browse the repository at this point in the history
…notebooks (#214)
  • Loading branch information
szabosteve authored Mar 26, 2024
1 parent 2d218fe commit d1eb753
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
12 changes: 6 additions & 6 deletions notebooks/integrations/cohere/inference-cohere.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@
"id": "96788aa1"
},
"source": [
"## Create the inference task\n",
"## Create the inference endpoint\n",
"\n",
"Let's create the inference task by using the [Create inference API](https://www.elastic.co/guide/en/elasticsearch/reference/current/put-inference-api.html).\n",
"Let's create the inference endpoint by using the [Create inference API](https://www.elastic.co/guide/en/elasticsearch/reference/current/put-inference-api.html).\n",
"\n",
"You'll need an Cohere API key for this that you can find in your Cohere account under the [API keys section](https://dashboard.cohere.com/api-keys). A paid membership is required to complete the steps in this notebook as the Cohere free trial API usage is limited."
]
Expand All @@ -204,7 +204,7 @@
"\n",
"client.inference.put_model(\n",
" task_type=\"text_embedding\",\n",
" model_id=\"cohere_embeddings\",\n",
" inference_id=\"cohere_embeddings\",\n",
" body={\n",
" \"service\": \"cohere\",\n",
" \"service_settings\": {\n",
Expand All @@ -226,7 +226,7 @@
"source": [
"## Create an ingest pipeline with an inference processor\n",
"\n",
"Create an ingest pipeline with an inference processor by using the [`put_pipeline`](https://www.elastic.co/guide/en/elasticsearch/reference/master/put-pipeline-api.html) method. Reference the Cohere model created above to infer against the data that is being ingested in the pipeline."
"Create an ingest pipeline with an inference processor by using the [`put_pipeline`](https://www.elastic.co/guide/en/elasticsearch/reference/master/put-pipeline-api.html) method. Reference the inference endpoint created above as the `model_id` to infer against the data that is being ingested in the pipeline."
]
},
{
Expand Down Expand Up @@ -265,7 +265,7 @@
"Let's note a few important parameters from that API call:\n",
"\n",
"- `inference`: A processor that performs inference using a machine learning model.\n",
"- `model_id`: Specifies the ID of the machine learning model to be used. In this example, the model ID is set to `cohere_embeddings`.\n",
"- `model_id`: Specifies the ID of the inference endpoint to be used. In this example, the model ID is set to `cohere_embeddings`.\n",
"- `input_output`: Specifies input and output fields.\n",
"- `input_field`: Field name from which the `dense_vector` representation is created.\n",
"- `output_field`: Field name which contains inference results."
Expand Down Expand Up @@ -406,7 +406,7 @@
" \"field\": \"plot_embedding\",\n",
" \"query_vector_builder\": {\n",
" \"text_embedding\": {\n",
" \"model_id\": \"cohere_embeddings\",\n",
" \"inference_id\": \"cohere_embeddings\",\n",
" \"model_text\": \"Fighting movie\",\n",
" }\n",
" },\n",
Expand Down
34 changes: 28 additions & 6 deletions notebooks/search/07-inference.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@
"id": "840d92f0",
"metadata": {},
"source": [
"## Create the inference task\n",
"## Create the inference endpoint\n",
"\n",
"Let's create the inference task by using the [Create inference API](https://www.elastic.co/guide/en/elasticsearch/reference/current/put-inference-api.html).\n",
"Let's create the inference endpoint by using the [Create inference API](https://www.elastic.co/guide/en/elasticsearch/reference/current/put-inference-api.html).\n",
"\n",
"You'll need an OpenAI API key for this that you can find in your OpenAI account under the [API keys section](https://platform.openai.com/api-keys). A paid membership is required to complete the steps in this notebook as the OpenAI free trial API usage is limited."
]
Expand All @@ -172,7 +172,7 @@
"\n",
"client.inference.put_model(\n",
" task_type=\"text_embedding\",\n",
" model_id=\"my_openai_embedding_model\",\n",
" inference_id=\"my_openai_embedding_model\",\n",
" body={\n",
" \"service\": \"openai\",\n",
" \"service_settings\": {\"api_key\": API_KEY},\n",
Expand All @@ -181,14 +181,22 @@
")"
]
},
{
"cell_type": "markdown",
"id": "1f2e48b7",
"metadata": {},
"source": [
"**NOTE:** If you use Elasticsearch 8.12, you must change `inference_id` in the snippet above to `model_id`! "
]
},
{
"cell_type": "markdown",
"id": "1024d070",
"metadata": {},
"source": [
"## Create an ingest pipeline with an inference processor\n",
"\n",
"Create an ingest pipeline with an inference processor by using the [`put_pipeline`](https://www.elastic.co/guide/en/elasticsearch/reference/master/put-pipeline-api.html) method. Reference the OpenAI model created above to infer against the data that is being ingested in the pipeline."
"Create an ingest pipeline with an inference processor by using the [`put_pipeline`](https://www.elastic.co/guide/en/elasticsearch/reference/master/put-pipeline-api.html) method. Reference the inference endpoint created above as `model_id` to infer against the data that is being ingested in the pipeline."
]
},
{
Expand Down Expand Up @@ -223,7 +231,7 @@
"Let's note a few important parameters from that API call:\n",
"\n",
"- `inference`: A processor that performs inference using a machine learning model.\n",
"- `model_id`: Specifies the ID of the machine learning model to be used. In this example, the model ID is set to `my_openai_embedding_model`. Use the model ID you defined when created the inference task.\n",
"- `model_id`: Specifies the ID of the inference endpoint to be used. In this example, the inference ID is set to `my_openai_embedding_model`. Use the inference ID you defined when created the inference task.\n",
"- `input_output`: Specifies input and output fields.\n",
"- `input_field`: Field name from which the `dense_vector` representation is created.\n",
"- `output_field`: Field name which contains inference results. "
Expand Down Expand Up @@ -348,7 +356,7 @@
" \"field\": \"plot_embedding\",\n",
" \"query_vector_builder\": {\n",
" \"text_embedding\": {\n",
" \"model_id\": \"my_openai_embedding_model\",\n",
" \"inference_id\": \"my_openai_embedding_model\",\n",
" \"model_text\": \"Fighting movie\",\n",
" }\n",
" },\n",
Expand All @@ -364,6 +372,20 @@
" plot = hit[\"_source\"][\"plot\"]\n",
" print(f\"Score: {score}\\nTitle: {title}\\nPlot: {plot}\\n\")"
]
},
{
"cell_type": "markdown",
"id": "7e4055ba",
"metadata": {},
"source": [
"**NOTE:** If you use Elasticsearch 8.12, you must change `inference_id` in the snippet above to `model_id`."
]
},
{
"cell_type": "markdown",
"id": "59220b82",
"metadata": {},
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit d1eb753

Please sign in to comment.