问题验证
- 我已经在文档和discord上搜索了答案。
问题
当使用MilvusVectorStore创建Milvus索引时,将enable_sparse设置为True不会创建索引,但我想使用Milvus的混合搜索。
代码:
mvs_args = {'uri': uri,
'collection_name': _collection,
'similarity_metric': metric_type,
'dim': dim,
'overwrite': _overwrite,
'index_config': {
"index_type": "FLAT",
"metric_type": metric_type,
}
}
if _enable_sparse:
mvs_args['enable_sparse'] = True
mvs_args['sparse_embedding_function'] = MyEmbeddingFunction()
vector_store = MilvusVectorStore(**mvs_args)
发生了一个未知错误。
错误信息:RPC error: [create_index], <MilvusException: (code=1100, message=create index on 104 field is not supported: invalid parameter[expected=supported field][actual=create index on 104 field])>, <Time:{'RPC start': '2024-07-22 09:19:40.888340', 'RPC error': '2024-07-22 09:19:40.894984'}> Traceback (most recent call last): storage_context = StorageContext.from_defaults(vector_store=self.index_milvus.conn_milvus(1792, True, True)) File "/***/llamaindex/llama_index_milvus.py", line 67, in conn_milvus vector_store = MilvusVectorStore(**mvs_args) File "/***/llamaindex/lib/python3.10/site-packages/llama_index/vector_stores/milvus/base.py", line 272, in __init__ self._create_hybrid_index(collection_name) File "/***/envs/llamaindex/lib/python3.10/site-packages/llama_index/vector_stores/milvus/base.py", line 624, in _create_hybrid_index self._collection.create_index(self.sparse_embedding_field, sparse_index) File "/***/envs/llamaindex/lib/python3.10/site-packages/pymilvus/orm/collection.py", line 1367, in create_index return conn.create_index(self._name, field_name, index_params, timeout=timeout, **kwargs) File /***/envs/llamaindex/lib/python3.10/site-packages/pymilvus/decorators.py", line 147, in handler raise e from e File "/***/envs/llamaindex/lib/python3.10/site-packages/pymilvus/decorators.py", line 143, in handler return func(*args, **kwargs) File "/***/envs/llamaindex/lib/python3.10/site-packages/pymilvus/decorators.py", line 182, in handler return func(self, *args, **kwargs) File "/***/envs/llamaindex/lib/python3.10/site-packages/pymilvus/decorators.py", line 122, in handler raise e from e File "/home/wangliang/anaconda3/envs/llamaindex/lib/python3.10/site-packages/pymilvus/decorators.py", line 87, in handler return func(*args, **kwargs) File "/***/envs/llamaindex/lib/python3.10/site-packages/pymilvus/client/grpc_handler.py", line 987, in create_index check_status(status) File "/***/envs/llamaindex/lib/python3.10/site-packages/pymilvus/client/utils.py", line 63, in check_status raise MilvusException(status.code, status.reason, status.error_code) pymilvus.exceptions.MilvusException: <MilvusException: (code=1100, message=create index on 104 field is not supported: invalid parameter[expected=supported field][actual=create index on 104 field])>
1条答案
按热度按时间8wtpewkr1#
要解决错误并成功创建具有混合搜索功能的Milvus索引,请确保您使用的是Milvus 2.4.0或更高版本。以下是设置
MilvusVectorStore
的分步指南:确保Milvus版本:确保您使用的是Milvus 2.4.0或更高版本,因为仅在这些版本中支持混合检索。
设置MilvusVectorStore:使用所需的参数初始化
MilvusVectorStore
,包括将enable_sparse
设置为True
并提供一个sparse_embedding_function
。创建混合索引:将调用
_create_hybrid_index
方法来为密集和稀疏嵌入创建必要的索引。以下是如何设置
MilvusVectorStore
的示例:from llama_index.vector_stores.milvus import MilvusVectorStore
from your_sparse_embedding_module import YourSparseEmbeddingFunction
Setup MilvusVectorStore
vector_store = MilvusVectorStore(
dim=1536,
collection_name="your_collection_name",
uri="http://milvus_address:port",
token="your_milvus_token_here",
overwrite=True,
enable_sparse=True,
sparse_embedding_function=YourSparseEmbeddingFunction(),
hybrid_ranker="RRFRanker",
hybrid_ranker_params={"k": 60}
)
此设置确保启用了混合搜索功能并正确配置。
sparse_embedding_function
应该是一个将文本转换为稀疏嵌入的类的示例。hybrid_ranker
和hybrid_ranker_params
也配置为使用Reciprocal Rank Fusion(RRF)算法,其参数k
设置为60。要获取更详细的示例,您可以参考Milvus Hybrid Index Demo1(https://github.com/run-llama/llama_index/blob/main/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py)2(https://github.com/run-llama/llama_index/blob/main/docs/docs/examples/vector_stores/MilvusHybridIndexDemo.ipynb)。