from __future__ import annotations

import logging
import os
from typing import List

EMBEDDINGS_ENABLED = os.getenv("ENABLE_EMBEDDINGS", "false").lower() == "true"

logger = logging.getLogger(__name__)


def embed_sentences(sentences: List[str]) -> List[List[float]]:
    if not EMBEDDINGS_ENABLED:
        return [[0.0] * 3 for _ in sentences]
    try:
        from sentence_transformers import SentenceTransformer  # type: ignore
        model_name = os.getenv("EMBEDDINGS_MODEL", "all-MiniLM-L6-v2")
        model = SentenceTransformer(model_name)
        vectors = model.encode(sentences, normalize_embeddings=True)
        return [v.tolist() for v in vectors]
    except Exception as e:
        logger.warning("Embeddings disabled due to error: %s", e)
        return [[0.0] * 3 for _ in sentences]


