File size: 909 Bytes
11eaf27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from pymilvus import Milvus, connections
from pymilvus.exceptions import ConnectionConfigException

class MilvusClientSingleton:
    _instance = None

    @staticmethod
    def get_instance(uri):
        if MilvusClientSingleton._instance is None:
            MilvusClientSingleton(uri)
        return MilvusClientSingleton._instance

    def __init__(self, uri):
        if MilvusClientSingleton._instance is not None:
            raise Exception("This class is a singleton!")
        try:
            # Use the regular Milvus client (not MilvusClient)
            self._instance = Milvus(uri=uri)
            print(f"Successfully connected to Milvus at {uri}")
        except ConnectionConfigException as e:
            print(f"Error connecting to Milvus: {e}")
            raise  # Re-raise the exception to stop initialization

    def __getattr__(self, name):
        return getattr(self._instance, name)