Retrieval-augmented generation (RAG) lets a generative model use relevant information from a private knowledge base when producing an answer. An application retrieves context, supplies it to the language model, and asks the model to generate a response or perform a task. section 8.0 section 8.6
A Postgres-backed RAG request follows this sequence:
- Context retrieval—embed the user’s question and use vector similarity search to find relevant private data. section 8.6 section 8.6.3
- LLM augmentation—provide the retrieved records as context so the model can use knowledge beyond its original training data. section 8.6 section 8.1.1
- Response generation—let the language model answer the user or perform the requested task using the supplied context. section 8.6 section 8.6.4
Movie recommendations from retrieved context
For the question “I’d like to watch the best movies about pirates,” the application retrieves three pirate-movie records from Postgres, including The Curse of the Black Pearl and Dead Man’s Chest. It passes those records to TinyLlama, which generates conversational recommendations based on them. section 8.6.4
Figure 8.10 Implementing RAG with an LLM, an embedding model, and Postgres
Use the architecture figure to follow the path from chatbot question through the backend, embedding model, Postgres retrieval, and final LLM response. section 8.6































