Project: AI Engineering Intern Assessment — end-to-end pipeline that extracts text from scanned images/PDFs, converts text to embeddings, stores them in FAISS, and answers queries with a small LLM (TinyLlama) using retrieval-augmented generation (RAG).
This repository contains:
chatpdf.ipynb— Jupyter Notebook demonstrating the full pipeline (OCR, preprocessing, embeddings, FAISS index, RAG queries).chatpdf_documentation.md— Documentation and reproduction notes (generated from the notebook).
The notebook implements the following flow:
- Upload or provide an image / PDF.
- Preprocess image (grayscale + CLAHE) for better OCR results.
- Run a vision-language OCR model (Qwen2-VL OCR variant) to extract text.
- Split text into chunks using LangChain's
RecursiveCharacterTextSplitter. - Embed chunks using
sentence-transformers/all-MiniLM-L6-v2and normalize embeddings. - Store embeddings in FAISS (index written to
ocr_docs_index.faiss) and cache mapping (docs_mapping.pkl). - Query the FAISS index and generate answers with
TinyLlama/TinyLlama-1.1B-Chat-v1.0(text-generation pipeline).
ocr_docs_index.faiss— FAISS index with embeddings (created at runtime).docs_mapping.pkl— Pickled mapping of index rows to text chunks.
See requirements.txt for a pinned list of core Python packages. There are notes in the file about optional GPU-specific packages.
On Windows (local development):
- Create and activate a virtual environment
python -m venv .venv
.\.venv\Scripts\activate- Install packages
pip install -r requirements.txt- Install Poppler for Windows
- Download a Poppler binary from a trusted source (e.g., conda-forge or the official Poppler releases). Add the
binfolder to your PATH or passpoppler_pathtopdf2image.convert_from_path.
- Open
chatpdf.ipynbin Jupyter or VS Code and run cells in order. Replacegoogle.colab.files.upload()with a local file picker or a path if needed.
On Google Colab
- Use the Colab notebook directly and run the
!apt-get install -y poppler-utilscell to install Poppler. The notebook already usesgoogle.colab.files.upload()for uploads.
- Run the notebook cells sequentially. After creating the FAISS index, call
query_document("Your question")to get answers orquery = "Summarize this document"as in the example cell.