pymilvus icon indicating copy to clipboard operation
pymilvus copied to clipboard

[Bug]: Not able to create the pymilvus client

Open vimalKeshu opened this issue 9 months ago • 7 comments
trafficstars

Is there an existing issue for this?

  • [x] I have searched the existing issues

Describe the bug

Not able to create the pymilvus client instance

>>> from pymilvus import MilvusClient
>>> client = MilvusClient('/mnt/data/milvus_production_2.db')

Error:

2025-02-06 09:33:01,663 [ERROR][_create_connection]: Failed to create new connection using: e28873b89c65473581512fba94fbe286 (milvus_client.py:920)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/pymilvus/milvus_client/milvus_client.py", line 66, in __init__
    self._using = self._create_connection(
  File "/usr/local/lib/python3.9/site-packages/pymilvus/milvus_client/milvus_client.py", line 921, in _create_connection
    raise ex from ex
  File "/usr/local/lib/python3.9/site-packages/pymilvus/milvus_client/milvus_client.py", line 918, in _create_connection
    connections.connect(using, user, password, db_name, token, uri=uri, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pymilvus/orm/connections.py", line 461, in connect
    connect_milvus(**kwargs, user=user, password=password, token=token, db_name=db_name)
  File "/usr/local/lib/python3.9/site-packages/pymilvus/orm/connections.py", line 411, in connect_milvus
    gh._wait_for_channel_ready(timeout=timeout)
  File "/usr/local/lib/python3.9/site-packages/pymilvus/client/grpc_handler.py", line 152, in _wait_for_channel_ready
    raise MilvusException(
pymilvus.exceptions.MilvusException: <MilvusException: (code=2, message=Fail connecting to server on unix:/tmp/tmpe2y_kvf0_milvus_production_2.db.sock, illegal connection params or server unavailable)>

Expected Behavior

No response

Steps/Code To Reproduce behavior


Environment details

- Hardware/Softward conditions (OS, CPU, GPU, Memory):
- Method of installation (Docker, or from source):
- Milvus version (v0.3.1, or v0.4.0):
- Milvus configuration (Settings you made in `server_config.yaml`):

Anything else?

No response

vimalKeshu avatar Feb 06 '25 09:02 vimalKeshu

@vimalKeshu What's your system platform?

XuanYang-cn avatar Feb 06 '25 09:02 XuanYang-cn

@XuanYang-cn

  1. kubernetes cluster,
  2. cent-os pod image
  3. Python version: 3.9 & 3.10 (tried both)

Sometime, i faced similar issue on my mac with jupyter notebook.

vimalKeshu avatar Feb 06 '25 12:02 vimalKeshu

@XuanYang-cn I tried to recreate the issue on my mac book and able to recreate it successfully.

i created the test.py using below code, ran it first and it ran successfully :

from pymilvus import connections, MilvusClient, model


def setup_db(client, collection_name):
    if not client.has_collection(collection_name=collection_name):
        client.create_collection(
            collection_name=collection_name,
            dimension=768,
        )    
        embedding_fn = model.DefaultEmbeddingFunction()
        docs = [
            "Artificial intelligence was founded as an academic discipline in 1956.",
            "Alan Turing was the first person to conduct substantial research in AI.",
            "Born in Maida Vale, London, Turing was raised in southern England.",
        ]
        vectors = embedding_fn.encode_documents(docs)
        print("Dim:", embedding_fn.dim, vectors[0].shape)  # Dim: 768 (768,)
        data = [
            {"id": i, "vector": vectors[i], "text": docs[i], "subject": "history"}
            for i in range(len(vectors))
        ]
        print("Data has", len(data), "entities, each with fields: ", data[0].keys())
        print("Vector dim:", len(data[0]["vector"]))
        res = client.insert(collection_name="demo_collection", data=data)
        print(res)


db_name="example.db"
collection_name="demo_collection"
client = MilvusClient(uri=db_name)
print(connections.list_connections())

setup_db(client=client, collection_name=collection_name)
embedding_fn = model.DefaultEmbeddingFunction()
query_vectors = embedding_fn.encode_queries(["Who is Alan Turing?"])
res = client.search(
    collection_name=collection_name,  # target collection
    data=query_vectors,  # query vectors
    limit=2,  # number of returned entities
    output_fields=["text", "subject"],  # specifies fields to be returned
)

print(res)

for con in connections.list_connections():
    print(f'disconnect: {con[0]}')
    connections.disconnect(con[0])
print(connections.list_connections())

Later, i created the jupyter notebook, ran below code and faced the similar kind of issue:

from pymilvus import MilvusClient
from pymilvus import model
from pymilvus import connections
import time
import traceback


client = None
db_name="example.db"
collection_name="demo_collection"

client = MilvusClient(db_name, timeout=20)
embedding_fn = model.DefaultEmbeddingFunction()
query_vectors = embedding_fn.encode_queries(["Who is Alan Turing?"])
res = client.search(
    collection_name=collection_name,  # target collection
    data=query_vectors,  # query vectors
    limit=2,  # number of returned entities
    output_fields=["text", "subject"],  # specifies fields to be returned
)

print(res)

Got below error:

MilvusException: <MilvusException: (code=2, message=Fail connecting to server on unix:/var/folders/57/lxmrd2t55j5356d00qmfj_wwmygpl1/T/tmpwwlbydek_example.db.sock, illegal connection params or server unavailable)>

vimalKeshu avatar Feb 06 '25 15:02 vimalKeshu

/assign @junjiejiangjjj Please take a look. Seems like using jupyter notebook milvus-lite cannot connect to the local exsiting milvus.db.

XuanYang-cn avatar Feb 07 '25 02:02 XuanYang-cn

@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:

/assign @junjiejiangjjj Please take a look. Seems like using jupyter notebook milvus-lite cannot connect to the local exsiting milvus.db.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

sre-ci-robot avatar Feb 07 '25 02:02 sre-ci-robot

This error means that milvus-lite starts failed. Milvus Lite currently supports the following environmnets:

  • Ubuntu >= 20.04 (x86_64 and arm64)
  • MacOS >= 11.0 (Apple Silicon M1/M2 and x86_64)

And the db file can only be opened by one process.

junjiejiangjjj avatar Feb 07 '25 03:02 junjiejiangjjj

@junjiejiangjjj Understood. As per your given environment description, it should work on my mac as i have macos 14 and intel x86_64 cpu.

For creating the issue on my mac, i ran the python scripts one after another to maintain the lock on db by only one process at a time.

vimalKeshu avatar Feb 07 '25 06:02 vimalKeshu