We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
기본 RAG에서 Agentic RAG로 | RAG 파이프라인을 다중 에이전트 파이프라인의 도구로 사용하세요
0:00 a lot of us heard about rag or retrieval
0:02 augmented generation but maybe not many
0:04 have heard about agentic rag or agent
0:06 based rag application and this is
0:08 exactly what we're going to look at in
0:10 this video now a typical drag
0:12 application have two different pipelines
0:14 one is to ingest data and the other one
0:17 is to query data or ask questions to it
0:20 now what we're seeing is we take our
0:21 documents we convert that into some sort
0:24 of vectors or embeddings and from there
0:26 we store it in a vector database and
0:28 then we can query based on that now this
0:31 step is same for the agent based rag or
0:34 a usual rag application what changes is
0:37 that in a typical drag application the
0:40 user asks questions and we convert that
0:43 question into embeddings and then we
0:45 search for answers in our Vector
0:47 database we send it to an LM and we say
0:51 this is the context and based on the
0:53 user question give an answer to the user
0:57 but this changes a little bit in agent
1:00 based rag application where now we have
1:02 an agent which has memory associated
1:05 with it and also we can select any of
1:08 the llm providers that we want and now
1:10 the key thing is the rag query pipeline
1:14 becomes a tool for this agent so if it
1:17 sees that it needs to query the answer
1:20 from the vector database then it's going
1:23 to go through the usual process and if
1:25 it sees that that's not needed if it can
1:27 just answer a question based on its own
1:29 knowledge then it's just going to go
1:31 ahead and answer that question this
1:33 opens up the possibilities now you can
1:35 attach multiple tools you can attach
1:37 something like an internet search tool
1:39 so if the agent sees that there is a
1:41 need to search internet it can do that
1:44 if it needs to call the vector database
1:46 it's going to do that or if it is
1:47 something within its own knowledge then
1:49 it's going to provide the answer so this
1:51 gives a lot more flexibility in
1:53 comparison to just a rag pipeline where
1:56 it's either going to answer based on the
1:58 vector database or it's going to say I
2:00 don't know the answer so probably one of
2:02 the easiest way to build this agent
2:03 based drag application is using langlow
2:06 and that's what we're going to look at
2:07 so we're going to start with a template
2:09 in langlow so this is the hosted version
2:12 of langlow so you can go to as.
2:14 data.com and then you can make a free
2:17 account and once you start a new account
2:19 you'll see that you will be landed at
2:22 the Astra DB this is the default so in
2:25 here what you want to do is make a
2:27 vector database what I did is I went
2:29 into database es and I created a new
2:31 database for langlow now the name I
2:33 called is langlow you can call any name
2:36 and once you create this now you can
2:38 head over to langlow now if you already
2:40 have a few projects you'll see them
2:42 listed here if it is something new
2:44 you'll see a page with welcome and then
2:46 a few templates so we're going to start
2:48 with a template that's very common so
2:50 this is the vector store Rag and then
2:52 we'll modify this to convert it into a
2:56 gentic rag application so right away
2:58 when you start this template you'll
2:59 notice that there are two different
3:01 flows Happening Here the one at the
3:03 bottom is where we are going to ingest
3:05 data and the one at the top is where we
3:08 can ask questions so this is a typical
3:11 rag application we are starting with a
3:14 file and then we do some sort of
3:17 splitting or chunking and then we store
3:20 that text into the vector database now
3:24 for our case where we have Astra DB this
3:28 component is already available in the
3:30 template if you already have a database
3:32 you're going to select that database and
3:34 then you can provide either a name that
3:37 you have said before or you can start a
3:40 new collection and and basically this
3:42 collection is where you're going to save
3:43 your embeddings now this step remains
3:46 same for any rag pipeline what we're
3:48 going to change is we will modify this
3:52 pipeline here where we can query and get
3:54 answers so instead of just calling open
3:57 AI directly based on the context that we
4:00 get this is going to be an agent I have
4:03 modified a few things so what you will
4:06 notice is that our Astra DB this
4:09 component Remains the Same we are going
4:11 to select the same collection as well as
4:14 the same database and then we have the
4:16 same embeddings that we use so the
4:19 embeddings that we used for data
4:21 ingestion we're going to use the same
4:23 embedding model now next step is that we
4:25 are going to connect this to a retriever
4:28 tool if you were to search in the
4:30 components you'll see that this is
4:32 available so we're just going to bring
4:34 that over and then we attach the Astra
4:38 DB as Retriever and pull the data that
4:41 we get from the DB into retriever tool
4:44 as needed and now this retriever tool is
4:47 what we're going to use with agent
4:49 agents are quite powerful in the new
4:52 Lang flow starting from version 1.1 so
4:55 you'll notice that there is a lot more
4:58 flexibility you can call different
5:00 providers you can use a lot more tools
5:02 than the version before and on top of
5:05 that you can use this in a tool mode so
5:08 any agent can become a tool as well or
5:11 you can use that as an agent blog so in
5:13 this case we're going to use as an agent
5:15 blog so as you notice here we have the
5:17 retriever tool attached to the agent and
5:20 then any question that's asked by the
5:23 user we bring the chat input directly to
5:27 this agent so this agent has the tools
5:29 for retrieval as well as it has a
5:31 built-in memory and then on the other
5:34 side we have just the chat output so one
5:36 key difference here is going to be in
5:38 the prompt to the agent so previously we
5:41 asked if the context has the response so
5:44 answer based on that if not just say I
5:46 don't know well in this case we have a
5:49 detailed prom and the key over here is
5:53 that we are going to say that you are an
5:55 intelligent agent if a question is asked
5:58 and if the respon response is available
6:00 in the vector database you query and try
6:03 to get the response you can retry if
6:06 needed and if then you don't have
6:08 response then you say I don't know or
6:11 you can answer based on the best
6:13 knowledge that you have we let agent do
6:15 the work query it and get the response
6:17 from the vector database and then
6:19 formulate the response based on that so
6:21 that completes the pipeline for agent
6:23 based rag app so with that if we ask
6:25 question that what is this document
6:28 you'll notice that it goes through a
6:29 thought process so I had asked a few
6:31 different questions so you can see the
6:32 responses now for this particular
6:35 question it looks at the document
6:37 available then it's going to get a few
6:40 different output from the Retriever and
6:43 based on that it's going to answer or
6:45 formulate an answer and then provide
6:47 that back to us as a response so that's
6:50 exactly what we see here as a response
6:53 now if you want to confirm that the tool
6:54 was used or not you can always go into
6:57 the logs and then see what happened in
6:59 the back ground so you'll notice over
7:01 here that there is the usage of
7:03 retriever tool and then based on that we
7:05 were given some response now if we want
7:08 to go One Step Beyond the basic rag what
7:11 we can do is we can attach another tool
7:13 to this agent so we can test if it is
7:15 able to search internet or do certain
7:18 task and also do the retrieval task so
7:21 let's do that we will take our same
7:24 template or flow and then in addition to
7:26 what we had before we're going to add
7:28 the search API component and this is
7:32 available in the components so if you
7:34 were to look at the tools there are
7:37 multiple tools available so you could
7:38 use something like Google search or
7:40 search API or if you want any data
7:43 extracted from a website you can use
7:46 something like fir crawl or if you want
7:48 to get something from Wikipedia you
7:50 could use that as well so there are a
7:52 lot more options available to us so if
7:54 you were to go to search API website
7:56 which is search api. and make a free
7:59 account you get up to 100 free searches
8:02 and that's enough for our particular use
8:04 case so we're going to copy this API key
8:06 and we go back to landf flow and provide
8:09 that API key here and now just with that
8:12 one component we have an agent
8:15 application which can perform retrieval
8:17 as well as search internet now in this
8:20 particular case since we added the
8:22 search API we need to modify the prompt
8:24 to the Asian so what we can do is we can
8:28 add information about the API so
8:30 basically what we're saying is that
8:32 first you can query the vector database
8:34 if you think that the response is in the
8:37 vector database if not you can search
8:39 internet and get the response from the
8:41 internet and then based on that respond
8:43 back to the user the strategy as well as
8:46 the response guidelines over here help
8:48 agent to make that decision and then
8:50 also we mentioned that there are these
8:52 tools available for you in case if you
8:54 want to use them and the description for
8:56 these tools could be changed or modified
8:58 if needed in the tool itself so if you
9:01 were to go to the retriever tool you can
9:03 add some descriptions what type of a
9:06 vector database this is or what type of
9:08 a document this is or in case if you
9:10 want to describe the document a little
9:12 bit saying that this document is about
9:14 the physics paper if that is the
9:16 question asked then you can use this
9:18 tool same thing in the search API now
9:22 this is something where the description
9:24 is provided in the tool you can always
9:27 go in if needed you can change the
9:29 description but even a short description
9:31 like this helps the agent to use the
9:34 tool if needed for searching the
9:36 internet so now if I were to ask
9:38 question from the document that we
9:40 provided then we'll notice that it goes
9:42 to the right tool and it's going to
9:45 retrieve some information and provide
9:47 that information to us and then if we
9:50 were to ask a general question which is
9:52 outside of the document then we'll
9:54 notice that it's going to reach to the
9:56 tool that is appropriate so there is
9:58 some history from the previous question
10:00 next question is where I asked about the
10:03 recent Olympics and the results for that
10:06 so what it's going to do is it's going
10:07 to go to the search API use that tool
10:11 and then it's going to retrieve some
10:12 answers some links and based on those
10:15 links and the available information it's
10:18 going to formulate the response and give
10:20 us the response which is the answer that
10:23 we were looking for again if you want to
10:25 confirm that in the logs you can see
10:28 that we are going to be using the
10:30 retriever tool based on the question as
10:33 well as if needed we are going to be
10:36 using the search API and if needed we
10:38 can always go into the details for these
10:41 logs and see how the agent worked on the
10:44 question that we asked hope this helps
10:46 you get started with your first agent
10:49 Bas rag application feel free to reach
10:51 out if you have any questions
0:00 Chắc hẳn nhiều người đã nghe nói về RAG, hay còn gọi là Retrieval Augmented Generation (Tạo sinh tăng cường truy xuất). Nhưng có lẽ ít ai biết đến Agentic RAG, tức là ứng dụng RAG dựa trên tác nhân. Và đó chính xác là những gì chúng ta sẽ tìm hiểu trong video này. Một ứng dụng RAG điển hình sẽ có hai quy trình riêng biệt: một để thu thập dữ liệu và một để truy vấn dữ liệu, hay đặt câu hỏi cho dữ liệu đó.
0:20 Quy trình hoạt động là chúng ta lấy tài liệu, chuyển đổi nó thành các vector hoặc embedding, rồi lưu trữ trong cơ sở dữ liệu vector để có thể truy vấn sau này. Bước này là giống nhau cho cả RAG dựa trên tác nhân và RAG thông thường. Điểm khác biệt nằm ở chỗ, trong một ứng dụng RAG thông thường, người dùng đặt câu hỏi, chúng ta chuyển đổi câu hỏi đó thành embedding, sau đó tìm kiếm câu trả lời trong cơ sở dữ liệu vector. Kết quả được gửi đến một LLM (mô hình ngôn ngữ lớn) cùng với ngữ cảnh, và LLM sẽ đưa ra câu trả lời cho người dùng dựa trên câu hỏi và ngữ cảnh đó.
0:57 Nhưng trong ứng dụng RAG dựa trên tác nhân, quy trình này có một chút thay đổi. Chúng ta có một tác nhân, được trang bị bộ nhớ và có thể sử dụng bất kỳ nhà cung cấp LLM nào. Điều quan trọng là quy trình truy vấn RAG trở thành một công cụ cho tác nhân này. Nếu tác nhân nhận thấy cần truy vấn câu trả lời từ cơ sở dữ liệu vector, nó sẽ thực hiện quy trình thông thường. Ngược lại, nếu nó có thể trả lời câu hỏi dựa trên kiến thức của mình, nó sẽ trả lời trực tiếp.
1:33 Điều này mở ra rất nhiều khả năng. Bạn có thể tích hợp thêm nhiều công cụ khác, ví dụ như công cụ tìm kiếm trên internet. Nếu tác nhân thấy cần tìm kiếm trên internet, nó sẽ làm. Nếu cần gọi cơ sở dữ liệu vector, nó cũng sẽ làm. Hoặc nếu câu trả lời nằm trong kiến thức của nó, nó sẽ cung cấp câu trả lời. Điều này mang lại sự linh hoạt hơn rất nhiều so với quy trình RAG thông thường, vốn chỉ trả lời dựa trên cơ sở dữ liệu vector hoặc đơn giản là nói "Tôi không biết".
2:00 Một trong những cách dễ nhất để xây dựng ứng dụng RAG dựa trên tác nhân là sử dụng Langflow. Và đó là những gì chúng ta sẽ xem xét ngay bây giờ. Chúng ta sẽ bắt đầu với một mẫu có sẵn trong Langflow. Đây là phiên bản Langflow được lưu trữ, bạn có thể truy cập as(dot)data(dot)com để tạo một tài khoản miễn phí. Khi bạn tạo tài khoản mới, bạn sẽ được chuyển đến Astra DB. Đây là mặc định. Ở đây, bạn cần tạo một cơ sở dữ liệu vector. Tôi đã tạo một cơ sở dữ liệu mới cho Langflow, đặt tên là Langflow. Bạn có thể đặt bất kỳ tên nào. Sau khi tạo xong, bạn có thể chuyển đến Langflow.
2:38 Nếu bạn đã có một vài dự án, chúng sẽ được liệt kê ở đây. Nếu bạn mới bắt đầu, bạn sẽ thấy một trang chào mừng và một vài mẫu. Chúng ta sẽ bắt đầu với một mẫu rất phổ biến: RAG cửa hàng vector. Sau đó, chúng ta sẽ sửa đổi nó để chuyển đổi thành một ứng dụng RAG di truyền. Ngay khi bạn mở mẫu này, bạn sẽ thấy có hai luồng khác nhau. Luồng ở phía dưới là nơi chúng ta thu thập dữ liệu, và luồng ở phía trên là nơi chúng ta đặt câu hỏi. Đây là một ứng dụng RAG điển hình. Chúng ta bắt đầu với một tệp, sau đó thực hiện phân tách hoặc chia nhỏ, rồi lưu trữ văn bản đó vào cơ sở dữ liệu vector.
3:24 Trong trường hợp của chúng ta, vì chúng ta có Astra DB, thành phần này đã có sẵn trong mẫu. Nếu bạn đã có cơ sở dữ liệu, bạn sẽ chọn cơ sở dữ liệu đó và cung cấp tên mà bạn đã đặt trước đó, hoặc bạn có thể tạo một bộ sưu tập mới. Về cơ bản, bộ sưu tập này là nơi bạn sẽ lưu trữ các embedding của mình. Bước này vẫn giống nhau đối với bất kỳ quy trình RAG nào. Chúng ta sẽ thay đổi quy trình ở phía trên, nơi chúng ta có thể truy vấn và nhận câu trả lời. Thay vì chỉ gọi Open AI trực tiếp dựa trên ngữ cảnh, chúng ta sẽ sử dụng một tác nhân.
4:03 Tôi đã sửa đổi một vài thứ. Bạn sẽ thấy rằng thành phần Astra DB của chúng ta vẫn giữ nguyên. Chúng ta sẽ chọn cùng một bộ sưu tập và cùng một cơ sở dữ liệu. Chúng ta cũng sử dụng cùng các embedding mà chúng ta đã sử dụng để thu thập dữ liệu, tức là cùng một mô hình embedding. Bước tiếp theo là kết nối nó với một công cụ truy xuất. Bạn có thể tìm thấy công cụ này trong danh sách các thành phần. Chúng ta sẽ kéo nó vào và đính kèm Astra DB làm Công cụ truy xuất, để kéo dữ liệu từ DB vào công cụ truy xuất khi cần thiết.
4:44 Và giờ đây, công cụ truy xuất này sẽ được sử dụng với tác nhân. Các tác nhân trong Langflow khá mạnh mẽ, đặc biệt là từ phiên bản 1.1 trở đi. Bạn sẽ thấy rằng có nhiều tính linh hoạt hơn rất nhiều. Bạn có thể gọi các nhà cung cấp khác nhau, sử dụng nhiều công cụ hơn so với phiên bản trước. Quan trọng hơn, bạn có thể sử dụng nó ở chế độ công cụ. Bất kỳ tác nhân nào cũng có thể trở thành một công cụ, hoặc bạn có thể sử dụng nó làm blog tác nhân. Trong trường hợp này, chúng ta sẽ sử dụng nó làm blog tác nhân. Như bạn thấy ở đây, chúng ta có công cụ truy xuất được đính kèm với tác nhân. Bất kỳ câu hỏi nào được người dùng đặt ra, chúng ta sẽ đưa đầu vào trò chuyện trực tiếp đến tác nhân này. Tác nhân này có các công cụ để truy xuất, bộ nhớ tích hợp, và ở phía bên kia, chúng ta chỉ có đầu ra trò chuyện.
5:36 Một điểm khác biệt chính nằm ở lời nhắc (prompt) cho tác nhân. Trước đây, chúng ta yêu cầu nếu ngữ cảnh có phản hồi, thì hãy trả lời dựa trên đó. Nếu không, chỉ cần nói "Tôi không biết". Nhưng trong trường hợp này, chúng ta có một lời nhắc chi tiết hơn. Điều quan trọng là chúng ta sẽ nói rằng "Bạn là một tác nhân thông minh. Nếu có câu hỏi và phản hồi có sẵn trong cơ sở dữ liệu vector, bạn hãy truy vấn và cố gắng
6:03 để nhận được phản hồi. Bạn có thể thử lại nếu cần. Nếu sau đó bạn vẫn không có phản hồi, bạn có thể nói 'Tôi không biết', hoặc bạn có thể trả lời dựa trên kiến thức tốt nhất mà bạn có." Chúng ta hãy để tác nhân thực hiện công việc, truy vấn và nhận phản hồi từ cơ sở dữ liệu vector, sau đó xây dựng phản hồi dựa trên đó. Vậy là chúng ta đã hoàn thành quy trình cho ứng dụng RAG dựa trên tác nhân. Bây giờ, nếu chúng ta đặt câu hỏi "Tài liệu này là gì?", bạn sẽ thấy rằng nó trải qua một quá trình suy nghĩ. Tôi đã hỏi một vài câu hỏi khác nhau, bạn có thể thấy các phản hồi.
6:32 Đối với câu hỏi cụ thể này, nó xem xét tài liệu có sẵn, sau đó nhận được một vài đầu ra khác nhau từ Công cụ truy xuất. Dựa trên đó, nó sẽ trả lời hoặc xây dựng một câu trả lời và cung cấp lại cho chúng ta dưới dạng phản hồi. Đó chính xác là những gì chúng ta thấy ở đây. Nếu bạn muốn xác nhận rằng công cụ đã được sử dụng hay chưa, bạn có thể xem nhật ký và xem điều gì đã xảy ra ở chế độ nền. Bạn sẽ thấy rằng có việc sử dụng công cụ truy xuất, và dựa trên đó, chúng ta đã nhận được một số phản hồi.
7:07 Để nâng cao ứng dụng RAG cơ bản, chúng ta có thể tích hợp thêm một công cụ khác vào tác nhân. Ví dụ, chúng ta có thể cho phép nó tìm kiếm trên internet, thực hiện các tác vụ nhất định, đồng thời vẫn giữ khả năng truy xuất thông tin từ cơ sở dữ liệu vector. Chúng ta sẽ sử dụng lại mẫu hoặc luồng đã có, và thêm thành phần API tìm kiếm. Thành phần này có sẵn trong danh sách các thành phần. Có rất nhiều công cụ khác nhau, ví dụ như Google Search, Search API, F crawl (nếu bạn muốn trích xuất dữ liệu từ một trang web), hoặc Wikipedia.
7:50 Có rất nhiều lựa chọn khác nhau. Nếu bạn truy cập trang web Search API (searchapi(dot)com) và tạo một tài khoản miễn phí, bạn sẽ nhận được tối đa 100 lượt tìm kiếm miễn phí, đủ cho mục đích sử dụng của chúng ta. Chúng ta sẽ sao chép khóa API này, quay lại Langflow và dán khóa API vào đây. Chỉ với một thành phần này, chúng ta đã có một ứng dụng tác nhân có thể vừa truy xuất thông tin, vừa tìm kiếm trên internet. Trong trường hợp này, vì chúng ta đã thêm API tìm kiếm, chúng ta cần sửa đổi lời nhắc cho tác nhân.
8:24 Chúng ta có thể thêm thông tin về API. Về cơ bản, chúng ta sẽ nói rằng "Bạn có thể truy vấn cơ sở dữ liệu vector trước nếu bạn nghĩ rằng câu trả lời nằm trong đó. Nếu không, bạn có thể tìm kiếm trên internet và lấy thông tin từ đó. Sau đó, dựa trên thông tin có được, hãy phản hồi cho người dùng." Chiến lược và hướng dẫn phản hồi ở đây giúp tác nhân đưa ra quyết định. Chúng ta cũng đề cập rằng có những công cụ này để bạn sử dụng, và mô tả cho các công cụ này có thể được thay đổi hoặc sửa đổi nếu cần trong chính công cụ đó.
9:01 Nếu bạn truy cập công cụ truy xuất, bạn có thể thêm mô tả về loại cơ sở dữ liệu vector này, hoặc loại tài liệu này. Ví dụ, bạn có thể nói rằng "Tài liệu này nói về bài báo vật lý, nếu đó là câu hỏi được hỏi, thì bạn có thể sử dụng công cụ này." Tương tự với API tìm kiếm. Mô tả được cung cấp trong công cụ. Bạn luôn có thể vào và thay đổi mô tả nếu cần. Ngay cả một mô tả ngắn như vậy cũng giúp tác nhân sử dụng công cụ nếu cần để tìm kiếm trên internet.
9:36 Bây giờ, nếu tôi đặt một câu hỏi từ tài liệu mà chúng ta đã cung cấp, bạn sẽ thấy rằng nó sẽ sử dụng đúng công cụ, truy xuất thông tin và cung cấp cho chúng ta. Và nếu chúng ta đặt một câu hỏi chung nằm ngoài tài liệu, bạn sẽ thấy rằng nó sẽ tiếp cận công cụ phù hợp. Có một số lịch sử từ câu hỏi trước. Câu hỏi tiếp theo là về Thế vận hội gần đây và kết quả. Nó sẽ truy cập API tìm kiếm, sử dụng công cụ đó, truy xuất một số câu trả lời, một số liên kết. Dựa trên những liên kết đó và thông tin có sẵn, nó sẽ xây dựng phản hồi và cung cấp cho chúng ta câu trả lời mà chúng ta đang tìm kiếm.
10:23 Một lần nữa, nếu bạn muốn xác nhận điều đó trong nhật ký, bạn có thể thấy rằng chúng ta sẽ sử dụng công cụ truy xuất dựa trên câu hỏi, và nếu cần, chúng ta sẽ sử dụng API tìm kiếm. Chúng ta luôn có thể xem chi tiết các nhật ký này và xem tác nhân đã hoạt động như thế nào đối với câu hỏi mà chúng ta đã hỏi. Hy vọng điều này giúp bạn bắt đầu với ứng dụng RAG dựa trên tác nhân đầu tiên của mình. Vui lòng liên hệ nếu bạn có bất kỳ câu hỏi nào.
번역된 시간: 2025-03-09T08:15:44Z
번역 버전: 3.1 Improved translation step with full context