> ## Documentation Index
> Fetch the complete documentation index at: https://docs.salmanahmad.online/llms.txt
> Use this file to discover all available pages before exploring further.

# RAG PDF Highlighter: How It Works and What It Does

> RAG PDF Highlighter is a stateless FastAPI service and Python library that finds text chunks in PDFs and returns highlighted documents for RAG pipelines.

RAG PDF Highlighter is a FastAPI microservice and Python library designed for teams building Retrieval-Augmented Generation (RAG) pipelines. It takes a PDF URL and a list of LangChain `Document` objects, finds each text chunk inside the PDF using a three-tier matching strategy, and returns a new PDF binary with every matched passage highlighted in yellow — giving your users a direct visual connection between retrieved chunks and their original source.

## Key Features

<CardGroup cols={2}>
  <Card title="3-Tier Text Matching" icon="magnifying-glass" href="/quickstart">
    Locates each chunk using a cascading strategy: exact match first, then sentence-level matching, then collapsed-whitespace matching — so even lightly reformatted text is found reliably.
  </Card>

  <Card title="Stateless & Async" icon="bolt" href="/quickstart">
    Every request is fully self-contained. The service holds no session state between calls, making it trivial to scale horizontally or deploy behind a load balancer.
  </Card>

  <Card title="Python Library Mode" icon="python" href="/installation">
    Import and call the highlighter directly in your own Python code without running a server. Install once with `pip` and integrate it into any existing RAG workflow.
  </Card>

  <Card title="Docker Ready" icon="docker" href="/installation">
    Ship a production container in minutes. The service listens on a configurable port and has no external runtime dependencies beyond its Python packages.
  </Card>
</CardGroup>

## How It Works

RAG PDF Highlighter follows a straightforward three-step process on every request:

1. **Download the PDF** — The service fetches the PDF from the URL you provide using an async HTTP client, so your application never needs to handle the raw file transfer itself.
2. **Locate each chunk** — For every `Document` in your list, the highlighter searches the corresponding page (or the full document if no page is specified) using exact matching, falling back to sentence-level and then collapsed-whitespace matching until a location is found.
3. **Return the annotated PDF** — The service writes yellow highlight annotations over every matched passage and streams the modified PDF binary back in the response, ready to save or serve directly to your users.

<Note>
  RAG PDF Highlighter requires no authentication. All endpoints are open by default, so make sure you deploy behind an appropriate network boundary or API gateway if you need access control.
</Note>

Ready to try it? Head over to the [Quickstart](/quickstart) to make your first highlight request in under five minutes.
