Skip to content

Grep File

POST/api/v1/retrieval/files/grep

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

Query ParametersExpand Collapse
organization_id: optional string
project_id: optional string
Cookie ParametersExpand Collapse
session: optional string
Body ParametersJSONExpand Collapse
file_id: string

ID of the file to grep.

index_id: string

ID of the index the file belongs to.

pattern: string

Regex pattern to search for.

context_chars: optional number

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

limit: optional number

Maximum number of matches to return.

ReturnsExpand Collapse
matches: array of object { content, end_char, start_char }

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

curl https://api.cloud.llamaindex.ai/api/v1/retrieval/files/grep \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $LLAMA_CLOUD_API_KEY" \
    -d '{
          "file_id": "file_id",
          "index_id": "idx-abc123",
          "pattern": "revenue|profit"
        }'
{
  "matches": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ]
}
Returns Examples
{
  "matches": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ]
}