RAG Module
The RAG module provides a thin orchestration layer over Knowledge for retrieval-augmented generation.Core Classes
RAG
The main pipeline class that orchestrates retrieval and generation.Methods
query(question, **kwargs) -> RAGResult
Execute a RAG query and return result with citations.
aquery(question, **kwargs) -> RAGResult
Async version of query.
stream(question, **kwargs) -> Iterator[str]
Stream response tokens.
astream(question, **kwargs) -> AsyncIterator[str]
Async streaming.
get_citations(question, **kwargs) -> List[Citation]
Get citations without generating an answer.
RAGConfig
Configuration for the RAG pipeline.Retrieval Strategies
RAGResult
Result from a RAG query.Properties
has_citations- Boolean indicating if citations existformat_answer_with_citations()- Format answer with source references
Citation
Source citation for RAG answers.Protocols
The RAG module uses protocols for extensibility.ContextBuilderProtocol
Custom context assembly logic.CitationFormatterProtocol
Custom citation formatting.Context Utilities
Helper functions for context building.Integration with Knowledge
RAG uses Knowledge for all retrieval operations:Error Handling
Performance Tips
- Batch indexing: Add multiple documents at once
- Tune top_k: Start with 5, adjust based on quality
- Use min_score: Filter low-relevance results
- Enable reranking: For higher precision (costs latency)
- Stream responses: Better UX for long answers

