> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# RAG Quickstart

> Get started with RAG in 5 minutes

# RAG Quickstart

Get up and running with RAG in just a few steps.

## Installation

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install praisonaiagents
```

For full RAG support with vector stores:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install "praisonaiagents[knowledge]"
```

## Method 1: Agent with Knowledge (Recommended)

The simplest way to use RAG is through the Agent's `knowledge` parameter:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

# Create agent with knowledge sources
agent = Agent(
    name="Research Assistant",
    instructions="You are a helpful research assistant.",
    knowledge=["paper.pdf", "docs/"],  # Files or directories
)

# Ask questions - RAG happens automatically
response = agent.start("What are the main conclusions?")
print(response)
```

## Method 2: Explicit RAG Pipeline

For more control, use the RAG class directly:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Knowledge, RAG, RAGConfig

# 1. Create and populate knowledge base
knowledge = Knowledge()
knowledge.add("research_paper.pdf")
knowledge.add("data_analysis.csv")

# 2. Create RAG pipeline
rag = RAG(
    knowledge=knowledge,
    config=RAGConfig(
        top_k=5,
        include_citations=True,
    )
)

# 3. Query with citations
result = rag.query("What methodology was used?")

print(result.answer)
print("\nSources:")
for citation in result.citations:
    print(f"  [{citation.id}] {citation.source}")
```

## Method 3: CLI

Index and query from the command line:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Index documents
praisonai rag index ./documents --collection my_docs

# Query
praisonai rag query "What is the main finding?" --collection my_docs

# Interactive chat
praisonai rag chat --collection my_docs
```

## Streaming Responses

For real-time output:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Knowledge, RAG

knowledge = Knowledge()
knowledge.add("large_document.pdf")

rag = RAG(knowledge=knowledge)

# Stream the response
for chunk in rag.stream("Summarize the document"):
    print(chunk, end="", flush=True)
```

## Configuration Options

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import RAGConfig

config = RAGConfig(
    top_k=5,                    # Number of chunks to retrieve
    min_score=0.5,              # Minimum relevance score
    max_context_tokens=4000,    # Context size limit
    include_citations=True,     # Include source citations
    rerank=False,               # Enable reranking (optional)
)
```

## Multi-Agent Shared Knowledge

Multiple agents can share the same knowledge base:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent, Knowledge, AgentTeam

# Shared knowledge base
shared_kb = Knowledge()
shared_kb.add("company_docs/")

# Multiple agents using same knowledge
researcher = Agent(
    name="Researcher",
    knowledge=shared_kb,
)

writer = Agent(
    name="Writer", 
    knowledge=shared_kb,
)

# Run together
agents = AgentTeam(agents=[researcher, writer])
```

## Next Steps

* [RAG Module Reference](/docs/rag/module) - Full API documentation
* [Citations](/docs/rag/citations) - Working with source attribution
* [CLI Commands](/docs/rag/cli) - Command-line reference
* [Evaluation](/docs/rag/evaluation) - Testing retrieval quality
