"""
RAG (Retrieval-Augmented Generation) module.

Provides backend-agnostic RAG interfaces and optional backend implementations.
"""

from __future__ import annotations

from typing import Any, TYPE_CHECKING

if TYPE_CHECKING:  # pragma: no cover
    from .base import BaseRAG
    from .llama_index.variants.simple import SimplePdfRag
    from .llama_index.variants.full_doc_in_ctx import FullDocInCtxRag

__all__ = ["BaseRAG", "SimplePdfRag", "FullDocInCtxRag"]


def __getattr__(name: str) -> Any:  # pragma: no cover
    if name == "BaseRAG":
        from .base import BaseRAG as _BaseRAG

        return _BaseRAG

    if name in ("SimplePdfRag", "FullDocInCtxRag"):
        try:
            from .llama_index.variants.simple import SimplePdfRag as _SimplePdfRag
            from .llama_index.variants.full_doc_in_ctx import FullDocInCtxRag as _FullDocInCtxRag
        except ModuleNotFoundError as e:
            raise ModuleNotFoundError(
                "ketju.rag backends require optional dependencies.\n"
                "Install with:\n"
                "  pip install 'ketju[rag]'\n"
                "Or, to run packaged examples:\n"
                "  pip install 'ketju[examples]'"
            ) from e

        return {"SimplePdfRag": _SimplePdfRag, "FullDocInCtxRag": _FullDocInCtxRag}[name]

    raise AttributeError(name)