# 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