run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
36.19k stars 5.16k forks source link

[Bug]: MilvusVectorStore failed to connect to the database when enable_sparse is True #13769

Closed osafaimal closed 4 months ago

osafaimal commented 4 months ago

Bug Description

The MilvusVectorStore failed to connect when enable_sparse is True. when i set it to false it can connect.

Version

0.10.38

Steps to Reproduce

you have just to do:

vector_store = MilvusVectorStore(uri="http://localhost:19530", dim=1024, token="root:Milvus",enable_sparse=True)

Relevant Logs/Tracbacks

---------------------------------------------------------------------------
_InactiveRpcError                         Traceback (most recent call last)
    [... skipping hidden 1 frame]

Cell In[7], line 5
      3 documents=[Document.example()]
----> 5 vector_store = MilvusVectorStore(uri="http://localhost:19530", dim=1024, overwrite=True, token="root:Milvus", collection_name="llamacollection_hybrid",enable_sparse=True, )

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/llama_index/vector_stores/milvus/base.py:269, in MilvusVectorStore.__init__(self, uri, token, collection_name, dim, embedding_field, doc_id_field, similarity_metric, consistency_level, overwrite, text_key, output_fields, index_config, search_config, batch_size, enable_sparse, sparse_embedding_function, hybrid_ranker, hybrid_ranker_params, **kwargs)
    268 host, port = extract_host_port(uri)
--> 269 connections.connect("default", host=host, port=port)
    270 self._collection = Collection(collection_name)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/orm/connections.py:447, in Connections.connect(self, alias, user, password, db_name, token, **kwargs)
    445         kwargs["secure"] = True
--> 447 connect_milvus(**kwargs, user=user, password=password, token=token, db_name=db_name)
    448 return

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/orm/connections.py:398, in Connections.connect.<locals>.connect_milvus(**kwargs)
    396 timeout = t if isinstance(t, (int, float)) else Config.MILVUS_CONN_TIMEOUT
--> 398 gh._wait_for_channel_ready(timeout=timeout)
    399 if kwargs.get("keep_alive", False):

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:155, in GrpcHandler._wait_for_channel_ready(self, timeout)
    154 except Exception as e:
--> 155     raise e from e

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:148, in GrpcHandler._wait_for_channel_ready(self, timeout)
    147     grpc.channel_ready_future(self._channel).result(timeout=timeout)
--> 148     self._setup_identifier_interceptor(self._user, timeout=timeout)
    149 except grpc.FutureTimeoutError as e:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:266, in GrpcHandler._setup_identifier_interceptor(self, user, timeout)
    265 host = socket.gethostname()
--> 266 self._identifier = self.__internal_register(user, host, timeout=timeout)
    267 self._identifier_interceptor = interceptor.header_adder_interceptor(
    268     ["identifier"], [str(self._identifier)]
    269 )

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:161, in error_handler.<locals>.wrapper.<locals>.handler(*args, **kwargs)
    157     LOGGER.error(
    158         f"grpc RpcError: [{inner_name}], <{e.__class__.__name__}: "
    159         f"{e.code()}, {e.details()}>, <Time:{record_dict}>"
    160     )
--> 161     raise e from e
    162 except Exception as e:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:143, in error_handler.<locals>.wrapper.<locals>.handler(*args, **kwargs)
    142     record_dict["RPC start"] = str(datetime.datetime.now())
--> 143     return func(*args, **kwargs)
    144 except MilvusException as e:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:182, in tracing_request.<locals>.wrapper.<locals>.handler(self, *args, **kwargs)
    181     self.set_onetime_request_id(req_id)
--> 182 return func(self, *args, **kwargs)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:91, in retry_on_rpc_failure.<locals>.wrapper.<locals>.handler(*args, **kwargs)
     90 if e.code() in IGNORE_RETRY_CODES:
---> 91     raise e from e
     92 if timeout(start_time):

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:87, in retry_on_rpc_failure.<locals>.wrapper.<locals>.handler(*args, **kwargs)
     86 try:
