5-Langchain Series-Advanced RAG Q&A Chatbot With Chain And Retrievers Using Langchain

Krish Naik
10 Apr 202419:48

Summary

TLDRIn this video, Krishak walks viewers through building an advanced RAG (Retrieval-Augmented Generation) pipeline using LangChain's Retriever and Chain concepts. He shares a personal anecdote before diving into the technical aspects, explaining how to retrieve documents and utilize large language models (LLMs) to generate responses based on context. Krishak demonstrates step-by-step how to set up vector stores, split documents, create a Q&A chatbot, and integrate LLMs like LLaMA 2, showcasing the practical application of chains and retrievers for building an intelligent pipeline.

Takeaways

  • 🏸 Krishak starts by sharing a funny incident from his badminton routine, where a neighbor recognized him by his shoes but noticed his new look.
  • 💡 The video continues the Langchain series, focusing on developing an advanced RAG (Retriever-Augmented Generation) pipeline using retrievers and chain concepts.
  • 📄 The initial tutorial discussed creating a simple RAG pipeline with data sources like PDFs and websites, loading and transforming the data into vector stores.
  • 🧩 The next step involves improving query efficiency by incorporating large language models (LLMs) and chaining techniques to retrieve more accurate results.
  • 🔗 Krishak explains the concept of chains, particularly the 'stuff document chain,' which formats documents into a prompt and passes them to the LLM.
  • 🛠️ The practical example demonstrates how to split a document into chunks, convert it into vectors, and store it in a vector store using OpenAI embeddings.
  • 🔍 The 'retriever' is introduced as an interface for extracting relevant documents from the vector store based on a user query.
  • 🤖 Krishak integrates the retriever with the LLM and the document chain to create a Q&A chatbot that can generate context-based answers.
  • 📝 He emphasizes the customization potential of the system, allowing it to work with open-source LLMs like Llama 2 for users without paid access.
  • 🚀 The tutorial concludes by showing how combining retrievers, chains, and LLMs creates a more advanced RAG pipeline for efficient document retrieval and query answering.

Q & A

  • What is the primary focus of this video?

    -The primary focus of this video is on developing an advanced RAG (Retrieval-Augmented Generation) pipeline using LangChain, specifically employing Retriever and Chain concepts along with LLMs (Large Language Models).

  • What was the funny incident that the speaker shared?

    -The speaker shared a funny incident about how one of his neighbors identified him just by his shoes after a badminton session, noting that his new low-maintenance look had completely changed his appearance.

  • What are the main steps in developing the RAG pipeline as described in the video?

    -The steps include: 1) Loading documents like PDFs and websites, 2) Breaking down large documents into chunks, 3) Converting those chunks into vectors and storing them in a vector store, 4) Using an LLM with Retriever and Chain concepts to retrieve information and generate a response based on a prompt.

  • What models can be used in this RAG pipeline?

    -The video discusses using both open-source and paid LLM models, such as OpenAI embeddings and LLaMA 2 from Meta. Users can choose between these models depending on their needs and resources.

  • What is the purpose of using a prompt in this pipeline?

    -The prompt is used to guide the LLM to answer a specific question based on the provided context. In the pipeline, the prompt helps format the documents from the vector store into a query that the LLM can use to generate a relevant response.

  • What is a 'stuff document chain' and how is it used?

    -A 'stuff document chain' is a sequence of operations that formats a list of documents into a prompt and passes it to the LLM. It helps combine the documents and the user's query into a format that the LLM can process, allowing for a more coherent response.

  • How does the retriever function within the pipeline?

    -The retriever is an interface connected to the vector store. When the user inputs a query, the retriever fetches the relevant documents from the vector store and passes them to the LLM to generate a response.

  • What is the role of the Vector Store in the pipeline?

    -The Vector Store holds the vectorized representations of the document chunks. It allows for similarity-based searching when queries are made, and the retriever fetches data from it to provide relevant documents to the LLM for processing.

  • What is the advantage of using LLMs in this pipeline?

    -LLMs enhance the RAG pipeline by providing more accurate and context-aware responses based on the documents retrieved from the vector store. LLMs can handle complex queries and generate more refined results compared to simple vector searches.

  • How can users customize their RAG pipeline based on their needs?

    -Users can customize their RAG pipeline by choosing between different LLMs (open-source or paid), adjusting document chunk sizes, tweaking prompts, and using various LangChain functions like retrievers, stuff document chains, and vector stores.

