Skip to content

Repository files navigation

TenderExtractPro

A production-grade RAG pipeline for extracting technical specifications and scope of work from tender documents. Processes real PDF, DOCX, and image files through a 6-stage pipeline: ingestion, table extraction, chunking, hybrid retrieval, LLM extraction, and grounding validation.

NEW: Includes an LLM-powered Scoring and Ranking mechanism to evaluate the extracted tender against a customized Company Profile to determine match score and cost feasibility.

Interface Overview

Upload & Processing

Upload and Processing

Extracted Specifications

Extracted Specifications

Detailed Component View

Specification Details Drawer

Source Grounding & Evidence Match

Evidence Match Parameter Map

Match Score & Ranking Analysis

Match Score Analysis

Interactive Document Q&A with AI Assistant

Ask Document Q&A Document Q&A Interface

Architecture

graph TD
    A[Input Document<br>PDF/DOCX/Image] --> B[1. Ingestion<br>PyMuPDF + OCR fallback]
    B --> C[2. Table Extraction<br>pdfplumber + optional Qwen2-VL fallback]
    C --> D[3. Chunking<br>Section-aware hierarchical chunking]
    D --> E[4. Hybrid Retrieval<br>BM25 + Qdrant + reranking]
    E --> F[5. LLM Extraction<br>Mistral-7B via llama-cpp-python]
    F --> G[6. Validation<br>rapidfuzz grounding verification]
    G --> H[7. Scoring & Ranking<br>Match evaluation against Company Profile]
    H --> I[Structured JSON Output & Match Score]
    
    style A fill:#2d3748,color:#fff
    style I fill:#2b6cb0,color:#fff
    style B fill:#4a5568,color:#fff
    style C fill:#4a5568,color:#fff
    style D fill:#4a5568,color:#fff
    style E fill:#4a5568,color:#fff
    style F fill:#4a5568,color:#fff
    style G fill:#4a5568,color:#fff
    style H fill:#4a5568,color:#fff
Loading

Quick Start

1. Setup Backend

# Setup environment
uv venv
source .venv/bin/activate
uv pip install -r requirements.txt

# Run the API server
uvicorn api.main:app --host 127.0.0.1 --port 8000 --reload

2. Setup Frontend

cd frontend
npm install
npm run dev

See SETUP.md for detailed installation instructions including Tesseract, Poppler, and model download.

Features

Extracted Tender Elements

The pipeline produces a JSON file containing:

  • Technical Specifications: Components, specs, and constraints.
  • Scope of Work: Summaries, deliverables, exclusions, and locations.
  • Every extracted value includes a source citation pointing back to the exact chunk and page in the original document.

Match Scoring & Ranking

You can define a Company Profile (via the UI or company_profile.json) specifying capabilities, budget constraints, and operational exclusions. The pipeline evaluates the tender's requirements against this profile to output:

  • Match Score (0-100): Quantitative alignment score.
  • Cost Feasibility (High/Medium/Low): Budget match based on the company's financial capabilities.
  • Strategic Reasoning: Paragraph outlining the reasoning and any potential red flags.

Anti-Hallucination Safeguards

  1. Prompt Engineering: The LLM prompt explicitly instructs "use NOT_FOUND for missing fields, NEVER invent values" and requires source citations.
  2. Grounding Verification: After LLM extraction, every spec is fuzzy-matched against source chunks using rapidfuzz. Specs with grounding score below 0.40 are rejected.
  3. Pydantic Validation: Output is validated against strict Pydantic v2 models.

Advanced RAG Enhancements (Inspired by SimpleRAG)

  1. Semantic Chunking

    • Logic: Replaced fixed-size splitting with SemanticChunker (from langchain-experimental). It identifies natural breakpoints based on embedding distances, ensuring that paragraphs are only split when the meaning changes.
    • Optimization: Implemented lazy-loading for the chunking embedding model to prevent high latency and memory churn during document processing.
  2. Parent-Child Retrieval

    • Logic: Implemented a sophisticated indexing strategy. Small "child" spans (~200 words) are indexed in Qdrant for high-precision semantic matching, while the full "parent" chunks are returned to the LLM.
    • Benefit: This provides the LLM with much richer context than standard chunking while maintaining pinpoint accuracy during retrieval.
  3. Enhanced Extraction & Grounding

    • Prompts: Refined system and user prompts to use professional "Tender Analyst" personas with strict verbatim extraction rules.
    • JSON Repair: Upgraded the JSON repair logic to handle common LLM failure modes like unescaped newlines and markdown fences more robustly.
  4. Environment & Stability Fixes

    • Virtual Environment: Ensured all dependencies are correctly isolated in the project's local venv.
    • LLM Fix: Resolved the PrefetchVirtualMemory error on Windows by disabling mmap during model loading.
    • Dependencies: Updated requirements.txt to include the retrieval and multimodal runtime libraries used directly by the codebase.
  5. Optional Multimodal Table Recovery

    • Logic: Conventional PDF extraction stays the default fast path for native tables.
    • Fallback: OCR-heavy or conventionally weak pages can be routed through an optional Qwen2-VL 2B table extractor when MULTIMODAL_ENABLED=1.
    • Device-aware: The vision model is released after table extraction so 8 GB-class GPUs can still run the Mistral text model afterward.

Project Structure

TenderExtractPro/
  api/
    main.py             -- FastAPI server with extraction, Q&A, and scoring endpoints
  frontend/             -- React + Vite User Interface
  tender_extraction/
    config.py           -- Centralized configuration
    schemas.py          -- Pydantic v2 models for structured output
    scoring.py          -- LLM matching logic for company profile
    extraction.py       -- LLM-powered specification extraction
    vision.py           -- Optional Qwen2-VL-based table recovery for difficult pages
    main.py             -- Pipeline orchestration and CLI
  company_profile.json  -- Active company profile configurations
  dataset/              -- Real tender PDF files for testing
  models/               -- LLM model files (not in version control)

Configuration

All tunable parameters are centralized in tender_extraction/config.py. Key settings:

Parameter Default Description
chunking.max_chunk_tokens 500 Maximum tokens per text chunk
retrieval.bm25_weight 0.35 BM25 weight in score fusion
retrieval.embedding_weight 0.65 Embedding weight in score fusion
llm.temperature 0.05 LLM generation temperature
validation.min_grounding_ratio 0.40 Minimum grounding score to accept a spec
multimodal.enabled False Enable Qwen2-VL table fallback for difficult pages

Contributors

A big thank you to our contributors! 🙌

  • Gaurav Varu - Fix: Preserve filtered components in scoring logic (#1)

See CONTRIBUTORS.md for more details.

License

MIT

About

AI-powered RAG system for extracting technical specifications and scope of work from tender documents using hybrid retrieval and anti-hallucination techniques.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages