ソースデータのクリーニングと重複除去
取り込み前にノイズの多いドキュメントを整理して重複コンテンツを削除し、RAGのインデックスを小さく正確に保ち、矛盾する回答をなくす方法を学びます。
「ソースデータのクリーニングと重複除去」はCoddyKit上の無料LLM Apps in Production (RAG + Vector DB + Caching)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLLM Apps in Production (RAG + Vector DB + Caching)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 LLM Apps in Production (RAG + Vector DB + Caching)コースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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.
よくある質問
「ソースデータのクリーニングと重複除去」レッスンは無料ですか?
はい。「ソースデータのクリーニングと重複除去」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、LLM Apps in Production (RAG + Vector DB + Caching)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 LLM Apps in Production (RAG + Vector DB + Caching)コースには全4レッスンが含まれています。
「ソースデータのクリーニングと重複除去」で何を学びますか?
取り込み前にノイズの多いドキュメントを整理して重複コンテンツを削除し、RAGのインデックスを小さく正確に保ち、矛盾する回答をなくす方法を学びます。 ブラウザで直接実行するハンズオンコードでLLM Apps in Production (RAG + Vector DB + Caching)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
LLM Apps in Production (RAG + Vector DB + Caching)を始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのLLM Apps in Production (RAG + Vector DB + Caching)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「ソースデータのクリーニングと重複除去」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このLLM Apps in Production (RAG + Vector DB + Caching)レッスンでコードを書いて実行できますか?
はい。すべてのLLM Apps in Production (RAG + Vector DB + Caching)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 多様なドキュメント形式の読み込み
- コンテキストを考慮した分割戦略
- メタデータの管理とフィルタリング
- ソースデータのクリーニングと重複除去