Outlines

00:00

😀 Introduction and Personal Anecdote

Krishak introduces himself and welcomes viewers to his YouTube channel, where he continues his series on LangChain. Before diving into the content, he shares a humorous story about a neighbor recognizing him by his shoes after a badminton game, commenting on his new low-maintenance look. He invites viewers to comment on his appearance before transitioning to the main content.

05:01

💻 Recap of Previous Video and Introduction to Advanced RAG Pipeline

Krishak recaps the previous video where he discussed creating a basic RAG (Retrieve and Generate) pipeline using LangChain. He explains how data from PDFs or websites was loaded, broken into chunks, converted into vectors, and stored in a vector store. He outlines the limitations of query vectors and introduces the concept of using LLMs (Large Language Models) and prompts to enhance retrieval. This marks the beginning of a more advanced pipeline, leveraging chains and retrievers for improved results.

10:02

🔗 Understanding Chains and Retrievers in LangChain

Krishak dives into the technical details of LangChain, explaining how chains and retrievers work together. He highlights the 'stuff document chain' and its importance in taking documents, formatting them into prompts, and feeding them to an LLM. The LLM then generates responses based on these prompts. He reiterates the importance of using chains and retrievers for building advanced RAG pipelines and explains that different LLM models (such as open-source Lama 2) can be used in this process.

15:05

🤖 Implementing the Chain with LangChain

Krishak discusses implementing a chain in LangChain. He outlines the steps to create a 'stuff document chain' by importing the required functions from LangChain and explains how to combine the LLM and the prompt to create the chain. He emphasizes the need for a retriever, which acts as an interface to fetch relevant documents from a vector store. He also explains how to use the 'DB.as_retriever' method to link the vector store to the retriever.

🔄 Combining Chains and Retrievers

Krishak explains how to combine the retriever and document chain to form a retriever chain. He describes the flow of information: user queries go through the retriever to fetch relevant documents from the vector store, which are then passed to the LLM along with the prompt. The LLM generates a response based on the provided context. This integrated setup forms the backbone of the advanced RAG pipeline.

🛠 Practical Implementation of the Retrieval Chain

In this section, Krishak demonstrates the practical implementation of the retriever chain in LangChain. He explains how to use the 'create_retrieval_chain' method to link the retriever and the document chain. He shows how to input a query, invoke the retriever chain, and get the response. Using an open-source LLM like Lama 2, he retrieves the context from the vector store and generates the output.

🎯 Building a Q&A System with the RAG Pipeline

Krishak concludes by showcasing how the RAG pipeline can be used to build a Q&A system. He walks through examples of inputting different queries and generating accurate answers from the vector store using the retriever chain. He highlights the effectiveness of combining the chain, retriever, and LLM to build a sophisticated question-answering system. He encourages viewers to try the implementation and invites them to stay tuned for more advanced topics.

Mindmap

Keywords

💡Retriever

A retriever in the context of LangChain refers to an interface that extracts documents based on an unstructured query. It is more general than a vector store and is used to return relevant documents for a user query. In the video, the retriever is connected to the vector store, fetching documents that will then be processed by the LLM model to generate responses.

💡Chain

A 'chain' in LangChain is a sequence of calls made to either an LLM, a tool, or a data pre-processing step. Chains help structure multiple operations in a logical order, making the overall process more organized and efficient. In the video, the speaker uses 'create stuff document chain,' which formats documents into a prompt that is sent to the LLM for processing.

💡LLM (Large Language Model)

