0Pricing
LLM Apps in Production (RAG + Vector DB + Caching) · Lezione

Pulire e deduplicare i dati sorgente

Imparate a pulire i documenti rumorosi e a rimuovere i contenuti duplicati prima dell’ingestione, così che l’indice RAG rimanga compatto, accurato e privo di risposte in conflitto.

Pulire e deduplicare i dati sorgente è una lezione LLM Apps in Production (RAG + Vector DB + Caching) gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento LLM Apps in Production (RAG + Vector DB + Caching), e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso LLM Apps in Production (RAG + Vector DB + Caching) include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Garbage In, Garbage Out

RAG quality is capped by the quality of what you ingest. Boilerplate, HTML tags, duplicate pages, and broken encoding all pollute retrieval.

Cleaning and deduplication happen before chunking and embedding.

Common Noise Sources

Typical junk found in raw documents:

  • Navigation menus, headers, footers
  • Cookie banners and ads
  • Repeated legal disclaimers
  • Mojibake from bad encoding
  • Excess whitespace and control chars

Basic Text Normalization

Normalize whitespace and strip control characters first.

import re

def clean(text):
    text = re.sub(r'[\t\r]+', ' ', text)
    text = re.sub(r' {2,}', ' ', text)
    text = re.sub(r'\n{3,}', '\n\n', text)
    return text.strip()

print(clean('Hello     world\n\n\n\nbye'))

Stripping Boilerplate

Remove repeated boilerplate that appears on many pages. A simple approach: collect lines that repeat across documents and drop them.

  • Footers, copyright lines
  • Share-this widgets
  • Identical navigation blocks

Fixing Encoding Issues

Mojibake like 'caf\u00c3\u00a9' instead of 'caf\u00e9' confuses embeddings. Detect the source encoding and decode consistently to UTF-8 before storage.

Exact Duplicate Detection

The cheapest dedup: hash the normalized text and drop exact repeats.

import hashlib

seen = set()

def is_dup(text):
    h = hashlib.sha256(text.encode()).hexdigest()
    if h in seen:
        return True
    seen.add(h)
    return False

print(is_dup('a'))
print(is_dup('a'))

Near-Duplicate Detection

Exact hashing misses pages that differ by a date or a word. Use near-duplicate techniques:

  • MinHash + Jaccard similarity
  • SimHash fingerprints
  • Embedding cosine similarity above a threshold

Jaccard Similarity

A quick token-set overlap score to flag near-duplicates.

def jaccard(a, b):
    sa, sb = set(a.split()), set(b.split())
    return len(sa & sb) / len(sa | sb)

print(round(jaccard('the cat sat', 'the cat ran'), 2))

Why Duplicates Hurt RAG

Duplicate chunks waste index space and skew retrieval: the top-k results fill up with copies of the same passage, crowding out diverse evidence. Conflicting near-duplicates (old vs new policy) can even produce contradictory answers.

Building a Cleaning Pipeline

Chain the steps in order: normalize -> fix encoding -> strip boilerplate -> exact dedup -> near dedup. Log how much was removed so you can audit aggressive filters.

Idempotent Re-ingestion

When documents are re-ingested, use a stable content hash as the record key so updates replace the old version instead of creating duplicates. This keeps the index clean over time.

Quick Check

Test your understanding of deduplication.

Recap

You learned to prepare clean source data: normalize text, fix encoding, strip boilerplate, then remove both exact and near-duplicates. Use stable content hashes for idempotent re-ingestion. Cleaner inputs mean a smaller index and more accurate, non-contradictory retrieval.

Domande Frequenti

La lezione «Pulire e deduplicare i dati sorgente» è gratuita?

Sì — il testo completo di «Pulire e deduplicare i dati sorgente» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso LLM Apps in Production (RAG + Vector DB + Caching), passa a CoddyKit PRO. Il corso LLM Apps in Production (RAG + Vector DB + Caching) include 4 lezioni in totale.

Cosa imparerò in «Pulire e deduplicare i dati sorgente»?

Imparate a pulire i documenti rumorosi e a rimuovere i contenuti duplicati prima dell’ingestione, così che l’indice RAG rimanga compatto, accurato e privo di risposte in conflitto. Eserciti LLM Apps in Production (RAG + Vector DB + Caching) con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare LLM Apps in Production (RAG + Vector DB + Caching)?

Non è richiesta alcuna esperienza precedente. LLM Apps in Production (RAG + Vector DB + Caching) su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Pulire e deduplicare i dati sorgente»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione LLM Apps in Production (RAG + Vector DB + Caching)?

Sì. Ogni lezione LLM Apps in Production (RAG + Vector DB + Caching) include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Caricare formati documentali diversi
  2. Strategie di chunking consapevoli del contesto
  3. Gestione e filtraggio dei metadati
  4. Pulire e deduplicare i dati sorgente
← Torna a LLM Apps in Production (RAG + Vector DB + Caching)