Spaces:
Sleeping
Sleeping
File size: 878 Bytes
732b14f | 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 | """Shared async Qdrant client (singleton) for search + semantic cache."""
from __future__ import annotations
from typing import TYPE_CHECKING
from app.config import settings
if TYPE_CHECKING:
from qdrant_client import AsyncQdrantClient
_async_client: AsyncQdrantClient | None = None
def get_async_qdrant_client() -> AsyncQdrantClient:
"""Return a process-wide ``AsyncQdrantClient`` (avoids per-request connection churn)."""
global _async_client
if _async_client is None:
from qdrant_client import AsyncQdrantClient
_async_client = AsyncQdrantClient(
url=settings.qdrant_url,
api_key=settings.qdrant_api_key or None,
)
return _async_client
def reset_async_qdrant_client() -> None:
"""Drop the shared client (tests / vectorstore factory reset)."""
global _async_client
_async_client = None
|