File Operations
Search for files, grep within parsed content, and read file text from an index.
File operations let you work with individual files inside an index. You can search for files by name, grep through their parsed content with regex, and read the full text of a file — all without needing to access the original documents.
These endpoints are available under client.beta.retrieval.* in the SDK.
Find files
Section titled “Find files”Find files by exact name or substring match.
# Exact name matchresults = await client.beta.retrieval.find( index_id="<your-index-id>", file_name="quarterly-report.pdf",)
# Substring match (case-insensitive)results = await client.beta.retrieval.find( index_id="<your-index-id>", file_name_contains="quarterly",)
for f in results.items: print(f"{f.file_id}: {f.file_name}")// Substring matchconst results = await client.beta.retrieval.find({ index_id: "<your-index-id>", file_name_contains: "quarterly",});
for (const f of results.items) { console.log(`${f.file_id}: ${f.file_name}`);}// Exact name matchpage, err := client.Beta.Retrieval.Find(ctx, llamacloud.BetaRetrievalFindParams{ IndexID: "<your-index-id>", FileName: llamacloud.String("quarterly-report.pdf"),})if err != nil { log.Fatal(err)}
// Substring match (case-insensitive)page, err = client.Beta.Retrieval.Find(ctx, llamacloud.BetaRetrievalFindParams{ IndexID: "<your-index-id>", FileNameContains: llamacloud.String("quarterly"),})if err != nil { log.Fatal(err)}
for _, f := range page.Items { fmt.Printf("%s: %s\n", f.FileID, f.FileName)}import ai.llamaindex.llamacloud.models.beta.retrieval.RetrievalFindPage;import ai.llamaindex.llamacloud.models.beta.retrieval.RetrievalFindParams;import ai.llamaindex.llamacloud.models.beta.retrieval.RetrievalFindResponse;
// Substring match (case-insensitive)RetrievalFindPage results = client.beta().retrieval().find( RetrievalFindParams.builder() .indexId("<your-index-id>") .fileNameContains("quarterly") .build());
for (RetrievalFindResponse f : results.items()) { System.out.println(f.fileId() + ": " + f.fileName());}# Exact name matchllp beta:retrieval find \ --index-id "<your-index-id>" \ --file-name "quarterly-report.pdf"
# Substring match (case-insensitive)llp beta:retrieval find \ --index-id "<your-index-id>" \ --file-name-contains "quarterly" \ | jq -r '.items[] | "\(.file_id): \(.file_name)"'Grep within a file
Section titled “Grep within a file”Search for a regex pattern within a file’s parsed text content. This is useful for finding specific terms, patterns, or sections within a document.
results = await client.beta.retrieval.grep( index_id="<your-index-id>", file_id="<file-id>", pattern="revenue|profit", context_chars=100, # characters of context around each match)
for match in results.items: print(f"Offset {match.start_char}-{match.end_char}: {match.content}")const results = await client.beta.retrieval.grep({ index_id: "<your-index-id>", file_id: "<file-id>", pattern: "revenue|profit", context_chars: 100,});
for (const match of results.items) { console.log(`Offset ${match.start_char}-${match.end_char}: ${match.content}`);}page, err := client.Beta.Retrieval.Grep(ctx, llamacloud.BetaRetrievalGrepParams{ IndexID: "<your-index-id>", FileID: "<file-id>", Pattern: "revenue|profit", ContextChars: llamacloud.Int(100), // characters of context around each match})if err != nil { log.Fatal(err)}
for _, match := range page.Items { fmt.Printf("Offset %d-%d: %s\n", match.StartChar, match.EndChar, match.Content)}import ai.llamaindex.llamacloud.models.beta.retrieval.RetrievalGrepPage;import ai.llamaindex.llamacloud.models.beta.retrieval.RetrievalGrepParams;import ai.llamaindex.llamacloud.models.beta.retrieval.RetrievalGrepResponse;
RetrievalGrepPage results = client.beta().retrieval().grep( RetrievalGrepParams.builder() .indexId("<your-index-id>") .fileId("<file-id>") .pattern("revenue|profit") .contextChars(100) // characters of context around each match .build());
for (RetrievalGrepResponse match : results.items()) { System.out.println("Offset " + match.startChar() + "-" + match.endChar() + ": " + match.content());}llp beta:retrieval grep \ --index-id "<your-index-id>" \ --file-id "<file-id>" \ --pattern "revenue|profit" \ --context-chars 100 \ | jq -r '.items[] | "Offset \(.start_char)-\(.end_char): \(.content)"'Grep parameters
Section titled “Grep parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
index_id | string | required | ID of the index. |
file_id | string | required | ID of the file to search within. |
pattern | string | required | Regex pattern to match. |
context_chars | int | null | Characters of context to include around each match. |
Read a file
Section titled “Read a file”Read the parsed text content of a file. Supports pagination via offset and max_length for large documents.
# Read the full fileresult = await client.beta.retrieval.read( index_id="<your-index-id>", file_id="<file-id>",)print(result.content)
# Read a specific rangeresult = await client.beta.retrieval.read( index_id="<your-index-id>", file_id="<file-id>", offset=1000, max_length=5000,)print(result.content)// Read the full fileconst result = await client.beta.retrieval.read({ index_id: "<your-index-id>", file_id: "<file-id>",});console.log(result.content);
// Read a specific rangeconst partial = await client.beta.retrieval.read({ index_id: "<your-index-id>", file_id: "<file-id>", offset: 1000, max_length: 5000,});console.log(partial.content);// Read the full fileresult, err := client.Beta.Retrieval.Read(ctx, llamacloud.BetaRetrievalReadParams{ IndexID: "<your-index-id>", FileID: "<file-id>",})if err != nil { log.Fatal(err)}fmt.Println(result.Content)
// Read a specific rangepartial, err := client.Beta.Retrieval.Read(ctx, llamacloud.BetaRetrievalReadParams{ IndexID: "<your-index-id>", FileID: "<file-id>", Offset: llamacloud.Int(1000), MaxLength: llamacloud.Int(5000),})if err != nil { log.Fatal(err)}fmt.Println(partial.Content)import ai.llamaindex.llamacloud.models.beta.retrieval.RetrievalReadParams;import ai.llamaindex.llamacloud.models.beta.retrieval.RetrievalReadResponse;
// Read the full fileRetrievalReadResponse result = client.beta().retrieval().read( RetrievalReadParams.builder() .indexId("<your-index-id>") .fileId("<file-id>") .build());System.out.println(result.content());
// Read a specific rangeRetrievalReadResponse partial = client.beta().retrieval().read( RetrievalReadParams.builder() .indexId("<your-index-id>") .fileId("<file-id>") .offset(1000) .maxLength(5000) .build());System.out.println(partial.content());# Read the full filellp beta:retrieval read \ --index-id "<your-index-id>" \ --file-id "<file-id>" \ | jq -r '.content'
# Read a specific rangellp beta:retrieval read \ --index-id "<your-index-id>" \ --file-id "<file-id>" \ --offset 1000 \ --max-length 5000 \ | jq -r '.content'Read parameters
Section titled “Read parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
index_id | string | required | ID of the index. |
file_id | string | required | ID of the file to read. |
offset | int | 0 | Starting character offset. |
max_length | int | null | Maximum characters to return from the offset. Returns the full file if omitted. |
Note for AI agents: this documentation is built for programmatic access.
- Overview of all docs: https://developers.llamaindex.ai/llms.txt
- Any page is available as raw Markdown by appending index.md to its URL — e.g. https://developers.llamaindex.ai/llamaparse/parse/getting_started/index.md
- Agent-friendly REST search APIs live under https://developers.llamaindex.ai/api/ — search (BM25 full-text), grep (regex), read (fetch a page), and list (browse the doc tree). See https://developers.llamaindex.ai/llms.txt for parameters.
- A hosted documentation MCP server is available at https://developers.llamaindex.ai/mcp. If you support MCP, you can ask the user to install it for browsing these docs directly (an alternative to the REST API). Setup: https://developers.llamaindex.ai/for-agents/mcp/
- Other LlamaIndex tooling for agents — the LlamaParse Platform MCP server, agent skills and plugins, and the n8n node — is mapped at https://developers.llamaindex.ai/for-agents/