---> 87     return func(*args, **kwargs)
     88 except grpc.RpcError as e:
     89     # Do not retry on these codes

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:220, in upgrade_reminder.<locals>.handler(*args, **kwargs)
    219         raise MilvusException(message=msg) from e
--> 220     raise e from e
    221 except Exception as e:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:212, in upgrade_reminder.<locals>.handler(*args, **kwargs)
    211 try:
--> 212     return func(*args, **kwargs)
    213 except grpc.RpcError as e:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:1965, in GrpcHandler.__internal_register(self, user, host, **kwargs)
   1964 req = Prepare.register_request(user, host)
-> 1965 response = self._stub.Connect(request=req)
   1966 check_status(response.status)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_interceptor.py:277, in _UnaryUnaryMultiCallable.__call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)
    268 def __call__(
    269     self,
    270     request: Any,
   (...)
    275     compression: Optional[grpc.Compression] = None,
    276 ) -> Any:
--> 277     response, ignored_call = self._with_call(
    278         request,
    279         timeout=timeout,
    280         metadata=metadata,
    281         credentials=credentials,
    282         wait_for_ready=wait_for_ready,
    283         compression=compression,
    284     )
    285     return response

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_interceptor.py:332, in _UnaryUnaryMultiCallable._with_call(self, request, timeout, metadata, credentials, wait_for_ready, compression)
    329 call = self._interceptor.intercept_unary_unary(
    330     continuation, client_call_details, request
    331 )
--> 332 return call.result(), call

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_channel.py:437, in _InactiveRpcError.result(self, timeout)
    436 """See grpc.Future.result."""
--> 437 raise self

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_interceptor.py:315, in _UnaryUnaryMultiCallable._with_call.<locals>.continuation(new_details, request)
    314 try:
--> 315     response, call = self._thunk(new_method).with_call(
    316         request,
    317         timeout=new_timeout,
    318         metadata=new_metadata,
    319         credentials=new_credentials,
    320         wait_for_ready=new_wait_for_ready,
    321         compression=new_compression,
    322     )
    323     return _UnaryOutcome(response, call)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_channel.py:1177, in _UnaryUnaryMultiCallable.with_call(self, request, timeout, metadata, credentials, wait_for_ready, compression)
   1171 (
   1172     state,
   1173     call,
   1174 ) = self._blocking(
   1175     request, timeout, metadata, credentials, wait_for_ready, compression
   1176 )
-> 1177 return _end_unary_response_blocking(state, call, True, None)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_channel.py:1003, in _end_unary_response_blocking(state, call, with_call, deadline)
   1002 else:
-> 1003     raise _InactiveRpcError(state)

_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.UNAUTHENTICATED
    details = "missing authorization in header"
    debug_error_string = "UNKNOWN:Error received from peer  {grpc_message:"missing authorization in header", grpc_status:16, created_time:"2024-05-28T13:29:24.059748287+02:00"}"
>

The above exception was the direct cause of the following exception:

_InactiveRpcError                         Traceback (most recent call last)
    [... skipping hidden 1 frame]

Cell In[7], line 5
      3 documents=[Document.example()]
----> 5 vector_store = MilvusVectorStore(uri="http://localhost:19530", dim=1024, overwrite=True, token="root:Milvus", collection_name="llamacollection_hybrid",enable_sparse=True, )

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/llama_index/vector_stores/milvus/base.py:269, in MilvusVectorStore.__init__(self, uri, token, collection_name, dim, embedding_field, doc_id_field, similarity_metric, consistency_level, overwrite, text_key, output_fields, index_config, search_config, batch_size, enable_sparse, sparse_embedding_function, hybrid_ranker, hybrid_ranker_params, **kwargs)
    268 host, port = extract_host_port(uri)
--> 269 connections.connect("default", host=host, port=port)
    270 self._collection = Collection(collection_name)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/orm/connections.py:447, in Connections.connect(self, alias, user, password, db_name, token, **kwargs)
    445         kwargs["secure"] = True
--> 447 connect_milvus(**kwargs, user=user, password=password, token=token, db_name=db_name)
    448 return

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/orm/connections.py:398, in Connections.connect.<locals>.connect_milvus(**kwargs)
    396 timeout = t if isinstance(t, (int, float)) else Config.MILVUS_CONN_TIMEOUT
