From 0f0f8d0ce988a8f98c03e8b6d98183f97210eb87 Mon Sep 17 00:00:00 2001 From: Ankit Chaurasia <8670962+sunank200@users.noreply.github.com> Date: Mon, 20 Nov 2023 20:22:09 +0545 Subject: [PATCH] Add MultiQueryRetriever WeaviateHybridSearchRetriever --- api/ask_astro/chains/answer_question.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/api/ask_astro/chains/answer_question.py b/api/ask_astro/chains/answer_question.py index 5b63b9a3..67fc69f3 100644 --- a/api/ask_astro/chains/answer_question.py +++ b/api/ask_astro/chains/answer_question.py @@ -11,6 +11,7 @@ MessagesPlaceholder, SystemMessagePromptTemplate, ) +from langchain.retrievers import MultiQueryRetriever from langchain.retrievers.weaviate_hybrid_search import WeaviateHybridSearchRetriever from ask_astro.clients.weaviate_ import client @@ -20,6 +21,8 @@ CONVERSATIONAL_RETRIEVAL_LLM_CHAIN_TEMPERATURE, CONVERSATIONAL_RETRIEVAL_LOAD_QA_CHAIN_DEPLOYMENT_NAME, CONVERSATIONAL_RETRIEVAL_LOAD_QA_CHAIN_TEMPERATURE, + MULTI_QUERY_RETRIEVER_DEPLOYMENT_NAME, + MULTI_QUERY_RETRIEVER_TEMPERATURE, ) with open("ask_astro/templates/combine_docs_chat_prompt.txt") as system_prompt_fd: @@ -31,12 +34,19 @@ ] # Initialize a MultiQueryRetriever using AzureChatOpenAI and Weaviate. -retriever = WeaviateHybridSearchRetriever( - client=client, - index_name=WeaviateConfig.index_name, - text_key=WeaviateConfig.text_key, - attributes=WeaviateConfig.attributes, - create_schema_if_missing=True, +retriever = MultiQueryRetriever.from_llm( + llm=AzureChatOpenAI( + **AzureOpenAIParams.us_east, + deployment_name=MULTI_QUERY_RETRIEVER_DEPLOYMENT_NAME, + temperature=MULTI_QUERY_RETRIEVER_TEMPERATURE, + ), + retriever=WeaviateHybridSearchRetriever( + client=client, + index_name=WeaviateConfig.index_name, + text_key=WeaviateConfig.text_key, + attributes=WeaviateConfig.attributes, + create_schema_if_missing=True, + ), ) # Set up a ConversationalRetrievalChain to generate answers using the retriever.