azurevectorimporterrorazure-cognitive-searchhnswlib

import Azure HnswVectorSearchAlgorithmConfiguration comes Error: cannot import name 'HnswVectorSearchAlgorithmConfiguration'


Here is the reference document I follow with: https://esteininger.medium.com/building-a-vector-search-engine-using-hnsw-and-cosine-similarity-753fb5268839 & https://github.com/Azure/cognitive-search-vector-pr/blob/main/demo-python/code/azure-search-vector-python-sample.ipynb

from azure.search.documents.models import Vector
from azure.search.documents.indexes.models import (  
    SearchIndex,  
    SearchField,  
    SearchFieldDataType,  
    SimpleField,  
    SearchableField,  
    SearchIndex,  
    SemanticConfiguration,  
    PrioritizedFields,  
    SemanticField,  
    SearchField,  
    SemanticSettings,  
    VectorSearch, 
    HnswVectorSearchAlgorithmConfiguration 
)

enter image description here

At first, I faced import error which is about import Vector. I saw its solution on stackoverflow by updating azure.search.documents to the version ==11.4.0b6; While HnswVectorSearchAlgorithmConfiguration would be alwasy error no matter which version I used. I've tried azure.search.documents 11.4.0b6 and 11.4.0b4

If the import error remain unsolved, the folling part would be error too.

vector_search = VectorSearch(

    algorithm_configurations=[

        HnswVectorSearchAlgorithmConfiguration(

            name="my-vector-config",

            kind="hnsw",

            parameters={

                "m": 4,

                "efConstruction": 400,
                "efSearch": 500,
                "metric": "cosine"
            }
        )
    ]
)

I also tried to walkaround by import hnswlib, but it didn't work... enter image description here

If someone has conquer this issue, please let me know. Thank you!


Solution

  • Using Azure Cognitive Search’s Vector feature you don’t have to install hnswlib separately.

    Can you ensure you’re using the latest azure-search-documents pip package?

    Try pip install azure-search-documents --pre --upgrade.

    The latest Python SDK pre-release version that includes Vector search capabilities can be found here: https://pypi.org/project/azure-search-documents/11.4.0b8/