Spaces:
Sleeping
Sleeping
File size: 1,002 Bytes
79d4fd5 | 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 28 29 30 31 32 33 34 35 | # Shared Qdrant client manager to prevent multiple instance conflicts
import logging
from typing import Optional
from qdrant_client import QdrantClient
from config import QDRANT_PATH, USE_MEMORY_MODE
logger = logging.getLogger(__name__)
_shared_client: Optional[QdrantClient] = None
def get_qdrant_client() -> QdrantClient:
"""Return shared Qdrant client instance."""
global _shared_client
if _shared_client is None:
if USE_MEMORY_MODE:
logger.info("Creating in-memory Qdrant client")
_shared_client = QdrantClient(":memory:")
else:
logger.info(f"Creating Qdrant client with path: {QDRANT_PATH}")
_shared_client = QdrantClient(path=QDRANT_PATH)
return _shared_client
def reset_qdrant_client():
"""Reset shared client for testing."""
global _shared_client
if _shared_client is not None:
try:
_shared_client.close()
except Exception:
pass
_shared_client = None
|