A Streamlit-based web application for asking questions about PDF books using Docling for document processing and LangChain for question-answering.
- PDF Upload: Easy file upload through the sidebar
- Document Processing: Uses Docling for advanced PDF processing with OCR and table structure recognition
- Vector Search: FAISS-based vector search for relevant document chunks
- Interactive Chat: Chat interface for asking questions about your book
- Source Documents: View the source chunks used to answer each question
- Document Preview: See the raw Docling markdown output in the right panel
- Persistent Storage: Vector stores are saved and reused for faster subsequent loads
Method A: Using Setup Script (Recommended)
python setup.pyMethod B: Manual Installation
# First, install specific versions to avoid conflicts
pip install numpy==1.24.3 pandas==2.1.4 bottleneck==1.3.7
# Then install remaining dependencies
pip install -r requirements.txtMethod C: Alternative Requirements File
pip install -r requirements_alternative.txtThis application uses a local LLM server. You need to set up a local model server at http://localhost:1234/v1.
Option A: Using LM Studio
- Download and install LM Studio
- Load your preferred model
- Start the local server on port 1234
Option B: Using Ollama
- Install Ollama
- Pull a model:
ollama pull llama2 - Start the server:
ollama serve - Update the API endpoint in
doclingbookloader.pyif needed
streamlit run streamlit_app.py- Upload PDF: Use the sidebar to upload a PDF book
- Processing: Wait for the document to be processed by Docling
- Ask Questions: Use the chat interface to ask questions about your book
- View Sources: Expand the "Source Documents" section to see relevant chunks
- Preview Content: Check the right panel to see the extracted markdown content
├── streamlit_app.py # Main Streamlit application
├── doclingbookloader.py # Document loader and QA system classes
├── requirements.txt # Python dependencies
└── README.md # This file
The application uses the following Docling configuration:
- OCR: Enabled for text extraction from images
- Table Structure: Enabled with cell matching
- Accelerator: Auto-detection with 8 threads
- Chunk Size: 1000 characters with 200 character overlap
Current settings in doclingbookloader.py:
- Model:
local-model - API Base:
http://localhost:1234/v1 - Temperature: 0 (deterministic responses)
- Search Type: MMR (Maximum Marginal Relevance)
- Retrieved Chunks: 5 per query
-
"AttributeError: ARRAY_API not found" (Bottleneck Error):
# Solution 1: Use the setup script python setup.py # Solution 2: Manual fix pip uninstall bottleneck pandas numpy -y pip install numpy==1.24.3 pandas==2.1.4 bottleneck==1.3.7 pip install -r requirements.txt # Solution 3: Alternative approach pip install -r requirements_alternative.txt
-
"Connection Error": Ensure your local LLM server is running
-
"FAISS Import Error": Install with
pip install faiss-cpu -
"Tokenizer Warnings": These are normal and don't affect functionality
-
"Memory Issues": Try reducing chunk size or using smaller models
If you're having persistent dependency conflicts:
# Create a fresh conda environment
conda create -n bookqa python=3.10
conda activate bookqa
# Then run the setup
python setup.py- First Load: Initial processing takes time but creates a reusable index
- Subsequent Loads: Vector stores are cached for faster startup
- Large Files: Consider splitting very large PDFs for better performance
To use a different LLM provider, modify the ChatOpenAI initialization in doclingbookloader.py:
# For OpenAI
llm = ChatOpenAI(
model="gpt-3.5-turbo",
openai_api_key="your-api-key",
temperature=0,
)
# For Anthropic
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(
model="claude-3-sonnet-20240229",
anthropic_api_key="your-api-key",
temperature=0,
)Modify the text splitter parameters in doclingbookloader.py:
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=1500, # Increase for more context
chunk_overlap=300, # Increase for better continuity
separators=["\n\n", "\n", " ", ""]
)This project is open source and available under the MIT License.