ares_rag/lib.rs
1//! Retrieval Augmented Generation (RAG) Pipeline
2//!
3//! This module provides the core RAG pipeline components for enhancing LLM responses
4//! with relevant context from your document collections.
5//!
6//! # Module Structure
7//!
8//! - `rag::embeddings` - Dense embedding models (fastembed, 38+ models) **[requires `local-embeddings` feature]**
9//! - [`rag::search`](crate::search) - Search strategies (semantic, BM25, fuzzy, hybrid)
10//! - `rag::reranker` - Cross-encoder reranking for improved relevance **[requires `local-embeddings` feature]**
11//! - [`rag::chunker`](crate::chunker) - Text chunking for document processing
12//! - [`rag::cache`](crate::cache) - Embedding cache for avoiding recomputation
13//!
14//! # Feature Flags
15//!
16//! The `local-embeddings` feature enables ONNX-based local embedding and reranking models.
17//! This feature is optional because the ONNX runtime (`ort`) can have build issues on some platforms,
18//! particularly Windows with certain MSVC versions.
19//!
20//! **Note:** The `local-embeddings` feature is NOT supported on Windows MSVC due to linker errors
21//! in `ort-sys`. Use WSL, Linux, or macOS for local embeddings, or use remote embedding APIs.
22//!
23//! Without `local-embeddings`, you can still use:
24//! - Remote embedding APIs (OpenAI embeddings, Ollama embeddings, etc.)
25//! - The chunker and search modules
26//! - The cache module (if you have embeddings from elsewhere)
27//!
28//! # RAG Pipeline
29//!
30//! The typical RAG pipeline flow:
31//!
32//! 1. **Ingestion** - Documents are chunked and embedded
33//! 2. **Storage** - Embeddings stored in vector database
34//! 3. **Retrieval** - Query embedded, similar chunks retrieved
35//! 4. **Reranking** - Cross-encoder reranks for relevance
36//! 5. **Generation** - LLM generates response with context
37//!
38//! # Example
39//!
40//! ```ignore
41//! use ares::rag::{embeddings::EmbeddingModel, chunker::Chunker, search::SearchStrategy};
42//!
43//! // Embed a document
44//! let embedder = EmbeddingModel::new("BAAI/bge-small-en-v1.5")?;
45//! let chunker = Chunker::new(512, 50); // chunk_size, overlap
46//!
47//! let chunks = chunker.chunk(&document_text);
48//! let embeddings = embedder.embed_batch(&chunks).await?;
49//!
50//! // Search
51//! let query_embedding = embedder.embed(&query).await?;
52//! let results = vector_store.search("my_collection", query_embedding, 10).await?;
53//! ```
54//!
55//! # Embedding Models
56//!
57//! Supports 38+ models via fastembed. Popular choices:
58//! - `BAAI/bge-small-en-v1.5` - Fast, good quality (default)
59//! - `BAAI/bge-base-en-v1.5` - Higher quality, slower
60//! - `sentence-transformers/all-MiniLM-L6-v2` - Lightweight
61
62// Compile-time error for unsupported platform + feature combination
63#[cfg(all(
64 feature = "local-embeddings",
65 target_os = "windows",
66 target_env = "msvc"
67))]
68compile_error!(
69 "The `local-embeddings` feature is not supported on Windows MSVC due to ort-sys linker errors. \
70 Please use one of the following alternatives:\n\
71 1. Use WSL (Windows Subsystem for Linux)\n\
72 2. Use remote embedding APIs (OpenAI, Ollama, etc.)\n\
73 3. Build on Linux or macOS\n\
74 4. Disable this feature: cargo build --no-default-features --features \"...\""
75);
76
77pub mod config;
78pub use config::{
79 HybridWeightsConfig, RagChunkingConfig, RagConfig, RagRerankingConfig, RagSearchConfig,
80 RAGVectorConfig,
81};
82
83pub mod cache;
84pub mod chunker;
85#[cfg(feature = "local-embeddings")]
86pub mod embeddings;
87#[cfg(feature = "local-embeddings")]
88pub mod reranker;
89pub mod search;
90
91#[cfg(test)]
92mod lib_tests {
93 use crate::chunker::ChunkingStrategy;
94 use std::str::FromStr;
95
96 #[test]
97 fn chunking_strategy_from_str() {
98 let strategy = ChunkingStrategy::from_str("semantic").expect("parse");
99 assert_eq!(strategy, ChunkingStrategy::Semantic);
100 }
101
102 #[test]
103 fn search_module_is_linked() {
104 let _ = std::any::type_name::<crate::search::SearchStrategy>();
105 }
106}