RAG Document Ingestion Pipeline
Build production-grade document ingestion pipelines that chunk, embed, and store documents in vector databases for retrieval-augmented generation.
Activation Triggers
Activate on: "document ingestion", "chunking strategy", "embedding pipeline", "vector DB ingestion", "RAG indexing", "ingest PDFs", "build knowledge base", "semantic chunking", "recursive chunking"
NOT for: LLM prompt design or retrieval query tuning (prompt-engineer, ai-engineer), vector DB operational migration (vector-database-migration-tool), or fine-tuning data preparation (fine-tuning-dataset-curator)
Quick Start
- Identify sources — PDFs, HTML, Markdown, databases, APIs. Use
unstructured or docling for parsing.
- Choose chunking strategy — Recursive character splitting for general text, semantic chunking for domain-specific content, or document-structure-aware chunking for technical docs.
- Select embedding model —
text-embedding-3-large (OpenAI), embed-v4 (Cohere), or BAAI/bge-m3 (local). Match dimensionality to your vector DB plan.
- Configure vector DB — Pinecone (managed), Qdrant (self-hosted or cloud), Weaviate (multi-tenant), or pgvector (Postgres-native).
- Run ingestion with observability — Batch embed, upsert with metadata, validate retrieval quality on a test set.
Core Capabilities
| Domain |
Technologies |
Notes |
| Document Parsing |
unstructured, docling, PyMuPDF, markitdown |
Handles PDF, DOCX, HTML, Markdown, images with OCR |
| Chunking |
LangChain splitters, semantic-chunkers, chonkie |
Recursive, semantic, markdown-header, code-aware |
| Embedding Models |
OpenAI text-embedding-3, Cohere embed-v4, BGE-M3, Nomic Embed |
Local or API; 256-3072 dimensions |
| Vector Databases |
Pinecone, Qdrant, Weaviate, pgvector, Milvus |
Managed or self-hosted; HNSW or IVF indexing |
| Orchestration |
LangChain, LlamaIndex, Haystack, custom Python |
Pipeline DAGs with retry and checkpointing |
Architecture Patterns
Pattern 1: Chunking Decision Tree
Document Type?
├── Structured (Markdown, HTML, code)
│ └── Structure-aware chunking (headers, functions)
│ └── Preserve hierarchy as metadata
├── Semi-structured (PDF with tables)
│ └── docling/unstructured → table extraction + text chunking
│ └── Embed tables as markdown, text as paragraphs
└── Unstructured (plain text, transcripts)
└── Semantic chunking (embedding similarity breakpoints)
└── Fallback: recursive character split (512-1024 tokens, 10% overlap)
Pattern 2: Production Ingestion Pipeline
Sources ──→ [Parser] ──→ [Chunker] ──→ [Enricher] ──→ [Embedder] ──→ [Vector DB]
│ │ │ │ │ │
│ unstructured recursive/ add metadata: batch embed upsert with
│ docling semantic source, date, (batch=256) namespace
│ section, hash partitioning
│
└── Dedup by content hash before embedding (saves 30-50% cost)
# Production ingestion skeleton
from langchain_text_splitters import RecursiveCharacterTextSplitter
from hashlib import sha256
def ingest_documents(docs: list[str], collection: str):
splitter = RecursiveCharacterTextSplitter(
chunk_size=512, chunk_overlap=64,
separators=["\n\n", "\n", ". ", " "]
)
seen_hashes = set()
chunks = []
for doc in docs:
for chunk in splitter.split_text(doc):
h = sha256(chunk.encode()).hexdigest()[:16]
if h not in seen_hashes:
seen_hashes.add(h)
chunks.append({"text": chunk, "hash": h})
# Batch embed and upsert
embeddings = embed_batch([c["text"] for c in chunks], batch_size=256)
vector_db.upsert(collection, chunks, embeddings)
Pattern 3: Metadata-Enriched Chunks
Always store metadata alongside vectors for filtered retrieval:
metadata = {
"source": "docs/api-reference.md",
"section": "Authentication",
"chunk_index": 3,
"total_chunks": 12,
"ingested_at": "2026-03-20T00:00:00Z",
"content_hash": "a1b2c3d4",
"token_count": 487,
}
Anti-Patterns
- Fixed-size chunking without overlap — Splits mid-sentence, destroys context. Always use overlap (10-15%) or semantic boundaries.
- Embedding everything without deduplication — Near-duplicate chunks waste storage and degrade retrieval. Hash-dedup or use MinHash for fuzzy dedup.
- Ignoring chunk metadata — Without source, section, and date metadata, you cannot filter, cite, or refresh stale content.
- One embedding model for all domains — Legal text and code have different semantic spaces. Benchmark retrieval quality per domain before committing.
- No ingestion idempotency — Re-running ingestion creates duplicates. Use content hashes as vector IDs for upsert-based idempotency.
Quality Checklist
1---2license: Apache-2.03name: rag-document-ingestion-pipeline4description: "Build production document ingestion pipelines with chunking, embedding, and vector DB storage. Activate on: document ingestion, chunking strategy, embedding pipeline, vector DB ingestion, RAG indexing. NOT for: LLM prompt design (prompt-engineer), retrieval query logic (ai-engineer), or vector DB ops/migration (vector-database-migration-tool)."5allowed-tools: Read,Write,Edit,Bash(python:*,pip:*,npm:*,npx:*)6category: AI & Machine Learning7tags:8 - rag9 - embeddings10 - vector-database11 - document-processing12 - chunking13pairs-with:14 - skill: ai-engineer15 reason: RAG retrieval and query logic sits downstream of ingestion16 - skill: data-pipeline-engineer17 reason: ETL patterns for source extraction before chunking18 - skill: vector-database-migration-tool19 reason: Schema and index design for the target vector store20metadata:21 source: https://skillmd.com/skills/curiositech/rag-document-ingestion-pipeline22---2324# RAG Document Ingestion Pipeline2526Build production-grade document ingestion pipelines that chunk, embed, and store documents in vector databases for retrieval-augmented generation.2728## Activation Triggers2930**Activate on**: "document ingestion", "chunking strategy", "embedding pipeline", "vector DB ingestion", "RAG indexing", "ingest PDFs", "build knowledge base", "semantic chunking", "recursive chunking"3132**NOT for**: LLM prompt design or retrieval query tuning (prompt-engineer, ai-engineer), vector DB operational migration (vector-database-migration-tool), or fine-tuning data preparation (fine-tuning-dataset-curator)3334## Quick Start35361. **Identify sources** — PDFs, HTML, Markdown, databases, APIs. Use `unstructured` or `docling` for parsing.372. **Choose chunking strategy** — Recursive character splitting for general text, semantic chunking for domain-specific content, or document-structure-aware chunking for technical docs.383. **Select embedding model** — `text-embedding-3-large` (OpenAI), `embed-v4` (Cohere), or `BAAI/bge-m3` (local). Match dimensionality to your vector DB plan.394. **Configure vector DB** — Pinecone (managed), Qdrant (self-hosted or cloud), Weaviate (multi-tenant), or pgvector (Postgres-native).405. **Run ingestion with observability** — Batch embed, upsert with metadata, validate retrieval quality on a test set.4142## Core Capabilities4344| Domain | Technologies | Notes |45|--------|-------------|-------|46| **Document Parsing** | unstructured, docling, PyMuPDF, markitdown | Handles PDF, DOCX, HTML, Markdown, images with OCR |47| **Chunking** | LangChain splitters, semantic-chunkers, chonkie | Recursive, semantic, markdown-header, code-aware |48| **Embedding Models** | OpenAI text-embedding-3, Cohere embed-v4, BGE-M3, Nomic Embed | Local or API; 256-3072 dimensions |49| **Vector Databases** | Pinecone, Qdrant, Weaviate, pgvector, Milvus | Managed or self-hosted; HNSW or IVF indexing |50| **Orchestration** | LangChain, LlamaIndex, Haystack, custom Python | Pipeline DAGs with retry and checkpointing |5152## Architecture Patterns5354### Pattern 1: Chunking Decision Tree5556```57Document Type?58├── Structured (Markdown, HTML, code)59│ └── Structure-aware chunking (headers, functions)60│ └── Preserve hierarchy as metadata61├── Semi-structured (PDF with tables)62│ └── docling/unstructured → table extraction + text chunking63│ └── Embed tables as markdown, text as paragraphs64└── Unstructured (plain text, transcripts)65 └── Semantic chunking (embedding similarity breakpoints)66 └── Fallback: recursive character split (512-1024 tokens, 10% overlap)67```6869### Pattern 2: Production Ingestion Pipeline7071```72Sources ──→ [Parser] ──→ [Chunker] ──→ [Enricher] ──→ [Embedder] ──→ [Vector DB]73 │ │ │ │ │ │74 │ unstructured recursive/ add metadata: batch embed upsert with75 │ docling semantic source, date, (batch=256) namespace76 │ section, hash partitioning77 │78 └── Dedup by content hash before embedding (saves 30-50% cost)79```8081```python82# Production ingestion skeleton83from langchain_text_splitters import RecursiveCharacterTextSplitter84from hashlib import sha2568586def ingest_documents(docs: list[str], collection: str):87 splitter = RecursiveCharacterTextSplitter(88 chunk_size=512, chunk_overlap=64,89 separators=["\n\n", "\n", ". ", " "]90 )91 seen_hashes = set()92 chunks = []93 for doc in docs:94 for chunk in splitter.split_text(doc):95 h = sha256(chunk.encode()).hexdigest()[:16]96 if h not in seen_hashes:97 seen_hashes.add(h)98 chunks.append({"text": chunk, "hash": h})99 # Batch embed and upsert100 embeddings = embed_batch([c["text"] for c in chunks], batch_size=256)101 vector_db.upsert(collection, chunks, embeddings)102```103104### Pattern 3: Metadata-Enriched Chunks105106Always store metadata alongside vectors for filtered retrieval:107108```python109metadata = {110 "source": "docs/api-reference.md",111 "section": "Authentication",112 "chunk_index": 3,113 "total_chunks": 12,114 "ingested_at": "2026-03-20T00:00:00Z",115 "content_hash": "a1b2c3d4",116 "token_count": 487,117}118```119120## Anti-Patterns1211221. **Fixed-size chunking without overlap** — Splits mid-sentence, destroys context. Always use overlap (10-15%) or semantic boundaries.1232. **Embedding everything without deduplication** — Near-duplicate chunks waste storage and degrade retrieval. Hash-dedup or use MinHash for fuzzy dedup.1243. **Ignoring chunk metadata** — Without source, section, and date metadata, you cannot filter, cite, or refresh stale content.1254. **One embedding model for all domains** — Legal text and code have different semantic spaces. Benchmark retrieval quality per domain before committing.1265. **No ingestion idempotency** — Re-running ingestion creates duplicates. Use content hashes as vector IDs for upsert-based idempotency.127128## Quality Checklist129130- [ ] Chunking strategy matches document structure (not just fixed-size)131- [ ] Chunk sizes benchmarked for retrieval quality (typically 256-1024 tokens)132- [ ] Overlap configured to preserve cross-boundary context133- [ ] Deduplication prevents redundant embeddings134- [ ] Metadata attached to every chunk (source, section, date, hash)135- [ ] Embedding model dimensionality matches vector DB index config136- [ ] Batch embedding with retry logic for API failures137- [ ] Ingestion is idempotent (re-run safe via content-hash IDs)138- [ ] Retrieval quality validated on test queries before production139- [ ] Monitoring: ingestion throughput, embedding latency, DB storage growth