RAG Pipeline
The traitclaw-rag crate provides a modular RAG pipeline with pluggable retrievers and chunkers.
Quick Start
Section titled “Quick Start”use traitclaw_rag::{RagContextManager, KeywordRetriever, FixedSizeChunker};
// 1. Chunk your documentslet chunker = FixedSizeChunker::new(512);let chunks = chunker.chunk(&document_text);
// 2. Create a retrieverlet retriever = KeywordRetriever::new(chunks);
// 3. Use as a ContextManagerlet rag = RagContextManager::new(retriever);
let agent = Agent::builder() .provider(provider) .context_manager(rag) .build()?;Retrievers
Section titled “Retrievers”| Retriever | Method | Best For |
|---|---|---|
KeywordRetriever | BM25 | Fast keyword matching |
EmbeddingRetriever | Cosine similarity | Semantic search |
HybridRetriever | BM25 + Embeddings | Best of both |
Chunkers
Section titled “Chunkers”| Chunker | Strategy |
|---|---|
FixedSizeChunker | Fixed token/char count |
SentenceChunker | Split on sentence boundaries |
RecursiveChunker | Hierarchical splitting |