Prompt
embedding pipeline for PDFs and wiki pages
Latest observation
Oct 12, 2026
OpenAI APIWeb search: off
Here’s a solid, practical embedding pipeline for PDFs and wiki pages that works well for search, RAG, and knowledge retrieval.
1) Ingest sources
- PDFs: upload, watch a folder, S3 bucket, or document management system
- Wiki pages: pull from Confluence, MediaWiki, Notion, GitHub Wiki, or internal docs APIs
- Keep source metadata:
source_type(pdf/wiki)source_idtitleurlcreated_at,updated_atauthorpermissions/access_control
2) Extract text
PDFs
- Use a parser depending on quality:
- Digital PDFs:
pymupdf,pdfplumber,unstructured - Scanned PDFs: OCR with
Tesseract, AWS Textract, Azure Document Intelligence, Google Document AI
- Digital PDFs:
- Extract:
- main text
- headings
- page numbers
- tables if useful
- figures/captions if relevant
Wiki pages
- Pull cleaned HTML/markdown/plain text from the API
- Remove navigation, boilerplate, repeated headers/footers, comments if not needed
- Preserve structure:
- page title
- section headings
- bullets/lists
- code blocks
- links
3) Normalize and clean
- Convert to consistent UTF-8 text
- Fix hyphenation, line breaks, and page artifacts from PDFs
- Remove duplicate repeated content
- Normalize whitespace
- Optionally detect language
- Keep formatting cues that help retrieval:
- headings
- lists
- code blocks
- tables as text
4) Chunk the content
Chunking is crucial.
Good defaults
- Chunk by structure first, then by size:
- split on headings/sections/paragraphs
- Target size:
- 300–800 tokens per chunk
- Overlap:
- 50–150 tokens overlap
- Avoid splitting:
- tables mid-row
- code blocks mid-block
- semantic units mid-thought
Recommended chunk metadata
doc_idchunk_idsection_titlepage नंबर / page_rangeheading_pathlike["Security", "Authentication", "OAuth"]offset_start,offset_endsource_url
5) Embed chunks
- Choose an embedding model:
- OpenAI embeddings
- Cohere
- Sentence Transformers
- domain-specific embedding model if needed
- Embed each chunk, not whole documents
- Store:
- vector embedding
- chunk text
- metadata
Best practices
- Use the same model for all sources
- Version your embedding model so you can reindex later
- If documents are multilingual, use a multilingual embedding model
6) Index and store
Use a vector database or hybrid search system:
- Vector DBs: Pinecone, Weaviate, Milvus, Qdrant, pgvector
- Hybrid search:
- vector similarity
- keyword/BM25
- reranker
Store:
- embedding vector
- chunk text
- metadata
- access permissions
7) Retrieval layer
When a user queries:
- Embed the query
- Retrieve top-k relevant chunks
- Optionally apply:
- metadata filters
- permission checks
- reranking
- Return chunks to the LLM with citations
Recommended retrieval setup
- hybrid search = best baseline
- rerank top 20–50 chunks to top 5–10
- include source citations for PDFs/wiki pages
8) Update and reindex
- Detect changes in PDFs/wiki pages
- Re-embed only changed documents or sections
- Maintain:
- document versioning
- deletion handling
- stale chunk cleanup
- If source pages change often, use incremental sync jobs
9) Quality improvements
- OCR cleanup for scanned PDFs
- table-aware extraction
- section-aware chunking
- deduplication
- citation-preserving chunks
- entity extraction for better metadata search
- security trimming so users only retrieve allowed content
Suggested architecture
Pipeline
- Source connector
- Text extraction
- Cleaning/normalization
- Chunking
- Embedding
- Vector store + keyword index
- Retrieval + reranking
- LLM answer generation with citations
Example chunking strategy
For a wiki page:
- Title:
Access Control - Sections:
OverviewRolesPermissionsExamples
- Create chunks per section, and sub-chunk if a section exceeds size limits
For a PDF:
- Use page + heading detection
- Chunk by logical sections rather than fixed page boundaries
- Keep page references for citations
Practical defaults to start with
- Chunk size: 500 tokens
- Overlap: 100 tokens
- Retrieval top-k: 20
- Rerank to: 5
- Store metadata: title, URL, page, section path, permissions, source type, version
If you want, I can also provide:
- a reference architecture diagram,
- a Python implementation using LangChain/LlamaIndex, or
- a production-ready pipeline with PDF + Confluence/wiki ingestion.