Skip to content

Commit b180b89

Browse files
authored
Merge branch 'main' into serverless_video_notebook
2 parents 26fd6ab + 5a008db commit b180b89

File tree

50 files changed

+17460
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+17460
-124
lines changed

.github/workflows/pre-commit.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
13-
- uses: actions/setup-python@v3
14-
- uses: pre-commit/[email protected]
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v3
14+
with:
15+
python-version: '3.13' # or '3.12'
16+
- uses: pre-commit/[email protected]

bin/find-notebooks-to-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ EXEMPT_NOTEBOOKS=(
55
"notebooks/esql/esql-getting-started.ipynb"
66
"notebooks/search/07-inference.ipynb"
77
"notebooks/search/08-learning-to-rank.ipynb"
8+
"notebooks/search/09-semantic-text.ipynb"
89
"notebooks/search/10-semantic-reranking-retriever-cohere.ipynb"
910
"notebooks/search/11-semantic-reranking-hugging-face.ipynb"
1011
"notebooks/search/12-semantic-reranking-elastic-rerank.ipynb"
@@ -57,7 +58,6 @@ EXEMPT_NOTEBOOKS__8_12=(
5758

5859
EXEMPT_NOTEBOOKS__8_14=(
5960
# Add any notebooks that must be skipped on versions 8.14 or older here
60-
"notebooks/search/09-semantic-text.ipynb",
6161
# This notebook has the text_expansion deprecation notice for 8.15.
6262
# Only running on 8.15 so includes the deprecation notice and newer so the local output is the same as CI
6363
"notebooks/langchain/langchain-vector-store-using-elser.ipynb",

notebooks/enterprise-search/app-search-engine-exporter.ipynb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"\n",
2525
"## Setup\n",
2626
"\n",
27-
"Let's start by making sure our Elasticsearch and Enterprise Search clients are installed. We'll also use `getpass` to ensure we can allow secure user inputs for our IDs and keys to access our Elasticsearch instance.\n"
27+
"Let's start by making sure our Elasticsearch and Enterprise Search clients are installed. We'll also use `getpass` to ensure we can allow secure user inputs for our IDs and keys to access our Elasticsearch instance. Note that we use the `elasticsearch8` package, as Enterprise Search is not available in Elasticsearch 9 and higher.\n"
2828
]
2929
},
3030
{
@@ -42,12 +42,12 @@
4242
"# install packages\n",
4343
"import sys\n",
4444
"\n",
45-
"!{sys.executable} -m pip install -qU elasticsearch elastic-enterprise-search\n",
45+
"!{sys.executable} -m pip install -qU elasticsearch8 elastic-enterprise-search\n",
4646
"\n",
4747
"# import modules\n",
4848
"from getpass import getpass\n",
4949
"from elastic_enterprise_search import AppSearch\n",
50-
"from elasticsearch import Elasticsearch\n",
50+
"from elasticsearch8 import Elasticsearch\n",
5151
"import json"
5252
]
5353
},
@@ -335,7 +335,7 @@
335335
},
336336
{
337337
"cell_type": "code",
338-
"execution_count": 7,
338+
"execution_count": null,
339339
"metadata": {},
340340
"outputs": [],
341341
"source": [
@@ -369,7 +369,7 @@
369369
},
370370
{
371371
"cell_type": "code",
372-
"execution_count": 8,
372+
"execution_count": null,
373373
"metadata": {},
374374
"outputs": [],
375375
"source": [
@@ -425,7 +425,7 @@
425425
},
426426
{
427427
"cell_type": "code",
428-
"execution_count": 9,
428+
"execution_count": null,
429429
"metadata": {},
430430
"outputs": [],
431431
"source": [
@@ -515,7 +515,7 @@
515515
},
516516
{
517517
"cell_type": "code",
518-
"execution_count": 10,
518+
"execution_count": null,
519519
"metadata": {},
520520
"outputs": [],
521521
"source": [
@@ -545,7 +545,7 @@
545545
},
546546
{
547547
"cell_type": "code",
548-
"execution_count": 11,
548+
"execution_count": null,
549549
"metadata": {},
550550
"outputs": [],
551551
"source": [
@@ -675,7 +675,7 @@
675675
},
676676
{
677677
"cell_type": "code",
678-
"execution_count": 15,
678+
"execution_count": null,
679679
"metadata": {},
680680
"outputs": [],
681681
"source": [
@@ -741,7 +741,7 @@
741741
},
742742
{
743743
"cell_type": "code",
744-
"execution_count": 19,
744+
"execution_count": null,
745745
"metadata": {},
746746
"outputs": [],
747747
"source": [
@@ -770,7 +770,7 @@
770770
},
771771
{
772772
"cell_type": "code",
773-
"execution_count": 20,
773+
"execution_count": null,
774774
"metadata": {},
775775
"outputs": [],
776776
"source": [

notebooks/langchain/multi-query-retriever-examples/langchain-multi-query-retriever.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
}
3939
],
4040
"source": [
41-
"!python3 -m pip install -qU lark langchain langchain-elasticsearh langchain_openai tiktoken\n",
41+
"!python3 -m pip install -qU lark langchain langchain-elasticsearch langchain_openai tiktoken\n",
4242
"\n",
4343
"from langchain.schema import Document\n",
4444
"from langchain_openai.embeddings import OpenAIEmbeddings\n",

notebooks/search/09-semantic-text.ipynb

Lines changed: 5 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"- An Elastic deployment:\n",
3535
" - 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",
3636
"\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)"
3838
]
3939
},
4040
{
@@ -84,7 +84,7 @@
8484
},
8585
"outputs": [],
8686
"source": [
87-
"!pip install \"elasticsearch<9\""
87+
"!pip install elasticsearch"
8888
]
8989
},
9090
{
@@ -241,109 +241,6 @@
241241
"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."
242242
]
243243
},
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-
},
347244
{
348245
"cell_type": "markdown",
349246
"id": "818f7a72a83b5776",
@@ -356,7 +253,8 @@
356253
"source": [
357254
"## Create the Index\n",
358255
"\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)."
360258
]
361259
},
362260
{
@@ -381,7 +279,7 @@
381279
" \"plot\": {\"type\": \"text\", \"copy_to\": \"plot_semantic\"},\n",
382280
" \"plot_semantic\": {\n",
383281
" \"type\": \"semantic_text\",\n",
384-
" \"inference_id\": \"my-elser-endpoint\",\n",
282+
" \"inference_id\": \".elser-v2-elastic\",\n",
385283
" },\n",
386284
" }\n",
387285
" },\n",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
RUN python -m venv /opt/venv
6+
7+
ENV PATH="/opt/venv/bin:$PATH"
8+
9+
COPY requirements.txt .
10+
11+
RUN pip install -r requirements.txt
12+
13+
COPY elastic_agent_builder_a2a.py .
14+
15+
CMD ["python", "elastic_agent_builder_a2a.py"]

0 commit comments

Comments
 (0)