Skip to main content

Content Deduplication

Hospital websites frequently contain duplicate or near-duplicate content: the same brochure accessible via multiple URL paths, navigation menus repeated on every page, footer text appearing in every document, and content published in multiple languages. Without deduplication, the RAG pipeline would retrieve redundant chunks that waste context window tokens and confuse the LLM.

The ZOL system implements seven deduplication layers, each targeting a different type of redundancy:

Layer 1: URL-Level Deduplication​

When: During crawl discovery

The crawler keeps a registry of discovered URLs with a uniqueness rule per hospital. When a URL is discovered multiple times (e.g., from different sitemap entries or internal links), only the first occurrence is recorded. Later discoveries update metadata but don't create duplicate entries.

This prevents the same page from being ingested twice when the URL is identical, but does not catch cases where different URLs serve the same content (handled by Layers 2 and 3).

Layer 2: Title-Level Deduplication​

When: During ingestion (before and after content extraction)

The ingestion service performs two title-based dedup checks:

Pre-flight check — Before fetching content, if the crawled URL already has a title (from the sitemap or a previous crawl), the system checks for an existing completed document with the same title. If one exists, the URL is linked to that document and fetching is skipped, saving an HTTP request and model costs.

Post-flight check — After extracting content (when the page title is definitively known), a second title check catches cases where the pre-flight title was absent or different from the extracted title.

This catches cases where the same content is published under different URLs but with identical page titles — common in content management systems such as Drupal, where content is accessible both through a friendly path and through an internal node number.

Layer 3: Canonical URL Detection​

When: During content extraction (after fetching HTML)

This layer addresses a common CMS problem: Drupal (and other CMSs) frequently expose the same content at multiple URL paths. For example, a hospital house-rules page was accessible under two different paths — identical content, different URLs, different page titles.

How it works:

  1. During HTML extraction, the system reads the standard "canonical" link declared in the page header
  2. If the canonical URL differs from the crawled URL, this indicates the page is an alias
  3. The system checks whether a document already exists for the canonical URL
  4. If found, the current page is skipped and linked to the existing document

