milvus-io / pymilvus

Python SDK for Milvus.
Apache License 2.0
952 stars 305 forks source link

[Bug]: illegal connection params or server unavailable #2162

Open zs856 opened 2 weeks ago

zs856 commented 2 weeks ago

Is there an existing issue for this?

Describe the bug

I tried to use the locally configured milvus for development work, and then it gave this exception.During the development process, I tried to switch the WIFI network. I don't know if it has anything to do with this:

2024-07-02 17:42:04,495 - sentence_transformers.SentenceTransformer - INFO - Use pytorch device_name: cpu
2024-07-02 17:42:04,496 - sentence_transformers.SentenceTransformer - INFO - Load pretrained SentenceTransformer: BAAI/bge-m3
2024-07-02 17:43:23,082 - langchain_milvus.vectorstores.milvus - ERROR - Failed to create new connection using: e31306a53b2c42458fb44bd7bf2d309f
---------------------------------------------------------------------------
FutureTimeoutError                        Traceback (most recent call last)
File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/client/grpc_handler.py:147, 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)

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/grpc/_utilities.py:162, in _ChannelReadyFuture.result(self, timeout)
    161 def result(self, timeout: Optional[float] = None) -> None:
--> 162     self._block(timeout)

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/grpc/_utilities.py:106, in _ChannelReadyFuture._block(self, timeout)
    105 if remaining < 0:
--> 106     raise grpc.FutureTimeoutError()
    107 else:

FutureTimeoutError: 

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

MilvusException                           Traceback (most recent call last)
Cell In[43], line 1
----> 1 retriever= Milvus(
      2     embedding_function=HuggingFaceEmbeddings(model_name=MODEL_NAME,multi_process=True, show_progress=True, model_kwargs={"local_files_only":True}),
      3     connection_args=connection_args,
      4     collection_name=COLLECTION_NAME,
      5 ).as_retriever(search_kwargs={"k": 10})

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/langchain_milvus/vectorstores/milvus.py:264, in Milvus.__init__(self, embedding_function, collection_name, collection_description, collection_properties, connection_args, consistency_level, index_params, search_params, drop_old, auto_id, primary_field, text_field, vector_field, metadata_field, partition_key_field, partition_names, replica_number, timeout, num_shards)
    262 if connection_args is None:
    263     connection_args = DEFAULT_MILVUS_CONNECTION
--> 264 self.alias = self._create_connection_alias(connection_args)
    265 self.col: Optional[Collection] = None
    267 # Grab the existing collection if it exists

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/langchain_milvus/vectorstores/milvus.py:346, in Milvus._create_connection_alias(self, connection_args)
    344 except MilvusException as e:
    345     logger.error("Failed to create new connection using: %s", alias)
--> 346     raise e

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/langchain_milvus/vectorstores/milvus.py:341, in Milvus._create_connection_alias(self, connection_args)
    339 alias = uuid4().hex
    340 try:
