Skip to content
Framework Docs

Grep File

RetrievalGrepPage beta().retrieval().grep(RetrievalGrepParamsparams, RequestOptionsrequestOptions = RequestOptions.none())
POST/api/v1/retrieval/files/grep

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

ParametersExpand Collapse
RetrievalGrepParams params
Optional<String> organizationId
Optional<String> projectId
String fileId

ID of the file to grep.

String indexId

ID of the index the file belongs to.

String pattern

Regex pattern to search for.

Optional<Long> contextChars

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

Optional<Long> pageSize

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.

Optional<String> pageToken

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

ReturnsExpand Collapse
class RetrievalGrepResponse:

A single grep match within a file.

String content

Matched text content.

long endChar

End character offset of the match.

long startChar

Start character offset of the match.

Grep File

package com.llamacloud_prod.api.example;

import com.llamacloud_prod.api.client.LlamaCloudClient;
import com.llamacloud_prod.api.client.okhttp.LlamaCloudOkHttpClient;
import com.llamacloud_prod.api.models.beta.retrieval.RetrievalGrepPage;
import com.llamacloud_prod.api.models.beta.retrieval.RetrievalGrepParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        LlamaCloudClient client = LlamaCloudOkHttpClient.fromEnv();

        RetrievalGrepParams params = RetrievalGrepParams.builder()
            .fileId("file_id")
            .indexId("idx-abc123")
            .pattern("revenue|profit")
            .build();
        RetrievalGrepPage page = client.beta().retrieval().grep(params);
    }
}
{
  "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
}