--> 398 gh._wait_for_channel_ready(timeout=timeout)
    399 if kwargs.get("keep_alive", False):

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:155, in GrpcHandler._wait_for_channel_ready(self, timeout)
    154 except Exception as e:
--> 155     raise e from e

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:148, in GrpcHandler._wait_for_channel_ready(self, timeout)
    147     grpc.channel_ready_future(self._channel).result(timeout=timeout)
--> 148     self._setup_identifier_interceptor(self._user, timeout=timeout)
    149 except grpc.FutureTimeoutError as e:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:266, in GrpcHandler._setup_identifier_interceptor(self, user, timeout)
    265 host = socket.gethostname()
--> 266 self._identifier = self.__internal_register(user, host, timeout=timeout)
    267 self._identifier_interceptor = interceptor.header_adder_interceptor(
    268     ["identifier"], [str(self._identifier)]
    269 )

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:161, in error_handler.<locals>.wrapper.<locals>.handler(*args, **kwargs)
    157     LOGGER.error(
    158         f"grpc RpcError: [{inner_name}], <{e.__class__.__name__}: "
    159         f"{e.code()}, {e.details()}>, <Time:{record_dict}>"
    160     )
--> 161     raise e from e
    162 except Exception as e:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:143, in error_handler.<locals>.wrapper.<locals>.handler(*args, **kwargs)
    142     record_dict["RPC start"] = str(datetime.datetime.now())
--> 143     return func(*args, **kwargs)
    144 except MilvusException as e:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:182, in tracing_request.<locals>.wrapper.<locals>.handler(self, *args, **kwargs)
    181     self.set_onetime_request_id(req_id)
--> 182 return func(self, *args, **kwargs)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:91, in retry_on_rpc_failure.<locals>.wrapper.<locals>.handler(*args, **kwargs)
     90 if e.code() in IGNORE_RETRY_CODES:
---> 91     raise e from e
     92 if timeout(start_time):

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:87, in retry_on_rpc_failure.<locals>.wrapper.<locals>.handler(*args, **kwargs)
     86 try:
---> 87     return func(*args, **kwargs)
     88 except grpc.RpcError as e:
     89     # Do not retry on these codes

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:220, in upgrade_reminder.<locals>.handler(*args, **kwargs)
    219         raise MilvusException(message=msg) from e
--> 220     raise e from e
    221 except Exception as e:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:212, in upgrade_reminder.<locals>.handler(*args, **kwargs)
    211 try:
--> 212     return func(*args, **kwargs)
    213 except grpc.RpcError as e:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:1965, in GrpcHandler.__internal_register(self, user, host, **kwargs)
   1964 req = Prepare.register_request(user, host)
-> 1965 response = self._stub.Connect(request=req)
   1966 check_status(response.status)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_interceptor.py:277, in _UnaryUnaryMultiCallable.__call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)
    268 def __call__(
    269     self,
    270     request: Any,
   (...)
    275     compression: Optional[grpc.Compression] = None,
    276 ) -> Any:
--> 277     response, ignored_call = self._with_call(
    278         request,
    279         timeout=timeout,
    280         metadata=metadata,
    281         credentials=credentials,
    282         wait_for_ready=wait_for_ready,
    283         compression=compression,
    284     )
    285     return response

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_interceptor.py:332, in _UnaryUnaryMultiCallable._with_call(self, request, timeout, metadata, credentials, wait_for_ready, compression)
    329 call = self._interceptor.intercept_unary_unary(
    330     continuation, client_call_details, request
    331 )
--> 332 return call.result(), call

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_channel.py:437, in _InactiveRpcError.result(self, timeout)
    436 """See grpc.Future.result."""
--> 437 raise self

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_interceptor.py:315, in _UnaryUnaryMultiCallable._with_call.<locals>.continuation(new_details, request)
    314 try:
