TRANSCRIPTEnglish

Production RAG with LangChain & Vector Databases – Full Course

7h 38m 40s73,539 words10,598 segmentsEnglish

What this video covers

This guide outlines the critical components required to transition Retrieval-Augmented Generation (RAG) systems from prototypes to resilient, cost-effective production applications. It explores advanced retrieval mechanics, vector database tuning, and caching techniques alongside full-stack considerations such as token budgeting, monitoring, and security. Additionally, it highlights self-correcting Agentic workflows built with LangGraph and served via robust FastAPI backends.

Key takeaways

  • Strict model congruency is mandatory: the exact same embedding model and version must be used across both indexing and query phases to prevent semantic drift.
  • Hybrid search combining BM25 keyword matching with dense vector retrieval via Reciprocal Rank Fusion (RRF) overcomes standard semantic search failures on SKUs, acronyms, and error codes.
  • Database costs and retrieval performance scale heavily on HNSW graph tuning (M and EF parameters), vector quantization, and dimension reduction strategies.
  • Advanced retrieval patterns—such as the Parent Document Retriever, Contextual Compression, and smart chunking fallbacks—significantly boost retrieval precision while preserving broader context.
  • Proactive token budgeting, embedding caching, and in-memory TTL response caching protect systems against unexpected inference costs and context window overflows.
  • Observability requires structured JSON logging, metrics aggregation, and step-by-step execution tracing via platforms like LangSmith to diagnose silent hallucinations.
  • Agentic RAG using LangGraph StateGraphs introduces self-correction by grading retrieved documents, rewriting ineffective queries, and triggering automated fallbacks.

Topics covered

Vector Database Scaling and Index Tuning
Covers foundational RAG indexing, deduplication via upserts, HNSW graph parameter tuning (connections M and search effort EF), and cost-optimization strategies such as Int8 quantization, dimension reduction, and managed PostgreSQL deployments with Supabase pgvector.
Hybrid Search and Advanced Retrieval Patterns
Details techniques to optimize context relevance, including BM25 and vector fusion (RRF), semantic versus recursive chunking trade-offs, Parent Document Retrievers, Contextual Compression for token reduction, and Multi-Query expansion.
System Reliability, Caching, and Observability
Focuses on production stability using pre-execution token budgeting, multi-layer caching (CacheBackedEmbeddings and SHA-256 hashed response caching), structured JSON logging, and LangSmith tracing for multi-node agent tracking.
Agentic Architecture and Production API Delivery
Demonstrates building self-correcting LangGraph loops (Retrieve-Grade-Rewrite-Generate), integrated into secure FastAPI applications featuring prompt injection defenses, PII masking, rate limiting, and automated unit testing.
“If you've never heard or don't understand what Docker is, I encourage you to actually learn online.”
▶ 336:29 · HEAR IT IN THE VIDEO

FULL TRANSCRIPT

0:00

Master the transition from simple

0:02

prototypes to production-grade rag

0:04

systems by addressing the critical

0:07

scaling, debugging, and security

0:10

challenges that standard tutorials often

0:13

ignore. This comprehensive course covers

0:16

the entire rag pipeline from vector

0:19

database optimization and observability

0:22

to advanced agentic and multimodal

0:24

architectures. You'll learn to make sure

0:27

your AI applications are robust, secure,

0:30

and ready for deployment.

0:32

>> So, you follow a rag tutorial. It worked

0:35

on 10 documents, but then you decide to

0:38

add 10,000 documents and everything

0:41

broke. Sound familiar? Now, here's the

0:44

thing. 90% of rack systems out there,

0:46

they fail in production. And they all

0:49

fail for the same reasons. So, in this

0:52

course, we're not just going to build a

0:53

rack system. I know most of you have

0:55

built a lot of rack system that actually

0:56

don't work. But anyway, we're not just

0:58

going to do that. We're going to do

0:59

something different. We're going to

1:00

debug it. We're going to optimize it and

1:03

scale it for production. Here's what

1:05

we're going to be covering. First part

1:07

is building the foundation. So, we're

1:09

going to go over documents, chunks,

1:11

embeddings, and vector stores. The

1:14

second part, it's all about the five

1:16

main failure modes when it comes to rack

1:18

systems. So, why rag breaks and how to

1:22

fix each one of them. Parts three and

1:24

four, we're going to optimize what we've

1:27

done. We're going to optimize for

1:29

quality, then scale for production. Part

1:32

five, we're going to build a complete

1:34

rag system. And part six, this is where

1:37

we're going to look at the current

1:39

cutting edge [clears throat] stack. So,

1:41

we're going to look at agentic rag,

1:44

we're going to look at graph rag, we're

1:45

going to look at contextual retrieval,

1:48

and of course, multi-model rag. Here's

1:51

my promise. By the end, you will have a

1:54

production ready rag that actually

1:56

works. I mean, assuming that you're

1:58

going to finish this course, but that's

1:59

on you. All right, let's build. Let's

2:03

get started with a full rag overview.

2:06

The idea we have the user query. So,

2:08

this is the input question comes in and

2:11

of course stripping down all the

2:13

intricacies here. Uh the idea is that we

2:16

want to get information from database.

2:19

So we want to find relevant documents

2:21

through a retriever and then the query

2:24

as well as the context from the

2:27

retriever combined with the prompt

2:29

that's what's taken to the large

2:31

language model to generate the answer.

