chat-pdf
Chat with PDF documents using LangChain and OpenAI.
chat-pdf is a lightweight Python library that allows you to load a PDF, ask questions about its content, and optionally retrieve the source passages used to generate the answers.
The library is intentionally simple and pinned to stable LangChain versions to avoid breaking changes.
Features
- Load and index PDF documents
- Ask natural language questions
- Retrieve answers with or without source documents
- Minimal, function-based API
- Stable LangChain 1.2.x compatibility
- Suitable for scripts, notebooks, and APIs
Installation
pip install chat-pdf
Requirements
- Python 3.10 or higher
- OpenAI API key
Set your API key as an environment variable or pass it directly in code:
export OPENAI_API_KEY="your-api-key"
Quick Start
1. Load a PDF
from chat_pdf import load_pdf
db = load_pdf(
"document.pdf",
api_key="OPENAI_API_KEY"
)
This will:
- Load the PDF file
- Split it into chunks
- Generate embeddings
- Store them in a Chroma vector database
2. Ask a Question
from chat_pdf import ask_question
answer = ask_question(
"What is this document about?",
db=db,
api_key="OPENAI_API_KEY"
)
print(answer)
3. Ask a Question with Sources (Optional)
from chat_pdf import ask_question_with_sources
result = ask_question_with_sources(
"What are the termination conditions?",
db=db,
api_key="OPENAI_API_KEY"
)
print("Answer:")
print(result["answer"])
print("\nSources:")
for doc in result["sources"]:
print(doc.metadata)
Returned keys:
answer– generated responsesources– list of retrieved document chunks
API Reference
load_pdf
load_pdf(
pdf_path: str,
api_key: str,
chunk_size: int = 1000,
chunk_overlap: int = 200,
persist_directory: str | None = None
)
ask_question
ask_question(
question: str,
db,
api_key: str,
model_name: str = "gpt-3.5-turbo",
search_kwargs: dict | None = None,
system_prompt: str | None = None
)
Returns a string answer.
ask_question_with_sources
ask_question_with_sources(
question: str,
db,
api_key: str,
model_name: str = "gpt-3.5-turbo",
search_kwargs: dict | None = None,
system_prompt: str | None = None
)
Returns a dictionary:
{
"answer": str,
"sources": list
}
Version Compatibility
This package is pinned for stability.
| chat-pdf | LangChain |
|---|---|
| 1.2.0.0 | 1.2.x |
Upgrading LangChain independently is not recommended.
Design Philosophy
- Simple over clever
- Stable over experimental
- Explicit over magical
This library is designed to be easy to read, debug, and extend.
License
MIT License
Metadata
Release files for easy-rag-pdf 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| easy_rag_pdf-0.0.1.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| easy_rag_pdf-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.1 kB
Release files / easy_rag_pdf-0.0.1.tar.gz
| Download URL | easy_rag_pdf-0.0.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
60a8aa05ca287a15d9bc0f5a41d4c8e0503b77b06f89e139610ce1c49ddaba27
|
|
BLAKE2b-256 checksum How to use checksums |
638191ce0cdd8040a54131340f49d2197441de44a636b8959a5d46460c131e9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Release files / easy_rag_pdf-0.0.1-py3-none-any.whl
| Download URL | easy_rag_pdf-0.0.1-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ac81299f150b66b14a9047cb4a482d5be3676b8d86287c8170023fa92719128
|
|
BLAKE2b-256 checksum How to use checksums |
2fd85f4f100d2091ff433c2b797f8a5f9d5e143a34060a1e09cbd0f46ac5abe1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|