Impact (self-reported, March 2026 analysis of the project's own crawl of the ZOL website): canonical URL detection identified 73 fully-duplicated document pairs (146 documents serving identical content at different URL paths), eliminating 184 redundant chunks.

Root cause analysis of the 73 duplicates:

PatternCount
Different clean URL paths (CMS aliases)66
Internal node-number URL versus clean URL alias7

Layer 4: Boilerplate Stripping​

When: During content extraction (CSS selectors) and after chunking (text patterns)

Hospital website pages contain repeated elements: navigation menus, footer links, cookie notices, sidebar widgets, breadcrumbs. These appear in every page's extracted text and would create near-identical chunks across all documents.

The boilerplate filter uses a tiered pattern system:

Tier 1: Generic CSS selectors​

A set of 34 generic selectors that work for any hospital website, targeting common structural elements: navigation, header, footer and sidebar elements, breadcrumb trails, cookie and consent banners, social-sharing and newsletter widgets.

Tier 2: Per-hospital CSS selectors​

Site-specific selectors are stored in the hospital's configuration, not in code. This keeps the system hospital-agnostic: the generic selectors and the hospital's own selectors are merged into a single list at runtime.

Tier 3: Text-level patterns​

Some boilerplate survives CSS selector removal because it lives inside the main content area. For ZOL, this includes an accessibility widget ("Moeilijk leesbaar?"), mega-menu navigation text that appears within the main content, and repeated doctor-listing links. These are handled by text patterns applied to the extracted markdown.

Configuring for a new hospital​

  1. Create the hospital in platform management — no boilerplate configuration is needed up front
  2. Run an initial crawl — the generic selectors (Tier 1) handle common patterns automatically
  3. Review chunks — if hospital-specific chrome appears, an administrator adds CSS selectors to the hospital's configuration
  4. Re-ingest affected URLs — the custom patterns are now active

Tier 4: PDF-specific boilerplate patterns​

PDF brochures have their own boilerplate that doesn't exist in HTML: cover pages with hospital addresses, phone numbers, and campus blocks. These are invisible to CSS selectors (no page structure) and often unique enough to defeat hash-based dedup (each cover has a different title).

PDF patterns are stored separately in the hospital's configuration and applied during PDF extraction. This was added after the PDF Corpus Scaling Incident, where hundreds of brochure cover pages polluted the retrieval index.

Current ZOL configuration​

TypeCount
Generic CSS selectors34
Hospital-configured CSS selectors5
Text patterns (HTML and PDF)20
PDF boilerplate patterns2

Layer 5: Cross-Document Content Hash Deduplication​

When: During chunk storage (after embedding generation)

This layer detects identical text appearing across different documents — for example, a standard disclaimer paragraph in every brochure, templated introductions shared across exercise program pages, or hospital policy text copied across admission information pages.

How it works:

  1. Hash computation: Each chunk's text content is hashed (SHA-256)
  2. Cross-document lookup: A single database query checks how many other completed documents contain chunks with the same hash
  3. Threshold filtering: Chunks whose hash already exists in at least the threshold number of other completed documents are skipped

Key design decisions:

  • Threshold = 1 (any chunk in another completed document is skipped). This was lowered from the initial value of 3 after analysis showed that most cross-document duplicates occur between exactly 2 documents, not 3 or more
  • Completed-only filter ensures that re-processing a document works correctly — when a document is re-processed, its old chunks are deleted first, so the new chunks won't falsely match against themselves
  • Intra-document dedup runs separately, catching duplicate chunks within the same document (e.g., repeated sections in a long brochure)

Partial-overlap analysis (ZOL corpus, March 2026, approximate counts from the project's own analysis):

Content typeShared chunksSource
Exercise-programme templates~20Templated intro/guidelines across 15+ exercise variants
Hospital policy paragraphs~15Standard admission/visitor rules shared across campus pages
Training program curricula~10Yearly editions sharing core curriculum content
Department sidebar navigation~15Cross-linked department lists

Layer 6: Language Filtering​

When: During chunk storage

Hospital content is primarily in Dutch, but extracted text sometimes contains fragments in other languages (French/German headers, English technical terms, untranslated CMS boilerplate). These fragments reduce retrieval quality for Dutch queries.

The language filter uses the Lingua library for language detection:

  1. For each chunk with 30+ characters of content, detect the primary language
  2. If the detected language is NOT in the expected set (Dutch by default), skip the chunk
  3. Short chunks (under 30 characters) bypass the filter — they're typically headings or labels

The filter and the expected languages are configurable.

Layer 7: Re-Ingestion Protection​

When: When a page is re-crawled or updated

When a URL is re-ingested (e.g., after content update), the system:

  1. Checks if the content hash has changed since last ingestion
  2. If unchanged, skips processing entirely (saves model costs for contextual embeddings)
  3. If changed, deletes old chunks and re-processes from scratch

Measured Impact​

An analysis of the ZOL corpus in March 2026 (self-reported: the project's own one-off analysis of its crawl, with approximate counts for the smaller layers) quantified the impact of each deduplication layer:

LayerWhat It PreventsChunks SavedMethod
1. URL dedupSame URL ingested twice~200 URLsUniqueness rule
2. Title dedupCMS path aliases (same title)~50 documentsPre/post-flight check
3. Canonical URLCMS URL aliases (different titles)184 chunks (73 documents)Canonical link extraction
4. Boilerplate strippingNav/footer/menu chunks~500 chunksCSS selectors + text patterns
5. Cross-doc hash dedupRepeated paragraphs across pages~60 chunksSHA-256 hash matching
6. Language filteringNon-Dutch fragments~30 chunksLingua language detection
7. Re-ingestion protectionUnchanged content on re-crawlVariesContent hash comparison

Before dedup: the raw ZOL corpus would produce about 5,400 chunks. After all layers: 4,408 unique chunks — roughly an 18% reduction in redundant content that would otherwise pollute retrieval results and waste LLM context tokens.

The pilot corpus has grown

The 5,400 → 4,408 figures are from the March 2026 HTML-only corpus and remain the cleanest "before vs after" comparison for the dedup layers. Following the PDF Corpus Scaling Incident and the period in which automatic ingest ran on the pilot, the pilot corpus reached 5,841 completed documents and about 10,430 chunks (May 2026), composed of HTML pages plus 573 PDF brochures with PDF-specific boilerplate stripping (Tier 4) operational. The dedup-layer mechanics are unchanged; only the absolute counts have grown.

Configuration​

The cross-document threshold (1 = exact dedup, 3 or more = boilerplate only), the language filter and the expected languages are configurable, as are the per-hospital boilerplate selectors and text patterns.