Skip to main content
RAG enables agents to retrieve relevant information from documents before generating responses, producing accurate, grounded answers with citations.

Quick Start

1

Install

2

Create Agent with Knowledge

3

Get Answer with Citations


How RAG Works

The RAG Process

PhaseWhat HappensWhen
IndexingDocuments → Chunks → Embeddings → Vector DBOnce per document
RetrievalQuery → Embedding → Similarity Search → Top-K chunksEvery query
GenerationQuery + Context → LLM → Answer + CitationsEvery query

Agent Methods for RAG

MethodReturnsUse Case
agent.start(prompt)StringInteractive terminal with RAG
agent.chat(prompt)StringProgrammatic RAG
agent.query(prompt)RAGResultStructured answer + citations
agent.retrieve(prompt)ContextPackContext only, no LLM generation

Example: All Methods


Knowledge Configuration

Basic: File List

Advanced: Full Configuration

Configuration Options

OptionTypeDefaultDescription
sourceslist[]Files, folders, or URLs
retrieval_kint5Number of chunks to retrieve
rerankboolFalseEnable reranking
chunking_strategystr"semantic"How to split documents
chunk_sizeint1000Max tokens per chunk
chunk_overlapint200Overlap between chunks
auto_retrieveboolTrueAuto-inject context

Retrieval Strategies

PraisonAI automatically selects the optimal strategy based on corpus size:
StrategyFilesTechnique
DIRECT< 10Load all content into context
BASIC< 100Embedding-based semantic search
HYBRID< 1000Keyword + semantic search
RERANKED< 10000Hybrid + cross-encoder reranking
COMPRESSED< 100000Reranked + contextual compression
HIERARCHICAL≥ 100000Summaries + top-down routing

Force a Strategy


RAG vs Knowledge vs Memory vs Context

Comparison Table

AspectRAGKnowledgeMemoryContext
WhatSearch techniquePre-loaded docsPersistent storageRuntime data
WhenQuery timeBefore executionAcross sessionsDuring execution
LifetimeN/APermanentPermanentSession only
DirectionRead-onlyRead-onlyRead + WriteRead-only
Agent ParamPart of knowledge=knowledge=memory=context=

When to Use What


Agent with Knowledge (Simple)

For small document sets where you don’t need advanced retrieval:

Agent with RAG (Advanced)

For large document sets requiring sophisticated retrieval:

Multi-Agent RAG

Share knowledge across multiple agents:

Supported File Types

Documents

PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX

Text

TXT, CSV, JSON, XML, MD, HTML

Media

Images (with OCR), Audio (with transcription)

Vector Store Backends


Citations

RAG automatically provides source citations:

Citation Modes

ModeDescription
APPENDAdd sources at end of response
INLINEInsert citation markers in text
HIDDENInclude in metadata only

Best Practices

Chunk Size

Use 500-1000 tokens per chunk. Too small = lost context. Too large = noise.

Overlap

Use 10-20% overlap to preserve context across chunk boundaries.

Reranking

Enable reranking for large corpora to improve relevance.

Top-K

Start with k=5, increase if answers lack detail.

Troubleshooting

  • Check if documents were indexed: knowledge.stats()
  • Lower the similarity threshold
  • Try different chunking strategy
  • Reduce retrieval_k
  • Disable reranking for faster results
  • Use persistent vector store
  • Increase chunk overlap
  • Use semantic chunking
  • Increase retrieval_k

Knowledge

Document loading and indexing

Memory

Persistent agent memory

Context

Runtime data flow

Quality RAG

Advanced quality patterns