Retrieval-augmented generation (RAG) gives a language model relevant external information when it answers a question. Instead of relying only on patterns learned during training, a chatbot can retrieve documents related to the user’s request and use them as context. This reduces the risk of plausible but incorrect answers; it does not guarantee accuracy. section 14.0 section 12.0
A document-based RAG pipeline has two phases: prepare information, then retrieve it for each question.
- 1. Parse source documents, such as PDFs, and split their text into coherent chunks. These documents provide the information on which answers should be grounded. section 14.1
- 2. Run each chunk through an embedding model and store the resulting vectors in a vector database. section 14.1
- 3. Embed the user’s query and use vector search to find semantically similar chunks. section 14.1
- 4. Assemble the retrieved chunks into a prompt. The language model uses that context to generate its response. section 14.1
Atlas best-practices chatbot
A chatbot can answer questions about MongoDB Atlas best practices using GPT-4 and prevalidated Atlas documentation extracted from a PDF. Atlas Vector Search retrieves relevant documents from stored embeddings, and LangChain orchestrates retrieval and generation. The retrieved documents become additional context for GPT-4’s answer. section 14.4
The integration work matters: embedding generation, storage, retrieval, and the language model must operate together. LangChain can coordinate those components; a MongoDB Atlas Vector Search and OpenAI template provides a starting point that can be deployed as a REST API with LangServe. section 14.6































