Skip to content

Grep File

RetrievalGrepPageResponse Beta.Retrieval.Grep(RetrievalGrepParamsparameters, CancellationTokencancellationToken = default)
POST/api/v1/retrieval/files/grep

Grep within a file’s parsed content using a regex pattern.

ParametersExpand Collapse
RetrievalGrepParams parameters
required string fileID

Body param: ID of the file to grep.

required string indexID

Body param: ID of the index the file belongs to.

required string pattern

Body param: Regex pattern to search for.

string? organizationID

Query param

formatuuid
string? projectID

Query param

formatuuid
Long? contextChars

Body param: Number of characters of context to include before and after the matched pattern in the content field of the response

Long? pageSize

Body param: The maximum number of items to return. The service may return fewer than this value. If unspecified, a default page size will be used. The maximum value is typically 1000; values above this will be coerced to the maximum.

string? pageToken

Body param: A page token, received from a previous list call. Provide this to retrieve the subsequent page.

ReturnsExpand Collapse
class RetrievalGrepPageResponse:

Paginated grep results for a file.

required IReadOnlyList<RetrievalGrepResponse> Items

The list of items.

required string Content

Matched text content.

required Long EndChar

End character offset of the match.

required Long StartChar

Start character offset of the match.

string? NextPageToken

A token, which can be sent as page_token to retrieve the next page. If this field is omitted, there are no subsequent pages.

Long? TotalSize

The total number of items available. This is only populated when specifically requested. The value may be an estimate and can be used for display purposes only.

Grep File

RetrievalGrepParams parameters = new()
{
    FileID = "file_id",
    IndexID = "idx-abc123",
    Pattern = "revenue|profit",
};

var page = await client.Beta.Retrieval.Grep(parameters);
await foreach (var item in page.Paginate())
{
    Console.WriteLine(item);
}
{
  "items": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ],
  "next_page_token": "next_page_token",
  "total_size": 0
}
Returns Examples
{
  "items": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ],
  "next_page_token": "next_page_token",
  "total_size": 0
}
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/