--> 315     response, call = self._thunk(new_method).with_call(
    316         request,
    317         timeout=new_timeout,
    318         metadata=new_metadata,
    319         credentials=new_credentials,
    320         wait_for_ready=new_wait_for_ready,
    321         compression=new_compression,
    322     )
    323     return _UnaryOutcome(response, call)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_channel.py:1177, in _UnaryUnaryMultiCallable.with_call(self, request, timeout, metadata, credentials, wait_for_ready, compression)
   1171 (
   1172     state,
   1173     call,
   1174 ) = self._blocking(
   1175     request, timeout, metadata, credentials, wait_for_ready, compression
   1176 )
-> 1177 return _end_unary_response_blocking(state, call, True, None)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_channel.py:1003, in _end_unary_response_blocking(state, call, with_call, deadline)
   1002 else:
-> 1003     raise _InactiveRpcError(state)

_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.UNAUTHENTICATED
    details = "missing authorization in header"
    debug_error_string = "UNKNOWN:Error received from peer  {grpc_message:"missing authorization in header", grpc_status:16, created_time:"2024-05-28T13:29:24.059748287+02:00"}"
>

The above exception was the direct cause of the following exception:

_InactiveRpcError                         Traceback (most recent call last)
Cell In[7], line 5
      2 from llama_index.vector_stores.milvus import MilvusVectorStore
      3 documents=[Document.example()]
----> 5 vector_store = MilvusVectorStore(uri="http://localhost:19530", dim=1024, overwrite=True, token="root:Milvus", collection_name="llamacollection_hybrid",enable_sparse=True, )

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/llama_index/vector_stores/milvus/base.py:269, in MilvusVectorStore.__init__(self, uri, token, collection_name, dim, embedding_field, doc_id_field, similarity_metric, consistency_level, overwrite, text_key, output_fields, index_config, search_config, batch_size, enable_sparse, sparse_embedding_function, hybrid_ranker, hybrid_ranker_params, **kwargs)
    267 else:
    268     host, port = extract_host_port(uri)
--> 269     connections.connect("default", host=host, port=port)
    270     self._collection = Collection(collection_name)
    272 self._create_index_if_required()

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/orm/connections.py:447, in Connections.connect(self, alias, user, password, db_name, token, **kwargs)
    444         if parsed_uri.scheme == "https":
    445             kwargs["secure"] = True
--> 447     connect_milvus(**kwargs, user=user, password=password, token=token, db_name=db_name)
    448     return
    450 # 2nd Priority, connection configs from env

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/orm/connections.py:398, in Connections.connect.<locals>.connect_milvus(**kwargs)
    395 t = kwargs.get("timeout")
    396 timeout = t if isinstance(t, (int, float)) else Config.MILVUS_CONN_TIMEOUT
--> 398 gh._wait_for_channel_ready(timeout=timeout)
    399 if kwargs.get("keep_alive", False):
    400     gh.register_state_change_callback(
    401         ReconnectHandler(self, alias, kwargs_copy).reconnect_on_idle
    402     )

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:155, in GrpcHandler._wait_for_channel_ready(self, timeout)
    150     raise MilvusException(
    151         code=Status.CONNECT_FAILED,
    152         message=f"Fail connecting to server on {self._address}, illegal connection params or server unavailable",
    153     ) from e
    154 except Exception as e:
--> 155     raise e from e

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:148, in GrpcHandler._wait_for_channel_ready(self, timeout)
    146 try:
    147     grpc.channel_ready_future(self._channel).result(timeout=timeout)
--> 148     self._setup_identifier_interceptor(self._user, timeout=timeout)
    149 except grpc.FutureTimeoutError as e:
    150     raise MilvusException(
    151         code=Status.CONNECT_FAILED,
    152         message=f"Fail connecting to server on {self._address}, illegal connection params or server unavailable",
    153     ) from e

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:266, in GrpcHandler._setup_identifier_interceptor(self, user, timeout)
    264 def _setup_identifier_interceptor(self, user: str, timeout: int = 10):
    265     host = socket.gethostname()
