Skip to content

Commit

Permalink
Add MultiQueryRetriever WeaviateHybridSearchRetriever
Browse files Browse the repository at this point in the history
  • Loading branch information
sunank200 committed Nov 20, 2023
1 parent ef49030 commit 3430a16
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions api/ask_astro/chains/answer_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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.
Expand Down

0 comments on commit 3430a16

Please sign in to comment.