Skip to content

Grep File

client.Beta.Retrieval.Grep(ctx, params) (*BetaRetrievalGrepResponse, error)
POST/api/v1/retrieval/files/grep

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

ParametersExpand Collapse
params BetaRetrievalGrepParams
FileID param.Field[string]

Body param: ID of the file to grep.

IndexID param.Field[string]

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

Pattern param.Field[string]

Body param: Regex pattern to search for.

OrganizationID param.Field[string]optional

Query param

formatuuid
ProjectID param.Field[string]optional

Query param

formatuuid
ContextChars param.Field[int64]optional

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

Limit param.Field[int64]optional

Body param: Maximum number of matches to return.

ReturnsExpand Collapse
type BetaRetrievalGrepResponse struct{…}

Grep results for a file.

Matches []BetaRetrievalGrepResponseMatch

Regex matches found in the file.

Content string

Matched text content.

EndChar int64

End character offset of the match.

StartChar int64

Start character offset of the match.

Grep File

package main

import (
  "context"
  "fmt"

  "github.com/stainless-sdks/llamacloud-prod-go"
  "github.com/stainless-sdks/llamacloud-prod-go/option"
)

func main() {
  client := llamacloudprod.NewClient(
    option.WithAPIKey("My API Key"),
  )
  response, err := client.Beta.Retrieval.Grep(context.TODO(), llamacloudprod.BetaRetrievalGrepParams{
    FileID: "file_id",
    IndexID: "idx-abc123",
    Pattern: "revenue|profit",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.Matches)
}
{
  "matches": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ]
}
Returns Examples
{
  "matches": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ]
}