--> 266     self._identifier = self.__internal_register(user, host, timeout=timeout)
    267     self._identifier_interceptor = interceptor.header_adder_interceptor(
    268         ["identifier"], [str(self._identifier)]
    269     )
    270     self._final_channel = grpc.intercept_channel(
    271         self._final_channel, self._identifier_interceptor
    272     )

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:161, in error_handler.<locals>.wrapper.<locals>.handler(*args, **kwargs)
    156     record_dict["gRPC error"] = str(datetime.datetime.now())
    157     LOGGER.error(
    158         f"grpc RpcError: [{inner_name}], <{e.__class__.__name__}: "
    159         f"{e.code()}, {e.details()}>, <Time:{record_dict}>"
    160     )
--> 161     raise e from e
    162 except Exception as e:
    163     record_dict["Exception"] = str(datetime.datetime.now())

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:143, in error_handler.<locals>.wrapper.<locals>.handler(*args, **kwargs)
    141 try:
    142     record_dict["RPC start"] = str(datetime.datetime.now())
--> 143     return func(*args, **kwargs)
    144 except MilvusException as e:
    145     record_dict["RPC error"] = str(datetime.datetime.now())

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:182, in tracing_request.<locals>.wrapper.<locals>.handler(self, *args, **kwargs)
    180 if req_id:
    181     self.set_onetime_request_id(req_id)
--> 182 return func(self, *args, **kwargs)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:91, in retry_on_rpc_failure.<locals>.wrapper.<locals>.handler(*args, **kwargs)
     88 except grpc.RpcError as e:
     89     # Do not retry on these codes
     90     if e.code() in IGNORE_RETRY_CODES:
---> 91         raise e from e
     92     if timeout(start_time):
     93         raise MilvusException(e.code, f"{to_msg}, message={e.details()}") from e

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:87, in retry_on_rpc_failure.<locals>.wrapper.<locals>.handler(*args, **kwargs)
     85 while True:
     86     try:
---> 87         return func(*args, **kwargs)
     88     except grpc.RpcError as e:
     89         # Do not retry on these codes
     90         if e.code() in IGNORE_RETRY_CODES:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:220, in upgrade_reminder.<locals>.handler(*args, **kwargs)
    215         msg = (
    216             "this version of sdk is incompatible with server, "
    217             "please downgrade your sdk or upgrade your server"
    218         )
    219         raise MilvusException(message=msg) from e
--> 220     raise e from e
    221 except Exception as e:
    222     raise e from e

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/decorators.py:212, in upgrade_reminder.<locals>.handler(*args, **kwargs)
    209 @functools.wraps(func)
    210 def handler(*args, **kwargs):
    211     try:
--> 212         return func(*args, **kwargs)
    213     except grpc.RpcError as e:
    214         if e.code() == grpc.StatusCode.UNIMPLEMENTED:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:1965, in GrpcHandler.__internal_register(self, user, host, **kwargs)
   1961 @retry_on_rpc_failure()
   1962 @upgrade_reminder
   1963 def __internal_register(self, user: str, host: str, **kwargs) -> int:
   1964     req = Prepare.register_request(user, host)
-> 1965     response = self._stub.Connect(request=req)
   1966     check_status(response.status)
   1967     return response.identifier

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_interceptor.py:277, in _UnaryUnaryMultiCallable.__call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)
    268 def __call__(
    269     self,
    270     request: Any,
   (...)
    275     compression: Optional[grpc.Compression] = None,
    276 ) -> Any:
--> 277     response, ignored_call = self._with_call(
    278         request,
    279         timeout=timeout,
    280         metadata=metadata,
    281         credentials=credentials,
    282         wait_for_ready=wait_for_ready,
    283         compression=compression,
    284     )
    285     return response

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_interceptor.py:332, in _UnaryUnaryMultiCallable._with_call(self, request, timeout, metadata, credentials, wait_for_ready, compression)
    327         return _FailureOutcome(exception, sys.exc_info()[2])
    329 call = self._interceptor.intercept_unary_unary(
    330     continuation, client_call_details, request
    331 )
--> 332 return call.result(), call

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_channel.py:437, in _InactiveRpcError.result(self, timeout)
    433 def result(
    434     self, timeout: Optional[float] = None
    435 ) -> Any:  # pylint: disable=unused-argument
    436     """See grpc.Future.result."""
