0Pricing
LLM Apps in Production (RAG + Vector DB + Caching) · درس

تنظيف بيانات المصدر وإزالة التكرار

تعلّم تنظيف المستندات المشوشة وإزالة المحتوى المكرر قبل الإدخال، حتى يظل فهرس RAG صغيرًا ودقيقًا وخاليًا من الإجابات المتعارضة.

تنظيف بيانات المصدر وإزالة التكرار درس مجاني في LLM Apps in Production (RAG + Vector DB + Caching) على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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.

الأسئلة الشائعة

هل درس «تنظيف بيانات المصدر وإزالة التكرار» مجاني؟

نعم — نص درس «تنظيف بيانات المصدر وإزالة التكرار» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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) مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 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) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تحميل تنسيقات المستندات المتنوعة
  2. استراتيجيات تقسيم النصوص الواعية بالسياق
  3. إدارة البيانات الوصفية وتصفيتها
  4. تنظيف بيانات المصدر وإزالة التكرار
← العودة إلى LLM Apps in Production (RAG + Vector DB + Caching)