Skip to main content
Learn how to enhance your agents with knowledge bases and retrieval-augmented generation (RAG).
from praisonaiagents import Agent, KnowledgeConfig

agent = Agent(
    name="Knowledge Assistant",
    instructions="Answer from the knowledge base.",
    knowledge=KnowledgeConfig(sources=["./docs"]),
)

agent.start("Find the section about session persistence.")
The user attaches a knowledge source, asks a question, and the agent grounds its reply in retrieved passages.

Quick Start

1

Simple Usage

Point the agent at a folder of documents and it answers from them.
from praisonaiagents import Agent, KnowledgeConfig

agent = Agent(
    name="Knowledge Assistant",
    instructions="Answer from the knowledge base.",
    knowledge=KnowledgeConfig(sources=["./docs"]),
)
agent.start("Find the section about session persistence.")
2

With Configuration

Tune how many passages come back and how similar they must be.
from praisonaiagents import Agent, KnowledgeConfig

agent = Agent(
    name="Knowledge Assistant",
    instructions="Cite retrieved passages.",
    knowledge=KnowledgeConfig(sources=["./docs"], top_k=5, similarity_threshold=0.7),
)
agent.start("Summarise the security section.")

How It Works


Knowledge Base Setup

Create and configure knowledge bases

Chunking Strategies

Optimize document chunking

Retrieval Methods

Configure retrieval strategies

Best Practices

KnowledgeConfig(sources=["./docs"]) indexes a directory directly. Remove boilerplate and duplicates first so retrieval returns signal, not noise.
A higher similarity_threshold filters weak matches. Start at 0.7 and adjust based on whether answers miss context or cite irrelevant passages.
Fewer, stronger passages usually beat many weak ones. Increase top_k only when answers lack coverage.