From URL to Answer: The Full RAG Pipeline for a Single Web Page
The gap between a working RAG demo and a production knowledge base is wide and filled with unglamorous failure modes — selector breakage, empty pages, duplicate content, and prompt injection — that most tutorials skip. This walkthrough names them explicitly, giving a team a concrete checklist of what to harden before shipping.
A real Juejin article serves as the knowledge source for a full Retrieval-Augmented Generation pipeline built with LangChain.js. The process starts with CheerioWebBaseLoader and a CSS selector to extract clean page content into a Document, then uses RecursiveCharacterTextSplitter with Chinese punctuation separators to break it into 30 overlapping chunks. Embeddings are generated in batches via a DashScope-compatible API and stored in an in-memory vector store for cosine similarity search. The top three retrieved fragments are fed into a prompt that instructs the model to answer only from the provided context, completing the URL-to-answer chain. The piece closes by listing the gaps between this demo and a production system: selector fragility, empty-content handling, incremental sync, persistent storage, similarity thresholds, metadata filtering, reranking, and prompt injection risks.
Most RAG tutorials stop at the happy path; this one enumerates the failure modes — selector drift, empty pages, duplicate content, prompt injection — that turn a demo into a maintenance burden.
The separator list is the unsung hero of chunking quality. Prioritizing paragraph breaks and Chinese punctuation before falling back to character-level splitting is what keeps code blocks and lists from being shredded mid-structure.
Treating retrieved web content as reference material rather than trusted instructions is a security posture that many early RAG systems overlook, and it becomes critical the moment a knowledge base ingests arbitrary URLs.