KnowledgeConfig

Configure RAG and knowledge retrieval for agents

Configure knowledge sources, embedding, chunking, and retrieval settings for RAG-powered agents.

Diagram

Knowledge Pipeline

📄 Sources

✂️ Chunk

🔢 Embed

🔍 Retrieve

📝 Augment

Quick Start

  1. Simple Usage

    Add knowledge sources directly:

    python
    from praisonaiagents import Agent
    
    agent = Agent(
        name="Knowledge Agent",
        instructions="Answer questions from the documentation",
        knowledge=["docs/", "data.pdf"]
    )
  2. With Configuration

    Configure retrieval settings:

    python
    from praisonaiagents import Agent
    from praisonaiagents.config import KnowledgeConfig
    
    agent = Agent(
        name="Knowledge Agent",
        instructions="Answer questions from the documentation",
        knowledge=KnowledgeConfig(
            sources=["docs/"],
            embedder="openai",
            chunking_strategy="semantic",
            retrieval_k=5,
            rerank=True
        )
    )

Configuration Options

python
from praisonaiagents.config import KnowledgeConfig, ChunkingStrategy

config = KnowledgeConfig(
    # Knowledge sources
    sources=["docs/", "data.pdf"],

    # Embedder configuration
    embedder="openai",
    embedder_config=None,

    # Chunking settings
    chunking_strategy=ChunkingStrategy.SEMANTIC,
    chunk_size=1000,
    chunk_overlap=200,
    chunker=None,  # Alternative dict config

    # Retrieval settings
    retrieval_k=5,
    retrieval_threshold=0.0,

    # Reranking
    rerank=False,
    rerank_model=None,

    # Auto-retrieval
    auto_retrieve=True,

    # Vector store
    vector_store=None,

    # Advanced config
    config=None
)
ParameterTypeDefaultDescription
sourcesList[str][]Files, directories, or URLs
embedderstr"openai"Embedding provider
embedder_config`Dict \None`NoneEmbedder-specific settings
chunking_strategy`str \ChunkingStrategy`"semantic"Chunking method (fixed, semantic, sentence, paragraph)
chunk_sizeint1000Target chunk size in tokens
chunk_overlapint200Overlap between chunks
chunker`Dict \None`NoneAlternative chunker config dict
retrieval_kint5Number of chunks to retrieve
retrieval_thresholdfloat0.0Minimum similarity threshold
rerankboolFalseEnable result reranking
rerank_model`str \None`NoneModel for reranking
auto_retrieveboolTrueAuto-inject relevant context
vector_store`Dict \None`NoneVector database settings
config`Dict \None`NoneAdvanced configuration dict

Common Patterns

Pattern 1: High-Precision Retrieval

python
from praisonaiagents import Agent
from praisonaiagents.config import KnowledgeConfig

agent = Agent(
    name="Precise Agent",
    instructions="Provide accurate answers",
    knowledge=KnowledgeConfig(
        sources=["docs/"],
        retrieval_k=10,
        rerank=True,
        retrieval_threshold=0.7
    )
)

Pattern 2: Custom Chunking

python
from praisonaiagents import Agent
from praisonaiagents.config import KnowledgeConfig

agent = Agent(
    name="Custom Chunk Agent",
    instructions="Process large documents",
    knowledge=KnowledgeConfig(
        sources=["large_docs/"],
        chunker={
            "type": "semantic",
            "chunk_size": 512,
            "chunk_overlap": 100
        }
    )
)

Pattern 3: External Vector Store

chroma is the shipped default. Providers like qdrant are plugin adapters — register them first.

python
from praisonaiagents import Agent
from praisonaiagents.config import KnowledgeConfig
from praisonaiagents.knowledge.adapters import register_knowledge_adapter

# qdrant is a plugin adapter — register it before use
register_knowledge_adapter("qdrant", MyQdrantAdapter)

agent = Agent(
    name="Qdrant Agent",
    instructions="Use external vector database",
    knowledge=KnowledgeConfig(
        sources=["docs/"],
        vector_store={
            "provider": "qdrant",
            "url": "http://localhost:6333",
            "collection": "my_docs"
        }
    )
)

Best Practices

Use Semantic Chunking for Documents

Semantic chunking preserves context better than fixed-size chunks, especially for technical documentation.

Enable Reranking for Accuracy

Reranking improves retrieval precision by using a cross-encoder to reorder results.

Set Retrieval Threshold

Use retrieval_threshold to filter low-quality matches and prevent hallucination.

Auto-Retrieve by Default

Keep auto_retrieve=True to automatically inject relevant context into prompts.


Related