Skip to main content
RAG agents retrieve relevant chunks from your documents before answering, grounding responses in your own knowledge.
from praisonaiagents import Agent

agent = Agent(
    name="Knowledge Agent",
    instructions="Answer from the provided knowledge only.",
    knowledge=["small.pdf"],
)

agent.start("What is KAG in one line?")
The user asks from their documents; the agent retrieves relevant chunks and grounds the reply.

Quick Start

1

Simple Usage

Pass file paths or directories — the agent indexes on first run, then retrieves on each query:
from praisonaiagents import Agent

agent = Agent(
    name="Knowledge Agent",
    instructions="Answer from the knowledge base.",
    knowledge=["small.pdf"],
)

agent.start("What is KAG in one line?")
2

With Configuration

Use KnowledgeConfig for vector store, chunking, and reranking:
from praisonaiagents import Agent, KnowledgeConfig

agent = Agent(
    name="Knowledge Agent",
    instructions="Answer from the provided knowledge.",
    knowledge=KnowledgeConfig(
        sources=["small.pdf"],
        vector_store={
            "provider": "chroma",
            "config": {"collection_name": "praison", "path": ".praison"},
        },
        retrieval_k=5,
        rerank=True,
    ),
)

agent.start("What is KAG in one line?")

How It Works

PhaseWhat happens
1. IndexDocuments are chunked and embedded into the vector store on first access
2. RetrieveUser query is embedded; top-k similar chunks are returned
3. GenerateRetrieved context is injected before the LLM prompt; LLM answers from your data
For pre-indexed stores, pass vector config via task context or call agent.retrieve("query") directly.

Configuration Options

OptionTypeDefaultDescription
sourcesList[str][]Files, directories, or URLs
embedderstr"openai"Embedding provider
chunk_sizeint1000Chunk size in tokens
chunk_overlapint200Overlap between chunks
retrieval_kint5Chunks retrieved per query
retrieval_thresholdfloat0.0Minimum similarity score
rerankboolFalseRerank retrieved chunks
auto_retrieveboolTrueInject context automatically
vector_storedictNoneBackend provider config
Install knowledge extras: pip install "praisonaiagents[knowledge]"

Best Practices

Pass sources via knowledge=["file.pdf"] at agent creation — first run indexes, later runs retrieve without re-indexing.
Narrow questions retrieve better chunks than broad prompts like “tell me everything”.
Set vector_store with Chroma path, Qdrant, or Pinecone — avoid in-memory stores for production.
Pair knowledge= with web tools when you need both static documents and real-time data.

Vector Store

Pluggable embedding storage

Knowledge

Sources and retrieval strategies