Skip to content
Framework Docs

Grep File

client.beta.retrieval.grep(RetrievalGrepParams { file_id, index_id, pattern, 5 more } params, RequestOptionsoptions?): PaginatedCursorPost<RetrievalGrepResponse { content, end_char, start_char } >
POST/api/v1/retrieval/files/grep

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

ParametersExpand Collapse
params: RetrievalGrepParams { file_id, index_id, pattern, 5 more }
file_id: string

Body param: ID of the file to grep.

index_id: string

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

pattern: string

Body param: Regex pattern to search for.

organization_id?: string | null

Query param

formatuuid
project_id?: string | null

Query param

formatuuid
context_chars?: number | null

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

page_size?: number | null

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.

page_token?: string | null

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

ReturnsExpand Collapse
RetrievalGrepResponse { content, end_char, start_char }

A single grep match within a file.

content: string

Matched text content.

end_char: number

End character offset of the match.

start_char: number

Start character offset of the match.

Grep File

import LlamaCloud from '@llamaindex/llama-cloud';

const client = new LlamaCloud({
  apiKey: process.env['LLAMA_CLOUD_API_KEY'], // This is the default and can be omitted
});

// Automatically fetches more pages as needed.
for await (const retrievalGrepResponse of client.beta.retrieval.grep({
  file_id: 'file_id',
  index_id: 'idx-abc123',
  pattern: 'revenue|profit',
})) {
  console.log(retrievalGrepResponse.content);
}
{
  "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
}