Closed Vivek-Kawathalkar closed 7 months ago
š¤
Hello @Vivek-Kawathalkar! I'm Dosu, a friendly bot here to assist you while we wait for a human maintainer. I can help with debugging, answering questions, and guiding you through becoming a contributor to our projects. Let's work together on the issue you've reported!
The error you're encountering is due to an ImportError
when trying to import 'HnswAlgorithmConfiguration' and 'HnswVectorSearchAlgorithmConfiguration' from 'azure.search.documents.indexes.models'. This is likely because the class names have changed in different versions of the Azure SDK for Python.
In the LangChain code, there is a try-except block that attempts to import 'HnswAlgorithmConfiguration' and 'SemanticSearch' from 'azure.search.documents.indexes.models'. If this import fails, it falls back to importing 'HnswVectorSearchAlgorithmConfiguration' and 'SemanticSettings' from the same module. This is because the class names have changed in versions >= 11.4.0 of the Azure SDK for Python.
Here is the relevant code:
# class names changed for versions >= 11.4.0
try:
from azure.search.documents.indexes.models import (
HnswAlgorithmConfiguration, # HnswVectorSearchAlgorithmConfiguration is old
SemanticPrioritizedFields, # PrioritizedFields outdated
SemanticSearch, # SemanticSettings outdated
)
NEW_VERSION = True
except ImportError:
from azure.search.documents.indexes.models import (
HnswVectorSearchAlgorithmConfiguration,
PrioritizedFields,
SemanticSettings,
)
NEW_VERSION = False
If you're using a version of the Azure SDK for Python that is less than 11.4.0, the import of 'HnswAlgorithmConfiguration' and 'SemanticSearch' will fail, and the code will fall back to importing 'HnswVectorSearchAlgorithmConfiguration' and 'SemanticSettings'. If you're using a version that is 11.4.0 or greater, the import of 'HnswAlgorithmConfiguration' and 'SemanticSearch' should succeed.
To resolve this issue, you should ensure that you're using the correct version of the Azure SDK for Python that matches the class names used in your code. You can check your current version of Azure SDK for Python by running pip show azure
in your terminal.
If you're still encountering issues after checking your Azure SDK version, please provide more information about your environment, such as the exact version of the Azure SDK for Python you're using, and any other relevant details about your setup.
You can find the relevant code in the LangChain repository.
I hope this helps! If you have any other questions, feel free to ask.
-Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a š if this is helpful and š if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
System Info
Traceback (most recent call last): File "C:\Users\vivek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\langchain_community\vectorstores\azuresearch.py", line 97, in _get_search_client from azure.search.documents.indexes.models import ( ImportError: cannot import name 'HnswAlgorithmConfiguration' from 'azure.search.documents.indexes.models' (C:\Users\vivek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\search\documents\indexes\models__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "c:\Users\vivek\OneDrive\Desktop\Hackathon\userdoc1.py", line 47, in
vector_store: AzureSearch = AzureSearch(
^^^^^^^^^^^^
File "C:\Users\vivek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\langchain_community\vectorstores\azuresearch.py", line 299, in init
self.client = _get_search_client(
^^^^^^^^^^^^^^^^^^^
File "C:\Users\vivek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\langchain_community\vectorstores\azuresearch.py", line 105, in _get_search_client
from azure.search.documents.indexes.models import (
ImportError: cannot import name 'HnswVectorSearchAlgorithmConfiguration' from 'azure.search.documents.indexes.models' (C:\Users\vivek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\azure\search\documents\indexes\models__init__.py)
Who can help?
No response
Information
Related Components
Reproduction
embedding_model="BAAI/bge-small-en-v1.5" embeddings= HuggingFaceEmbeddings(model_name=embedding_model)
embeddings = AzureOpenAIEmbeddings(deployment=model, chunk_size=100)
embeddings = AzureOpenAIEmbeddings(azure_deployment="T-ada-002",openai_api_version="2023-05-15")
index_name: str = "i17" vector_store: AzureSearch = AzureSearch( azure_search_endpoint=vector_store_address, azure_search_key=os.environ.get("AZURE_COGNITIVE_SEARCH_API_KEY"), index_name=index_name, embedding_function=embeddings.embed_query, )
loader = AzureBlobStorageContainerLoader( conn_str=os.environ.get("AZURE_CONN_STRING"), container=os.environ.get("CONTAINER_NAME"), ) documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=150, chunk_overlap=20) docs = text_splitter.split_documents(documents) vector_store.add_documents(documents=docs)
Expected behavior
data from azure cognitive service