LLM stands for Large Language Model, a type of AI model designed to understand and generate human-like text based on the input it receives. In the video, the LLM (Llama 2) is used in combination with prompts to generate responses to queries based on the provided context from the vector store.

💡Vector Store

A vector store is a storage system that holds text or documents converted into vectors, which are mathematical representations of the data. In the video, the speaker explains how documents are transformed into vectors and stored in a vector store, allowing for efficient retrieval of information based on query similarity.

💡Prompt

A prompt is a structured input given to an LLM to generate a response. In this video, prompts are used to structure queries such that the model can retrieve relevant information from the vector store and return answers based on context. The speaker even demonstrates how to design a prompt template in LangChain.

💡LangChain

LangChain is a framework used for developing applications powered by large language models. It provides tools for chaining different components, such as LLMs, retrievers, and vector stores, into coherent pipelines. The video showcases how LangChain can be used to develop an advanced RAG (Retrieve-then-Answer Generation) pipeline.

💡Document Chain

A document chain is a process in LangChain where a list of documents is formatted into a prompt and then passed to an LLM for processing. This chain helps combine context from multiple documents into a single query. The video explains how to create a document chain using LangChain's 'create stuff document chain' method.

💡Similarity Search

Similarity search is a method used to retrieve information that is semantically or contextually similar to a query. In the video, the speaker explains how to perform a similarity search on the vector store, allowing the retriever to find the most relevant chunks of information based on the user's input.

💡Embedding

Embeddings are numerical representations of text, which capture the semantic meaning of words, phrases, or documents. These embeddings are used to store and retrieve data in a vector store. The speaker explains how embeddings, such as OpenAI's embeddings or Meta's AMA embeddings, are used to transform documents into vectors for more efficient retrieval.

💡Stuff Document Chain

The 'stuff document chain' in LangChain refers to a method where documents are collected, formatted into a prompt, and passed to an LLM for response generation. It helps ensure that the relevant documents are used within the context window of the LLM, making sure that the response is accurate. The video illustrates how this chain is essential for combining retrievers and LLMs.

Highlights

Introduction to the LangChain series and the concept of developing an advanced RAG (Retrieval-Augmented Generation) pipeline using Retriever and chain concepts.

Discussion of a personal story about being identified by shoes after a change in appearance.

Overview of the previous tutorial where a simple RAG pipeline was created using a data source like PDF or website and vector store for storing chunks of data.

Explanation of how query vectors aren't efficient for retrieving complete results and the need to integrate LLM models with Retriever and chain.

Introduction of the advanced RAG pipeline implementation using LLM models, chain, and Retriever to improve retrieval and customization of prompts.

Overview of converting documents into chunks using RecursiveCharacterTextSplitter and storing them in a vector store.

Use of OpenAI or AMA embeddings for converting document chunks into vectors and saving them in a vector store for retrieval.

Key difference between vector store search (similarity search) and combining it with LLM models using chains for more context-aware responses.

Demonstration of creating a custom prompt template for a Q&A chatbot that fetches answers from context using both a Retriever and LLM model.

Detailed breakdown of the create_stuff_document_chain function, which formats a list of documents into a prompt for the LLM model to generate answers.

Description of the Retriever interface, which serves as a more general way to access data compared to a direct vector store query.

Explanation of how the retriever works as an interface to query the vector store, retrieve documents, and pass them to the LLM model for response generation.

Step-by-step process of implementing a retriever chain that combines the Retriever and document chain to handle both querying and formatting for the LLM.

Flowchart explanation of how user inquiries pass through the retriever, vector store, and LLM to generate context-driven responses.

Demonstration of how to invoke the retrieval chain and use the LLM model (e.g., LLaMA 2) to provide answers based on context from a PDF file.

Transcripts

play00:00

hello all my name is krishak and welcome

play00:02

to my YouTube channel so guys we are

play00:04

going to continue the langin series and

play00:06

now we will be developing Advanced rag

