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:
pip install "praisonaiagents[knowledge]"
Set API Key
Set your OpenAI API key:
export OPENAI_API_KEY = xxxxx
Create Script
Create a new file app.py
:
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
Indexing and Ingestion are relatively the same.
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?" ) # Retrieval
Advanced 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 = [ "small.pdf" ], # Indexing
knowledge_config = config # Configuration
)
agent.start( "What is KAG in one line?" ) # Retrieval
Multi-Agent Knowledge System
For more complex scenarios, you can create a knowledge-based system with multiple agents:
from praisonaiagents import Agent, Task, PraisonAIAgents
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 = [ "sample.pdf" ], # Indexing
knowledge_config = config, # Configuration
verbose = True
)
# 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 = PraisonAIAgents(
agents = [knowledge_agent],
tasks = [knowledge_task],
process = "sequential" ,
user_id = "user1" # User ID
)
# Start execution
result = agents.start() # Retrieval
Retrieval Agents
Retrieval is the process of querying the vector database for information.
Considering there is data already in the Vector Database.
Install Package
First, install the PraisonAI Agents package:
pip install praisonaiagents
Set API Key
Set your OpenAI API key as an environment variable in your terminal:
export OPENAI_API_KEY = your_api_key_here
Create a file
Create a new file rag_agent.py
with the basic setup:
from praisonaiagents import Agent, Task, PraisonAIAgents
# 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 = PraisonAIAgents(
agents = [rag_agent],
tasks = [rag_task],
user_id = "user1"
)
# Start Agents
agents.start()
Start Agents
Type this in your terminal to run your agents:
Requirements
Python 3.10 or higher
OpenAI API key. Generate OpenAI API key here . Use Other models using this guide .
ChromaDB or other supported vector database
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 = [ "small.pdf" ], # Indexing
knowledge_config = config # Configuration
)
agent.start( "What is KAG in one line?" ) # Retrieval
Understanding 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
RAG Architecture Store and manage vector embeddings efficiently.
Semantic Search Find relevant information using semantic similarity.
Knowledge Integration Seamlessly integrate with existing knowledge bases.
Context Management Handle complex contextual queries and responses.
Troubleshooting
RAG Issues If RAG system isn’t working:
Check database configuration
Verify connection settings
Enable verbose mode for debugging
Query Issues If queries aren’t returning expected results:
Check embedding quality
Verify search parameters
Monitor similarity thresholds
Next Steps
For optimal results, ensure your vector database is properly configured and indexed for your specific use case.