Skip to content
Guide
Index

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.retrieval.* in the SDK.

Find files by exact name or substring match.

# Exact name match
results = await client.retrieval.find(
index_id="<your-index-id>",
file_name="quarterly-report.pdf",
)
# Substring match, case-insensitive
results = await client.retrieval.find(
index_id="<your-index-id>",
file_name_contains="quarterly",
)
for f in results.items:
print(f"{f.file_id}: {f.file_name}")

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.

found = await client.retrieval.find(
index_id="<your-index-id>",
file_name="quarterly-report.pdf",
)
if not found.items:
raise SystemExit("quarterly-report.pdf is not in the index")
file_id = found.items[0].file_id
results = await client.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}")
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 the parsed text content of a file. Supports pagination via offset and max_length for large documents.

found = await client.retrieval.find(
index_id="<your-index-id>",
file_name="quarterly-report.pdf",
)
if not found.items:
raise SystemExit("quarterly-report.pdf is not in the index")
file_id = found.items[0].file_id
# Read the full file
result = await client.retrieval.read(
index_id="<your-index-id>",
file_id=file_id,
)
print(result.content)
# Read a specific range
result = await client.retrieval.read(
index_id="<your-index-id>",
file_id=file_id,
offset=1000,
max_length=5000,
)
print(result.content)
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/