A citation-grounded Retrieval-Augmented Generation (RAG) assistant for technical machine learning and security PDFs.
This project processes technical PDFs into structured retrieval-ready artifacts, builds configurable vector indexes, retrieves relevant context for user queries, and generates citation-grounded answers using multiple LLM backends.
The system is designed as a portfolio-ready applied GenAI project focused on:
- modular RAG architecture
- retrieval quality experimentation
- reproducible workflows
- production-style engineering practices
- scalable ingestion and indexing pipelines
This project aims to:
- Build a modular LangChain-based RAG pipeline
- Support configurable embedding and LLM backends
- Improve retrieval quality through reranking and retrieval strategies
- Preserve structured metadata for grounded citations
- Support incremental indexing workflows
- Create a clean engineering-oriented codebase suitable for extension and deployment
- Enable reproducible experimentation and evaluation
- Modular ingestion, retrieval, and generation architecture
- PDF ETL preprocessing pipeline
- Section-aware document chunking
- Processed PDF caching
- Configurable embedding backends
- FAISS vector indexing
- Similarity and MMR retrieval
- Cross-encoder reranking
- Incremental FAISS index updates
- Citation-grounded answer generation
- Swappable LLM backends
- Streamlit user interface
- Structured application logging
- Automatic processed-PDF synchronization
- MLflow experiment tracking
- reproducible retrieval experiments
- evaluation-ready architecture
A user asks:
What are common attacks on CAV networks?
The assistant will:
- Retrieve relevant chunks from indexed technical PDFs
- Optionally rerank retrieved passages
- Pass grounded context into the LLM
- Generate a citation-grounded answer
- Return references linked to retrieved sources
rag-pdf-assistant/
│
├── data/
│ ├── eval/
│ ├── processed/
│ └── raw/
│
├── notebooks/
│ ├── Evaluation.ipynb
│ └── RAG Test.ipynb
│
├── outputs/
│ ├── experiments/
│ ├── indexes/
│ └── logs/
│
src/
├── ResearchRAG/
│ ├── embedding/
│ │ ├── __init__.py
│ │ ├── embeddings.py
│ │ └── vectorstore.py
│ │
│ ├── evaluation/
│ │ ├── __init__.py
│ │ ├── evaluation.py
│ │ └── experiment.py
│ │
│ ├── generation/
│ │ ├── __init__.py
│ │ ├── llms.py
│ │ └── rag_chain.py
│ │
│ ├── ingestion/
│ │ ├── __init__.py
│ │ ├── chunking.py
│ │ ├── loaders.py
│ │ ├── pdf_cleaning.py
│ │ └── pdf_etl.py
│ │
│ ├── retrieval/
│ │ ├── __init__.py
│ │ ├── reranking.py
│ │ └── retriever.py
│ │
│ ├── ui/
│ │ ├── __init__.py
│ │ ├── app.py
│ │ └── eval_dashboard.py
│ │
│ └── utils/
│ │ ├── __init__.py
│ │ └── logging_config.py
│ │
│ ├── __init__.py
│ └── config.py
│
└── README.md
The system follows this workflow:
- Upload or place PDFs into
data/raw/ - Run PDF ETL preprocessing
- Clean and normalize extracted text
- Chunk content into structured retrieval units
- Cache processed artifacts into JSON files
- Generate embeddings
- Create or update a FAISS vector index
- Retrieve relevant chunks
- Optionally rerank retrieved passages
- Generate grounded answers with citations
The ingestion system uses docling converting raw PDFs into reusable structured artifacts.
The ETL process:
- extracts text from PDFs
- extracts images and tables from document
- chunks content using semantic headers
- stores processed outputs for reuse
Processed artifacts are cached under:
data/processed/
The application automatically synchronizes missing processed files during startup.
The project supports multiple retrieval configurations.
- similarity retrieval
- MMR retrieval
- cross-encoder reranking
The system supports second-stage reranking using HuggingFace cross-encoder models. This improves retrieval quality by:
- rescoring retrieved chunks
- improving ranking precision
- filtering noisy retrieval results
The application supports incremental FAISS updates. When new PDFs are uploaded:
- only new PDFs are processed
- only new chunks are embedded
- the existing FAISS index is updated in place
This avoids rebuilding the entire vector index for every upload.
The Streamlit application supports:
- PDF upload/remove directly from the UI
- automatic indexing of uploaded PDFs
- deletion of PDFs from the vector index
- configurable embedding model selection
- configurable LLM backend selection
- optional reranking
- retrieved chunk inspection
- grounded answer generation
The project uses structured logging across ingestion, indexing, retrieval, and generation modules.
Features include:
- module-level loggers
- per-run log files
- exception trace logging
- pipeline-stage visibility
- debugging support for ingestion and indexing workflows
Logs are stored under:
outputs/logs/
Handles document ingestion and preprocessing.
Runs the PDF ETL pipeline using docling and manages processed artifacts.
Cleans extracted PDF text and repairs section structure. (Not used in this version)
Loads processed PDF artifacts into LangChain Document objects.
Splits documents into retrieval-ready chunks.
Handles embedding generation and vector indexing.
Builds configurable embedding backends.
Supported providers include:
- HuggingFace
- Cohere
Builds, saves, loads, updates, and modifies FAISS indexes.
Handles retrieval and reranking logic.
Builds configurable retrievers for similarity and MMR search.
Builds cross-encoder reranking pipelines.
Handles LLM orchestration and answer generation.
Builds configurable LLM backends.
Supported providers include:
- OpenAI
- Cohere
- Ollama
Runs the full RAG orchestration pipeline:
- retrieve documents
- format context
- invoke the LLM
- return grounded answers
Initializes structured logging and per-run log files.
Examples:
- all-MiniLM
- MPNet
- BGE
- Cohere embeddings
Examples:
- Mistral
- Llama
- Qwen
- OpenAI models
- Cohere chat models
- Ollama-hosted local models
The project supports experiment tracking using MLflow.
Tracked experiment components may include:
- embedding model selection
- retriever configuration
- reranker usage
- chunking parameters
- evaluation metrics
- generated outputs
This enables reproducible comparison between retrieval and generation configurations.
Core technologies used in this project:
- Python
- LangChain
- FAISS
- Streamlit
- HuggingFace
- Cohere API
- OpenAI API
- Ollama
- Docling
- MLflow
- sentence-transformers
Clone the repository and install dependencies:
git clone https://github.com/pegahmansourian/RAG_Assistant
cd rag-pdf-assistant
pip install -r requirements.txtCreate a .env file in the project root for any required API keys.
Example:
COHERE_API_KEY=your_cohere_api_key_here
OPENAI_API_KEY=your_openai_api_key_hereYou only need the keys for providers you actually use.
From the project root:
streamlit run src/ResearchRAG/ui/app.pyThis launches the Streamlit interface for querying the indexed PDF collection.
Example experiment run:
python run_experiment.py --config configs/exp_reranker.yamlTo inspect tracked runs locally with MLflow:
mlflow uiThen open http://localhost:5000 in your browser.
Potential extensions include:
- hybrid retrieval with BM25 + dense search
- metadata-aware retrieval
- conversational memory
- benchmark evaluation suites
- cloud deployment architecture
Pegah Mansourian
Applied ML / AI researcher focused on trustworthy AI, anomaly detection, and security-oriented machine learning systems.
ChatGPT AI tools were used as a development aid for code debugging and documentation support. The project structure, implementation, experimentation, and final validation were completed by the author.