play00:08

pipeline using Retriever and chain

play00:10

Concepts that are available in Lang

play00:11

chain now before I go ahead I really

play00:14

want to talk about a funny incident that

play00:15

really happened uh recently just today

play00:18

itself so what I did what I do is that

play00:20

every day morning I usually go and play

play00:23

some badminton you know I play for 1

play00:24

hours one and a half hour and usually a

play00:27

lot of my friends and neighbors usually

play00:28

come and play you know so today what

play00:30

happened after playing I went today in

play00:32

this look okay I played around three to

play00:34

four games and then one of my neighbors

play00:36

said hey Kish your Chris right you just

play00:39

got identified right now just by seeing

play00:41

your shoes I identified you but your

play00:43

look has completely changed so let me

play00:45

know if this is true in the comment

play00:46

section of this particular video but I

play00:48

am liking this look uh you know it's

play00:50

like so much of less maintenance you

play00:53

don't have to maintain your beard your

play00:55

mustach or your hair also right it looks

play00:58

super cool now uh let's go ahead and uh

play01:01

work towards this specific project in

play01:03

our previous tutorial what we had

play01:06

actually done is that we had created

play01:07

this simple rack pipeline okay we had a

play01:11

data data source like we took PDF we

play01:14

took website then we uh load that

play01:17

particular data set using different

play01:18

different data injection techniques uh

play01:20

that were available in Lang chain then

play01:22

we did transformation where in we broke

play01:25

down our bigger PDFs into chunks and

play01:28

then we converted all all these

play01:30

particular chunks into vectors and

play01:32

stored it in a vector store and then

play01:34

with the help of query we are able to

play01:37

probably retrieve some of the data that

play01:39

is available in the vector store now

play01:41

this is one step now the further step

play01:44

after this particular query Vector Now

play01:45

understand query Vector are not that

play01:47

efficient you know when in terms of

play01:49

retrieving the entire results here we

play01:52

will also specifically use llm models

play01:55

okay so now what we will try to do is

play01:57

that using some prompts

play02:00

okay and we will take this specific

play02:03

prompts we will take this particular

play02:04

data using the concept of chain and

play02:08

retriever okay and understand this topic

play02:11

is very important because this is where

play02:14

your advanc rack pipeline implementation

play02:17

will start using chain and retriever we

play02:20

will also use and in this chain and

play02:22

retriever what we do is that we

play02:23

specifically use llm models it can be

play02:26

open source it can be paid whatever

play02:29

model you want so so we will

play02:30

specifically use this llm model and

play02:32

based on this prompt we will try to get

play02:34

the

play02:35

response on what we are specifically

play02:37

looking right so there will be a lot of

play02:39

customization that will be added once we

play02:42

implement this specific part in the

play02:44

first part we discussed about this and

play02:46

this is the second part that we are

play02:47

going to discuss okay how we can use

play02:50

chain how we can use retriever what

play02:52

exactly is chain how you can integrate

play02:54

in this particular llm model there is a

play02:56

concept of something called a stuff

play02:58

document chain what exactly it it is so

play03:00

we will discuss everything all about it

play03:03

and here we also going to do a practical

play03:05

implementation so please make sure that

play03:07

you watch this video till the end and we

play03:09

are going to learn a lot of things okay

play03:11

so here the first step what we had done

play03:13

on already uh we have implemented this

play03:16

in our previous tutorial also so here

play03:18

you'll be able to see that I trying to

play03:20

read attention. PDF which is present in

play03:23

a folder and then we just write loader.

play03:25

load and we get the documents okay so

play03:28

these are all the documents that will be

play03:29

available in this specific PDF okay then

play03:33

what we are specifically doing next step

play03:34

is that from lin. text plat we will be

play03:36

using recursive character text splitter

play03:38

wherein we convert the entire document

play03:40

into chunks right and then we are

play03:43

probably using this text splitter and we

play03:45

are using a chunk size of thousand

play03:47

overlap of 20 so this everything is

