Overview

4 Augmenting LLMs with your own documents

Large language models are powerful, but by default they are broad generalists that rely on pre-trained knowledge and often miss organization-specific, current, or traceable information. This makes them a poor fit for tasks like answering questions about a shop’s hours, a company’s policies, or any curated document collection unless they are given access to those sources. The chapter introduces Retrieval-Augmented Generation as the remedy: a way to combine the model’s reasoning ability with knowledge pulled from documents we control, so responses can be more accurate, up to date, and easier to justify.

RAG is presented as a three-step process: ingest documents, retrieve the most relevant chunks, and generate an answer using that retrieved context. Ingestion means reading files of many kinds, splitting them into chunks, converting those chunks into embeddings, and storing them in a vector database along with useful metadata. Retrieval means turning the user’s question into an embedding, comparing it against stored vectors with a similarity measure, and selecting the closest matches. Generation then places those matches into a prompt so the LLM can answer based on the retrieved context rather than only on its general training.

The chapter then shows how to build this workflow in Langflow using a practical pizza-restaurant example. One subflow handles ingestion with components for reading files, splitting text, creating embeddings, and storing them in Chroma; the other handles runtime search and answering with a chat input, retriever, parser, prompt template, LLM, and chat output. It also highlights the main tuning levers that affect quality, such as chunk size, chunk overlap, top-k retrieval, query rewriting, and metadata use, and suggests expanding the system with memory or other document sources like webpages and folders. Finally, it notes that the same logic can be implemented directly in code with common LangChain tools, making the RAG pipeline explicit and reusable.

A RAG-based flow includes three essential steps: document ingestion, document retrieval and answer generation.
The invisible work behind any RAG response: collecting knowledge, retrieving relevant pieces, and crafting the final answer by stitching together the right context.
Moving from documents onto a vector DB during the ingestion phase in a RAG system.
Six pet-related chunks laid in a 2D embedding space.
Euclidean distances between our question and each embedding in the vector DB.
No escape for naughty cats: the closest matches always get picked.
Looking for the perfect wine pairing? Ask PizzaMate™.
The document ingestion subflow of our RAG system.
The perfect RAG recipe.
The Read File component lets you extract text from document files.
We extracted all the text from a PDF file.
The poor text will now be chopped up into chunks.
The raw text is split into chunks, partially overlapping each other.
The Document Ingestion subflow is ready to go.
A simplified sketch of our Retrieve and Answer subflow.
This flow can retrieve relevant entries from a vector DB and transform them into plain text.
The Retrieve and Answer subflow is ready to chat about pizzas.
PizzaMate™ got it right!
In RAG, pre-trained knowledge and retrieved documents come together to serve smarter answers.
The Chroma DB component has some useful additional controls.
The URL component lets you scrape webpages recursively.

Summary

  • When you want an LLM to include knowledge that wasn’t part of its pre-training, you need a RAG system.
  • Embeddings are numeric vectors that can place any chunk of text as a point in a multi-dimensional space, where close points refer to semantically similar texts.
  • In RAG, you first ingest the data, in whatever format it comes to you, and transform it into text, which is then split into chunks. Then, each chunk is transformed into embeddings and saved in a vector DB. When the user asks a query, the closest chunks are provided to the LLM, which will ultimately generate the answer.
  • Langflow helps you implement RAG by providing components for reading documents, embedding text, storing vectors, and querying them.
  • The PizzaMate™ flow demonstrates how you can easily equip an LLM with the information stored in a file.
  • You can further improve RAG performance by changing parameters like the size of chunks, their level of overlap, the top k retrieval setting, or by rewriting your search query with the help of another LLM call.

FAQ

What is Retrieval-Augmented Generation (RAG)?Retrieval-Augmented Generation, or RAG, is a technique that combines an LLM’s generative abilities with information retrieved from your own documents. Instead of relying only on pre-trained knowledge, the model gets relevant context from a vector database and uses it to answer the user’s question.
Why do we need RAG instead of using a normal LLM by itself?A normal LLM is generic, may not know your organization’s specific information, may be outdated, and cannot easily explain where its answers came from. RAG solves these issues by grounding answers in documents you control, such as policies, manuals, menus, or opening hours.
What are the three main stages of a RAG pipeline?The three main stages are document ingestion, document retrieval, and answer generation. Ingestion prepares and stores documents, retrieval finds the most relevant chunks for a question, and generation uses those chunks as context to produce the final answer.
What happens during document ingestion?During ingestion, documents are read from their source, split into smaller chunks, converted into embeddings, and stored in a vector database along with metadata. This prepares the content so it can be searched semantically later.
Why do documents need to be split into chunks?Large documents are difficult to retrieve from efficiently as a whole. Splitting them into chunks makes retrieval more precise, helps preserve relevant context, and allows the system to fetch only the parts needed to answer a question.
What are embeddings in RAG?Embeddings are numerical vector representations of text that capture meaning. They let the system compare a user’s question with document chunks based on semantic similarity rather than just matching exact keywords.
Why is metadata important in a vector database?Metadata helps identify and reference chunks by details such as file name, path, author, title, or date. It can also be used to filter retrieval results and improve accuracy, trust, and explainability in responses.
How does document retrieval work in RAG?The user’s question is converted into an embedding, and the system searches the vector database for the nearest chunks in semantic space. The closest chunks are considered most relevant and are selected as context for the LLM.
What role does the LLM play after retrieval?The LLM does not search the database itself. It receives the retrieved chunks inside a prompt and then generates an answer based on that context, combining the retrieved facts with its language reasoning capabilities.
What should be tuned to improve a RAG system?Common tuning areas include chunk size, chunk overlap, the number of top results retrieved, query rewriting, and how metadata is used. Adjusting these settings can improve retrieval quality and make answers more accurate and useful.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Applications ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Applications ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Applications ebook for free