Skip to content

Commit 5f362e5

Browse files
Added support for ELSERv2 (#210)
* Added support for ELSERv2 * Added support for ELSERv2
1 parent 3778ae8 commit 5f362e5

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

notebooks/integrations/gemma/rag-gemma-huggingface-elastic.ipynb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"metadata": {},
5252
"outputs": [],
5353
"source": [
54-
"pip install -q -U elasticsearch langchain transformers huggingface_hub"
54+
"pip install -q -U elasticsearch langchain transformers huggingface_hub torch"
5555
]
5656
},
5757
{
@@ -191,7 +191,9 @@
191191
" es_cloud_id=ELASTIC_CLOUD_ID,\n",
192192
" es_api_key=ELASTIC_API_KEY,\n",
193193
" index_name=elastic_index_name,\n",
194-
" strategy=ElasticsearchStore.SparseVectorRetrievalStrategy(),\n",
194+
" strategy=ElasticsearchStore.SparseVectorRetrievalStrategy(\n",
195+
" model_id=\".elser_model_2\"\n",
196+
" ),\n",
195197
")\n",
196198
"\n",
197199
"es"
@@ -298,16 +300,16 @@
298300
"metadata": {},
299301
"outputs": [],
300302
"source": [
301-
"retriever = es.as_retriever(search_kwargs={\"k\": 10})\n",
303+
"retriever = es.as_retriever(search_kwargs={\"k\": 5})\n",
302304
"\n",
303305
"template = \"\"\"Answer the question based only on the following context:\\n\n",
304306
"\n",
305307
"{context}\n",
306308
"\n",
307309
"Question: {question}\n",
308310
"\"\"\"\n",
309-
"prompt = ChatPromptTemplate.from_template(template)\n",
310311
"\n",
312+
"prompt = ChatPromptTemplate.from_template(template)\n",
311313
"\n",
312314
"chain = (\n",
313315
" {\"context\": retriever | format_docs, \"question\": RunnablePassthrough()}\n",
@@ -327,23 +329,23 @@
327329
},
328330
{
329331
"cell_type": "code",
330-
"execution_count": 11,
332+
"execution_count": 55,
331333
"id": "ba312f17-44ae-423d-89a0-ea01eccd85b5",
332334
"metadata": {},
333335
"outputs": [
334336
{
335337
"data": {
336338
"text/plain": [
337-
"'Answer: The pet policy in the office allows employees to bring pets to the office, subject to approval by the HR department. Pets covered under this policy include dogs, cats, and other small, non-exotic animals, subject to approval by the HR department.'"
339+
"'Answer: The sales goals are to increase revenue, expand market share, and strengthen customer relationships in our target markets.'"
338340
]
339341
},
340-
"execution_count": 11,
342+
"execution_count": 55,
341343
"metadata": {},
342344
"output_type": "execute_result"
343345
}
344346
],
345347
"source": [
346-
"chain.invoke(\"What is the pet policy in the office?\")"
348+
"chain.invoke(\"What are the sales goals?\")"
347349
]
348350
}
349351
],

0 commit comments

Comments
 (0)