--> 437     raise self

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_interceptor.py:315, in _UnaryUnaryMultiCallable._with_call.<locals>.continuation(new_details, request)
    306 (
    307     new_method,
    308     new_timeout,
   (...)
    312     new_compression,
    313 ) = _unwrap_client_call_details(new_details, client_call_details)
    314 try:
--> 315     response, call = self._thunk(new_method).with_call(
    316         request,
    317         timeout=new_timeout,
    318         metadata=new_metadata,
    319         credentials=new_credentials,
    320         wait_for_ready=new_wait_for_ready,
    321         compression=new_compression,
    322     )
    323     return _UnaryOutcome(response, call)
    324 except grpc.RpcError as rpc_error:

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_channel.py:1177, in _UnaryUnaryMultiCallable.with_call(self, request, timeout, metadata, credentials, wait_for_ready, compression)
   1162 def with_call(
   1163     self,
   1164     request: Any,
   (...)
   1169     compression: Optional[grpc.Compression] = None,
   1170 ) -> Tuple[Any, grpc.Call]:
   1171     (
   1172         state,
   1173         call,
   1174     ) = self._blocking(
   1175         request, timeout, metadata, credentials, wait_for_ready, compression
   1176     )
-> 1177     return _end_unary_response_blocking(state, call, True, None)

File ~/Documents/LLM_from_base/.venv/lib/python3.11/site-packages/grpc/_channel.py:1003, in _end_unary_response_blocking(state, call, with_call, deadline)
   1001         return state.response
   1002 else:
-> 1003     raise _InactiveRpcError(state)

_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.UNAUTHENTICATED
    details = "missing authorization in header"
    debug_error_string = "UNKNOWN:Error received from peer  {grpc_message:"missing authorization in header", grpc_status:16, created_time:"2024-05-28T13:29:24.059748287+02:00"}"
dosubot[bot] commented 4 months ago

The MilvusVectorStore fails to connect to the database when enable_sparse is set to True because hybrid retrieval, which involves sparse embeddings, is only supported in Milvus 2.4.0 or later. If your Milvus instance is older than version 2.4.0, the connection will fail [1].

Additionally, ensure that your network and firewall configurations allow traffic on the specified host and port, as the connection process involves extracting the host and port from the URI and connecting to the Milvus instance [1].

To resolve this issue, verify that your Milvus instance is version 2.4.0 or later and check your network and firewall settings.

#### Details **About 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.

To continue the conversation, mention @dosu.

osafaimal commented 4 months ago

in the docker-compose: image: milvusdb/milvus:v2.4.14.1

llama-index-vector-stores-milvus Version: 0.1.14 pymilvus Version: 2.4.3

osafaimal commented 4 months ago

@dosu

dosubot[bot] commented 4 months ago

To resolve the issue with MilvusVectorStore failing to connect to the database when enable_sparse is set to True, ensure that you provide the token parameter correctly when initializing the MilvusVectorStore. The error message "missing authorization in header" indicates that the token might not be properly included in the request.

Here is an example of how to properly initialize the MilvusVectorStore with the token parameter:

from llama_index.vector_stores.milvus import MilvusVectorStore

# Setup MilvusVectorStore with token for authorization
vector_store = MilvusVectorStore(
    dim=1024,
    collection_name="llamacollection_hybrid",
    uri="http://localhost:19530",
    token="root:Milvus",  # Ensure you provide the token here
    overwrite=True,
    enable_sparse=True,  # Enable sparse embeddings
    sparse_embedding_function=your_sparse_embedding_function  # Provide your sparse embedding function
)

Make sure to replace "your_sparse_embedding_function" with the actual sparse embedding function you are using. This should resolve the "missing authorization in header" error [1][2].

#### Details **About 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.

To continue the conversation, mention @dosu.

RussellLuo commented 4 months ago

The crux of the problem is that token is not included when making the connection:

https://github.com/run-llama/llama_index/blob/038d5105b684e5286b5771e7722ad3a9e3e8ec75/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py#L268-L269

To my understanding, there should be no difference in the handling regardless of whether enable_sparse is true or false. I'll try to submit a PR to fix this.