Skip to content

Commit

Permalink
Added support for ELSERv2 (#210)
Browse files Browse the repository at this point in the history
* Added support for ELSERv2

* Added support for ELSERv2
  • Loading branch information
ashishtiwari1993 authored Mar 21, 2024
1 parent 3778ae8 commit 5f362e5
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions notebooks/integrations/gemma/rag-gemma-huggingface-elastic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"metadata": {},
"outputs": [],
"source": [
"pip install -q -U elasticsearch langchain transformers huggingface_hub"
"pip install -q -U elasticsearch langchain transformers huggingface_hub torch"
]
},
{
Expand Down Expand Up @@ -191,7 +191,9 @@
" es_cloud_id=ELASTIC_CLOUD_ID,\n",
" es_api_key=ELASTIC_API_KEY,\n",
" index_name=elastic_index_name,\n",
" strategy=ElasticsearchStore.SparseVectorRetrievalStrategy(),\n",
" strategy=ElasticsearchStore.SparseVectorRetrievalStrategy(\n",
" model_id=\".elser_model_2\"\n",
" ),\n",
")\n",
"\n",
"es"
Expand Down Expand Up @@ -298,16 +300,16 @@
"metadata": {},
"outputs": [],
"source": [
"retriever = es.as_retriever(search_kwargs={\"k\": 10})\n",
"retriever = es.as_retriever(search_kwargs={\"k\": 5})\n",
"\n",
"template = \"\"\"Answer the question based only on the following context:\\n\n",
"\n",
"{context}\n",
"\n",
"Question: {question}\n",
"\"\"\"\n",
"prompt = ChatPromptTemplate.from_template(template)\n",
"\n",
"prompt = ChatPromptTemplate.from_template(template)\n",
"\n",
"chain = (\n",
" {\"context\": retriever | format_docs, \"question\": RunnablePassthrough()}\n",
Expand All @@ -327,23 +329,23 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 55,
"id": "ba312f17-44ae-423d-89a0-ea01eccd85b5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'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.'"
"'Answer: The sales goals are to increase revenue, expand market share, and strengthen customer relationships in our target markets.'"
]
},
"execution_count": 11,
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chain.invoke(\"What is the pet policy in the office?\")"
"chain.invoke(\"What are the sales goals?\")"
]
}
],
Expand Down

0 comments on commit 5f362e5

Please sign in to comment.