Skip to main content

Knowledge Quick Start

Give your agent access to documents and get answers with citations.

Installation

pip install "praisonaiagents[knowledge]"

1. Simplest Usage (Default)

from praisonaiagents import Agent

agent = Agent(
    name="Research Assistant",
    knowledge=["research.pdf"]  # Just pass files
)

response = agent.start("What are the key findings?")

2. Multiple Sources (Array)

from praisonaiagents import Agent

agent = Agent(
    name="Research Assistant",
    knowledge=[
        "paper.pdf",
        "notes.txt", 
        "docs/",           # Entire directory
        "https://example.com/article"  # URLs work too
    ]
)

response = agent.start("Summarize all documents")

3. Custom Configuration (Dict)

from praisonaiagents import Agent

agent = Agent(
    name="Research Assistant",
    knowledge={
        "sources": ["research.pdf", "data/"],
        "chunker": {
            "type": "semantic",      # Better topic boundaries
            "chunk_size": 512
        },
        "vector_store": {
            "provider": "chroma",
            "config": {"collection_name": "my_research"}
        }
    }
)

response = agent.start("What methodology was used?")

4. With Retrieval Config

from praisonaiagents import Agent

agent = Agent(
    name="Research Assistant",
    knowledge=["research.pdf"],
    retrieval_config={
        "policy": "always",     # always, auto, never
        "top_k": 5,             # Number of chunks
        "citations": True,      # Include sources
        "rerank": True          # Better relevance
    }
)

result = agent.query("What are the conclusions?")
print(result.answer)
print(result.citations)

5. Shared Knowledge (Instance)

from praisonaiagents import Agent
from praisonaiagents.knowledge import Knowledge

# Create shared knowledge base
kb = Knowledge(config={
    "vector_store": {"provider": "chroma"}
})
kb.add("company_docs/")

# Multiple agents share same knowledge
analyst = Agent(name="Analyst", knowledge=kb)
writer = Agent(name="Writer", knowledge=kb)

Supported File Types

CategoryFormats
DocumentsPDF, DOC, DOCX, TXT, MD, RTF
DataCSV, JSON, XML, Excel
WebURLs, HTML pages
MediaImages (OCR), YouTube

Next Steps