Knowledge Quick Start

Get started with knowledge-based agents in 5 minutes

Knowledge Quick Start

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

Installation

bash
pip install "praisonaiagents[knowledge]"

1. Simplest Usage (Default)

python
from praisonaiagents import Agent

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

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

Verify it grounded

Search returning results does not prove your agent used them. Run a unique-marker check — both flags must be True:

python
search_ok = any("ZEBRA-QUOTA-9917" in str(r) for r in agent.knowledge.search("ZEBRA-QUOTA-9917"))
answer = agent.chat("What is policy ZEBRA-QUOTA-9917 daily limit?")
chat_ok = "ZEBRA-QUOTA-9917" in answer
print(f"SEARCH_OK={search_ok}  CHAT_OK={chat_ok}")

If SEARCH_OK=True but CHAT_OK=False, see Knowledge Troubleshooting.

2. Multiple Sources (Array)

python
from praisonaiagents import Agent

agent = Agent(
    name="Research Assistant",
    knowledge=[
        "paper.pdf",
        "notes.txt", 
        "docs/",           # Entire directory
    ]
)

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

3. Custom Configuration (Dict)

python
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 Options

python
from praisonaiagents import Agent

agent = Agent(
    name="Research Assistant",
    knowledge={
        "sources": ["research.pdf"],
        "retrieval_k": 5,            # Number of chunks
        "rerank": True               # Better relevance
    }
)

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

5. Shared Knowledge (Instance)

python
from praisonaiagents import Agent, 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

Agent(knowledge=[...]) accepts local files, directories, and raw text. Knowledge.add(...) additionally accepts remote URLs.

InputAccepted by Agent(knowledge=[...])Accepted by Knowledge.add(...)
Documents (PDF, DOC, DOCX, TXT, MD, RTF)YesYes
Data (CSV, JSON, XML, Excel)YesYes
DirectoriesYes — every supported file insideYes
Raw text stringsYes — stored directlyYes
Local HTML files (.html, .htm)YesYes
Remote URLs (http://, https://)No — warned and skipped (PR #4004)Yes — fetched via MarkItDown (PR #4334)

Next Steps