Reputation: 3
I am trying to use Azure Cognitive Search for Vector search. Trying to use the python sdk and I am getting an error saying ImportError: cannot import name 'Vector' from 'azure.search.documents.models'.
I did install azure-search-documents using pip and it is the latest version. Any pointers on what I am missing here.
Using the github sample on creating a vector store in Azure Cognitive Search
Upvotes: 0
Views: 10603
Reputation: 374
The link provided above has the answer. The problem you are facing is because the latest version of
azure-search-documents==11.4.0
doesn't have the Vector class anymore instead we have to use VectorizedQuery as provided in the above link shared.
Earlier preview versions had this Vector class.
For eg: azure-search-documents==11.4.0b8
So you have to update to latest which is always better and update code to use VectorizedQuery instead of Vector. The search_client also takes a new parameter vector_queries instead of earlier vectors
from azure.search.documents.models import VectorizedQuery
...
vector_query = VectorizedQuery(vector=get_embeddings(query), k_nearest_neighbors=3, fields="descriptionVector")
results = search_client.search(
vector_queries=[vector_query],
select=["hotelId", "hotelName"],
)
Upvotes: 1
Reputation: 1
If it doesn't work while you've already chosen other versions. Try changing the kernel, that worked for me after trying all the versions of azure-search-documents and it still did not work.
Upvotes: 0
Reputation: 19
I'd like to add to Hacker's answer. Newer preview versions also work. Therefore below command should also solve your problem:
pip install azure-search-documents==11.4.0b6
Upvotes: 0
Reputation: 24
Azure Cognitive Search for Vector search is available only for private preview . If you want to use it, you need to install specific version. azure-search-documents==11.4.0a20230509004
for more info: refer this link https://github.com/Azure/cognitive-search-vector-pr/blob/main/demo-python/code/azure-search-vector-python-sample.ipynb
Upvotes: 0