I am seeing a "cannot import name 'Vector' from azure.search.documents.models" error when I invoke my chain. Origin of my error is line 434 in lanchain/vectorstores/azuresearch.py (from azure.search.documents.models import Vector)
this is the relevant code snippet, I get the import error when I execute rag_chain.invoke(question)
from langchain.schema.runnable import RunnablePassthrough
from langchain.prompts import ChatPromptTemplate
from langchain.chat_models.azure_openai import AzureChatOpenAI
question = "my question.."
# vector_store is initialized using AzureSearch(), not including that snippet here
retriever = vector_store.as_retriever()
template = '''
Answer the question based on the following context:
{context}
Question: {question}
'''
prompt = ChatPromptTemplate.from_template(template=template)
llm = AzureChatOpenAI( deployment_name='MY_DEPLOYMENT_NAME', model_name='MY_MODEL', openai_api_base=MY_AZURE_OPENAI_ENDPOINT, openai_api_key=MY_AZURE_OPENAI_KEY, openai_api_version='2023-05-15', openai_api_type='azure' )
rag_chain = {'context' : retriever, 'question' : RunnablePassthrough} | prompt | llm
rag_chain.invoke(question)
my package versions
- langchain==0.0.331
- azure-search-documents==11.4.0b11
- azure-core==1.29.5
- openai==0.28.1
According to this document you need to install the
azure-search-documents==11.4.0b8
for vector stores of azure search.Now you can use the below code that I tested in my environment:
Code:
Output:
Reference: Langchain-Full-Course/langchain_expressions.ipynb at main · Coding-Crashkurse/Langchain-Full-Course · GitHub