A production-ready Vector Space Model (VSM) Information Retrieval engine built from scratch in Python using the Natural Language Toolkit (NLTK). This engine implements efficient text preprocessing, TF-IDF vectorization, an inverted index architecture, and an optimized top-K document retrieval strategy utilizing mathematical upper-bounding to prune the search space.
This project mimics production-grade search engines by avoiding naive sequential scans over the entire document corpus. Instead, it utilizes a multi-stage data pipeline to achieve sub-millisecond query execution.
Every document and search query undergoes a strict tokenization and standardization pipeline:
- Case Folding: Converts all text to lowercase to ensure case-insensitive matching.
- Regex Tokenization: Extracts purely alphabetic words using NLTK's
RegexpTokenizer. - Stopword Removal: Filters out high-frequency, low-meaning words (e.g., the, is, at) using the NLTK English stopword matrix to reduce index noise.
- Morphological Stemming: Applies the Porter Stemmer algorithm to reduce words to their base linguistic roots.
The mathematical importance of each token
Each document vector is
Evaluating every document for a multi-word query is computationally expensive ($O(N)$). To bypass this, this engine implements an early-termination pruning strategy:
- For each query term, it inspects only the top-10 highest-weighted documents in its postings list.
- If a document is missing from the top-10 list of a query term, the engine computes a strict mathematical upper-bound score to safely discard non-viable candidate documents instantly without exhaustive scanning.
- Clone the repository:
git clone (https://github.com/YOUR_USERNAME/vector-space-search-engine.git) cd vector-space-search-engine - Setup virtual environment:
python3 -m venv .venv
source .venv/bin/activate- Install dependencies:
pip install -r requirements.txt4.Run
python3 main.py