play03:50

implemented in my previous videos right

play03:52

so we are going to split this entire

play03:53

document and save it in this particular

play03:55

documents in the previous tutorial you

play03:56

have implemented all these things now

play03:59

here what we are going to take do now

play04:01

we'll take all these documents and then

play04:03

we will convert it into a vector store

play04:05

right so Vector store for that we are

play04:07

using this F okay so here we are going

play04:10

we can use AMA embedding or open AI

play04:12

embedding right as I said you open AI

play04:14

embedding is very much Advanced and it

play04:16

will perform better than AMA embedding

play04:19

if you don't have opening a API key use

play04:22

AMA embedding instead of open AI

play04:24

embedding over here you can just write

play04:25

AMA embedding right so from here I'll be

play04:28

using fires which is is again a kind of

play04:30

vector store and it has been developed

play04:32

by meta so fest. from documents document

play04:35

of 20 so I'm just taking the first 20

play04:37

documents and I'm just writing open AI

play04:39

Bings let's make it to 30 so that it

play04:41

will have some amount of data right now

play04:44

we are specifically using open IM

play04:46

bidding and this DB that you

play04:48

specifically see is a my Vector store

play04:50

okay so here you can see Vector store f

play04:53

f of type okay perfect

play04:57

now any question that I ask attention

play04:59

function can be described as a mapping

play05:01

query and then we can take this Vector

play05:02

store and just write do similarity

play05:04

search on this query and we will get the

play05:06

result over here okay so this all things

play05:09

we have actually done in our previous

play05:11

video now is the most important thing

play05:13

how I can combine prompt along with

play05:16

chains and Retriever and then probably

play05:19

get a response based on the prompt okay

play05:21

so since many people have the use of

play05:24

only open source uh they have the exess

play05:26

of Open Source model llm model so I'm

play05:29

going to use AMA from lin. community.

play05:31

llms import olama then I'm going to use

play05:34

AMA over here model will be Lama 2 if

play05:37

you don't have Lama 2 just do go to

play05:39

command prompt after downloading o Lama

play05:41

I hope everybody knows how to download

play05:43

it if you're seeing my series of videos

play05:45

here you can just write AMA run Lama 2

play05:48

right so once you write like this then

play05:50

the model will get downloaded right if

play05:52

it is already downloaded it will be

play05:53

coming something like this okay so this

play05:56

is the first step that you really need

play05:57

to do then I have written from lin.com

play05:59

community. LMS AMA load olama so

play06:03

whatever AMA model we are specifically

play06:05

using that is Lama 2 so this is my open

play06:06

source model so if you see Lama llm it

play06:09

is nothing but AMA now is the time we

play06:12

will start designing our prompt template

play06:15

now in order to design the chat prompt

play06:17

template I will be using chat linore

play06:19

core. prompts import chat prompt

play06:21

template okay and then from chat pron

play06:24

template from template I'm just writing

play06:25

like this so I'm saying answer the

play06:27

following question based only on the

play06:31

provided context now see we are trying

play06:33

to develop a Q&A Q&A chatboard based on

play06:36

the context it should provide me the

play06:37

response

play06:39

previously what we are doing using

play06:41

Vector store we used to if you see the

play06:45

code over here we used to query the

play06:47

vector score right Vector store by using

play06:49

similarity search algorithm but here

play06:51

what we are doing here we are defining

play06:53

our own prompt and we saying hey answer

play06:56

the following question based on the

play06:57

provided context right I will and simply

play07:00

I'm writing away I'll tip you $1,000 if

play07:03

you find the answer helpful okay if the

play07:05

user find the answer helpful okay just

play07:08

at least by seeing money the AI May

play07:10

perform well and then we are giving our

play07:12

context and then question will be input

play07:14

okay how why I'm writing in this

play07:17

specific way because this chain and

play07:18

retriever right you'll be understanding

play07:20

this context will be autofilled and this

play07:23

input will also get autofilled okay how

play07:24

