|
34 | 34 | "- An Elastic deployment:\n",
|
35 | 35 | " - We'll be using [Elastic Cloud](https://www.elastic.co/guide/en/cloud/current/ec-getting-started.html) for this example (available with a [free trial](https://cloud.elastic.co/registration?onboarding_token=vectorsearch&utm_source=github&utm_content=elasticsearch-labs-notebook))\n",
|
36 | 36 | "\n",
|
37 |
| - "- Elasticsearch 8.15 or above, or [Elasticsearch serverless](https://www.elastic.co/elasticsearch/serverless)" |
| 37 | + "- Elasticsearch 9.1 or above, or [Elasticsearch serverless](https://www.elastic.co/elasticsearch/serverless)" |
38 | 38 | ]
|
39 | 39 | },
|
40 | 40 | {
|
|
84 | 84 | },
|
85 | 85 | "outputs": [],
|
86 | 86 | "source": [
|
87 |
| - "!pip install \"elasticsearch<9\"" |
| 87 | + "!pip install elasticsearch" |
88 | 88 | ]
|
89 | 89 | },
|
90 | 90 | {
|
|
241 | 241 | "Read [this page](https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/connecting.html#connect-self-managed-new) to learn how to connect using API keys."
|
242 | 242 | ]
|
243 | 243 | },
|
244 |
| - { |
245 |
| - "cell_type": "markdown", |
246 |
| - "id": "22fa643780acd44a", |
247 |
| - "metadata": { |
248 |
| - "collapsed": false, |
249 |
| - "jupyter": { |
250 |
| - "outputs_hidden": false |
251 |
| - } |
252 |
| - }, |
253 |
| - "source": [ |
254 |
| - "## Create the Inference Endpoint\n", |
255 |
| - "\n", |
256 |
| - "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", |
257 |
| - "\n", |
258 |
| - "For this example we'll use the [ELSER service](https://www.elastic.co/guide/en/machine-learning/current/ml-nlp-elser.html), but the inference API also supports [many other inference services](https://www.elastic.co/guide/en/elasticsearch/reference/current/put-inference-api.html#put-inference-api-desc)." |
259 |
| - ] |
260 |
| - }, |
261 |
| - { |
262 |
| - "cell_type": "code", |
263 |
| - "execution_count": null, |
264 |
| - "id": "8ee2188ea71324f5", |
265 |
| - "metadata": { |
266 |
| - "collapsed": false, |
267 |
| - "jupyter": { |
268 |
| - "outputs_hidden": false |
269 |
| - } |
270 |
| - }, |
271 |
| - "outputs": [], |
272 |
| - "source": [ |
273 |
| - "try:\n", |
274 |
| - " client.inference.delete(inference_id=\"my-elser-endpoint\")\n", |
275 |
| - "except exceptions.NotFoundError:\n", |
276 |
| - " # Inference endpoint does not exist\n", |
277 |
| - " pass\n", |
278 |
| - "\n", |
279 |
| - "try:\n", |
280 |
| - " client.options(\n", |
281 |
| - " request_timeout=60, max_retries=3, retry_on_timeout=True\n", |
282 |
| - " ).inference.put(\n", |
283 |
| - " task_type=\"sparse_embedding\",\n", |
284 |
| - " inference_id=\"my-elser-endpoint\",\n", |
285 |
| - " body={\n", |
286 |
| - " \"service\": \"elser\",\n", |
287 |
| - " \"service_settings\": {\"num_allocations\": 1, \"num_threads\": 1},\n", |
288 |
| - " },\n", |
289 |
| - " )\n", |
290 |
| - " print(\"Inference endpoint created successfully\")\n", |
291 |
| - "except exceptions.BadRequestError as e:\n", |
292 |
| - " if e.error == \"resource_already_exists_exception\":\n", |
293 |
| - " print(\"Inference endpoint created successfully\")\n", |
294 |
| - " else:\n", |
295 |
| - " raise e" |
296 |
| - ] |
297 |
| - }, |
298 |
| - { |
299 |
| - "cell_type": "markdown", |
300 |
| - "id": "e94fd66761fd8087", |
301 |
| - "metadata": { |
302 |
| - "collapsed": false, |
303 |
| - "jupyter": { |
304 |
| - "outputs_hidden": false |
305 |
| - } |
306 |
| - }, |
307 |
| - "source": [ |
308 |
| - "Once the endpoint is created, we must wait until the backing ELSER service is deployed.\n", |
309 |
| - "This can take a few minutes to complete." |
310 |
| - ] |
311 |
| - }, |
312 |
| - { |
313 |
| - "cell_type": "code", |
314 |
| - "execution_count": null, |
315 |
| - "id": "adb33329ce20b2f1", |
316 |
| - "metadata": { |
317 |
| - "collapsed": false, |
318 |
| - "jupyter": { |
319 |
| - "outputs_hidden": false |
320 |
| - } |
321 |
| - }, |
322 |
| - "outputs": [], |
323 |
| - "source": [ |
324 |
| - "inference_endpoint_info = client.inference.get(inference_id=\"my-elser-endpoint\")\n", |
325 |
| - "model_id = inference_endpoint_info[\"endpoints\"][0][\"service_settings\"][\"model_id\"]\n", |
326 |
| - "\n", |
327 |
| - "while True:\n", |
328 |
| - " status = client.ml.get_trained_models_stats(\n", |
329 |
| - " model_id=model_id,\n", |
330 |
| - " )\n", |
331 |
| - "\n", |
332 |
| - " deployment_stats = status[\"trained_model_stats\"][0].get(\"deployment_stats\")\n", |
333 |
| - " if deployment_stats is None:\n", |
334 |
| - " print(\"ELSER Model is currently being deployed.\")\n", |
335 |
| - " time.sleep(5)\n", |
336 |
| - " continue\n", |
337 |
| - "\n", |
338 |
| - " nodes = deployment_stats.get(\"nodes\")\n", |
339 |
| - " if nodes is not None and len(nodes) > 0:\n", |
340 |
| - " print(\"ELSER Model has been successfully deployed.\")\n", |
341 |
| - " break\n", |
342 |
| - " else:\n", |
343 |
| - " print(\"ELSER Model is currently being deployed.\")\n", |
344 |
| - " time.sleep(5)" |
345 |
| - ] |
346 |
| - }, |
347 | 244 | {
|
348 | 245 | "cell_type": "markdown",
|
349 | 246 | "id": "818f7a72a83b5776",
|
|
356 | 253 | "source": [
|
357 | 254 | "## Create the Index\n",
|
358 | 255 | "\n",
|
359 |
| - "Now we need to create an index with a `semantic_text` field. Let's create one that enables us to perform semantic search on movie plots." |
| 256 | + "Now we need to create an index with a `semantic_text` field. Let's create one that enables us to perform semantic search on movie plots.\n", |
| 257 | + "We use the preconfigured `.elser-2-elastic` inference endpoint which uses the ELSER model via the [Elastic Inference Service](https://www.elastic.co/docs/explore-analyze/elastic-inference/eis)." |
360 | 258 | ]
|
361 | 259 | },
|
362 | 260 | {
|
|
381 | 279 | " \"plot\": {\"type\": \"text\", \"copy_to\": \"plot_semantic\"},\n",
|
382 | 280 | " \"plot_semantic\": {\n",
|
383 | 281 | " \"type\": \"semantic_text\",\n",
|
384 |
| - " \"inference_id\": \"my-elser-endpoint\",\n", |
| 282 | + " \"inference_id\": \".elser-v2-elastic\",\n", |
385 | 283 | " },\n",
|
386 | 284 | " }\n",
|
387 | 285 | " },\n",
|
|
0 commit comments