//! RAG (Retrieval-Augmented Generation) Pipeline - Phase-72
//!
//! Implements a conversational database query system that combines:
//!
//! - **Vector retrieval**: Semantic similarity search via CollectionStore/Lance/HNSW
//! - **Full-text search**: BM25 keyword matching via Tantivy
//! - **Reranking**: RRF / Linear / Cross-Encoder multi-signal fusion
//! - **Context assembly**: Token-budget-aware prompt construction
//! - **LLM generation**: MicroGPT (local) or External API (OpenAI/Ollama)
//!
//! # Architecture
//!
//! ```text
//! User Question
//!       |
//!       v
//! +-------------------+
//! | PerceptionEngine  |  <- Embed query -> Vec<f32>
//! | (Embedder)        |
//! +--------+----------+
//!          |
//!          v
//! +-------------------+
//! |    Retriever      |  <- Vector + BM25 hybrid search
//! | (HybridRetriever) |
//! +--------+----------+
//!          |
//!          v
//! +-------------------+
//! |    Reranker       |  <- RRF / CrossEncoder re-scoring
//! +--------+----------+
//!          |
//!          v
//! +---------------------+
//! |  ContextAssembler   |  <- Format docs + history -> prompt
//! |  (token budget)     |
//! +--------+------------+
//!          |
//!          v
//! +-------------------+
//! |    Generator      |  <- MicroGPT or External LLM
//! +--------+----------+
//!          |
//!          v
//!   RagResponse { answer, sources, usage }
//! ```
//!
//! # Quick Start
//!
//! ```ignore
//! use aifastdb_core::rag::{RagConfig, ChatMessage, RagResponse};
//!
//! // Configure the pipeline
//! let config = RagConfig {
//!     top_k: 5,
//!     generator_backend: "external".to_string(),
//!     ..Default::default()
//! };
//! ```

pub mod types;
pub mod traits;
pub mod error;
pub mod retriever;
pub mod graph_retriever;
pub mod tree_retriever;
pub mod assembler;
pub mod generator;
pub mod session;
pub mod pipeline;

// Re-export core types
pub use types::{
    RagConfig, ChatMessage, ChatRole, ChatSession,
    RetrievalResult, SourceReference, RagResponse, RagTokenUsage,
};

// Re-export traits
pub use traits::{Retriever, Generator, ContextAssembler, SessionManager};
#[cfg(feature = "llm-gateway")]
pub use traits::StreamGenerator;

// Re-export errors
pub use error::{RagError, RagResult};

// Re-export implementations
pub use retriever::HybridRetriever;
pub use graph_retriever::{
    GraphRetriever, GraphRetrieverConfig,
    GraphContextExpander, CommunitySummaryCache, CommunitySummary,
    ThreeWayFusionRetriever, FourWayFusionRetriever,
};
pub use assembler::DefaultContextAssembler;
pub use assembler::GraphRagAssembler;
#[cfg(feature = "llm-gateway")]
pub use assembler::TemplateAssembler;
pub use generator::ExternalLlmGenerator;
#[cfg(feature = "candle")]
pub use generator::MicroGptGenerator;
#[cfg(feature = "llm-gateway")]
pub use generator::LlmGatewayGenerator;
pub use session::InMemorySessionManager;
#[cfg(feature = "llm-gateway")]
pub use session::ConversationSessionAdapter;
pub use tree_retriever::{TreeRetriever, TreeRetrieverConfig};
pub use pipeline::{RagPipeline, RagPipelineBuilder};