liveBook · Manning

Retrieval-augmented generation

As explained in MongoDB 8.0 in Action, Third Edition

Retrieval-augmented generation is an AI technique that retrieves external information and supplies it to a generative model when producing a response.

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

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Walks through document chunking, embeddings, vector retrieval, prompt assembly, and generation, then describes a LangChain-orchestrated chatbot.
Examples
Uses an Atlas best-practices chatbot grounded in PDF documentation and GPT-4 responses.
What it assumes
Introduces chunking and embeddings within the pipeline while requiring source documents, an embedding model, a vector database, and a language model.
What you can do after
Apply it via LangChain and Atlas Vector Search to retrieve documentation as context for a GPT-4 chatbot.
How it connects
Connects vector search, text embeddings, vector databases, prompt construction, language models, and hallucinations.

Also explained in

Compare how 32 books explain retrieval-augmented generation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.