Grep or Embeddings? Agentic Search Over Company Documents — George He, LlamaIndex
Loading slides…
Read the talk
Grep or Embeddings? Agentic Search Over Company Documents
George He explains how company-document agents can use hybrid retrieval to find a direction, then list, filter, grep and read remote files to build answers grounded in their contents. The hard work includes preserving document layout, keeping permissions current and avoiding repeated ingestion.
From a talk by George He
At a glance
Ideas worth remembering
Direct file search works well when the corpus is manageable, textual and navigable. Large, mixed-format company collections make pre-indexed retrieval useful for avoiding repeated exploration.
A document-search harness can combine hybrid retrieval with listing, metadata filtering, grep and reading, letting the agent expand or narrow its investigation after the first search.
Prepare structured text and page screenshots together. Preserving table structure and layout matters because downstream models must reason from the representation they receive.
Production freshness includes permissions and metadata as well as content. Ingestion, parsing and indexing are distinct stages with different synchronization work.
Remote grep and bounded reads give an agent familiar file operations without downloading the whole corpus. Connecting a synthesized answer to specific source files makes it easier to check.
Why grep works so well on code
A coding agent can find useful context by following imports, searching identifiers and reading nearby files. Why give it a vector database as well? George He, head of engineering at LlamaIndex, opens with that practical question: better instruction following and tool use have made file traversal increasingly capable, but the choice between direct search and pre-indexed retrieval still depends on the data.
In He’s account of Claude Code’s design, local search won partly because an index would introduce another thing to maintain. Code changes frequently; a vectorized copy must stay synchronized with those changes. Searching and reading the files already on disk avoids that synchronization problem.
The repository also supplies its own navigation aids. Code is already text, usually fits within a manageable local corpus, and has a semi-structured hierarchy. Imports and tests leave “breadcrumbs” that tell an agent where to look next. Those properties make direct traversal useful: a match can lead to a definition, then to its callers or tests, without first building a separate retrieval system.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Company documents change the cost of exploration
A company’s document collection rarely offers the same starting conditions. PDFs, images, PowerPoints and manufacturing schematics mix formats and representations. They do not necessarily contain useful textual references to one another, and their organization has not received the syntactic discipline that code requires. At company scale, access rights also matter: finding a relevant document is insufficient if the person asking cannot read it.
MCP servers, skills and instruction files such as CLAUDE.md can explain how to navigate a collection. They still require someone to maintain useful structure. The decision therefore combines two questions: how much data must the agent explore, and how much curation will the organization do to make that exploration affordable?
He offers roughly 100–1,000 files as a range where local file search may be reasonable. An agent can inspect filenames and iterate through files without spending too much context on discovery. With thousands or millions of files, repeatedly reading the collection becomes wasteful. Pre-indexed search supplies a “rough compass”: enough direction to choose a promising subset before paying to inspect its details. These ranges are practical guidance rather than a fixed cutoff; document complexity and curation affect the choice.
Larger context windows do not remove the cost. He points to million-token context as an available capability, then asks whether it is sensible to pay for document ingestion, rendering and extraction inside model context every time a question arrives. Subagents can separate work and return compact answers, but their own context and execution add tokens and latency. Pre-parsing and pre-indexing move repeated preparation out of the query path.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Give the agent a compass and tools to investigate
The proposed harness gives the agent both indexed retrieval and file operations. Semantic search narrows the initial field; familiar operations such as grep, reading, filename filtering and metadata filtering let the agent investigate what it finds. The agent can choose its next operation instead of following a manually fixed choice between RAG and file traversal.
The five tools answer different questions:
- Hybrid search: Where should I begin looking? Retrieve a promising set of documents or chunks.
- File listing: What else exists in this part of the collection? Inspect the surrounding corpus.
- Metadata filtering: Which files match useful attributes? Narrow the collection using information attached to documents.
- Grep: Which files or passages contain a specific word or pattern? Check precise textual evidence.
- Reading: What does the document actually say? Inspect relevant content, including rendered pages when text alone is insufficient.
For the compass, LlamaIndex recommends combining keyword retrieval, such as BM25, with semantic similarity. Keywords help when the agent knows a particular term; semantic retrieval helps when relevant content expresses the idea differently. Fusion combines and weights the results. A subsequent reranker can examine, for example, the top 100 candidates with an LLM or another deeper scoring process. He reports better retrieval from this combination, without specifying a benchmark or effect size that would establish a universal improvement.
The first ranked result set does not have to become the final evidence set. Once the agent learns relevant metadata or finds a promising file, it can list related files that the initial search missed, expand its investigation and narrow again. This matters because the agent begins without knowing every attribute or document in the corpus. File operations make retrieval an investigation rather than a single top-k lookup.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Reading a document requires preserving its structure
A scanned chart or schematic does not become understandable merely because its words have been extracted. Its meaning also depends on spatial relationships. Document preparation must therefore produce useful representations before the agent asks a question: text that preserves structure, and rendered page images that retain the human-readable arrangement.
LlamaParse and the open-source LiteParse enter here as tools for structural content extraction. Tables, charts and segmented information can be represented in Markdown or another form the agent can read. During rendering, the pipeline should also persist page screenshots. Keeping both representations gives the agent a way to read extracted content and inspect its original arrangement without rendering the document anew for each query.
What information must survive parsing? The diagram separates the two representations of the same document. Structured text supports search and focused reading; screenshots preserve layout for visual inspection. Their shared origin lets an agent connect a retrieved passage to the page it came from.
Parsing quality should be judged by the relationships downstream reading needs. For an OCR pipeline such as Textract or Tesseract, He asks whether it captures the table representation and how faithfully it preserves layout. If the representation loses location or structure, the later model has to interpret damaged evidence. Scaling and distributing parsing helps process the corpus; it does not substitute for checking that the resulting representation remains useful.
One document, two complementary reading paths
Read the diagram as text
- Complex source document. A PDF, chart, scan or schematic contains text and spatial relationships.
- Structured text. Extract tables and segmented content into Markdown or another readable representation.
- Persisted page screenshots. Render pages during preparation and keep their visual layout.
- Agent inspection. Read a relevant chunk alongside its corresponding page and request surrounding context.
- Complex source document → Structured text: Structural extraction.
- Complex source document → Persisted page screenshots: Render and persist.
- Structured text → Agent inspection: Retrieved content.
- Persisted page screenshots → Agent inspection: Corresponding visual context.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Keep content, permissions and indexes synchronized
Production introduces two moving targets: the document and the rules governing access to it. Multi-tenancy requires preventing one customer from seeing another’s data. Connectors to Google Drive or SharePoint must also bring in permission metadata and keep it current. A permission update should not force the system to re-parse all the underlying content. Freshness includes metadata as well as document text.
He separates synchronization into three stages:
- Ingest: Bring documents into a synchronized system.
- Parse: Convert them into a standardized representation—Markdown or text for this demonstration, with other representations possible for multimodal uses.
- Index: Transform and export the prepared data into the indexed state that the search and traversal tools use.
Storage then trades memory residency against loading data from disk into faster memory. Drawing on LlamaIndex’s experience with millions to tens of millions of documents across tenants, He recommends persisting data on disk with a memory layer for efficient retrieval. The demonstration uses turbopuffer. The recommendation addresses the size of the stored corpus; keeping everything in memory is a different cost and retrieval tradeoff.
Metadata goes into the vector-storage layer during ingestion so queries can filter large collections, including by attributes used for permissions. This makes filtering part of retrieval rather than something the agent discovers only after downloading content. The talk identifies permission synchronization as necessary production work, but does not provide a complete access-control implementation; storing permission tags alone does not explain how every read operation enforces them.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
From 135 Alphabet filings to a cash-flow table
The demonstration starts with 135 pre-indexed files derived from Alphabet’s financial reports, mixing HTM files and PDFs. Source-location metadata accompanies the documents. Additional tags such as year and company would give the agent further ways to filter the collection. The initial question is deliberately broad: find cash-flow statements.
With keyword and semantic retrieval set to an even balance, the search returns chunks paired with screenshots of their source pages. The observable change is from a collection of files to specific candidate passages with visual context. A chunk points the agent toward relevant content; its page helps the agent inspect the surrounding document, and the tool can supply more context around that chunk.
The next operation becomes precise. Grep can look for a cash-flow phrase or regex pattern inside a selected file, then a read operation can fetch text using an offset and a maximum length. In a separate file example, He reads 1,000 characters beginning at offset 500. The important mechanism is bounded access: the agent receives the passage it requests rather than downloading the entire remote collection.
How does a broad search become a source-backed table? The flow below follows the cash-flow example from indexed candidates to focused inspection and synthesis. The return path matters: inspecting one result can change what the agent searches for next. Remote file operations let that investigation continue without requiring a local copy of every filing.
The chat request asks for cash flow as a table covering 2021–2025. While the rerun is still thinking, He opens an existing response and describes a cash-flow summary assembled from multiple files. The retrieval process can search, review screenshots and context, read particular files, then search again with a revised scope. The displayed result illustrates multi-document grounding; the recording does not establish the completed rerun or supply the table’s values for checking its numerical accuracy.
The ending makes trust a property of the whole investigation. Search finds likely evidence, but the harness lets the agent inspect it, revise its search and connect the answer to particular files or chunks. For the cash-flow task, that connection gives a reader somewhere concrete to check the summary. The index supplies direction; the subsequent reads supply the substance of the answer.
The cash-flow investigation
Read the diagram as text
- 135 Alphabet report files. Pre-indexed HTM and PDF documents with source metadata.
- Search for cash-flow statements. Use an even keyword and semantic balance to return chunks and page screenshots.
- Inspect relevant files. Review screenshots, grep for text and read bounded passages.
- Cash-flow table request. Synthesize across files for the requested 2021–2025 period and retain source grounding.
- 135 Alphabet report files → Search for cash-flow statements: Retrieve candidates.
- Search for cash-flow statements → Inspect relevant files: Follow chunks into their files.
- Inspect relevant files → Search for cash-flow statements: Revise the query and scope.
- Inspect relevant files → Cash-flow table request: Combine evidence from multiple files.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Full transcript
Loading transcript…