it will get autofilled I'll let you know

play07:26

so now what I will do I will execute

play07:28

this now I will go ahead and Implement

play07:30

about chain uh it is always a good idea

play07:35

okay to probably go to your browser and

play07:38

check about each and every topic that

play07:40

I'm explaining so what does chain refer

play07:42

to chain referred to a sequence of calls

play07:45

whether to an llm tool or data

play07:48

pre-processing step the primary

play07:50

supported way to do this is LCL okay now

play07:53

if you talk about chain over here there

play07:56

are multiple functions with respect to

play07:58

chain one of the function that I'm going

play08:00

to use is create stuff document chain

play08:03

now what this exactly does this chain

play08:05

takes a list of documents and formats

play08:08

them into all into a prompt then passes

play08:11

that prompt to an llm okay see this this

play08:15

chains take a list of documents and

play08:17

formats them based on the prompt formats

play08:19

them into a prompt sorry not based on

play08:21

the prompt into the prompt that

play08:22

basically means over here if I go ahead

play08:26

and open my

play08:28

browser here in the context I definitely

play08:32

require my document s self right based

play08:34

on that context and based on this input

play08:36

I will be able to give the answer right

play08:38

so based on this context and based on

play08:40

the input right context basically means

play08:42

all the documents that are there

play08:44

available in the vector store right

play08:46

inputs are what question I'm asking

play08:48

right so with the help of this create

play08:51

stuff document chain what is basically

play08:53

happening this chain takes a list of

play08:55

documents and formats them all into a

play08:57

prompt then passes that prompt to an llm

play09:00

it passes all the documents show that

play09:01

you should make sure that it fits within

play09:03

the context window the llm you are using

play09:06

so what it is exactly doing it'll take

play09:07

up all the documents from the vector

play09:08

store it will put that put inside that

play09:10

particular prom template and then it

play09:12

will send the to the llm and then we

play09:14

finally get the response okay and that

play09:16

is what we'll be using similarly there

play09:18

are different different uh things also

play09:20

over here like create stuff document

play09:22

chain is there create SQL query chain if

play09:24

you are working with respect to SQL

play09:25

database for natural language and this

play09:27

is one of the very important project

play09:29

that I'll also do in the future one or

play09:31

the other way I'll try to use one or the

play09:34

other functionalities to just make you

play09:36

understand how we can use all these

play09:38

functionalities itself right but it is

play09:40

always good that we have a specific use

play09:43

case okay now if I open this okay let's

play09:47

go ahead and create my chain how do I

play09:49

create my chain over here again it's

play09:51

very simple so I will write from Lang

play09:54

chain Lang chain uncore community so it

play09:57

is present inside Community itself or

play09:59

not Community sorry chains Lang chore

play10:02

chains dot combine

play10:07

documents

play10:08

import create stuff document chain now

play10:12

how do I know this okay I did not create

play10:14

this I have already seen the

play10:16

documentation okay that is the reason

play10:17

I'm writing then I will go ahead and

play10:19

create my document chain now inside this

play10:23

document chain as I said I'll be using

play10:25

create stuff document chain okay that we

play10:28

have already seen now inside this chain

play10:30

two things are basically required one is

play10:33

the llm model and the second one is the

play10:36

prompt that I have created because

play10:39

inside this prompt itself the list of

play10:41

documents will be added right whatever

play10:43

documents is basically coming from here

play10:45

right from my Vector store that will be

play10:47

added over here okay so once I create

play10:50

this so This basically becomes my

play10:52

document chain okay very much simple now

play10:56

after this we also have to learn about

play10:58

one very important thing which is called

play11:00

as

play11:02

retrievers okay so I will go ahead and

play11:04

write something called as

play11:08

retri retriever Lang chain okay now what

play11:12

exactly retriever Lang chain is it is an

play11:14

interface that Recs document given an

play11:17

unstructured query it is more General

play11:19

than a vector store right a retriever

play11:22

does not need to be able to store the

