ทำความสะอาดและลบข้อมูลต้นฉบับที่ซ้ำกัน
เรียนรู้การทำความสะอาดเอกสารที่มีสัญญาณรบกวนและลบเนื้อหาซ้ำก่อนนำเข้าระบบ เพื่อให้ดัชนี RAG มีขนาดเล็ก แม่นยำ และไม่มีคำตอบที่ขัดแย้งกัน
ทำความสะอาดและลบข้อมูลต้นฉบับที่ซ้ำกัน เป็นบทเรียน LLM Apps in Production (RAG + Vector DB + Caching) ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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.
คำถามที่พบบ่อย
บทเรียน “ทำความสะอาดและลบข้อมูลต้นฉบับที่ซ้ำกัน” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ทำความสะอาดและลบข้อมูลต้นฉบับที่ซ้ำกัน” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส 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) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน LLM Apps in Production (RAG + Vector DB + Caching) หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน LLM Apps in Production (RAG + Vector DB + Caching) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “ทำความสะอาดและลบข้อมูลต้นฉบับที่ซ้ำกัน” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน LLM Apps in Production (RAG + Vector DB + Caching) นี้ได้ไหม
ได้ บทเรียน LLM Apps in Production (RAG + Vector DB + Caching) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การโหลดเอกสารหลากหลายรูปแบบ
- กลยุทธ์การแบ่งข้อความตามบริบท
- การจัดการและกรองข้อมูลเมทาดาทา
- ทำความสะอาดและลบข้อมูลต้นฉบับที่ซ้ำกัน