RAG Quickstart
Get started with RAG in 5 minutes
RAG Quickstart
Get up and running with RAG in just a few steps.
Installation
pip install praisonaiagentsFor full RAG support with vector stores:
pip install "praisonaiagents[knowledge]"Method 1: Agent with Knowledge (Recommended)
The simplest way to use RAG is through the Agent’s knowledge parameter:
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:
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:
# 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_docsCheck the exit code — rag index now exits 1 if any source stored zero chunks, so a broken embedding backend or an empty glob no longer looks like a successful import. See Knowledge Indexing Errors for the SDK-side failure modes.
Streaming Responses
For real-time output:
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
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:
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 – Full API documentation
- Citations – Working with source attribution
- CLI Commands – Command-line reference
- Evaluation – Testing retrieval quality