2:33

So then we have response which is

2:35

grounded in the documents relevant

2:38

documents that is okay. So all of that

2:40

of course is driven

2:43

by the vector store. So in vector store

2:46

we have embedded documents and we have

2:48

indexed which are indexed for search.

2:51

The key concept to keep in mind is that

2:53

rag grounds large language model

2:56

responses in actual documents which

3:00

reduces hallucination which means then

3:03

the large language model is not going

3:06

crazy and is not going to go and

3:08

completely hallucinate our responses. So

3:12

here's a basic rag chain. So we have the

3:16

question, we have the context. This will

3:18

come in parallel inputs of course. And

3:21

then we chain that with the prompt

3:23

template. In this case, we pass all of

3:25

that into large language model. And then

3:27

if need be, you most cases we need this.

3:30

We use an output parser, right? To sort

3:34

of parse our output and also create

3:37

parser. So we can control and customize

3:39

our output. Context and question are

3:41

going to go hand in hand. This is part

3:44

of augmented our retrieval augmented

3:47

generation side of things. So it's

3:49

important to know that context comes

3:51

from the retriever. And so the retriever

3:54

is important because it goes and gets

3:57

the relevant documents but also all has

3:59

to be driven by the question the query.

4:02

And in this case the question is going

4:04

to go through what we call the runnable

4:06

pass through. If you remember, it's just

4:08

a way of saying, okay, do not modify

4:10

anything when it comes to the question.

4:12

It has to be as original as possible and

4:14

just pass through as we pass through

4:16

this parallel input processing. Okay, so

4:19

question passes through unchanged. So in

4:22

our prompt template, we want to make

4:23

sure that we specify, we ground the

4:25

large language model with the

4:27

information and instructions it need. So

4:29

we may say something hey make sure to

4:31

answer based only on the context which

4:35

was retrieved from the retriever and the

4:37

question which we retrieved from the p

4:41

which we got from the user but we made

4:43

sure to pass through unchanged. So now

4:46

we have a prompt template that has the

4:49

context which is part of the retriever

4:51

and all that stuff and the question

4:53

which is needed so that the large

4:55

language model is able to generate the

4:58

response. It's important that the large

4:59

language model as it generates the

5:02

response with all the documents with all

5:04

the retrieved relevant documents that it

5:07

also knows how to say I don't know and

5:10

so this is when we pass instructions for

5:13

instance without instructions if we ask

5:16

what is quantum computing it will just

5:18

go ahead and say quantum computing uses

5:20

cubits and starts making stuff up okay

5:23

now with instruction what is quantum

5:26

computing it will say well I don't No, I

5:28

don't have enough information pertaining

5:31

to this topic. This is way better than

5:34

this for obvious reason because we don't

5:36

want hallucination. Even though it may

5:38

sound coherent, but it is hallucinating,

5:41

which means it's just making stuff up.

5:43

You will see that the prompt is also

5:46

very important for many reasons. One of

5:48

which is we are able to quickly ground

5:51

our large language model. So the prompt

5:54

pattern that you should look into is

5:56

something like this. You would say

5:57

answer based only on the following

6:00

context. So you can also say if the

6:02

context doesn't contain the answer say I

6:06

don't have information about that or I

6:08

don't know or something along those

6:10

lines. Okay. Of course in this prompt

6:13

passing the context and the question

6:15

along. This is the lowhanging fruit when

6:18

it comes to prompt engineering. Yet a

6:20

lot of people forget about it or don't

6:22

pay attention to this. Prompting is

6:25

extremely important. But it doesn't have

6:27

to be such a large thing to be done, but

6:30

it can be something that we can use a

6:32

pattern especially when we don't want

6:34

the LLM to elucinate answers. So make

6:37

sure to specify in the prompt pattern

6:40

that only follow the following only to

6:44

answer based only on the following

6:45

context and then if it doesn't know just

6:48

say I don't know and you pass the

6:50

context and of course the question and

6:52

to make sure that the results that are

6:54

coming from a rack system are indeed

6:57

based off or grounded in the documents

7:00

retrieved documents we want to make sure

7:02

that we also add some sources. Okay. So

7:06

the retriever would output something

7:08

like this page content here and then you

7:10

will see something like this source

7:11

doc.pdf. This is very important not only

7:14

for the users but also for the system

7:16

itself. So it knows okay I got this

7:20

answer but I got it from where? I got it

7:22

based on this document based on this

7:25

header based on this place. So this is

7:29

real good to always allow to always

7:33

retrieve the actual sources as well. And

7:35

it's really easy to do that as you will

7:37

see because we can just call the format

7:39

docs with source which is going to add

7:41

source tags to each chunk. That way when

7:44

we are retrieving using a retriever it's

7:47

going to be able to pull the correct

7:50

chunk with the actual resources. Okay.

7:53

And so we'll have something formatted

7:54

context such as this source doc PDF and

7:57

then page content and all of that. This

7:59

is how you do rag with sources. The

8:03

reason why sources matter is because

8:04

users are going to be able to verify

8:06

those answers. So we can have citations

8:10

and it's going to obviously build trust.

8:13

So our system is going to build trust

8:15

and our customers or users are going to

8:17

be able to say okay I know the answer is

GET MORE FROM YOUR TRANSCRIPTS

Sign up for free and unlock interactive viewer, AI summaries, translations, concept maps, and more. No credit card required.