From 5f362e5b208723c3e3da52c8a2895ea59c894df1 Mon Sep 17 00:00:00 2001 From: Ashish Tiwari Date: Thu, 21 Mar 2024 19:08:32 +0530 Subject: [PATCH] Added support for ELSERv2 (#210) * Added support for ELSERv2 * Added support for ELSERv2 --- .../gemma/rag-gemma-huggingface-elastic.ipynb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/notebooks/integrations/gemma/rag-gemma-huggingface-elastic.ipynb b/notebooks/integrations/gemma/rag-gemma-huggingface-elastic.ipynb index 893c123b..74e6fb4b 100644 --- a/notebooks/integrations/gemma/rag-gemma-huggingface-elastic.ipynb +++ b/notebooks/integrations/gemma/rag-gemma-huggingface-elastic.ipynb @@ -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" ] }, { @@ -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" @@ -298,7 +300,7 @@ "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", @@ -306,8 +308,8 @@ "\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", @@ -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?\")" ] } ],