play11:24

documents only to return or retrieve

play11:26

them Vector store can be based as the

play11:29

back backbone of the retriever now see

play11:31

there is a vector store which is having

play11:33

some information some Vector stored in

play11:35

it right if I want to take out any data

play11:38

from there right I can actually do a

play11:40

similarity search which we have already

play11:41

seen okay but langen what it did is that

play11:45

since we usually do a lot of programming

play11:47

in a way right where in classes are used

play11:50

interfaces are used so it created a

play11:52

separate interface which is called as

play11:54

Retriever and that interface has a

play11:57

backend source to that particular Vector

play11:59

store to retrieve any information right

play12:03

whenever a query is given right that

play12:05

entire Vector store will be passing the

play12:08

information through this retriever okay

play12:10

so what we will do is that here I will

play12:14

quickly open this I have also written

play12:16

some amount of description so that it

play12:19

will be helpful for you whenever you

play12:21

probably go ahead and check it this

play12:23

entire materials okay so now what I will

play12:25

do I will just go ahead and write DB Dot

play12:30

DB dot as retriever now once I do like

play12:34

this DB do as retriever this basically

play12:37

has become my retriever right so what we

play12:40

have done DB is our Vector store already

play12:43

it is there we have connected to an

play12:45

interface which is basically this

play12:47

particular variable now okay so if you

play12:49

go ahead and ex uh probably display this

play12:53

what is retriever it is nothing but it

play12:54

is a vector store retriever internally

play12:57

you'll be also able to see that what all

play12:59

it is implemented F and open AI Bings

play13:01

and all all the information are there

play13:03

now retriever is done chain is also done

play13:06

okay now is the time that what I will do

play13:09

I will try to use this Retriever and

play13:12

document chain both together to probably

play13:16

see when we combine both of them then

play13:18

only we'll be able to get the response

play13:20

right so with respect to this now let's

play13:23

go ahead and create my retriever chain

play13:27

okay so the next step is what but since

play13:29

I need to combine both of them one is

play13:32

Retriever and one is the document chain

play13:35

right this document chain is responsible

play13:37

for putting the information in the

play13:38

context when we combine both of them

play13:41

then it becomes a retriever chain now

play13:42

what is the definition this chain takes

play13:44

an input as a user inquiry which is then

play13:48

passed to the retriever to fetch the

play13:49

relevant documents so it passes through

play13:51

the retriever it is connected to the

play13:53

vector store then those documents are

play13:55

then passed to an llm to generate the

play13:57

response and this l M that we are

play14:00

basically getting it is basically coming

play14:02

from what this document chain understand

play14:04

the flow okay so let me just go ahead

play14:07

and mention this flow again so that it

play14:09

becomes very much easy for you so

play14:12

whenever the

play14:13

users this is my user okay whenever the

play14:17

user asks for any

play14:19

inquiry okay any inquiry so first what

play14:23

it is going it is going to this

play14:25

retriever okay very much important okay

play14:28

so this this is my retriever this

play14:31

retriever is an interface to what Vector

play14:34

store which has all the information

play14:37

right so once we basically get the

play14:39

retriever then the next step what it

play14:40

happens it goes to what it goes to my

play14:45

llm model with some prompt right there

play14:48

will be some prompt involved to this and

play14:50

how this is basically

play14:52

happening with the help of stuff

play14:54

document

play14:56

chain so this stuff document chain has

play14:59

has already both these things combined

play15:01

llm and prompt right and then finally we

play15:04

get our

play15:07

response I hope you're able to

play15:09

understand this right and this is what

play15:10

we have basically implemented over here

play15:13

now how to basically create a retriever

play15:15

chain so first for for all of this again

play15:18

I will be using a library um with

play15:21

respect to chains okay so form Lang

play15:25

chain Lang

play15:27

chain Dot

play15:29

chains

play15:31

import create retrieval chain right and

play15:35

there are lot of things create Q with

play15:37

Source chain retrieval chain this chain

