Grep or Embeddings? Agentic Search Over Company Documents — George He, LlamaIndex

AI Engineer · 23 min · 232 sentences · from YouTube's caption track

Each timecode opens YouTube at the start of that sentence. Line anchors (#s42) are the cue ids in the WebVTT, and every line carries its start and end seconds. All transcripts has every talk, and the whole corpus as one file.

  1. 00:01[music]
  2. 00:12We're going to get going.
  3. 00:13Nice to meet you everyone.
  4. 00:14Uh my name is George.
  5. 00:15Uh today uh we'll be going over a talk on search document search and uh how we get better results here at Llama Index.
  6. 00:24Um my name is George.
  7. 00:25I'm the head of engineering here at Llama Index.
  8. 00:28We are a series A startup.
  9. 00:30We focus quite a bit on document parsing, orchestration and uh knowledge management.
  10. 00:35Um today the topic of the talk will center around how we've helped enterprise customers scale up search GP and generally manage context using aentic orchestration and just general infrastructure tooling.
  11. 00:51Uh the plan today is going to be going through a discussion or a debate around uh how to best orchestrate and perform document search uh how to get the best results and we'll iterate through their uh technical challenges that we've seen all the way to a live demo at the end if we do have time.
  12. 01:11All right.
  13. 01:12So to get started um the question that I like to pose to everyone is when and why specifically do agents need vector context in some discussions or just context period.
  14. 01:24Um and the major takeaway here is over the last few years models have gotten much better at orchestration and instruction following.
  15. 01:32They're able to traverse local file systems.
  16. 01:35They're able to work with skills MCPS in order to retrieve information in ways that are better than before.
  17. 01:41But you still have your local search and your local context problems, right?
  18. 01:45Um in order to manage large corpuses, in order to manage complex documents, easiest way is still to manage it locally.
  19. 01:53Um and so there are kind of two evolving approaches to orchestration uh between GP or what I like to call kind of local file search and file execution or embeddings or pre-indexing
  20. 02:05pre- retrieval.
  21. 02:06Um we'll kind of talk through what the different approaches offer and when you might prefer one over the other or when it's appropriate to do a hybrid of both.
  22. 02:15Uh to get started in understanding where this problem kind of popped up in industry u when cloud code launched uh you know there was a lot of discussion around the internal mechanics of how cloud code works.
  23. 02:27It's actually a really interesting problem to think about how you're going to traverse and manage your local file system if you're going to go through coding right as a solution or a problem.
  24. 02:37Um, and Anthropic's taken the approach of using your local file system prep read using glob management basically to manage your local file system and it's perfect for your local execution needs because code is easy to manage locally.
  25. 02:52It's concise and it's already in text format.
  26. 02:55But you'll also notice that um this tweet by Boris uh cloud code creator kind of highlights that uh cloud code experimented with a vector database didn't end up choosing it and the reasons aren't just for performance reasons but because of practical scaling and maintenance reasons.
  27. 03:13It's hard to keep a pre-indexed vectorized index in sync especially as code keeps on updating.
  28. 03:20And so specifically the solution that cloud code took which was no pre-indexing, no rag, no vector search, uh works really well but only because of a few characteristics of code.
  29. 03:30Um they did not care about pre-indexing information because the code in your repo is usually small.
  30. 03:36It's usually semistructured.
  31. 03:38Usually your code leaves breadcrumbs for what else is being imported, what else is being tested.
  32. 03:43Um and it leaves a natural hierarchy for how an agent might move about your file system.
  33. 03:48Um and the largest part there is code is already on disk and local uh especially if your agent has context.
  34. 03:54So why complicate it with a pre pre- retrieval system?
  35. 03:59And the reality is when you switch over to larger company data sets uh where you have images, you have PDFs, you have powerpoints mixed in uh it's harder because there's not really a folder to grip.
  36. 04:13Uh you can't really grip the folders across a company data set because it's not organized like code, right?
  37. 04:17You have to think about how much effort has been put into curating the code that you write, right?
  38. 04:22It must be syntactically sound.
  39. 04:23It must have proper references.
  40. 04:25And then you see your company database or you know whatever is in your data lake.
  41. 04:30Um and you realize it's really hard to keep things in sync, right?
  42. 04:33The scale is at a completely different level.
  43. 04:35Uh you care quite a bit more about security.
  44. 04:38Uh who can access what information.
  45. 04:40Uh the format is not standardized.
  46. 04:41you might have really complex PDFs, schematics, manufacturing diagrams mixed in and the scale just makes it so that you can't run this locally anymore.
  47. 04:49So, how do how do you keep a system in sync?
  48. 04:52Right?
  49. 04:52The industry has gone through many different solutions.
  50. 04:54Um, you can use MCP server, you can try to manage this using Anthropics CloudMD.
  51. 05:00So, you in addition to having just this blob of a data source available somewhere, you keep track and let your agent know, hey, you can traverse the data this way, right?
  52. 05:10So MCP skills, claude, claude, uh agent files, instruction files, these are all options for keeping track of some type of hierarchy.
  53. 05:18But the major takeaway here is actually it really comes down to the scale of the data that you have and how much curation effort you're going to put in in order to maintain that retrieval system or that data management system.
  54. 05:29That makes sense, right?
  55. 05:31People are talking about context engineering, about harness, you know, making a harness, but at the end of the day, it's all about keeping the right primitives in place.
  56. 05:39Um but in order to do that you have to understand what's the scale that you're dealing with right so if you have 100 to you know 100 or you know 100 to a thousand files
  57. 05:49uh it may be appropriate to just keep down to local file search because your agent can manage this in context.
  58. 05:54It won't burn too many tokens just iterating through files or managing the literal file names as it traverses.
  59. 06:00Um but as you scale out right to thousands or millions of files that's not possible.
  60. 06:05You don't want to burn those tokens.
  61. 06:07uh you don't want to read the files every single time.
  62. 06:08You want to have some needle in the haststack sense of roughly where you're looking for at least if it's not the needle in the haststack.
  63. 06:14It's a rough compass on the direction you should be going, right?
  64. 06:17Um and so we'll talk a bit about kind of what the right approach is uh between hybrid based search, semantic based search as well as uh your old school file traversal here.
  65. 06:29Uh the other reason for why you might care about this is obviously as each model increases in its memory capabilities, right?
  66. 06:36We got 1 million token context length now.
  67. 06:38Uh before it used to be 200k, before that 100k and even smaller before that.
  68. 06:42Um the important thing to think about here is actually as the model capabilities increase what you're willing to pay as you're going through this process, right?
  69. 06:50Do you want to shove those tokens through the model's ingestion pipeline?
  70. 06:53Do you want to uh send binary data over to your model for it to try to render in maybe its own engine and then extract data out of uh for your search?
  71. 07:04um it just becomes extremely expensive, right?
  72. 07:07In order to use your model context for ingestion and search.
  73. 07:10Um and you know there have been solutions around how you can use sub agents right have one larger agent issue subcomands so that a smaller agent can deal with the memory context the memory bloat and just give a response back.
  74. 07:22Um but the issue there is because each sub aent needs full context because sub aents uh even though they might use cheaper or simpler models uh if you've noticed in cloud code sometimes your you know main session may issue commands to weaker model
  75. 07:37uh sub sessions in order to execute the jobs.
  76. 07:40um the environments are actually rather tokenheavy and latencyheavy, right?
  77. 07:45So in order to speed up your process and make sure that you're not burning tokens unnecessarily reprocessing documents each time, uh you may actually think about building out a pre-indexing
  78. 07:55system.
  79. 07:56Um and so we'll kind of talk about that here.
  80. 07:59Um in kind of building out a harness and letting it agent choose what's going on, right?
  81. 08:04So uh specifically we don't really want our system or any system that can scale out to be manually deciding uh should I use a hybrid rag approach or should I just individually search through files and the cleanest way that we found that in this era of engineering is
  82. 08:25uh managing that with a harness.
  83. 08:27So give your agent the tools needed to either search through specific files using your old school GP, your old school cat, file name filtering or metadata filtering in addition to semantic filtering.
  84. 08:40Um, and that way you can get kind of the best of both worlds going through traversal.
  85. 08:43uh so you can get the rough direction of which files you want to search and use semantic search to down scope your files and then using your agent's built-in file traversal capabilities to dig into the meat of the details so that you can actually ground your answers instead of hallucinating them.
  86. 09:01So the five tools that we'll talk through today um in enabling kind of document search or uh complex document search uh as you might see in like insurance, finance, healthcare industries, right?
  87. 09:12Where you just have a ton of unatategorized or semilablled data is what are the tools that we're going to use?
  88. 09:18Right?
  89. 09:19So the question first is where am I even going to look?
  90. 09:21What's the compass direction we're going to go?
  91. 09:23Um and then you have three tools that are going to be there and you know you have a lot more of these in your local file system to figure out what actually
  92. 09:31is in this subset or this subcorpus of documents that we've identified with our compass direction.
  93. 09:37Right?
  94. 09:37So listing files, traversing files by metadata, uh gpping specific files to see if there are multiple keywords available that make a specific document more desirable.
  95. 09:46These are all things that you could run in a pre-indexing pipeline or a live pipeline.
  96. 09:51Um, and the last one is kind of, you know, what does the document actually say?
  97. 09:55And specifically for multimmodal documents, you need a way to pre-render the documents.
  98. 10:00And this is one kind of unique approach uh to multi-page or long schematics, which is in your pre-indexing process, one of the most important parts is to chunk or break your document down into digestible portions, right?
  99. 10:13But that applies to not just the textual side, but also the rendering side.
  100. 10:16uh because one of the hardest parts of free form document rendering is you actually have to rasterize or render the document into a human compatible view.
  101. 10:25Uh these use cases are usually where you have an actual person that would have done this uh instead of AI, right?
  102. 10:31So these schematics, these PDFs, these PowerPoints, they're not really built for pure machine consumption.
  103. 10:36Um so giving the agent a pre-built screenshot index to search through is also very useful as you're performing rag.
  104. 10:46All right.
  105. 10:47So, we'll take a look at some of the details of the tool itself.
  106. 10:51Um, so in terms of retrieval itself, right, which is the compass direction.
  107. 10:56There are tons of approaches you can take here.
  108. 10:57There's graph rag, there's traditional rag, there's kind of your old school keyword- based BM25 search.
  109. 11:02Um, we we usually recommend a hybrid for enterprise use cases.
  110. 11:05And that's just mostly because uh keyword-based search has its place for developers.
  111. 11:10Keyword based search also has its place for AI agents that are looking for specific pre-indexed words in a corpus, right?
  112. 11:17Um at the same time, semantic meaning and similarity is really important.
  113. 11:21Uh combining the two through a hybrid based search usually gives to much gives you much better results.
  114. 11:26Um you can see in various benchmarking data sets that you know just raw keyword or vector will get you to a baseline.
  115. 11:32But when you put in a fusion, you know, you combine and weight uh keyword as well as vector search, you get better results uh because you aren't blinded by, you know, specifics of your search
  116. 11:42uh method.
  117. 11:43And re-ranking the final results, you know, you might take the top 100, re-rank them using an LLM or some other deeper process uh ultimately gets you much better retrieval results.
  118. 11:52U but that's just one part of the pipeline, right?
  119. 11:54That's the document search.
  120. 11:55Uh we care about results.
  121. 11:58Um and so tools two through four we'll talk through and kind of show later which is um once you have the compass direction of what are the what is the general group of files that might matter right what's the metadata that might associate most closely with your query
  122. 12:11uh because your agent at the start might not know all the metadata or the extracted content of your system um it can then traverse through the file hierarchy uh search for similar files inside of your corpus that weren't even returned in that initial search in order to expand out and then further narrow down its results.
  123. 12:28Um, so giving your agent the primitives of listing out the files GP and read that you have locally is really important in a shared and distributed file system, especially if it's one that you don't want to download onto your agents context every single time, which can get expensive.
  124. 12:45And um, diving a bit deeper into the content itself, right?
  125. 12:49Um this is where uh complex documents like you know stuff with charts, stuff that's scanned in, stuff that has uh you know schematics for example kind of breaks apart for your traditional document indexing and chunking workflow
  126. 13:02because it is not a human read line of text right it's a separate representation.
  127. 13:08Um and so thinking about how you do your pre-indexing flow and parsing flow uh so that you don't have to reread the documents every single time using your agent is also important.
  128. 13:17you don't want to burn those uh you know binary encoded tokens every single time you want to read a new document.
  129. 13:23So we usually recommend pre-indexing uh or pre-parssing your documents using uh structured parsing flow.
  130. 13:29Um we have a product called Llama parse.
  131. 13:31We've also open sourced a tool called light parse which handles structural content extraction.
  132. 13:35So this is like if you have tables, charts or segmented uh information, you want to encode that as either markdown or just something that your agent really can understand the spatial reasoning of.
  133. 13:45uh because when you have multimmodal data uh spatial reasoning is important.
  134. 13:51Last one there is of course uh in your pre-parssing flow you usually want to generate those screenshots as you actually render the page right.
  135. 13:57So whatever you're doing for pre-parssing you probably also want to store and persist screenshots as they're being generated from document rendering.
  136. 14:04Uh it's not always clear if something is text or is you know got metadata associated with it.
  137. 14:09You probably want to combine the two together.
  138. 14:13Um and so parsing is an important part but it's not the only part of a pipeline.
  139. 14:18Uh we usually you know advocate for people to think about how you can distribute parsing um and think about scaling out to improve your parsing pipeline right um there are some metrics that I would advocate for people to think about you know if they're relevant to your pipeline and uh kind of how you can optimize or
  140. 14:34uh improve your pipeline for each of those dimensions.
  141. 14:37So if you dump your data into a traditional OCR pipeline like Textract uh or you use a OCR engine like Tesseract um does it actually capture the tables the table representation?
  142. 14:49How faithful is it to act the actual content layout?
  143. 14:52Right?
  144. 14:52Because if you get those wrong your LLM on its semantic reading side later down the line is going to pay for it.
  145. 14:58Uh it might be fine at the start but if your LM doesn't understand the location and spatial reasoning it falls apart um at some point.
  146. 15:08All right, so before we get to the demo, uh there are just a few caveats to think about with building out an actual production pipeline, right?
  147. 15:14Which is when you have actual customers that care about using it and scaling it out.
  148. 15:18There are a few things that will always be brought up.
  149. 15:20Um there's like multi-tenency, you know, can one person see another person's data?
  150. 15:25How does permissioning metadata get pulled in?
  151. 15:27Right?
  152. 15:27if I'm using Google Drive or if I'm using SharePoint, how do I pull in and yank that permission metadata without causing the whole system to grind to a halt or without reindexing and repparssing the pipelines each time?
  153. 15:37Um, and that's related to the last one which is freshness, right?
  154. 15:40This is kind of why Anthropic, a lot of other companies have kind of given up on trying to pre-index data uh because data freshness is really hard to achieve if your datas are complex,
  155. 15:50your data is complex, and you also have metadata that needs to be up to date.
  156. 15:56All right.
  157. 15:56So, uh in order to break it down more easily, um we like to think about the synchronization process as three steps, right?
  158. 16:02One is pure ingestion.
  159. 16:03You know, can we get all your documents into a synchronized system?
  160. 16:06Uh the second step is going to be parsing, which is how do we actually convert your document to a standardized format.
  161. 16:12Uh for our use cases today, we'll talk through converting all documents into a markdown or a text format.
  162. 16:17But there are also other formats you can use if you only care about multimodal representations.
  163. 16:21Um and last stage is obviously uh rebungging that data and then exporting it into a pre-index state um in order to make it available for all of the tools and steps that we talked about before.
  164. 16:39All right.
  165. 16:40So uh I'm going to skip through this uh for the sake of time.
  166. 16:44Um, one major thing that we want to highlight here is, you know, storing your data is actually quite important.
  167. 16:49Um, in order to distribute your data out, you usually want some type of layered storage system.
  168. 16:54Um, a lot of vector storage, uh, services store everything on memory.
  169. 16:59Um, usually you're playing with some trade-off of do I want it on disk and then loaded into a faster memory store or do I want everything just in the memory store.
  170. 17:07Um, for us, you know, we've dealt with this problem at the multi-tenant level to, you know, millions, tens of millions of documents.
  171. 17:12Our recommendation here is to try to persist your data onto disk and then have a shielded memory layer in order to retrieve the data more efficiently.
  172. 17:21Uh for our use cases today, we'll be looking at turbopuffer.
  173. 17:24Um and turbopuffer as well as most vector stores will also handle uh permissioning, right?
  174. 17:29So what's the metadata that you have?
  175. 17:31How do you pull the data in?
  176. 17:32Uh is actually quite an important part of your system success because when you have too many documents, you need to filter by metadata.
  177. 17:39Um, so we push that into the vector storage layer.
  178. 17:42You know, as the data is being ingested, let's just make sure we tag that into the vector stores.
  179. 17:47All right.
  180. 17:48So, uh, we're going to jump through a demo.
  181. 17:51Um, and for the demo today, the the process to think about is, you know, how is the agent going to use the subcomponents in order to actually give you a response that's grounded
  182. 18:02that actually can traverse multiple documents and actually gets you gets you a result that you're pretty happy with.
  183. 18:08Um, all right.
  184. 18:10So, we'll go through there here.
  185. 18:12Uh, let's see.
  186. 18:21All right.
  187. 18:22So, in this demo, um, we will have a pre-index set of documents um that is available from a data source that we've defined ahead of time.
  188. 18:31This is going to be 135 files uh that are derived from Alphabet's financial reports, right?
  189. 18:39So, we have all these uh htm files, they're mixed in with raw PDF files and if you actually look at them, uh we've pulled in the metadata for where this information can be found.
  190. 18:51So if you have file metadata available along with uh you know later on you can tag this with uh the year that it came from or the specific company it came from that gives your agents the capabilities to filter down uh the data.
  191. 19:04Um and what we'll see here is uh in your hybrid retrieval flow right uh you'll have the option of if you want to be more keyword based or more semantic based in your retrieval flow.
  192. 19:15Um let's just do a even balance for now and we're going to search for uh just any cash flow statements and we'll talk through kind of the tools that your agent would want to use along this process.
  193. 19:26Right?
  194. 19:26So um what you've seen here on the right is the set of chunks that are returned from our query as well as page screenshots that correspond to uh what is essentially
  195. 19:38uh the page that it came from.
  196. 19:40Right?
  197. 19:41So these two together gives your agents the capability to uh filter down to a specific chunk and request context around that specific chunk in a much cleaner way than before.
  198. 19:50Um you then might want to think about how you would GP for a specific uh piece of text in the file, right?
  199. 19:57So what happens if you have a reax pattern that you're looking for uh you know now you're looking specifically for cash flow um and you can find that easily.
  200. 20:07uh in order to find that in a specific file, all you need to do is issue a GP command and then read from that specific command kind of what that offset is
  201. 20:15and then uh kind of what the max length is that you want.
  202. 20:18So, uh this is a different file.
  203. 20:19So, I'll just give an example.
  204. 20:21You know, if we offset 500 characters and pull in the next thousand, we'll end up with this text being available, right?
  205. 20:27So, with these two tools, this suite of tools together, your agent doesn't really need the files on a local file state anymore.
  206. 20:33um you can interact with what is effectively a remote file storage without needing to spin up or download all the data that would need to be streamed to your system.
  207. 20:41Um and that uh gives the agent a much more capable uh set of capabilities without actually downloading all the information and burning the tokens.
  208. 20:50So we will uh go to a chat example and I'm going to pull it up here.
  209. 20:55So uh give me the cash flow from as a table from 2021 to 2025 income as a table.
  210. 21:14All right.
  211. 21:15So give me a second here.
  212. 21:17Run this again.
  213. 21:26Give it a few seconds.
  214. 21:28Uh, while that's running, I'm going to show you guys the end results.
  215. 21:32Uh, let's go to the chat.
  216. 21:34So, this is going to be in the chat flow timeline.
  217. 21:37Um, let's see.
  218. 21:38Still thinking there.
  219. 21:39So, as the as an agent is running over the over the process of, you know, retrieving your answers from the corpus, it's going to look through uh your corpus by issuing search commands, right?
  220. 21:50And as it's issuing the search commands, you want your agent to be able to review the screenshots, review the context, and then determine what is actually relevant for its search in a much
  221. 22:01more holistic way, right?
  222. 22:03So you get to think through the process, you get to read specific files, you get to search through files again and rescope your queries.
  223. 22:10And in the end, that gives you a much cleaner result, right?
  224. 22:13So uh in this agent response uh you can see the cash flow summary uh by you know and you can see that it's been pulled in from multiple files as part of its thinking process.
  225. 22:24So when we do go into the traversal flow um you can usually find and ground your answers in uh in a specific file and that gives you much more confidence that your agents found the right component or the right chunk.
  226. 22:38Um, you know, that's what we're looking for at the end of the day for agent-based retrieval.
  227. 22:44All right, so we're going to jump back here.
  228. 22:45We'll take a look at uh that session once it finishes streaming.
  229. 22:48Uh, but you know, the idea here and the takeaway is that, you know, search helps you find information and the harness gives you the results that you can trust.
  230. 22:56So, okay, if you're interested, um, feel free to, uh, visit the QR code here.
  231. 23:01Thank you.
  232. 23:19[music]