# src/extractor/canon/embedder.py

EMBEDDING_MERGE_THRESHOLD = 0.92

_model_singleton = None


def embedding_similarity(text_a: str, text_b: str) -> float:
    global _model_singleton
    try:
        from sentence_transformers import SentenceTransformer  # type: ignore[import-untyped]

        if _model_singleton is None:
            _model_singleton = SentenceTransformer("all-MiniLM-L6-v2", device="cpu")
        embs = _model_singleton.encode([text_a, text_b], normalize_embeddings=True)
        return float(embs[0] @ embs[1])
    except ImportError:
        return 0.0
