Retrieval Augmented Generation (RAG) Pipeline
This module provides the core RAG pipeline components for enhancing LLM responses with relevant context from your document collections.
Module Structure
rag::embeddings- Dense embedding models (fastembed, 38+ models) [requireslocal-embeddingsfeature]rag::search- Search strategies (semantic, BM25, fuzzy, hybrid)rag::reranker- Cross-encoder reranking for improved relevance [requireslocal-embeddingsfeature]rag::chunker- Text chunking for document processingrag::cache- Embedding cache for avoiding recomputation
Feature Flags
The local-embeddings feature enables ONNX-based local embedding and reranking models.
This feature is optional because the ONNX runtime (ort) can have build issues on some platforms,
particularly Windows with certain MSVC versions.
Note: The local-embeddings feature is NOT supported on Windows MSVC due to linker errors
in ort-sys. Use WSL, Linux, or macOS for local embeddings, or use remote embedding APIs.
Without local-embeddings, you can still use:
- Remote embedding APIs (OpenAI embeddings, Ollama embeddings, etc.)
- The chunker and search modules
- The cache module (if you have embeddings from elsewhere)
RAG Pipeline
The typical RAG pipeline flow:
- Ingestion - Documents are chunked and embedded
- Storage - Embeddings stored in vector database
- Retrieval - Query embedded, similar chunks retrieved
- Reranking - Cross-encoder reranks for relevance
- Generation - LLM generates response with context
Example
use ares::rag::{embeddings::EmbeddingModel, chunker::Chunker, search::SearchStrategy};
// Embed a document
let embedder = EmbeddingModel::new("BAAI/bge-small-en-v1.5")?;
let chunker = Chunker::new(512, 50); // chunk_size, overlap
let chunks = chunker.chunk(&document_text);
let embeddings = embedder.embed_batch(&chunks).await?;
// Search
let query_embedding = embedder.embed(&query).await?;
let results = vector_store.search("my_collection", query_embedding, 10).await?;
Embedding Models
Supports 38+ models via fastembed. Popular choices:
BAAI/bge-small-en-v1.5- Fast, good quality (default)BAAI/bge-base-en-v1.5- Higher quality, slowersentence-transformers/all-MiniLM-L6-v2- Lightweight