Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔍 DocQuery: RAG-Based Intelligent Document Retrieval Assistant

An intelligent, web-based document search and information retrieval platform that leverages a Retrieval-Augmented Generation (RAG) architecture pattern to parse unstructured documents (.txt, .pdf) and retrieve contextually relevant answers with TF-IDF similarity scoring. Built as the Capstone Final Project for CS50x: Introduction to Computer Science at Harvard University.

CS50x Completed Python Flask SQLite Bootstrap Video Demo


📌 Overview & Background

In modern workflows, researchers and professionals frequently deal with lengthy articles, technical reports, and multi-page documents. Manually scanning hundreds of pages to locate specific facts or answers is time-consuming and inefficient.

DocQuery addresses this problem by providing a streamlined interface where users can:

  1. Upload text and PDF documents (.txt, .pdf).
  2. Automatically parse and index raw content into modular, overlapping text chunks.
  3. Pose natural-language queries to retrieve exact matching excerpts along with computed relevance scores.

🎥 Video Demo & Walkthrough

Watch the full project presentation explaining the RAG architecture and web application workflow:
👉 Watch DocQuery Demo on YouTube


🏗️ System Architecture & Project Structure

The project follows a modular Model-View-Controller (MVC) pattern powered by Flask and SQLite:

  • app.py: Main Flask application logic & routing
  • helpers.py: Core NLP, RAG chunking & TF-IDF algorithm logic
  • assistant.db: Relational SQLite database
  • requirements.txt: Python dependencies
  • uploads/: Staging folder for uploaded documents
  • templates/: UI Layer (Jinja2 + Bootstrap 5)
    • layout.html: Base navigation layout
    • index.html: Search interface & result presentation
    • upload.html: Drag-and-drop document upload interface
    • history.html: Search prompt history & logs
    • apology.html: Custom error handling page

⚙️ Key Technical Components

1. RAG Core & NLP Processing (helpers.py)

  • Sliding Window Chunking (split_into_chunks): Slices text into 200-word blocks with a 30-word overlap. Overlapping preserves semantic continuity across chunk boundaries so search keywords aren't lost at edges.
  • Text Normalization (tokenize): Cleans raw input strings using Regular Expressions (re) and normalizes case for precise token matching.
  • TF-IDF Vectorization (compute_tfidf): Evaluates Term Frequency against Inverse Document Frequency across all indexed chunks to rank and retrieve the most contextually relevant passage for any natural-language query.

2. Application Logic & Routes (app.py)

  • GET / POST / (Index): Processes user search prompts, executes TF-IDF scoring against the SQLite chunk database, logs search history, and displays relevant results.
  • GET / POST /upload: Manages file uploads, parses .pdf files via pypdf, breaks text into chunks, and populates the database tables.
  • GET /history: Displays historical queries, matching outputs, source document tags, and timestamps.

3. Database Schema (assistant.db)

  • documents: Stores uploaded document metadata (id, filename, uploaded_at).
  • chunks: Contains segmented text blocks linked via Foreign Key (doc_id).
  • history: Records user query history, returned answers, source documents, and execution timestamps.

💡 Key Design & Engineering Decisions

  • Deterministic TF-IDF vs. Heavy ML Embeddings: TF-IDF was deliberately chosen over heavy PyTorch/Transformer neural models to guarantee fast, low-latency execution inside lightweight environments (like CS50 Codespaces) without needing external GPU resources or third-party paid API keys.
  • Relational Normalization: Slicing documents into an explicit chunks table linked to parent documents ensures clean cascade operations and prevents orphaned text fragments when files are updated or removed.

🛠️ Quickstart & Local Setup

Prerequisites

  • Python 3.9+
  • pip package manager

1. Clone the Repository

  • git clone https://github.com/T2004-la/docquery.git
  • cd docquery

2. Install Dependencies

  • pip install -r requirements.txt

3. Run the Application

  • flask run

Open http://127.0.0.1:5000 in your web browser to start indexing and searching documents.


🎓 Verified Certificate & Final Project

Developed by Tara Latifi as the capstone final project for CS50x: CS50's Introduction to Computer Science (Harvard University).

CS50x Certificate

Releases

Packages

Contributors

Languages