Retrieval-Augmented Generation (RAG)
Search developer docs with LangChain and pgvector, then answer with checked source links.
How can an assistant answer from your documents?
A model may not know your team’s current deployment procedure. You can supply that procedure with the question instead of training the model again. Retrieval-augmented generation (RAG) searches your documents, adds selected passages to the request, and asks the model to answer from that context.
A chunk is a searchable passage. An embedding represents its text as numbers that can be compared with a question’s embedding. A vector store keeps those numbers with the text and source. The embedding model helps find passages; the answer model uses their text to write a reply.
This course follows a developer asking, “How do I roll back a service?” The supplied platform guide says to select the previous production image digest and create a new deployment. It also says rollback does not undo database migrations. The application needs the passage containing those details before it can ask for a source-backed explanation.
- Ask a question.
- Create the question embedding.
- Search the vector database.
- Retrieve matching passages.
- Combine instructions, the original question and passages.
- Send the prompt to the LLM.
- Check citations, then return the answer with sources.
Build the mechanism in six lessons
First prepare the chunks and maintain their PostgreSQL rows. Then compare exact and approximate search on the same saved questions. Connect retrieval to a cited answer, extend the input to retained chart images, and finish with an optional NumPy view of cosine distance.
The text labs reuse the supplied developer documentation and embedding records. The image lab adds retained charts. Each lesson keeps its runnable code, raw results and failure tests; saved-vector checks and fresh model calls are identified separately.
What you'll learn
- Split and embed documents with LangChain while recording the model and chunk settings.
- Use PGVectorStore to replace, filter and delete indexed chunks.
- Compare exact, HNSW and IVFFlat results with the same saved questions.
- Retrieve source chunks and chart images, then check citation IDs and excerpts.
Lessons
Build an embedding pipeline with LangChainRead
Prepare documents for search by splitting them into passages and creating embeddings. Keep source details and settings with the vectors.
Build a PostgreSQL vector store with LangChainRead
Store searchable document passages in PostgreSQL. Update, filter and delete them, then check what happens when a write is retried or interrupted.
Compare exact, HNSW and IVFFlat search in pgvectorRead
Compare exact and approximate vector search on the same questions. Inspect which passages each method returns and how PostgreSQL runs the query.
Build a RAG pipeline with citationsRead
Answer questions from retrieved document passages. Check that each citation names a supplied source and quotes text that actually appears in it.
Build multimodal RAG with chart source referencesRead
Find a chart through its description, then let a model read the image. Check the image’s identity and inspect the answer against its source.
Rank document vectors with cosine distanceRead
See how cosine distance ranks document vectors for a question. Check vector dimensions and lengths, then inspect the returned passages.