YouTube2Text

8 сентября 2026 г. — Transcript

by Andrei · 10,044 words · 1,427 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hey everyone, this is Sean. Today let's
  2. 0:01think about how to design an AI agent
  3. 0:03system like a pro. It doesn't matter if
  4. 0:05you're technical or not. If you're a
  5. 0:06product manager, designer, data
  6. 0:07scientist or computer scientist, does
  7. 0:09not matter. The goal here really is to
  8. 0:11understand how do we think holistically
  9. 0:13about you know starting from the front
  10. 0:15end all the way to the back end database
  11. 0:17and setting up AI agents so that your
  12. 0:19app will be smarter than just the
  13. 0:21traditional SAS product. So today's
  14. 0:23example is about how do we design this
  15. 0:25agent system for the e-commerce direct
  16. 0:27to customer brands D2C brands to manage
  17. 0:30their customer support. So as we know
  18. 0:32that customer support is a field that
  19. 0:33traditionally has a lot of human
  20. 0:35involvement when it comes to things like
  21. 0:37return products, exchange products or
  22. 0:39you know asking about the status of
  23. 0:41where my product is when it's being
  24. 0:42shipped. And u for a lot of e-commerce
  25. 0:45company they probably cannot afford to
  26. 0:47hire a bunch of like call centers or
  27. 0:48message replying agents. So this would
  28. 0:51be a perfect use case for them to you
  29. 0:53know increase their response rate as
  30. 0:55well as you know um improve the
  31. 0:57satisfaction for their customers. So now
  32. 0:59let's jump in and think about how do we
  33. 1:01think through this step by step. Okay.
  34. 1:03So the first thing is that our goal
  35. 1:04today is that we want to make sure that
  36. 1:08we will have over 70%
  37. 1:11automation in this customer support
  38. 1:13flow. Which means that the other 30%
  39. 1:15probably be like we're going to loop the
  40. 1:17humans back into the conversation when a
  41. 1:21e-commerce site is talking to a
  42. 1:22customer, right? And also we want to
  43. 1:24make sure that the customer satisfaction
  44. 1:26rate sees greater than 4.5 out of five,
  45. 1:30right? And last but not least, we want
  46. 1:31to make sure that the response with the
  47. 1:3450% of the percentile of the customers
  48. 1:36is below 1 second. And then 95% of your
  49. 1:40customers will get a response under 2.5
  50. 1:42seconds. Why is this important? This is
  51. 1:44important because if the response time
  52. 1:47is too long, it really affects your
  53. 1:49satisfaction from your customers. Okay,
  54. 1:52so this is our goal. And um let's also
  55. 1:54think about what is our scope today. Our
  56. 1:57scope is very simple. We want to focus
  57. 2:00on returns, exchanges,
  58. 2:04and where is my order? Okay, so let me
  59. 2:08just delete this flow and then let's
  60. 2:10walk through it together. So firstly,
  61. 2:12let's think about the rules of this
  62. 2:14scope.
  63. 2:16In order to return to the customer, we
  64. 2:18need to make sure that the products for
  65. 2:21example will only be returned if it's
  66. 2:23bought over under 30 days before. It
  67. 2:25must be returned in good conditions,
  68. 2:26right? Otherwise, the agents probably
  69. 2:28will just allow any products to be
  70. 2:30returned at any time, which is not what
  71. 2:31we want, right? The second rule we think
  72. 2:33about is um how do we think about the
  73. 2:35refund policy, right? In this case, most
  74. 2:38companies probably have a refund policy.
  75. 2:40for example, if it's under $50 and if
  76. 2:42they're using a human call center uh as
  77. 2:44a service, then they will automatically
  78. 2:47let it to um return the product. But if
  79. 2:50it's over or equal to $50, then they
  80. 2:52probably need to loop in their manager.
  81. 2:53We want to mimic the exact user behavior
  82. 2:55here. The third one is called exchange
  83. 2:58policy. So if a customer want to
  84. 3:00exchange the product, they also need to
  85. 3:02make sure a few things. um it needs to
  86. 3:05be in good conditions and certain
  87. 3:06categories of products cannot be
  88. 3:08returned because for example if it's
  89. 3:10food and you already open it you cannot
  90. 3:11really return it right
  91. 3:14and lastly that um how do we route back
  92. 3:16to a human right and there could be all
  93. 3:18sorts of scenarios here um it could be
  94. 3:21because the user directly asked that
  95. 3:23they want to talk to a human or we have
  96. 3:25detected that there's some very negative
  97. 3:28emotions in the chat so that we must uh
  98. 3:31involve a human being to basically
  99. 3:34provide emotional support for the
  100. 3:36customer. Okay. Um from a backend and
  101. 3:39database perspective, there are a few
  102. 3:41things that we should consider in this
  103. 3:43case. Let me just paste it right in. The
  104. 3:45first thing is that when and how much is
  105. 3:48the peak for requests per second and
  106. 3:52about the seasonality as well. Imagine
  107. 3:53this is Black Friday or Christmas time.
  108. 3:55Then probably there will be a lot more
  109. 3:56people doing online shopping versus the
  110. 3:59other period of time of the year. And
  111. 4:01also we need to think about how are we
  112. 4:03going to store all the chat history
  113. 4:06um information about the transactions
  114. 4:09about return and logistics. Do we store
  115. 4:11it in a relational database or do we
  116. 4:14store it in a vector database? So here's
  117. 4:16a concept we need to introduce for AI
  118. 4:18agents which is vector database. What it
  119. 4:20really means is that traditionally we
  120. 4:24basically define data tables in imagine
  121. 4:27you have an Excel sheet there are rows
  122. 4:28and columns. every column means a
  123. 4:30different feature. Every row means like
  124. 4:32a different entry, right? Um but in
  125. 4:36order to search some of the say
  126. 4:37unstructured data like the return policy
  127. 4:40or refund policy, these kind of things
  128. 4:42are not going to be stored in
  129. 4:44traditional like table format. They're
  130. 4:45probably a paragraph or PDF, right? So
  131. 4:48the way to do is that we can store this
  132. 4:50information in a vector database in
  133. 4:53which we will embed each word or each
  134. 4:56you know paragraphs into uh vectors.
  135. 5:00Right? So what we mean by that is that
  136. 5:01we're going to turn these words into
  137. 5:04numbers that are in high dimensions. If
  138. 5:06you're really not from a technical
  139. 5:08background, just think of it as like we
  140. 5:09got to digitize something. Like if
  141. 5:11you're looking at a photo on your
  142. 5:13iPhone, it will be stored in digits and
  143. 5:16then when they're stored in digits,
  144. 5:18you'll be able to search them by
  145. 5:19calculating some similarity between
  146. 5:21photos. Similarly, here we're allowing
  147. 5:23it to calculate similarities between uh
  148. 5:26vectors. Right? So given this current
  149. 5:29scope, the goal, the rule, the backend
  150. 5:31database, let's jump in to start
  151. 5:33designing the agent system here. Okay.
  152. 5:36The first thing we're going to do is
  153. 5:37that we need to think about when will a
  154. 5:41user start to interact with our system.
  155. 5:43Right? So in this case, our user
  156. 5:45channels are going to be website chat
  157. 5:47and emails. Okay? So if you think about
  158. 5:50this more holistically, we're not going
  159. 5:52to directly allow anybody to start using
  160. 5:54the system. So we're going to start um
  161. 5:56doing some authentication first. So here
  162. 5:58we're going to introduce a gateway. A
  163. 6:01gateway is going to deal with the
  164. 6:03authentication single sign on or PII
  165. 6:06which is for privacy of the user or
  166. 6:09you're going to think through the rate
  167. 6:10limit like how many times people can
  168. 6:12actually use this product request for
  169. 6:14this product and checking for
  170. 6:16duplication. So all these kind of things
  171. 6:18are sort of we need to double check with
  172. 6:19a gateway. So let's add a bit of arrow
  173. 6:22to confirm this relationship before we
  174. 6:25continue to process any information. We
  175. 6:27need to finish authentication first
  176. 6:30and also in order to load the previous
  177. 6:32chat and emails we need to query our
  178. 6:34data from a relational database.
  179. 6:36Remember we talked about the rectangle
  180. 6:38data tables. So what happens here is
  181. 6:39basically user of fetch the chats and
  182. 6:44emails. Okay, we're going to start think
  183. 6:46about how would the agent help with u
  184. 6:49talking to these conversations from
  185. 6:51customers. Okay, imagine a customer has
  186. 6:54just asked a question. ask a question.
  187. 6:58They said, "I want to return my product
  188. 7:03X." You probably would think, "Hey, um,
  189. 7:06okay, let me try to check my policy. Let
  190. 7:08me try to understand uh, what do I do
  191. 7:10next?" Right? So, exactly for AI agents,
  192. 7:13the first thing we do is that we're
  193. 7:15going to introduce this thing called a
  194. 7:17router agent. What it does is that it's
  195. 7:19trying to understand the intent of the
  196. 7:21question so that it knows what to do
  197. 7:22next. A router agent. There we go. So
  198. 7:27this router agent will try to understand
  199. 7:29the user intent and then decide the
  200. 7:32agent routing. Remember that one of our
  201. 7:34goals is that we we need to make sure
  202. 7:36that the response time for 50% of the
  203. 7:38users is always under 1 second. The way
  204. 7:41we do that is that we need to introduce
  205. 7:44another agent called a Q&A agent. What
  206. 7:46this Q&A agent does is that after you
  207. 7:50get the first question, I want to return
  208. 7:51my product X. You want to allow yourself
  209. 7:54a little bit of time for the router to
  210. 7:56think through it, right? It depends on
  211. 7:58the exact situation like how many steps
  212. 8:00is going to happen right after the
  213. 8:02router agent. You want the conversation
  214. 8:04to flow like natural. So perhaps after
  215. 8:06you ask the first question, it will flow
  216. 8:08into the Q&A agent and then that will sp
  217. 8:11that will start to speak to the user all
  218. 8:12the time and they'll probably start to
  219. 8:14respond to the user um by saying
  220. 8:17something like, "Oh, thanks for asking
  221. 8:18the question. Let me just check it for
  222. 8:20you." and then start showing them like
  223. 8:22an thinking process. Uh respond to the
  224. 8:25user
  225. 8:27um real time. Okay. So here for the
  226. 8:31router agent, let's think about the edge
  227. 8:32case first, right? If the router agent
  228. 8:35realize that this customer is very angry
  229. 8:37like the customer say that I I must deal
  230. 8:40with like or they ask a very very
  231. 8:41complex question and we think that our
  232. 8:44agent decides that it's it's way u
  233. 8:46beyond the confidence that I have to
  234. 8:49deal with myself. We need to have a
  235. 8:50mechanism to allow to trigger looping
  236. 8:52the human back into this agentic system
  237. 8:55so that the humans will take over so
  238. 8:57that our overall customer satisfaction
  239. 8:58ray will not be affected. Right? So I'm
  240. 9:01just going to add in this human in the
  241. 9:04loop. Oh this is so difficult to use. So
  242. 9:07now in this case the human will start to
  243. 9:10approve or disapprove any request from
  244. 9:13the users. If the router agent decides
  245. 9:15now that this is a valid request and let
  246. 9:17me just double check if it fits with our
  247. 9:19policy so that I will process the rest
  248. 9:21of the steps for you then we will allow
  249. 9:23it to move on to the next step right so
  250. 9:26the next step we're calling it a planner
  251. 9:29agent let me just move it back here
  252. 9:32decide to take the return route action
  253. 9:37so what happens now is that because
  254. 9:39we're the router agent understood the
  255. 9:41intent which is to um return the product
  256. 9:44then it will start to call the return
  257. 9:46planning agent. So the planning agent
  258. 9:48for return will start to process what's
  259. 9:50going to happen next. A very important
  260. 9:52concept is called functional calling. So
  261. 9:55what will happen is that we will prepare
  262. 9:57a very long list of functions that will
  263. 10:00be available as tools for AI agents to
  264. 10:02select from. And I'll show you a few
  265. 10:04example which is
  266. 10:07for instance um if the user need to
  267. 10:10return you need to introduce a stripe
  268. 10:12API that will allow them to get refund
  269. 10:14or start paying for another product as
  270. 10:16an alternative a Shopify agent which
  271. 10:18will allow us to u pull in the
  272. 10:20information about how do we what's the
  273. 10:22track what's the order status right now
  274. 10:24and what is the return merchandise
  275. 10:26authorization right now RMA and perhaps
  276. 10:30for some exchanges actions as well and
  277. 10:32also So things like oh where's my order
  278. 10:34right? So we got to pull in the API tool
  279. 10:37that will check some third party
  280. 10:38logistics 3PL to to understand where the
  281. 10:42product it is right now in real time and
  282. 10:44also for example if the user is managing
  283. 10:47some of their customer relationship
  284. 10:48information in a CRM system then they
  285. 10:51will be able to pull in some CRM APIs to
  286. 10:53start writing or fetching some deal from
  287. 10:55their pipeline or create and update some
  288. 10:57tickets. Okay, these are the tool that
  289. 10:59we're talking about here. So if we move
  290. 11:01back to where we were, this planner
  291. 11:04agent will decide what tool we're going
  292. 11:06to call. And in this case, the tools
  293. 11:08we're going to call are the return API,
  294. 11:11which is from Shopify, and the Stripe
  295. 11:13API, which is for processing payments.
  296. 11:15Right? The reason why I said there's a
  297. 11:18bit of a catch here is that this
  298. 11:19planning agent really depends on um the
  299. 11:23logic for finishing this task. It could
  300. 11:26be a deterministic workflow as well
  301. 11:28which means that we could just use some
  302. 11:29rules to process the rest of the steps
  303. 11:32especially when the steps are very
  304. 11:34fixed. For example, if we know that the
  305. 11:36user is just going to return the
  306. 11:37products, then what we do is basically
  307. 11:40okay checkify, right? Try to understand
  308. 11:43if um the product is still um a okay for
  309. 11:47for return or for exchange, right? And
  310. 11:49then trigger um stripe API to process
  311. 11:53all the payments related information,
  312. 11:54right? So actually one very good
  313. 11:57practice is that if we can reduce the
  314. 12:00amount of automation of using agents for
  315. 12:02cases where it doesn't really need an
  316. 12:04agent then your system will be more
  317. 12:06reliable. In this case just for the sake
  318. 12:09of presentation I'm going to show you
  319. 12:11how to think through the agentic way of
  320. 12:13a planner for return rather than the
  321. 12:15deterministic way but just a very good
  322. 12:17thing to keep in mind. Okay so let's
  323. 12:19move on. So in order for the return
  324. 12:21planner agent to function, it needs to
  325. 12:23firstly check some return policies to
  326. 12:25make sure that it's actually fitting
  327. 12:27into the scenario that we're talking
  328. 12:29about. Right? So in this case, we need
  329. 12:31to finally start
  330. 12:34looking into vector database which will
  331. 12:37include things like frequently asked
  332. 12:39questions, policies, all these kind of
  333. 12:41unstructured data that are in
  334. 12:42paragraphs. So that it's because it's
  335. 12:44not easy to search in the table. So it
  336. 12:47will be easier for us to search
  337. 12:48semantically. using vector embeddings.
  338. 12:50This process is also called rag
  339. 12:52retrieval augmented generation. Right?
  340. 12:56It's a very fancy word and a buzz word
  341. 12:58at the same time. But it's important to
  342. 13:00understand that it's basically just
  343. 13:02fetching information through a semantic
  344. 13:05search so that we will get more relevant
  345. 13:08information about this company's return
  346. 13:10policy which the large language model
  347. 13:13does not even know right because this is
  348. 13:15a private data and we want to feed this
  349. 13:17private data into our AI agent. So I'm
  350. 13:20also going to paste the policy in guard
  351. 13:23rails um services here. Right. So what
  352. 13:26this one does is they basically want to
  353. 13:28double check if it fits with the policy,
  354. 13:30right? So there's a bit of a decision-m
  355. 13:33uh mechanism here just from a diagram
  356. 13:35perspective say check policy
  357. 13:38via vector DB and then this vector DB's
  358. 13:42information will go through this policy
  359. 13:44check and we're going to say okay align
  360. 13:47with policy inform the agent. So this is
  361. 13:51a little thinking process for the
  362. 13:52planner agent to go through before we
  363. 13:56trigger any functional calls. You will
  364. 13:59need to define very clearly in the
  365. 14:01prompts for this return planner agent so
  366. 14:04that it knows that you need to firstly
  367. 14:06refer to all the checks. And if you
  368. 14:09realize that one agent is probably doing
  369. 14:10too many tasks, feel free to split it up
  370. 14:12into smaller ones so that it will do
  371. 14:14exact one thing so that it does not
  372. 14:16hallucinate. Here we're sort of a little
  373. 14:19bit oversimplifying the situation but
  374. 14:21just to make sure that you define your
  375. 14:22types and define everything very clearly
  376. 14:25so that your prompts your agent will
  377. 14:27understand what it needs to do exactly
  378. 14:29right so after we finish the ra check
  379. 14:31from the vector database our planner
  380. 14:33agent finally understood okay we need to
  381. 14:36trigger some APIs okay so the first API
  382. 14:38they're going to trigger
  383. 14:40is
  384. 14:42Shopify API if it fits
  385. 14:47the policy
  386. 14:50call Shopify API for return and if the
  387. 14:54next step is about returning the money
  388. 14:56then we should also call the stripe API
  389. 14:58right here. So after the stripe API has
  390. 15:00been introduced which means that we have
  391. 15:02finished the um money return. So the
  392. 15:06stripe API should return the information
  393. 15:09back to the return planner and say okay
  394. 15:13um payment
  395. 15:15refund done. Right
  396. 15:18after this the return planner agent
  397. 15:21should be updating all the context back
  398. 15:24to this Q&A agent because this Q&A agent
  399. 15:27is really doing the conversation with
  400. 15:29the original user channels which
  401. 15:31includes the web chat or the emails.
  402. 15:34Right? So imagine this Q&A agent is just
  403. 15:36like the central brain or the CEO of the
  404. 15:40company who needs to do all the
  405. 15:41communication with their customers and
  406. 15:43then the rest of these people are just
  407. 15:45part of the organization who's doing
  408. 15:47their task right just that the router
  409. 15:49agent is sort of at a higher level
  410. 15:51return planner is the one that the
  411. 15:53router agent decides to route to right
  412. 15:56and then you could also route to
  413. 15:57exchange planner or you know where is my
  414. 16:00order planner all these kind of tools
  415. 16:02right but after this planner has done
  416. 16:05its job, what it should do is that you
  417. 16:07should always update the information or
  418. 16:10the context back to the Q&A agent,
  419. 16:13right? So the Q&A agent is like, okay,
  420. 16:15so um return the latest updates,
  421. 16:22the latest status of return
  422. 16:26back to Q&A agent to talk to the user.
  423. 16:32So this can also include situations when
  424. 16:35the question or the product doesn't fit
  425. 16:38into the policy for return. In this
  426. 16:40case, we will also update the latest
  427. 16:44information back to the Q&A agent. So
  428. 16:46they will be able to talk to um the
  429. 16:48user, right? Respond to the user real
  430. 16:50time. So you can see that we currently
  431. 16:51have a pretty solid system right here
  432. 16:55for the goal we have, right? So what do
  433. 16:57we still need to do? Few things. Number
  434. 17:00one is that as an agentic system, we
  435. 17:04should always be thinking about
  436. 17:06observability
  437. 17:08metrics and evaluations. Okay, remember
  438. 17:10our goal
  439. 17:13is that we need to make sure 70% are
  440. 17:15automation, 30% are looping back to
  441. 17:18human, right? And then the satisfaction
  442. 17:20rate should be over 4.5 and the response
  443. 17:22time should be um this much, right? So
  444. 17:25what we do is that we got to track the
  445. 17:27relevant metrics across the entire
  446. 17:29system to make sure that these metrics
  447. 17:31are being met, these goals are being
  448. 17:33met. Okay. So that's the first thing.
  449. 17:36The second thing is that it depends on
  450. 17:39if um this current website or this
  451. 17:41current client is already dealing with
  452. 17:43some external like say CRM systems
  453. 17:45perhaps there there should be some
  454. 17:48automatic triggers as well for us to
  455. 17:49write back to the CRM. Okay. So we could
  456. 17:53add something like this here.
  457. 17:56a CRM system that will fetch, write,
  458. 17:59deal pipeline or create, update tickets
  459. 18:01for their internal team to manage um you
  460. 18:04know some of the processes, right? So
  461. 18:06I'm just going to add a simple arrow
  462. 18:07here.
  463. 18:10Okay,
  464. 18:12cool. So we got a pretty solid um system
  465. 18:16right here. So again this is a very
  466. 18:18simple overview on how do you think
  467. 18:21about the agentic system um from a
  468. 18:23non-technical background from a
  469. 18:25nontechnical perspective but also I know
  470. 18:27that I have introduced quite a lot of
  471. 18:29technical concepts here too but um if
  472. 18:31you're a technical you realize that
  473. 18:33there are a lot of things that we're
  474. 18:33missing out right there are a lot of
  475. 18:35things that we didn't mention for
  476. 18:36example about scalability about you know
  477. 18:38things that are related to like the
  478. 18:40requests per second seasonality all
  479. 18:42these server side of things I think at
  480. 18:44the end of the day if you're a product
  481. 18:45manager
  482. 18:46you will need to discuss with your
  483. 18:47engineering leader anyways to figure
  484. 18:49these things out. But you need to have
  485. 18:51like this basic concept of what we need
  486. 18:54in order to set up this product ready
  487. 18:56for production. I hope this is helpful.
  488. 18:58I hope uh you have learned something
  489. 18:59from this and let me know if you like
  490. 19:01this kind of format of video. I'm happy
  491. 19:03to make more and I'll probably also be
  492. 19:05making some videos to explain how do you
  493. 19:07actually build a system like this with
  494. 19:08code. So stay tuned. If you like this
  495. 19:10video, like and subscribe and make a
  496. 19:12comment down below. Thanks very much.
  497. 19:14Cheers. Hey everyone, this is Sean. So
  498. 19:15today let me show you how to design and
  499. 19:17build rag like a pro. Rag is basically
  500. 19:20retrieval augmented generation. It's one
  501. 19:22of the most important concept in AI
  502. 19:24system design or for AI agents. And a
  503. 19:27lot of people who watch my previous
  504. 19:28video about AI system design really
  505. 19:30asked me to dive deeper into these kind
  506. 19:32of concepts. So today we're really going
  507. 19:34to dive deeper into what exactly does
  508. 19:36rag work and what exactly is a vector
  509. 19:38database. And I'll not only show you
  510. 19:40something like this, which is a system
  511. 19:42design to think through how do you build
  512. 19:43or design a rag system, but also I'll
  513. 19:46show you some live code which I'll open
  514. 19:48source on GitHub. So feel free to check
  515. 19:50out my GitHub repo. I'll also show you
  516. 19:52how to deploy it to a Google Cloud
  517. 19:54Platform GCP so that if you have a front
  518. 19:57end, you can just connect it into your
  519. 19:58app and start using it right away. Okay,
  520. 20:00cool. Let's jump right into it and
  521. 20:01start. Um, so I've got the system right
  522. 20:04here, but I'm going to just walk you
  523. 20:05through it real quick. And if you
  524. 20:07already know what rag is, feel free to
  525. 20:09jump into the coding part. First, let's
  526. 20:10imagine you're a user and you have a
  527. 20:12user channel. You either talk to
  528. 20:14customer support with web chat or an
  529. 20:15email. And then let's imagine here we're
  530. 20:17using the same example as the last
  531. 20:18video, which is a customer support for
  532. 20:20an e-commerce website where you're going
  533. 20:22to ask questions about certain policies
  534. 20:24about the company. And let's imagine
  535. 20:26like the user has asked a question and
  536. 20:28that question is speaking to an AI
  537. 20:29agent. We have an AI agent that will
  538. 20:32speak to the user interface. So let's
  539. 20:34say the user has sent a question, ask a
  540. 20:38question to the UI agent and then the AI
  541. 20:41agent is supposed to respond with an
  542. 20:44answer. The AI agent might not
  543. 20:46understand when you can return a product
  544. 20:49for e-commerce site or D2C brand because
  545. 20:51maybe some of the products are over $200
  546. 20:54and you cannot just return the money to
  547. 20:55the user and you must check a certain
  548. 20:57policy or you must ask a certain manager
  549. 21:00to approve the return, right? So, how
  550. 21:02would an AI agent know if this is an
  551. 21:04LLM? It has no access to your private
  552. 21:06data about your e-commerce site. Then,
  553. 21:08we're going to introduce this concept
  554. 21:09called a vector database, which will
  555. 21:11store some of the policies about your um
  556. 21:14company uh return policy. And also, we
  557. 21:17will use the system that will do the
  558. 21:19retrieval to let the agent to retrieve
  559. 21:22the information from the database and
  560. 21:24then get informed so that the LM knows,
  561. 21:26oh, anything over $200, we cannot just
  562. 21:28return money back to you. We must talk
  563. 21:30to a manager. Okay, so let's break it
  564. 21:33down and see what exactly will happen
  565. 21:34here. So as I mentioned, we need a
  566. 21:38vector database. Okay, it's a vector
  567. 21:40database that will store things like
  568. 21:42FAQs, policies, these kind of things.
  569. 21:44And the way that the AI agent will speak
  570. 21:46to it is basically
  571. 21:50a rack
  572. 21:52which is going to check the policy and
  573. 21:55then the way that this vector database
  574. 21:57is built is very simple. Okay, so we're
  575. 22:00going to create a frame here. The first
  576. 22:02one is that you might have a bunch of
  577. 22:04original documents. Okay, some of these
  578. 22:06documents could be in like PDF or could
  579. 22:09be like a very long paragraph. So in
  580. 22:11order for this AI agent system to run
  581. 22:13very efficiently, we need to introduce
  582. 22:16this concept called text to chunks or
  583. 22:18anything PDF to chunks so that every
  584. 22:20little chunk is a piece of condensed
  585. 22:22information so that we're not like
  586. 22:24overwhelming the system. Okay. Then
  587. 22:26later we're going to need to turn these
  588. 22:28chunks into a thing called embeddings.
  589. 22:32So what is an embedding? An embedding is
  590. 22:35basically an array of numbers in a very
  591. 22:37large dimension. What I mean by that is
  592. 22:39that say okay now I'm going to input
  593. 22:41these words into chachbt and it's going
  594. 22:44to give me an answer. The way chach
  595. 22:46understood it is not like hey I you just
  596. 22:48it processes all the words. Instead it's
  597. 22:51processing a bunch of numbers. So every
  598. 22:53little word that you see here
  599. 22:55to chache is probably a 10,00 dimension
  600. 22:58vector with like 0.01 0.67 0.86 all the
  601. 23:03way until the 1,500 something dimension.
  602. 23:07Okay. So that the the machine will
  603. 23:09understand okay so with different
  604. 23:11numbers at different dimension or at
  605. 23:14different space it means differently.
  606. 23:16Okay. So in math there's a concept
  607. 23:18called vector similarity or embedded
  608. 23:21similarity. What it does is that maybe
  609. 23:23like the word of you know French, uh,
  610. 23:26Spanish, Chinese, these are all
  611. 23:28languages. So they're probably similar
  612. 23:30in higher dimensions in mathematics.
  613. 23:32Okay, but this is not the focus of this
  614. 23:34video. If you're not technical or
  615. 23:35technical, doesn't matter. Okay, so what
  616. 23:37we do is that we're going to use the
  617. 23:38tools that already built for us and
  618. 23:40we're going to use it well so that the
  619. 23:42system will function properly. Okay,
  620. 23:45this process is actually called seeding.
  621. 23:49I'm going to show you in the code in the
  622. 23:50real example very soon. Okay. So after
  623. 23:52we did the seeding,
  624. 23:54you have put your policy into these
  625. 23:56chunks of embeddings and then feed it
  626. 23:58into the vector database. What happens
  627. 24:01next is that because now the agent is
  628. 24:04doing the retrieval augmented generation
  629. 24:06by referring to the database in the
  630. 24:09vector database and just searching for
  631. 24:11the relevant information. We're turning
  632. 24:13the customer question into embeddings as
  633. 24:15well. And we're calculating, hey, what
  634. 24:17kind of chunks are actually relevant
  635. 24:19here so that we'll be able to align with
  636. 24:22the policy. Let me just draw this
  637. 24:25diamond here real quick.
  638. 24:28We're going to align with this policy
  639. 24:33and then we're going to inform
  640. 24:36sorry and then we're going to inform the
  641. 24:39AI agents
  642. 24:41so that it knows what exactly is going
  643. 24:43on with the policy. Okay. So this is
  644. 24:47already a very simple system designed
  645. 24:50for um rag for retrieval argument
  646. 24:53generation and vector database. So now
  647. 24:55I'm going to show you a real example of
  648. 24:57how do you interact with a rack system
  649. 24:59with an use case of a customer support
  650. 25:01for e-commerce DTOC brand. So I'm just
  651. 25:04going to type in the website. So you can
  652. 25:05see that this is a live link. You guys
  653. 25:07can try it as well. Um now we're landing
  654. 25:09in this chatbot. Not a big surprise. But
  655. 25:12now we have like four documents on the
  656. 25:14right hand side which are all related to
  657. 25:15the policy of um say for example how
  658. 25:18about returns, how about shipping uh the
  659. 25:20guide of the sizing as well as the
  660. 25:22support for contact. And let's just do
  661. 25:24it in one example, which is um for for
  662. 25:27the shipping policy, there's free
  663. 25:29shipping for anything that's over $50.
  664. 25:31So if I just ask a question be like, I
  665. 25:33bought my
  666. 25:36shoes for $80. Can I get it shipped for
  667. 25:42free and send it over?
  668. 25:46Could have chosen a better color, but
  669. 25:48this is not the focus of uh this video.
  670. 25:50This just front end. They say, "Yeah,
  671. 25:52you can get free standard shipping since
  672. 25:54your order is over $50. According to the
  673. 25:56policy, it's okay as long as it's below
  674. 25:58$80." So, I'm going to say, "I bought a
  675. 26:00pair of shoes for $30, which is very
  676. 26:04unlikely. Uh, can I get it shipped for
  677. 26:08free?"
  678. 26:10Ask the question, and then let's see
  679. 26:12what the rag would say.
  680. 26:15Okay, it told me, "Uh, your your thing
  681. 26:17is not qualified because under $30 for
  682. 26:19free shipping. Uh, there's a $50
  683. 26:20threshold." Okay, that's one example.
  684. 26:22Let's do another example. Let's say,
  685. 26:24okay, there's a return policy and says
  686. 26:26that every item that's over $200 require
  687. 26:28manual approval for returns and you need
  688. 26:30to email the company. So, I say, okay,
  689. 26:32can I return the shoes that I bought for
  690. 26:38um $1,000.
  691. 26:44Now, it's doing the retrieval, doing the
  692. 26:45thinking, doing the similarity search,
  693. 26:47and it's going to tell me very soon.
  694. 26:49Okay. Yes, you can return the shoes, but
  695. 26:50since the purchase amount over $200,
  696. 26:53you'll need the manual approval first.
  697. 26:54Okay, so you can see that this entire
  698. 26:56conversation with this chatbot has been
  699. 26:58strictly following the policies on the
  700. 26:59right hand side. And you might argue
  701. 27:01that why don't I just like feed these
  702. 27:02information into chatbt? Why do I need a
  703. 27:04rag here? Well, you're right. In this
  704. 27:07case, we don't really need a rag. But
  705. 27:09imagine this policy is like instead of
  706. 27:11three paragraph for each, it could be
  707. 27:13300 pages. Imagine you're dealing with
  708. 27:15like legal documents or stuff like that.
  709. 27:17And then that would be a different
  710. 27:18story. Okay, so in this example, we're
  711. 27:20just showing you an MVP of how it works
  712. 27:22and how you actually build it and make
  713. 27:24sure you understand the concepts. And
  714. 27:26then if you're like scaling things up,
  715. 27:28there are more things that you need to
  716. 27:29deal with for the back end. Okay, so
  717. 27:32let's try another thing real quick.
  718. 27:34Let's say, okay, if anything is over um
  719. 27:38$2,000, then that would need an annual
  720. 27:40approval. Okay, if I save this
  721. 27:45and I've asked the question again, I
  722. 27:46say, "Okay, can I return the shoes that
  723. 27:49I bought for $1,000?"
  724. 27:57It told me, "Yes, you can return for
  725. 27:59$1,000 as long as they meet these
  726. 28:01criteria. They're unworn, blah blah
  727. 28:03blah. And since your purchase is under
  728. 28:05$2,000, you don't need any special
  729. 28:07approval for return." Look at this. It's
  730. 28:08like immediate once I like update my my
  731. 28:11vector database for these
  732. 28:12documentations. Immediately my app will
  733. 28:15know what exactly is a policy. How easy
  734. 28:18is that? Right? Imagine you have like
  735. 28:19300 pages of policy documents as long as
  736. 28:21you edit it real quick and then database
  737. 28:23sort of re-mbbed um the entire policy
  738. 28:25and your robot knows exactly how to
  739. 28:27answer your questions. Okay, I think
  740. 28:29this is very convenient and now let me
  741. 28:32show you how to actually build it and
  742. 28:33use it. Okay, you don't actually need to
  743. 28:35build anything. I already prepared the
  744. 28:37GitHub repo for you. It's open source,
  745. 28:39completely free. Just try it. Okay, so
  746. 28:41my GitHub is right here. It's got
  747. 28:43shenanT-ra.
  748. 28:45YT stands for YouTube. Rack stands for
  749. 28:47retrieval augmented generation. Okay, so
  750. 28:50if this is the first time you're going
  751. 28:52to touch code, don't freak out. What you
  752. 28:54can do is that you can just sort of you
  753. 28:56can honestly you can just like command A
  754. 28:58and copy and then paste the whole thing
  755. 29:00into chat GPT or into cursor and ask it
  756. 29:03to tell you what you're going to do. All
  757. 29:05right. Well, in this case, I'm going to
  758. 29:06show you step by step how to do this and
  759. 29:08launch this as a fullstack product and
  760. 29:10um so that you can like link it to your
  761. 29:12own project. You can even try it in your
  762. 29:14own real business. Okay. And if you're a
  763. 29:16business in e-commerce brands, feel free
  764. 29:18to let me know. Happy to do some um
  765. 29:20extra sessions with you uh if you're
  766. 29:22interested in me helping you out with
  767. 29:24these AI automation. Okay. Let's jump
  768. 29:26right into it. Cool. So, uh what we're
  769. 29:29going to do is that firstly I'm going to
  770. 29:31clone the code. I'm going to say copy
  771. 29:33this clone. Okay. And then I'm going to
  772. 29:36turn on my favorite app, which is
  773. 29:38cursor. Uh let me create a new window
  774. 29:41here. Okay. So, uh I'm going to go into
  775. 29:45my um
  776. 29:49uh so I'm going to open my project uh
  777. 29:52desktop developer
  778. 29:54and YT rag and I'm going to say okay
  779. 29:58YT-R
  780. 30:01showcase. Okay, create that. Open.
  781. 30:06All right, I just created this new
  782. 30:07folder in cursor called yt-rag-
  783. 30:10showcase. What you got to do is that you
  784. 30:12got to turn on this terminal. Okay, and
  785. 30:15then what you got to do is you're going
  786. 30:16to say get clone and then paste this in.
  787. 30:20All right, you see now you got this, you
  788. 30:22got this open source project. Okay, so
  789. 30:25how do we deploy this and how do we use
  790. 30:27this? All right, let me try to guide you
  791. 30:30through the readme documents. So
  792. 30:32firstly, we have um this architecture
  793. 30:34that has an app that has the core
  794. 30:36service, a core folder that will
  795. 30:39basically define the configuration and
  796. 30:40infrastructure. We have the models,
  797. 30:42pyenic models that basically defines
  798. 30:44what are the data types that are going
  799. 30:45to be required for every model or every
  800. 30:47API. And we're going to have a service
  801. 30:49model, sorry. Then we're going to have a
  802. 30:51service folder that's going to deal with
  803. 30:52all the business logic regarding rags,
  804. 30:55embeddings, AI agents, all these kind of
  805. 30:56stuff. All right. And then we have a
  806. 30:58main.py, which is a fast API application
  807. 31:00for the back end. If this is your first
  808. 31:02time to deal with backend, trust me,
  809. 31:05don't freak out. This is super easy. I'm
  810. 31:07not from a computer science background.
  811. 31:09I learned all of this by myself through
  812. 31:11AI. And you can do this, too. And I'm
  813. 31:12going to show you how to do it. Okay,
  814. 31:15cool. So, we already did the first step,
  815. 31:17which is get clone. And now all we got
  816. 31:19to do is got we got to go back to let me
  817. 31:22just set it set this up. Now we got to
  818. 31:24do is that we got to go to cdt-ra.
  819. 31:28Okay, as this said and then we're going
  820. 31:30to create this virtual environment.
  821. 31:31Literally just copy this. Okay, paste it
  822. 31:35in your terminal. All right, so what
  823. 31:37this did is that created this virtual
  824. 31:39environment called uh vm_yt-ra
  825. 31:44and then you can basically install your
  826. 31:45Python packages in it. Okay, so we
  827. 31:48already have our Python packages ready
  828. 31:49which is in requirements.tsx.
  829. 31:52We only using these few. All right, and
  830. 31:54just paste this in
  831. 32:00and you're going to install the packages
  832. 32:01you need for running this project. Okay.
  833. 32:06And then we're going to need to set up
  834. 32:08our vector database. In this case, we're
  835. 32:10using Superbase. For the vector
  836. 32:11database, we're going to use the PG
  837. 32:12vector. I know there are a lot of
  838. 32:14options on the market. There's Pine
  839. 32:15Corn, there's Reviet, and we're not
  840. 32:17talking about which one is better here.
  841. 32:19I'm just talking about how it works.
  842. 32:21Okay, feel free to try other tools if
  843. 32:23you want to. Okay, cool. Let's get
  844. 32:25started. Um, so the reason why we need
  845. 32:28to set up Superase, one is because we
  846. 32:30need to set up this place where it's
  847. 32:32going to store these policies for
  848. 32:34documentations. Number two is that we
  849. 32:36need these keys from Superbase so that
  850. 32:38our app is connected to the database so
  851. 32:40that they're communicating with each
  852. 32:41other. Okay, just follow me. Like trust
  853. 32:43trust me like this is pretty easy. We
  854. 32:45can do this. Cool. So let me start uh
  855. 32:48creating a new superbase project for us.
  856. 32:51Uh
  857. 32:53superbase.com.
  858. 32:55Okay. If I go to dashboard, let's make
  859. 32:58it bigger. I can go to YouTube. You can
  860. 33:01see that I already have a yt-ra. I'm
  861. 33:03going to create a new one just for this
  862. 33:05showcase. You can click on new project.
  863. 33:08And then I'm going to say yt-rag-
  864. 33:12um showcase. And then I just input in my
  865. 33:15database password. And let's just create
  866. 33:18the project.
  867. 33:20I'm going to delete this later. So don't
  868. 33:23even try to use things here because I'm
  869. 33:25going to show some keys here. And I'm
  870. 33:27going to just delete it. Don't try to
  871. 33:28use it. And you should set it up
  872. 33:29yourself. Okay. Um cool. So now we set
  873. 33:33up this superb basease. Let's see what's
  874. 33:35what's going to happen next. Okay. Let's
  875. 33:36come back to the GitHub. You see that?
  876. 33:38Wait for the project to be ready and
  877. 33:39then go to settings and get all these
  878. 33:41APIs and copy them into our um uh into
  879. 33:45our code. All right. So, let's I'm going
  880. 33:46to do it. So, go to superbase,
  881. 33:50come over here. I think if I just scroll
  882. 33:52down. Yeah, but if you just scroll down,
  883. 33:54you can see that there's project URL and
  884. 33:56API keys here. And then we're just going
  885. 33:58to literally going to um firstly, we can
  886. 34:01see that there is a file called uh
  887. 34:04M.ample. All right, we're just going to
  888. 34:07copy this and paste this again. And
  889. 34:09we're just going to call it M instead of
  890. 34:11M example.
  891. 34:13So that this is for production. And then
  892. 34:15we're going to copy the project URL
  893. 34:17here. Click on copy. You can see there's
  894. 34:19a project URL. Replace this with the
  895. 34:21real one. And then you can see that
  896. 34:23there's this Anom public key. Copy that.
  897. 34:26Come here. Replace the second one with
  898. 34:28it. Hit command S to save it. Third one
  899. 34:31is a service ro key. Service ro key is
  900. 34:33right here. Let's see. Uh let's go to um
  901. 34:37project setting and then we can find API
  902. 34:39keys and then we can see this service
  903. 34:41row key. All right. Going to reveal it.
  904. 34:43Copy it. Come back here. Paste it in.
  905. 34:47Command S to save it. Okay. I'm going to
  906. 34:49delete all these projects. So if we
  907. 34:50click back into table editor, you can
  908. 34:52see that we don't have tables now. We're
  909. 34:54going to set it up real quick. All
  910. 34:55right. One small thing is that you can
  911. 34:57see that in this environment variables
  912. 34:58right now, um there's an AI provider.
  913. 35:01I'm choosing anthropic. You can also
  914. 35:03replace it with open AAI, right? And
  915. 35:04then there's also like this OpenAI key,
  916. 35:07OpenAI embedding model. We're actually
  917. 35:08using this embedding model to embed
  918. 35:10these words. Remember we say we're going
  919. 35:12to turn every word into a 1,500
  920. 35:15dimension of numbers, right? And then
  921. 35:18we're going to use OpenAI. If you're if
  922. 35:19you're using OpenAI, you're going to use
  923. 35:21GBT40. If you're using Enthropic, you're
  924. 35:24going to use enthropic chat model, which
  925. 35:26is in our case, I'm going to use 3.5.
  926. 35:28Doesn't matter. Choose whatever you
  927. 35:29want. Okay. Last but not least, the
  928. 35:31environments development and log info is
  929. 35:33info right now. Okay. So, what's missing
  930. 35:36in the environment variable is just I
  931. 35:38need my open AI key and my uh anthropic
  932. 35:41API key. Okay.
  933. 35:43Um, so I'm going to just going to paste
  934. 35:44my own keys here. Here I'm going to
  935. 35:46block it. And if you don't know where to
  936. 35:48find it, you can just find you can just
  937. 35:49literally search OpenAI API key on
  938. 35:52Google and then you can just create an
  939. 35:55OpenI key. Login if you haven't logged
  940. 35:58in. Just click on create new keys and
  941. 36:00type a name here and then copy it,
  942. 36:02right? And then you're going to start
  943. 36:03using it. Enthropic is the same thing.
  944. 36:05Now we're going to initialize the
  945. 36:07database. The way we do that is we have
  946. 36:10a file called SQL/init
  947. 36:14superbase.sql. Just do command A,
  948. 36:16command C. Come to your superbase. Come
  949. 36:19to the left hand side. There's a SQL
  950. 36:21editor. Open it. Click in. Command V to
  951. 36:24paste it. Command enter to run it.
  952. 36:29Okay, you see, oh, your superbase
  953. 36:30database is ready for rag. Okay, what
  954. 36:32did we do exactly? I'll ver briefly
  955. 36:34explain. Go to the left side bar. Let me
  956. 36:36just make it bigger for you. Go to the
  957. 36:38left side bar. Click on table editor.
  958. 36:40You can see there's a table here called
  959. 36:41rag chunks. Okay, remember earlier we
  960. 36:45said we need to do this thing called
  961. 36:48seeding, which we're going to turn
  962. 36:49original documents into text chunks and
  963. 36:52then embed the text chunks. Okay, here
  964. 36:54I'm going to show you how to do that
  965. 36:55exactly. So for now you can see this
  966. 36:58table that has ID chunk ID source where
  967. 37:01does the chunk come from text what
  968. 37:03exactly is in that chunk what is the
  969. 37:05embedding for this text right when is it
  970. 37:08created that's all u we're just keeping
  971. 37:10things simple here if you go to the
  972. 37:12sidebar and click on database you can
  973. 37:14see that there's one table here listed
  974. 37:16and then you can also click into
  975. 37:18functions okay why we're in the
  976. 37:20functions that's because if we go back
  977. 37:23to uh this we actually defined some
  978. 37:26functions here. One function is called
  979. 37:28match chunks. You can just copy this and
  980. 37:31come back here and then search match
  981. 37:32chunks. You see this is basically doing
  982. 37:35like matching like doing the retrieval,
  983. 37:37right? Comparing if your query embedding
  984. 37:39is similar to the embedding that you
  985. 37:41added to the chunk. All right. And
  986. 37:42there's several other functions that we
  987. 37:44defined. Um there's also a function
  988. 37:46called
  989. 37:50There's also a function called get chunk
  990. 37:52stats, right? Let's just search this row
  991. 37:54here. Here real quick. Yeah. And you can
  992. 37:56also click on these three dots and click
  993. 37:58on edit function to edit things. And if
  994. 37:59you're familiar with the SQL, you will
  995. 38:01know what's going on. It's going to it's
  996. 38:02going to s select from the rack chunks
  997. 38:04and count how many total chunks you
  998. 38:06have. Uh what are some unique sources
  999. 38:08you have and what are some of what is
  1000. 38:10the total maximum sorry and what is the
  1001. 38:12latest time when you update the chunk
  1002. 38:13table. Okay. So this is called superbase
  1003. 38:15functions. Again, this is not the focus
  1004. 38:17of the video. If you're interested in
  1005. 38:18superbase, feel free to watch my
  1006. 38:19previous videos on superbase. Let's move
  1007. 38:21on. Continue.
  1008. 38:23Come back to this. You can see that we
  1009. 38:25initialized the database. Um so here one
  1010. 38:29thing to interesting to explain is that
  1011. 38:31we're using this thing called pg vector
  1012. 38:32which is part of postgress and it's
  1013. 38:34basically a way to save vector database
  1014. 38:36right again feel free to use pine con we
  1015. 38:39or lchain stuff all these things work
  1016. 38:41right doesn't matter you don't have to
  1017. 38:42use this one okay so with the rack
  1018. 38:44chunks crael currently we're using um a
  1019. 38:47vector of dimension 372 dimensions so
  1020. 38:50that's like doubling of 1,500 when I
  1021. 38:52said it okay so uh now let's move on
  1022. 38:57uh oh sorry now let's move on so you can
  1023. 39:00see that I have this thing called test
  1024. 39:02setup.py okay let's come back here and
  1025. 39:05see where is it we have this file called
  1026. 39:07test setup.py Pi. So what this test up
  1027. 39:09do does is that I'm doing a few things.
  1028. 39:11Firstly, I'm going to import the
  1029. 39:12modules. Second, I'm going to check the
  1030. 39:14configuration and then I'm going to
  1031. 39:16start doing the database connection and
  1032. 39:18then I'm going to start doing the schema
  1033. 39:19validation. And now I'll do the seeding
  1034. 39:22documentation. Look at this. I'm doing
  1035. 39:23the seeding documentation so that we are
  1036. 39:25seating the documents into our database
  1037. 39:28so that later we can do the rack query.
  1038. 39:30I'm going to show you step by step.
  1039. 39:31Okay. Uh feel free to just run this doc
  1040. 39:33if you're familiar with this. But if
  1041. 39:34you're not familiar with this, I'll show
  1042. 39:35you what exactly we're going to do.
  1043. 39:37Okay, so firstly, how does seating work?
  1044. 39:40Okay, so the main.py is an app
  1045. 39:42slashmain.py.
  1046. 39:45Okay, so this is basically a backend
  1047. 39:47endpoint. What it does is that sorry,
  1048. 39:50maybe it looks scary if you're not
  1049. 39:51technical, but I'll explain everything
  1050. 39:52as I as I as I always mention. Okay,
  1051. 39:55first you have this live span
  1052. 39:57definition. What it does is basically
  1053. 39:58just going to try to, you know, connect
  1054. 40:00to the database, initialize the schema,
  1055. 40:02all these kind of stuff. And then we
  1056. 40:04have this thing called fast API. We're
  1057. 40:05defining fast API as this name called
  1058. 40:08app. So anything with app app do
  1059. 40:10something app do something that's fast
  1060. 40:12API. Okay. And we're going to add this
  1061. 40:14middleware which is basically saying hey
  1062. 40:16local host 3000 local host 30001 they're
  1063. 40:18accessible to this back end. Because if
  1064. 40:20you're building like the front end with
  1065. 40:21an XJS you'll be able to you know use
  1066. 40:23localhost 3000 or recell as your URL.
  1067. 40:27We're just basically telling the back
  1068. 40:29end that these URLs are access can
  1069. 40:31access you right so that there's no
  1070. 40:33access issues.
  1071. 40:36Um and then we have a chat interface uh
  1072. 40:39which is an HTML. Here we're not using
  1073. 40:41X.js. We're just using a plain front
  1074. 40:43end. Okay. And then um what's important
  1075. 40:46is that we can just sort of like start
  1076. 40:48trying things. Okay. So what I'm going
  1077. 40:50to do is that remember to do source
  1078. 40:53vimt_ra
  1079. 40:56bin slash uh activivate. So, what you
  1080. 41:00can do is just you can type in uvorn
  1081. 41:03main app-reload.
  1082. 41:06After we run this, we're going to get uh
  1083. 41:08a live backend called 127.0.0.18000.
  1084. 41:16Okay. So, if I just do commandclick on
  1085. 41:18this thing, it's going to show me this
  1086. 41:20thing called welcome to Rack AI Asian
  1087. 41:22backend version blah blah blah blah blah
  1088. 41:23blah blah. Okay. And a quick way to
  1089. 41:26check it is that there's this thing
  1090. 41:28called um basically you can check either
  1091. 41:30the health of it or you can do something
  1092. 41:32fun like for me I did like slashgreet
  1093. 41:34slashname so that it will tell me uh if
  1094. 41:37it actually worked. So if you go to this
  1095. 41:39URL and do slash greetan
  1096. 41:42it's going to tell you hey Sean I think
  1097. 41:44you're great. Okay and if I just greet
  1098. 41:46like Donald I think you're great. So so
  1099. 41:49this is like working. Okay, this is
  1100. 41:51working. And uh or you can just type in
  1101. 41:54uh slash health,
  1102. 41:58right? And then it's going to tell you,
  1103. 41:59oh database connected is true. All
  1104. 42:01right, so now let's move on.
  1105. 42:05So here are the three things that are
  1106. 42:06very important. The first one is an
  1107. 42:08endpoint called the slash documents.
  1108. 42:10This is where we're going to save all
  1109. 42:11the documents. Okay, so if you go to
  1110. 42:13slash documents, it's going to return to
  1111. 42:15you what documents you have. All right,
  1112. 42:17so let's try that. So if you do slash
  1113. 42:21documents you can see all the documents
  1114. 42:23we have I'll show you in the code where
  1115. 42:26is it where is it so if I just do double
  1116. 42:29click command default command c command
  1117. 42:31f command v search you can see that we
  1118. 42:34imported from this okay which is where
  1119. 42:37is it
  1120. 42:39uh from data slashdefault documents so
  1121. 42:42from data folder where's data folder
  1122. 42:45there we go data folder/default
  1123. 42:47documents So these are the documents for
  1124. 42:49the policies that we're going to input.
  1125. 42:51All right. So we're going to have a
  1126. 42:53policy for return as I if you still
  1127. 42:56remember in our app we have a policy for
  1128. 42:58return v1 policy for shipping sizing
  1129. 43:01guide and support contact. Okay. So we
  1130. 43:04have basically the exact same thing.
  1131. 43:05Policy return policy for shipping policy
  1132. 43:09for sizing and policy for support
  1133. 43:11contact. Okay. So if we go back to
  1134. 43:13main.py.
  1135. 43:16So if you go to go back to app/main.py,
  1136. 43:19if you call the API of u the URL/d
  1137. 43:23documents, it's basically going to show
  1138. 43:25you the default documentations as I
  1139. 43:26showed you earlier. Okay. Another
  1140. 43:28endpoint is called slash seed. What this
  1141. 43:30one does is they're going to take the
  1142. 43:31input of the documentation and then
  1143. 43:33start showing you, you know, hey, we're
  1144. 43:35going to we're going to we're going to
  1145. 43:36like turn your documents into chunk ID,
  1146. 43:40source, and text. Remember, this is how
  1147. 43:42we're going to store it in the database.
  1148. 43:43All right. So this API I'm literally
  1149. 43:45going to show you how to turn these
  1150. 43:46documentation into the database. All
  1151. 43:48right. So what it does is that it
  1152. 43:50firstly split your thing into chunks.
  1153. 43:54All right, split thing into chunks and
  1154. 43:56then it's going to show you and then
  1155. 43:59it's going to run this function called
  1156. 44:00rack service C documents. You can do
  1157. 44:03commandclick into this. Sorry.
  1158. 44:07And then it's going to run this function
  1159. 44:09called the rack seed documents. Okay.
  1160. 44:12And then it will get to this the
  1161. 44:14inserted account. So, so how did how did
  1162. 44:16the whole thing happen? Right? Let me
  1163. 44:18show you. So, if you do if you run this
  1164. 44:21API, if you run this API, what it does
  1165. 44:24is that it's going to run this function
  1166. 44:25for you. Okay, let's find out where is
  1167. 44:27this function. Command C, command F,
  1168. 44:29command V. All right, we define it in
  1169. 44:33services.rag.
  1170. 44:35Right, we have a folder called services.
  1171. 44:37This is basically where we're going to
  1172. 44:38save all these AI agents, right? Or
  1173. 44:40agent related stuff. So let's go go to
  1174. 44:42the rag.py. Within the rag.py, remember
  1175. 44:46like we I mention remember I mentioned
  1176. 44:48that we have a function called seed
  1177. 44:49documents. What this one does is that
  1178. 44:51it's going to turn your documents into
  1179. 44:53chunks and turn chunks into embeddings.
  1180. 44:56Okay, so let's briefly go through it. We
  1181. 44:58have a function here that say okay we're
  1182. 45:01going to use the chunk function to chunk
  1183. 45:03the documentations and then we're going
  1184. 45:05to embed the documentation using
  1185. 45:07embedding service which is imported from
  1186. 45:09embedding.py. Pi. And last but not
  1187. 45:12least, we're going to combine the chunks
  1188. 45:13into embeddings so that we can insert it
  1189. 45:15into the database. Okay. Um, let's check
  1190. 45:18the embedding. Let's check the
  1191. 45:20embedding.py real quick, too. In the
  1192. 45:22embedding, what we do is that you can
  1193. 45:24see that here we have embed text. What
  1194. 45:27it does is it uses this OpenAI client
  1195. 45:29with embeddings to create the embeddings
  1196. 45:31based on the text input. Remember, we
  1197. 45:33already cut the text into smaller
  1198. 45:35chunks. So, it's going to it's going to
  1199. 45:36embed every text into embeddings. Okay.
  1200. 45:39I know I say a lot of tongue twisters.
  1201. 45:41Let's just run it and see what happens.
  1202. 45:43All right. So all you got to do is that
  1203. 45:45if you have defined properly of your
  1204. 45:48default documentations, what we can do
  1205. 45:50is that we can just do test the setup to
  1206. 45:53set up the whole thing. Okay. So come to
  1207. 45:55your terminal again if you're are not in
  1208. 45:58your virtual environment do source
  1209. 46:00vt-_rag
  1210. 46:04bin activate. Okay. And then we're going
  1211. 46:06to do a Python test setup. Now it's
  1212. 46:11going to run this setup and I'll show
  1213. 46:13you what exactly we're doing.
  1214. 46:16So we imported the modules testing the
  1215. 46:19configuration did the database
  1216. 46:20connection schema documentation seating.
  1217. 46:23You can see that it successfully seated
  1218. 46:25the four document chunks and then it
  1219. 46:27tested the rag. It worked. Okay. And it
  1220. 46:29passed everything. Okay. So now if we go
  1221. 46:34back to the database,
  1222. 46:36go to the left sidebar, table editor,
  1223. 46:40you're going to see all four
  1224. 46:41documentations are here. All right.
  1225. 46:44Policy, return, shipping, guide,
  1226. 46:46contact, and you can see where the
  1227. 46:48sources from and you can see what the
  1228. 46:50text exactly is if you double click on
  1229. 46:52it. Okay. Anything that items over $200
  1230. 46:54require manual approval for return. And
  1231. 46:56then there's this embedding that is
  1232. 46:583,000 columns of dimension. And if you
  1233. 47:01do this slash chat, you were to turn it
  1234. 47:04on. And now you have these policies
  1235. 47:06right here. Okay. So this is literally
  1236. 47:08using what we defined here. Okay. So let
  1237. 47:12me prove it to you by making this a
  1238. 47:14little bit smaller. Making this a little
  1239. 47:16bit smaller.
  1240. 47:18And our eye should be focused on our
  1241. 47:20terminal here. Okay. So what we got to
  1242. 47:22do is that I'm just going to say okay
  1243. 47:25what is what is my return policy and hit
  1244. 47:29send. You can see that here it's running
  1245. 47:32because now it's doing the vector
  1246. 47:34database retrieval and you can see that
  1247. 47:36it's using anthropic. All right. And
  1248. 47:39then it did the query processing with
  1249. 47:41one citation. So that means it find one
  1250. 47:44reference one citation. All right. Which
  1251. 47:46is the policy that we refer to return
  1252. 47:49policy. Okay. And I just asked the
  1253. 47:51question again. Can I return for return
  1254. 47:54my product that was $800?
  1255. 48:00You see now it's doing this another uh
  1256. 48:02retrieval again. And then you see they
  1257. 48:03it tells me since your item is already
  1258. 48:05$200, you'll need manual approval for
  1259. 48:07the return. Okay. So now we prove that
  1260. 48:09this rack system already works, right?
  1261. 48:11It already works.
  1262. 48:14One more thing I want to show you is the
  1263. 48:15chat. If you click on serviceshat.py,
  1264. 48:18Pi. You can see that we're currently
  1265. 48:19doing this function called generate
  1266. 48:21answer. What this one does is that
  1267. 48:23there's a system prompt, right? It says
  1268. 48:25that you're a helpful AI assistant for
  1269. 48:27customer support. And there's some
  1270. 48:28important rules. You basically say you
  1271. 48:30can only answer questions for policy,
  1272. 48:32return, shipping, and sizing. And you
  1273. 48:34should for questions outside of
  1274. 48:35knowledge base, you can just politely
  1275. 48:37reject that. All right. And then we can
  1276. 48:39just test it real quick too. You can say
  1277. 48:42uh who is the US president now?
  1278. 48:52Yeah, I apologize. It's not relevant.
  1279. 48:55So, he's not going to answer me. Okay.
  1280. 48:57Feel free to play around with this
  1281. 48:58GitHub if you're technical. And if
  1282. 49:01you're not technical, if you follow this
  1283. 49:02exact steps that I talked about, you can
  1284. 49:04set this up for your business. Happy to
  1285. 49:06help you to set up for you if you're
  1286. 49:07interested in this kind of AI
  1287. 49:09automation. And the last step I do is
  1288. 49:12I'm going to make this live. I always
  1289. 49:14always want to make product live because
  1290. 49:15I feel like that's the final step you
  1291. 49:17do. Like that's that's the core of
  1292. 49:19building a product. It needs to be live.
  1293. 49:21It needs to be able to be used by
  1294. 49:22someone. Let's do that. Cool. So, um
  1295. 49:27what I'm going to do is I'm going to go
  1296. 49:29to my u Google cloud. So, I normally use
  1297. 49:32Google Cloud for this. And I'm I already
  1298. 49:35have a project. If you don't have a
  1299. 49:36project, feel free to click on here and
  1300. 49:38then click on create a new project.
  1301. 49:40Okay? But that's not in the scope of
  1302. 49:41ours. So, I already have a project. I'm
  1303. 49:43going to go right into Cloud Run on the
  1304. 49:45left hand sidebar. Okay. And then I'm
  1305. 49:47going to select a project which is the
  1306. 49:49project I created. And you can see all
  1307. 49:51the project I have here. And I already
  1308. 49:53have one called YT-Rack. And the rest of
  1309. 49:55them are my previous projects. So what I
  1310. 49:57do is that I first need to commit the
  1311. 49:59code to the GitHub. And then we can
  1312. 50:01connect it through GitHub into Google
  1313. 50:04Cloud. Okay. So let's try this real
  1314. 50:07quick. Let's come back to cursor.
  1315. 50:10And one thing I didn't show you earlier
  1316. 50:12is how to connect to GitHub. And if you
  1317. 50:14are creating your own thing, you can
  1318. 50:16also come back to your folder and do
  1319. 50:18remove- rf uh git. Okay. Hit run. Create
  1320. 50:22a new repository. Okay. And I'm just
  1321. 50:25going to say yt- um rack slash um
  1322. 50:31private
  1323. 50:32showcase. Okay. Create the repository.
  1324. 50:37Get remote ad. Make sure you make sure
  1325. 50:40you navigate your folder into YT-R and
  1326. 50:44then get branch man.
  1327. 50:47Okay, let's come back here. Command R to
  1328. 50:49refresh it. Cool. This is good. Um, so
  1329. 50:52now we got this. All right, we got the
  1330. 50:55whole thing. Let's come back to Google
  1331. 50:57Cloud.
  1332. 50:58Let's click on connect repo in Cloud
  1333. 51:02Run.
  1334. 51:04Let's set up the cloud build name. All
  1335. 51:06right. And then I'm gonna click on here
  1336. 51:09to repository. I can say yt-rag dash.
  1337. 51:12You can see I have two of them but I'm
  1338. 51:14going to use the private showcase
  1339. 51:16understand. Next
  1340. 51:24okay we're going to use this thing
  1341. 51:26called docker file. Okay. What this one
  1342. 51:28does is basically telling Google cloud
  1343. 51:29that we need you need to install
  1344. 51:31requirements.txt
  1345. 51:32and the main working directory is app.
  1346. 51:34Come back here and just hit on save.
  1347. 51:39Okay. And I'm going to allow public
  1348. 51:42access because it's not a big deal right
  1349. 51:44now. And then if I come back here,
  1350. 51:47there's an important thing called
  1351. 51:48variable and secrets under containers.
  1352. 51:51We need to add the variables here.
  1353. 51:52Select the whole thing. Paste it here.
  1354. 51:55Okay. And just hit on create.
  1355. 52:02Now you're deploying the app. Okay. So
  1356. 52:04this will be a URL.
  1357. 52:07All right. So now creating the service
  1358. 52:09by the way. Now if you go to your GitHub
  1359. 52:12and if you refresh it,
  1360. 52:16you can see that something's running
  1361. 52:17here, right? Because we're connected to
  1362. 52:19GCP through Docker, right? Can click on
  1363. 52:21the details. You can see that it's in
  1364. 52:24progress. So it's it's very well
  1365. 52:25integrated. So if you click on view more
  1366. 52:27details on Google Cloud, you can see how
  1367. 52:29exactly it's been built. You see it's
  1368. 52:31very well connected. If you click on
  1369. 52:32this commit thing, it will lead you back
  1370. 52:34to your GitHub for the exact commit. Oh,
  1371. 52:37good. So, now we're officially live. And
  1372. 52:39then we click on YT RA private showcase.
  1373. 52:43You see, we have this URL here. Copy
  1374. 52:45this. Command T, command V. Good guys,
  1375. 52:49this is live. And then let's do slash
  1376. 52:51chat. Cool. We got our policies here.
  1377. 52:55So, for return, let's say it should
  1378. 52:58become if anything is over $8,000.
  1379. 53:01All right. If I hit on save, by the way,
  1380. 53:04double click here again. You see it
  1381. 53:06changed into 8,000 immediately. And they
  1382. 53:07updated this embedding as well,
  1383. 53:09immediately. Okay. So, this template
  1384. 53:11really works well. Okay. So, now if I
  1385. 53:13ask the exact same question again,
  1386. 53:16it's doing retrieval on an updated
  1387. 53:18database, vector database, and it's
  1388. 53:20going to tell me uh yes, you can return
  1389. 53:23it and purchase 8 1,000, which is lower
  1390. 53:26than 8,000 is fine. This is the end of
  1391. 53:28the video and I hope you enjoyed it. I
  1392. 53:31hope this is straightforward. I hope
  1393. 53:33this is like easy to follow and again
  1394. 53:37like I I would like to hear any feedback
  1395. 53:39from most of you guys and a lot of
  1396. 53:42people ask me for making more videos
  1397. 53:43regarding you know showing you AI agent
  1398. 53:45system design and people also ask me
  1399. 53:47about deployment. So I'm trying to keep
  1400. 53:48the balance. So let me know if this
  1401. 53:50format of video works for you. like I'll
  1402. 53:52show the system design at the beginning
  1403. 53:54and I'll show you like the exact code
  1404. 53:56example and open source the code on
  1405. 53:58GitHub and show you how to deploy it.
  1406. 54:00Let me know if this kind of format of
  1407. 54:01content is really helpful for you. I
  1408. 54:03don't think anyone else I don't I didn't
  1409. 54:05find any other YouTubers or influencers
  1410. 54:07doing this. Um so I'm sort of also
  1411. 54:10experimenting this myself and at the
  1412. 54:13same time if you're a business if you're
  1413. 54:15are running an e-commerce website or D2C
  1414. 54:18brand um I'm running my own startup
  1415. 54:20called automatis.io IO which is a which
  1416. 54:23is basically an AI agent system that
  1417. 54:25helps people selling physical products
  1418. 54:27to manage their sales leads. And I'm
  1419. 54:29also open for discussing any AI
  1420. 54:31automation requests or demands from a
  1421. 54:33business perspective. Just let me know
  1422. 54:35and I have all my social media contacts
  1423. 54:37down below in the description and in the
  1424. 54:39comment section. So feel free to reach
  1425. 54:41out. Hey everyone, this is Sean. Today I
  1426. 54:43want to talk about how to build a strong
  1427. 54:44AI agent system.

About this transcript

This page contains the full transcript of 8 сентября 2026 г. by Andrei, generated from the public captions YouTube serves with the video. The transcript has 10,044 words across 1,427 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.