> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat with PDF Agents

> Learn how to create AI agents that can intelligently chat with PDF documents using vector databases for efficient information retrieval.

A PDF-centric workflow where Chat agents interact with vector databases to store and retrieve information from PDF documents, enabling natural conversations and intelligent question-answering capabilities.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="researcher",
    instructions="Answer questions using the uploaded PDF",
    knowledge=True,
)

agent.start("Summarise chapter 2 of the document")
```

The user uploads a PDF and asks questions; answers cite the indexed content.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Chat with PDF"
        PDF[📋 PDF Document] --> Agent[🤖 PDF Chat Agent]
        Agent --> VDB[💾 Vector DB]
        VDB --> Out[✅ Response]
    end

    classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef success fill:#10B981,stroke:#7C90A0,color:#fff
    class PDF input
    class Agent agent
    class VDB tool
    class Out success
```

## Quick Start

**1. Install Package**

Install PraisonAI Agents with PDF chat support:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install "praisonaiagents[knowledge]"
```

**2. Set API Key**

Set your OpenAI API key:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export OPENAI_API_KEY="${OPENAI_API_KEY:?Set OPENAI_API_KEY in your shell}"
```

**3. Create Script**

Create a new file `chat_with_pdf.py`:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="PDF Chat Agent",
    instructions="You answer questions based on the provided PDF document.",
    knowledge=["document.pdf"], # PDF Indexing
)

agent.start("What is the main topic of this PDF?") # Chat Query
```

## PDF Processing and Chat Agents

> [!NOTE]
>
> PDF processing involves indexing the document content for efficient retrieval during chat.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
flowchart LR
    subgraph In[Input]
        PDF[PDF Documents]
    end

    subgraph Router[Vector Store]
        DB[(Vector DB)]
    end
    
    subgraph Out[Chat Agents]
        A1[Chat Agent 1]
        A2[Chat Agent 2]
        A3[Chat Agent 3]
    end

    In --> Router
    Router --> A1
    Router --> A2
    Router --> A3

    style In fill:#8B0000,color:#fff
    style Router fill:#189AB4,color:#fff
    style Out fill:#8B0000,color:#fff
```

The simplest way to create a PDF chat agent is without any configuration:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="PDF Chat Agent",
    instructions="You answer questions based on the provided PDF document.",
    knowledge=["document.pdf"] # PDF Indexing
)

agent.start("What are the key points in this document?") # Chat Query
```

### Advanced Configuration

For more control over the knowledge base, you can specify a configuration:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

config = {
    "vector_store": {
        "provider": "chroma",
        "config": {
            "collection_name": "praison",
            "path": ".praison",
        }
    }
}

agent = Agent(
    name="PDF Chat Agent",
    instructions="You answer questions based on the provided PDF document.",
    knowledge={
        "sources": ["document.pdf"],
        **config
    }
)

agent.start("What is the main topic of this PDF?") # Chat Query
```

### Multi-Agent Knowledge System

For more complex scenarios, you can create a knowledge-based system with multiple agents:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent, Task, AgentTeam
import logging
import os

# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

# Define the configuration for the Knowledge instance
config = {
    "vector_store": {
        "provider": "chroma",
        "config": {
            "collection_name": "praison",
            "path": ".praison",
        }
    }
}

# Create an agent with knowledge capabilities
knowledge_agent = Agent(
    name="KnowledgeAgent",
    role="Information Specialist",
    goal="Store and retrieve knowledge efficiently",
    backstory="Expert in managing and utilizing stored knowledge",
    knowledge={
        "sources": ["sample.pdf"],
        **config
    }
)

# Define a task for the agent
knowledge_task = Task(
    name="knowledge_task",
    description="Who is Mervin Praison?",
    expected_output="Answer to the question",
    agent=knowledge_agent # Agent
)

# Create and start the agents
agents = AgentTeam(
    agents=[knowledge_agent],
    tasks=[knowledge_task],
    process="sequential",
    memory={"user_id": "user1"} # User ID
)

# Start execution
result = agents.start() # Retrieval
```

## How It Works

The user uploads a PDF and asks a question; the agent retrieves the most relevant chunks from the vector store and answers from them.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant VectorDB

    User->>Agent: knowledge=["document.pdf"]
    Agent->>VectorDB: Index PDF chunks
    User->>Agent: start("Summarise chapter 2")
    Agent->>VectorDB: Retrieve relevant chunks
    VectorDB-->>Agent: Matching passages
    Agent-->>User: Answer from PDF
```

***

## Understanding PDF Chat Agents

> [card] What are PDF Chat Agents?
>
> PDF Chat agents enable:
>
> * Natural conversation with PDF documents
> * Intelligent information extraction
> * Context-aware document understanding
> * Quick answers to document-specific questions

## Features

> [card] PDF Processing
>
> Process and index PDF documents efficiently.

> [card] Natural Chat
>
> Have natural conversations about PDF content.

> [card] Smart Retrieval
>
> Intelligently retrieve relevant information from PDFs.

> [card] Context Awareness
>
> Maintain context throughout the conversation.

## Troubleshooting

> [card] PDF Issues
>
> If PDF processing isn't working:
>
> * Check PDF file format and encoding
> * Verify document accessibility
> * Enable verbose mode for debugging

> [card] Chat Issues
>
> If chat responses aren't accurate:
>
> * Check PDF indexing quality
> * Verify question clarity
> * Monitor context retention

## Best Practices

> [accordion] Install the knowledge extra
>
> Run `pip install "praisonaiagents[knowledge]"` before indexing PDFs. Core install alone lacks Chroma and document parsers needed for retrieval.

> [accordion] Use text-searchable PDFs
>
> Scanned image-only PDFs index poorly. Prefer native text PDFs or run OCR upstream so chunking and embedding capture meaningful content.

> [accordion] Pin a persistent vector store path
>
> Set `path` and `collection_name` in your Chroma config so re-indexing does not wipe prior embeddings between restarts.

> [accordion] Keep queries specific to the document
>
> Ask about sections, figures, or claims in the PDF rather than open-ended prompts — retrieval quality depends on query–chunk alignment.

## Next Steps

> [card] [AutoAgents](https://praison.ai/docs/features/autoagents.md)
>
> Learn about automatically created and managed AI agents

> [card] [Mini Agents](https://praison.ai/docs/features/mini.md)
>
> Explore lightweight, focused AI agents

> [!NOTE]
>
> For optimal chat experience, ensure your PDFs are properly formatted and text-searchable.

## Related

> [card]
>
> Give agents a searchable knowledge base from your documents.
>
> [Open](https://praison.ai/docs/features/knowledge.md)

> [card]
>
> Retrieve relevant chunks from large document sets at query time.
>
> [Open](https://praison.ai/docs/features/rag.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.