Skip to content

[Bug]: Commit 2c2d6eb introduce a bug, pymilvus.exceptions.ConnectionNotExistException: <ConnectionNotExistException: (code=1, message=should create connection first.)> #3316

@BaoZheIsMe

Description

@BaoZheIsMe

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am new to use pymilvus, I just copy code from https://milvus.io/docs/zh/basic_usage_langchain.md, and it fails. At last I found the bug reason, new code three days ago:

# legacy compatibility - store alias for _using attribute
 self._using = f"cm-{id(self._handler)}"

My code here:

from langchain_huggingface import HuggingFaceEmbeddings
from langchain_milvus import Milvus

from pymilvus import __version__
from pymilvus import connections


print(__version__)

connections.connect(
    alias="default",
    host="localhost",
    port="19530"
)

embeddings = HuggingFaceEmbeddings(
    model_name="../document_processor/BAAI/bge-large-zh"
)

vector = embeddings.embed_query("Hello, world!")

test_docs = ["testdoc1", "testdoc2"]

vector_db = Milvus.from_texts(
    texts=test_docs,
    embedding=embeddings,
    collection_name="minimal_test",
    connection_args={
        "host": "localhost",
        "port": "19530",
        "alias": "default"
    },
)

and error is:

Traceback (most recent call last):
  File "D:\tool\model\test\langchainTest.py", line 26, in <module>
    vector_db = Milvus.from_texts(
        texts=test_docs,
    ...<6 lines>...
        },
    )
  File "D:\tool\Python313\Lib\site-packages\langchain_milvus\vectorstores\milvus.py", line 2254, in from_texts
    vector_db = cls(
        embedding_function=embedding,
    ...<8 lines>...
        **kwargs,
    )
  File "D:\tool\Python313\Lib\site-packages\langchain_milvus\vectorstores\milvus.py", line 411, in __init__
    self._init(
    ~~~~~~~~~~^
        partition_names=partition_names,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        replica_number=replica_number,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        timeout=timeout,
        ^^^^^^^^^^^^^^^^
    )
    ^
  File "D:\tool\Python313\Lib\site-packages\langchain_milvus\vectorstores\milvus.py", line 733, in _init
    self._extract_fields()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "D:\tool\Python313\Lib\site-packages\langchain_milvus\vectorstores\milvus.py", line 1018, in _extract_fields
    if isinstance(self.col, Collection):
                  ^^^^^^^^
  File "D:\tool\Python313\Lib\site-packages\langchain_milvus\vectorstores\milvus.py", line 580, in col
    self._col_cache = Collection(self.collection_name, using=self.alias)
                      ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\tool\Python313\Lib\site-packages\pymilvus\orm\collection.py", line 120, in __init__
    conn, context = self._get_connection(**kwargs)
                    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "D:\tool\Python313\Lib\site-packages\pymilvus\orm\collection.py", line 192, in _get_connection
    handler = connections._fetch_handler(self._using)
  File "D:\tool\Python313\Lib\site-packages\pymilvus\orm\connections.py", line 571, in _fetch_handler
    raise ConnectionNotExistException(message=ExceptionsMessage.ConnectFirst)
pymilvus.exceptions.ConnectionNotExistException: <ConnectionNotExistException: (code=1, message=should create connection first.)>

After I roll back version to 2.6.9, my code is running successfully.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't workingwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions