这是我遵循的参考文档: 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
)
首先,我遇到了有关导入 Vector 的导入错误。我在 stackoverflow 上看到了它的解决方案,将 azure.search.documents 更新到版本 ==11.4.0b6;而无论我使用哪个版本,HnswVectorSearchAlgorithmConfiguration 总是会出错。我尝试过 azure.search.documents 11.4.0b6 和 11.4.0b4
如果导入错误仍未解决,下面的部分也会出错。
vector_search = VectorSearch(
algorithm_configurations=[
HnswVectorSearchAlgorithmConfiguration(
name="my-vector-config",
kind="hnsw",
parameters={
"m": 4,
"efConstruction": 400,
"efSearch": 500,
"metric": "cosine"
}
)
]
)
我也尝试过绕行
import hnswlib
,但没成功...
如果有人解决了这个问题,请告诉我。谢谢!
使用 Azure 认知搜索的矢量功能,您无需单独安装 hnswlib。
您能否确保使用最新的 azure-search-documents pip 包?
尝试 pip install azure-search-documents --pre —-upgrade
可以在此处找到包含矢量搜索功能的最新 Python SDK 预发布版本:https://pypi.org/project/azure-search-documents/11.4.0b8/