from __future__ import annotations

from typing import Any

DEFAULT_MODEL = "sentence-transformers/all-MiniLM-L6-v2"


def create_and_index(data: list[str], model: str = DEFAULT_MODEL) -> Any:
    """Create and index embeddings from text.

    Requires txtai (uv sync --extra kg). Returns a txtai Embeddings instance.
    """
    try:
        from txtai.embeddings import Embeddings
    except ImportError as exc:
        raise ImportError("create_and_index needs txtai: uv sync --extra kg") from exc

    embeddings = Embeddings(
        {
            "path": model,
            "content": True,
            "hybrid": True,
            "scoring": "bm25",
        }
    )
    embeddings.index(data)
    return embeddings
