Skip to content

Grep File

client.beta.retrieval.grep(RetrievalGrepParams { file_id, index_id, pattern, 4 more } params, RequestOptionsoptions?): RetrievalGrepResponse { matches }
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, 4 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

limit?: number | null

Body param: Maximum number of matches to return.

ReturnsExpand Collapse
RetrievalGrepResponse { matches }

Grep results for a file.

matches: Array<Match>

Regex matches found in the 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
});

const response = await client.beta.retrieval.grep({
  file_id: 'file_id',
  index_id: 'idx-abc123',
  pattern: 'revenue|profit',
});

console.log(response.matches);
{
  "matches": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ]
}
Returns Examples
{
  "matches": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ]
}