play15:40

that chain I will try to explain you all

play15:42

of things don't worry okay I will cast

play15:44

the right kind of use case and I will be

play15:48

showcasing you all these things don't

play15:50

worry about that okay then what I will

play15:52

do I will I will take this entire create

play15:54

retrieval chain and then I will create

play15:57

my uh retrieval chain

play15:59

so here I will write

play16:02

retrieval chain is equal

play16:05

to create retrieval chain and here I'm

play16:08

going to use first parameter that I'm

play16:10

going to use is retriever then the

play16:12

second parameter is nothing but document

play16:14

chain so once I have this chain right

play16:17

now I will be able to invoke any queries

play16:20

so I will go ahead and write retrieval

play16:22

chain dot invoke okay and now what are

play16:27

the parameters that I have to to give

play16:29

nothing I have to give my input so the

play16:32

input will be given over here colon and

play16:35

whatever input that I can give uh let's

play16:37

say from the PDF I have put some input

play16:41

over here let me just copy and paste it

play16:44

okay so this is one of the text that is

play16:45

available in the PDF that is attention.

play16:47

PDF and now if I invoke this you'll be

play16:50

able to see that I will be able to get

play16:52

the entire response okay so retrieval do

play16:55

chain. invoke and again we are using

play16:57

open source llm model that is Lama 2

play17:00

okay yeah I've used openi bidding so

play17:02

here you can see this is my input this

play17:04

was the context right all the context

play17:07

information is there and finally I get

play17:08

the answer and this answer I will just

play17:11

try to save it over here something like

play17:16

response uh res

play17:19

response okay and then I will execute

play17:25

response response of answer so this

play17:29

finally becomes my output that is

play17:31

probably coming over here okay so this

play17:32

if I execute it the answer to the

play17:34

question is right and all the

play17:37

information you can see the answer to

play17:40

the question and it is retrieving all

play17:41

the details right so here you'll be able

play17:44

to see that how beautifully with the

play17:46

help of llm we have constructed this

play17:48

entire thing and we have used this

play17:51

chains Retriever and this is the first

play17:53

step towards developing a advanced rack

play17:56

pipeline right so whatever question you

play17:58

ask let let me just open this and

play18:00

probably show you some more examples

play18:03

okay so what I will do I will just open

play18:06

my download

play18:08

page let's see my download page I'll ask

play18:12

for any statement okay just a second um

play18:17

attention Okay so this is my

play18:20

thing uh let me just go ahead and search

play18:23

for

play18:24

anything the decoder is the this and

play18:27

this okay so I'll be searching from here

play18:29

to here okay now let me go ahead and

play18:33

change my

play18:35

input and search for it so chain. invoke

play18:39

I've done and here I've got the response

play18:43

now let me just go and everything uh the

play18:45

answer to this question is

play18:47

six um the decoder is also composed of

play18:50

stack of n6 oh it has basically taken

play18:52

this no worries okay let's take some

play18:54

more

play18:57

thing I'll write scaled do product

play19:01

attention some more

play19:07

examples oops uh

play19:11

error okay just a second no I think it

play19:16

should not

play19:19

be okay it is taking that question and

play19:22

it is trying to form some answers out of

play19:24

it

play19:25

okay got it got it it is not a mistake I

play19:28

thought it was a mistake mistake out

play19:29

there scale is a type of this this this

play19:31

see I'm getting all the answers over

play19:33

here so now it has become a perfect Q&A

play19:37

um Q&A with rack pipeline along with

play19:40

this Retriever and chain with Lang chain

play19:42

so I hope you like this particular video

play19:43

this was it from my side I'll see you in

play19:45

the next video have a great day thank

play19:46

you one all take care bye-bye

Rate This

5.0 / 5 (0 votes)

相关标签
LangChainRAG pipelineLLM modelsAdvanced AIBadminton storyRetriever chainsVector storeAI developmentPrompt templatesQ&A chatbot
您是否需要英文摘要?