Spaces:
Sleeping
Sleeping
File size: 985 Bytes
623fdec 11eaf27 f496b94 11eaf27 f496b94 623fdec 11eaf27 623fdec 11eaf27 623fdec |
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 26 27 |
from pymilvus import 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 connections.connect() to establish the connection
connections.connect(uri=uri)
self._instance = connections # Store the connections object
print(f"Successfully connected to Milvus at {uri}")
except ConnectionConfigException as e:
print(f"Error connecting to Milvus: {e}")
raise
def __getattr__(self, name):
# Delegate attribute access to the default connection
return getattr(connections, name) |