refactor: consolidate duplicate QdrantService singleton into singleton.py
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
"""Global singleton instances for Vera-AI."""
|
||||
from typing import Optional
|
||||
from .qdrant_service import QdrantService
|
||||
from .config import config
|
||||
|
||||
_qdrant_service: QdrantService = None
|
||||
_qdrant_service: Optional[QdrantService] = None
|
||||
|
||||
|
||||
def get_qdrant_service() -> QdrantService:
|
||||
|
||||
19
app/utils.py
19
app/utils.py
@@ -1,5 +1,6 @@
|
||||
"""Utility functions for vera-ai."""
|
||||
from .config import config
|
||||
from .singleton import get_qdrant_service
|
||||
import tiktoken
|
||||
import os
|
||||
from typing import List, Dict, Optional
|
||||
@@ -13,24 +14,6 @@ ENCODING = tiktoken.get_encoding("cl100k_base")
|
||||
PROMPTS_DIR = Path(os.environ.get("VERA_PROMPTS_DIR", "/app/prompts"))
|
||||
STATIC_DIR = Path(os.environ.get("VERA_STATIC_DIR", "/app/static"))
|
||||
|
||||
# Global qdrant_service instance for utils
|
||||
_qdrant_service = None
|
||||
|
||||
def get_qdrant_service():
|
||||
"""Get or create the QdrantService singleton."""
|
||||
global _qdrant_service
|
||||
if _qdrant_service is None:
|
||||
from .config import config
|
||||
from .qdrant_service import QdrantService
|
||||
_qdrant_service = QdrantService(
|
||||
host=config.qdrant_host,
|
||||
collection=config.qdrant_collection,
|
||||
embedding_model=config.embedding_model,
|
||||
vector_size=config.vector_size,
|
||||
ollama_host=config.ollama_host
|
||||
)
|
||||
return _qdrant_service
|
||||
|
||||
def count_tokens(text: str) -> int:
|
||||
"""Count tokens in text."""
|
||||
if not text:
|
||||
|
||||
Reference in New Issue
Block a user