RAG Quick Start
Learn how to configure retrieval behavior for AI agents with knowledge bases.
A knowledge-centric workflow where RAG (Retrieval Augmented Generation) agents interact with vector databases to store and retrieve information efficiently, enabling sophisticated question-answering and information retrieval capabilities.
Quick Start
- Install Package
Install PraisonAI Agents with knowledge support:
bash pip install "praisonaiagents[knowledge]" - Set API Key
Set your OpenAI API key:
bash export OPENAI_API_KEY=xxxxx - Create Script
Create a new file
app.py:python from praisonaiagents import Agent agent = Agent( name="Knowledge Agent", instructions="You answer questions based on the provided knowledge.", knowledge=["small.pdf"], # Indexing ) agent.start("What is KAG in one line?") # Retrieval
Data Indexing and Retrieval Agents
The simplest way to create a knowledge-based agent is without any configuration:
from praisonaiagents import Agent
agent = Agent(
name="Knowledge Agent",
instructions="You answer questions based on the provided knowledge.",
knowledge=["small.pdf"] # Indexing
)
agent.start("What is KAG in one line?") # RetrievalAdvanced Configuration
For more control over the knowledge base, you can specify a configuration:
from praisonaiagents import Agent
config = {
"vector_store": {
"provider": "chroma",
"config": {
"collection_name": "praison",
"path": ".praison",
}
}
}
agent = Agent(
name="Knowledge Agent",
instructions="You answer questions based on the provided knowledge.",
knowledge={
"sources": ["small.pdf"],
**config
}
)
agent.start("What is KAG in one line?") # RetrievalMulti-Agent Knowledge System
For more complex scenarios, you can create a knowledge-based system with multiple agents:
from praisonaiagents import Agent, Task, AgentTeam
import logging
import os
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# Define the configuration for the Knowledge instance
config = {
"vector_store": {
"provider": "chroma",
"config": {
"collection_name": "praison",
"path": ".praison",
}
}
}
# Create an agent with knowledge capabilities
knowledge_agent = Agent(
name="KnowledgeAgent",
role="Information Specialist",
goal="Store and retrieve knowledge efficiently",
backstory="Expert in managing and utilizing stored knowledge",
knowledge={
"sources": ["sample.pdf"],
**config
}
)
# Define a task for the agent
knowledge_task = Task(
name="knowledge_task",
description="Who is Mervin Praison?",
expected_output="Answer to the question",
agent=knowledge_agent # Agent
)
# Create and start the agents
agents = AgentTeam(
agents=[knowledge_agent],
tasks=[knowledge_task],
process="sequential",
memory={"user_id": "user1"} # User ID
)
# Start execution
result = agents.start() # RetrievalRetrieval Agents
- Install Package
Retrieval uses a vector store, so install the
knowledgeextra:bash pip install "praisonaiagents[knowledge]" - Set API Key
Set your OpenAI API key as an environment variable in your terminal:
bash export OPENAI_API_KEY=your_api_key_here - Create a file
Create a new file
rag_agent.pywith the basic setup:python from praisonaiagents import Agent, Task, AgentTeam # Define the configuration for the Knowledge instance config = { "vector_store": { "provider": "chroma", "config": { "collection_name": "praison", "path": ".praison" } } } # Create an agent rag_agent = Agent( name="RAG Agent", role="Information Specialist", goal="Retrieve knowledge efficiently", llm="gpt-4o-mini" ) # Define a task for the agent rag_task = Task( name="RAG Task", description="What is KAG?", expected_output="Answer to the question", agent=rag_agent, context=[config] # Retrieval : Vector Database provided as context ) # Build Agents agents = AgentTeam( agents=[rag_agent], tasks=[rag_task], memory={"user_id": "user1"} ) # Start Agents agents.start() - Start Agents
Type this in your terminal to run your agents:
bash python rag_agent.py
Adding Knowledge to RAG Agents
from praisonaiagents import Agent
config = {
"vector_store": {
"provider": "chroma",
"config": {
"collection_name": "praison",
"path": ".praison",
}
}
}
agent = Agent(
name="Knowledge Agent",
instructions="You answer questions based on the provided knowledge.",
knowledge={
"sources": ["small.pdf"],
**config
}
)
agent.start("What is KAG in one line?") # RetrievalUnderstanding RAG Agents
What are RAG Agents?RAG (Retrieval Augmented Generation) agents enable: – Efficient knowledge retrieval – Semantic search capabilities – Persistent knowledge storage – Context-aware responses
Features
Store and manage vector embeddings efficiently.
Semantic SearchFind relevant information using semantic similarity.
Knowledge IntegrationSeamlessly integrate with existing knowledge bases.
Context ManagementHandle complex contextual queries and responses.
Troubleshooting
If RAG system isn’t working: – Check database configuration – Verify connection settings – Enable verbose mode for debugging
Query IssuesIf queries aren’t returning expected results: – Check embedding quality – Verify search parameters – Monitor similarity thresholds