--> 341     connections.connect(alias=alias, **connection_args)
    342     logger.debug("Created new connection using: %s", alias)
    343     return alias

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/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 /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/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 /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/client/grpc_handler.py:150, in GrpcHandler._wait_for_channel_ready(self, 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
    154 except Exception as e:
    155     raise e from e

MilvusException: <MilvusException: (code=2, message=Fail connecting to server on uni[x:/tmp/tmph2hmv5a4_milvus_demo.db.sock](file:///X:/tmp/tmph2hmv5a4_milvus_demo.db.sock), illegal connection params or server unavailable)>

Expected Behavior

Local Milvus files can be used normally

Steps/Code To Reproduce behavior

1. configuration:

CHUNK_SIZE = 400
CHUNK_OVERLAP = 20
COLLECTION_NAME='ragas'
MODEL_NAME= "BAAI/bge-m3"
connection_args = {
    "uri": "./milvus_demo.db",
}
  1. Ingest data:
    
    import logging
    from typing import List
    from langchain.text_splitter import (
    RecursiveCharacterTextSplitter,
    )
    from langchain_core.documents.base import Document
    from langchain_milvus.vectorstores import Milvus
    from langchain_huggingface import (
    HuggingFaceEmbeddings,
    )
    import os

logging.info(f"RecursiveCharacterTextSplitter: {CHUNK_SIZE=},{CHUNK_OVERLAP=}") text_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder( chunk_size=CHUNK_SIZE, chunk_overlap=CHUNK_OVERLAP ) doc_splits = text_splitter.split_documents(docs)

Add to Milvus

vectorstore =Milvus.from_documents( documents=doc_splits, collection_name=COLLECTION_NAME, embedding=HuggingFaceEmbeddings(model_name=MODEL_NAME,multi_process=False, show_progress=True, model_kwargs={"local_files_only":True}), connection_args=connection_args, )

Environment details

- Hardware/Softward conditions (OS, CPU, GPU, Memory):
Windows 11
16GB
I didn't use GPU
- Method of installation (Docker, or from source):
- Milvus version (v0.3.1, or v0.4.0):
name = "pymilvus"
version = "2.4.4"
- Milvus configuration (Settings you made in `server_config.yaml`):

Anything else?

No response

XuanYang-cn commented 2 weeks ago

@zs856 From your exceptions, your're actually connecting to milvus using this: uni[x:/tmp/tmph2hmv5a4_milvus_demo.db.sock](file:///X:/tmp/tmph2hmv5a4_milvus_demo.db.sock) and it failed.

Seems like something's wrong when connecting to Milvus lite. @junjiejiangjjj Please help identify if this's a bug of Milvus-lite

XuanYang-cn commented 2 weeks ago

/assign @junjiejiangjjj

sre-ci-robot commented 2 weeks ago

@XuanYang-cn: GitHub didn't allow me to assign the following users: junjiejiangjjj.

Note that only milvus-io members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time. For more information please see the contributor guide

In response to [this](https://github.com/milvus-io/pymilvus/issues/2162#issuecomment-2202633263): >/assign @junjiejiangjjj Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
junjiejiangjjj commented 2 weeks ago

Right now milvus-lite doesn't support native Windows install yet, but can work around with wsl (https://learn.microsoft.com/en-us/windows/wsl/install),

zs856 commented 2 weeks ago

I am currently developing in WSL, Ubuntu 24 + VSCode + Jupyter Lab (with port forwarding)

junjiejiangjjj commented 2 weeks ago

Try running this code directly on wsl

from pymilvus import MilvusClient
milvus_client = MilvusClient('./milvus_demo.db')
zs856 commented 2 weeks ago
from pymilvus import MilvusClient
milvus_client = MilvusClient('./milvus_demo.db')
2024-07-02 22:35:22,904 - pymilvus.milvus_client.milvus_client - ERROR - Failed to create new connection using: 0632f8c0045d4cd6b811b2dd0ab219f3
---------------------------------------------------------------------------
MilvusException                           Traceback (most recent call last)
    [... skipping hidden 1 frame]

Cell In[97], line 2
      1 from pymilvus import MilvusClient
----> 2 milvus_client = MilvusClient('./milvus_demo.db')

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/milvus_client/milvus_client.py:58, in MilvusClient.__init__(self, uri, user, password, db_name, token, timeout, **kwargs)
     46 """A client for the common Milvus use case.
     47 
     48 This client attempts to hide away the complexity of using Pymilvus. In a lot ofcases what
   (...)
     56         to None.
     57 """
---> 58 self._using = self._create_connection(
     59     uri, user, password, db_name, token, timeout=timeout, **kwargs
     60 )
     61 self.is_self_hosted = bool(utility.get_server_type(using=self._using) == "milvus")

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/milvus_client/milvus_client.py:651, in MilvusClient._create_connection(self, uri, user, password, db_name, token, **kwargs)
    650     logger.error("Failed to create new connection using: %s", using)
--> 651     raise ex from ex
    652 else:

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/milvus_client/milvus_client.py:648, in MilvusClient._create_connection(self, uri, user, password, db_name, token, **kwargs)
    647 try:
--> 648     connections.connect(using, user, password, db_name, token, uri=uri, **kwargs)
    649 except Exception as ex:

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/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 /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/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 /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/client/grpc_handler.py:150, in GrpcHandler._wait_for_channel_ready(self, 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
    154 except Exception as e:

MilvusException: <MilvusException: (code=2, message=Fail connecting to server on uni[x:/tmp/tmp54q1oh9l_milvus_demo.db.sock](file:///X:/tmp/tmp54q1oh9l_milvus_demo.db.sock), illegal connection params or server unavailable)>

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

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

Cell In[97], line 2
      1 from pymilvus import MilvusClient
----> 2 milvus_client = MilvusClient('./milvus_demo.db')

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/milvus_client/milvus_client.py:58, in MilvusClient.__init__(self, uri, user, password, db_name, token, timeout, **kwargs)
     46 """A client for the common Milvus use case.
     47 
     48 This client attempts to hide away the complexity of using Pymilvus. In a lot ofcases what
   (...)
     56         to None.
     57 """
---> 58 self._using = self._create_connection(
     59     uri, user, password, db_name, token, timeout=timeout, **kwargs
     60 )
     61 self.is_self_hosted = bool(utility.get_server_type(using=self._using) == "milvus")

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/milvus_client/milvus_client.py:651, in MilvusClient._create_connection(self, uri, user, password, db_name, token, **kwargs)
    650     logger.error("Failed to create new connection using: %s", using)
--> 651     raise ex from ex
    652 else:

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/milvus_client/milvus_client.py:648, in MilvusClient._create_connection(self, uri, user, password, db_name, token, **kwargs)
    647 try:
--> 648     connections.connect(using, user, password, db_name, token, uri=uri, **kwargs)
    649 except Exception as ex:

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/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 /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/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 /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/client/grpc_handler.py:150, in GrpcHandler._wait_for_channel_ready(self, 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
    154 except Exception as e:

MilvusException: <MilvusException: (code=2, message=Fail connecting to server on uni[x:/tmp/tmp54q1oh9l_milvus_demo.db.sock](file:///X:/tmp/tmp54q1oh9l_milvus_demo.db.sock), illegal connection params or server unavailable)>

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

MilvusException                           Traceback (most recent call last)
Cell In[97], line 2
      1 from pymilvus import MilvusClient
----> 2 milvus_client = MilvusClient('./milvus_demo.db')

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/milvus_client/milvus_client.py:58, in MilvusClient.__init__(self, uri, user, password, db_name, token, timeout, **kwargs)
     36 def __init__(
     37     self,
     38     uri: str = "http://localhost:19530",
   (...)
     44     **kwargs,
     45 ) -> None:
     46     """A client for the common Milvus use case.
     47 
     48     This client attempts to hide away the complexity of using Pymilvus. In a lot ofcases what
   (...)
     56             to None.
     57     """
---> 58     self._using = self._create_connection(
     59         uri, user, password, db_name, token, timeout=timeout, **kwargs
     60     )
     61     self.is_self_hosted = bool(utility.get_server_type(using=self._using) == "milvus")

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/milvus_client/milvus_client.py:651, in MilvusClient._create_connection(self, uri, user, password, db_name, token, **kwargs)
    649 except Exception as ex:
    650     logger.error("Failed to create new connection using: %s", using)
--> 651     raise ex from ex
    652 else:
    653     logger.debug("Created new connection using: %s", using)

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/milvus_client/milvus_client.py:648, in MilvusClient._create_connection(self, uri, user, password, db_name, token, **kwargs)
    646 using = uuid4().hex
    647 try:
--> 648     connections.connect(using, user, password, db_name, token, uri=uri, **kwargs)
    649 except Exception as ex:
    650     logger.error("Failed to create new connection using: %s", using)

File /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/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 /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/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 /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/pymilvus/client/grpc_handler.py:150, in GrpcHandler._wait_for_channel_ready(self, 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
    154 except Exception as e:
    155     raise e from e

MilvusException: <MilvusException: (code=2, message=Fail connecting to server on unix:/tmp/tmp54q1oh9l_milvus_demo.db.sock, illegal connection params or server unavailable)>

I got this

junjiejiangjjj commented 2 weeks ago

Run this command in the wsl terminal so that the error log is clearer。Please make sure milvus_lite is installed in this directory:/mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/

LD_LIBRARY_PATH=/mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/milvus_lite/lib/  /mnt/d/development/Github/streamlit-hello/.venv/lib/python3.12/site-packages/milvus_lite/lib/milvus ./mivlus.db unix:/tmp/tmp54q1oh9l_milvus_demo.db.sock INFO