# Retrieval

## Retrieve

`client.Retrieval.Get(ctx, params) (*RetrievalGetResponse, error)`

**post** `/api/v1/retrieval/retrieve`

Retrieve relevant chunks via hybrid search (vector + full-text), with filtering on built-in or user-defined metadata.

### Parameters

- `params RetrievalGetParams`

  - `IndexID param.Field[string]`

    Body param: ID of the index to retrieve against.

  - `Query param.Field[string]`

    Body param: Natural-language query to retrieve relevant chunks.

  - `OrganizationID param.Field[string]`

    Query param

  - `ProjectID param.Field[string]`

    Query param

  - `CustomFilters param.Field[map[string, *RetrievalGetParamsCustomFilterUnion]]`

    Body param: Filters on user-defined metadata fields.

    - `type RetrievalGetParamsCustomFilterValueFilter struct{…}`

      Filter on a single metadata field value.

      - `Operator string`

        - `const RetrievalGetParamsCustomFilterValueFilterOperatorEq RetrievalGetParamsCustomFilterValueFilterOperator = "eq"`

        - `const RetrievalGetParamsCustomFilterValueFilterOperatorGt RetrievalGetParamsCustomFilterValueFilterOperator = "gt"`

        - `const RetrievalGetParamsCustomFilterValueFilterOperatorGte RetrievalGetParamsCustomFilterValueFilterOperator = "gte"`

        - `const RetrievalGetParamsCustomFilterValueFilterOperatorIn RetrievalGetParamsCustomFilterValueFilterOperator = "in"`

        - `const RetrievalGetParamsCustomFilterValueFilterOperatorLt RetrievalGetParamsCustomFilterValueFilterOperator = "lt"`

        - `const RetrievalGetParamsCustomFilterValueFilterOperatorLte RetrievalGetParamsCustomFilterValueFilterOperator = "lte"`

        - `const RetrievalGetParamsCustomFilterValueFilterOperatorNe RetrievalGetParamsCustomFilterValueFilterOperator = "ne"`

        - `const RetrievalGetParamsCustomFilterValueFilterOperatorNin RetrievalGetParamsCustomFilterValueFilterOperator = "nin"`

      - `Value RetrievalGetParamsCustomFilterValueFilterValueUnion`

        - `string`

        - `bool`

        - `float64`

        - `type RetrievalGetParamsCustomFilterValueFilterValueArray []RetrievalGetParamsCustomFilterValueFilterValueArrayItemUnion`

          - `string`

          - `bool`

          - `float64`

    - `type RetrievalGetParamsCustomFilterArray []RetrievalGetParamsCustomFilterArrayItem`

      - `Operator string`

        - `const RetrievalGetParamsCustomFilterArrayItemOperatorEq RetrievalGetParamsCustomFilterArrayItemOperator = "eq"`

        - `const RetrievalGetParamsCustomFilterArrayItemOperatorGt RetrievalGetParamsCustomFilterArrayItemOperator = "gt"`

        - `const RetrievalGetParamsCustomFilterArrayItemOperatorGte RetrievalGetParamsCustomFilterArrayItemOperator = "gte"`

        - `const RetrievalGetParamsCustomFilterArrayItemOperatorIn RetrievalGetParamsCustomFilterArrayItemOperator = "in"`

        - `const RetrievalGetParamsCustomFilterArrayItemOperatorLt RetrievalGetParamsCustomFilterArrayItemOperator = "lt"`

        - `const RetrievalGetParamsCustomFilterArrayItemOperatorLte RetrievalGetParamsCustomFilterArrayItemOperator = "lte"`

        - `const RetrievalGetParamsCustomFilterArrayItemOperatorNe RetrievalGetParamsCustomFilterArrayItemOperator = "ne"`

        - `const RetrievalGetParamsCustomFilterArrayItemOperatorNin RetrievalGetParamsCustomFilterArrayItemOperator = "nin"`

      - `Value RetrievalGetParamsCustomFilterArrayItemValueUnion`

        - `float64`

        - `type RetrievalGetParamsCustomFilterArrayItemValueArray []float64`

  - `FullTextPipelineWeight param.Field[float64]`

    Body param: Weight of the full-text search pipeline (0-1).

  - `NumCandidates param.Field[int64]`

    Body param: Number of candidates for approximate nearest neighbor search.

  - `Rerank param.Field[RetrievalGetParamsRerank]`

    Body param: Reranking configuration applied after hybrid search. Enabled by default.

    - `Enabled bool`

      Set to false to disable reranking.

    - `TopN int64`

      Number of results to return after reranking.

  - `ScoreThreshold param.Field[float64]`

    Body param: Minimum score threshold for returned results.

  - `StaticFilters param.Field[RetrievalGetParamsStaticFilters]`

    Body param: Filters on built-in document fields (page range, chunk index, etc.).

    - `ParsedDirectoryFileID RetrievalGetParamsStaticFiltersParsedDirectoryFileID`

      Filter on a string field.

      - `Operator string`

        - `const RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperatorEq RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperator = "eq"`

        - `const RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperatorGt RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperator = "gt"`

        - `const RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperatorGte RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperator = "gte"`

        - `const RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperatorIn RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperator = "in"`

        - `const RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperatorLt RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperator = "lt"`

        - `const RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperatorLte RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperator = "lte"`

        - `const RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperatorNe RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperator = "ne"`

        - `const RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperatorNin RetrievalGetParamsStaticFiltersParsedDirectoryFileIDOperator = "nin"`

      - `Value RetrievalGetParamsStaticFiltersParsedDirectoryFileIDValueUnion`

        - `string`

        - `type RetrievalGetParamsStaticFiltersParsedDirectoryFileIDValueArray []string`

  - `TopK param.Field[int64]`

    Body param: Maximum number of results to return. Values above 500 are capped at 500.

  - `VectorPipelineWeight param.Field[float64]`

    Body param: Weight of the vector search pipeline (0-1).

### Returns

- `type RetrievalGetResponse struct{…}`

  Response containing retrieval results.

  - `Results []RetrievalGetResponseResult`

    Ordered list of retrieved chunks.

    - `Content string`

      Text content of the retrieved chunk.

    - `Metadata map[string, RetrievalGetResponseResultMetadataUnion]`

      User-defined metadata associated with the chunk.

      - `string`

      - `int64`

      - `float64`

      - `bool`

      - `type RetrievalGetResponseResultMetadataMetadataListValue []string`

    - `RerankScore float64`

      Relevance score from the reranker, if reranking was applied.

    - `Score float64`

      Hybrid search relevance score.

    - `StaticFields RetrievalGetResponseResultStaticFields`

      Built-in fields stored for every exported chunk.

      - `Attachments []RetrievalGetResponseResultStaticFieldsAttachment`

        Attachments associated with the chunk

        - `AttachmentName string`

          Attachment-relative path, e.g. 'screenshots/page_7.jpg'.

        - `SourceID string`

          File ID to pass as source_id when fetching the attachment.

        - `Type string`

          Attachment kind, e.g. 'screenshot', 'items'.

      - `ChunkEndChar int64`

        End character offset of the chunk.

      - `ChunkIndex int64`

        Index of the chunk within the file.

      - `ChunkStartChar int64`

        Start character offset of the chunk.

      - `ChunkTokenCount int64`

        Token count of the chunk.

      - `PageRangeEnd int64`

        Last page number covered by this chunk.

      - `PageRangeStart int64`

        First page number covered by this chunk.

      - `ParsedDirectoryFileID string`

        ID of the parsed file.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/run-llama/llama-parse-go"
  "github.com/run-llama/llama-parse-go/option"
)

func main() {
  client := llamacloud.NewClient(
    option.WithAPIKey("My API Key"),
  )
  retrieval, err := client.Retrieval.Get(context.TODO(), llamacloud.RetrievalGetParams{
    IndexID: "idx-abc123",
    Query: "What are the key findings?",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", retrieval.Results)
}
```

#### Response

```json
{
  "results": [
    {
      "content": "content",
      "metadata": {
        "foo": "string"
      },
      "rerank_score": 0,
      "score": 0,
      "static_fields": {
        "attachments": [
          {
            "attachment_name": "attachment_name",
            "source_id": "source_id",
            "type": "type"
          }
        ],
        "chunk_end_char": 0,
        "chunk_index": 0,
        "chunk_start_char": 0,
        "chunk_token_count": 0,
        "page_range_end": 0,
        "page_range_start": 0,
        "parsed_directory_file_id": "parsed_directory_file_id"
      }
    }
  ]
}
```

## Find Files

`client.Retrieval.Find(ctx, params) (*PaginatedCursorPost[RetrievalFindResponse], error)`

**post** `/api/v1/retrieval/files/find`

Search for files by name.

### Parameters

- `params RetrievalFindParams`

  - `IndexID param.Field[string]`

    Body param: ID of the index to search within.

  - `OrganizationID param.Field[string]`

    Query param

  - `ProjectID param.Field[string]`

    Query param

  - `FileName param.Field[string]`

    Body param: Exact file name to match.

  - `FileNameContains param.Field[string]`

    Body param: Substring match on file name (case-insensitive).

  - `PageSize param.Field[int64]`

    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.

  - `PageToken param.Field[string]`

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

### Returns

- `type RetrievalFindResponse struct{…}`

  A file returned by find.

  - `FileID string`

    ID of the file.

  - `FileName string`

    Display name of the file.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/run-llama/llama-parse-go"
  "github.com/run-llama/llama-parse-go/option"
)

func main() {
  client := llamacloud.NewClient(
    option.WithAPIKey("My API Key"),
  )
  page, err := client.Retrieval.Find(context.TODO(), llamacloud.RetrievalFindParams{
    IndexID: "idx-abc123",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
```

#### Response

```json
{
  "items": [
    {
      "file_id": "file_id",
      "file_name": "file_name"
    }
  ],
  "next_page_token": "next_page_token",
  "total_size": 0
}
```

## Grep File

`client.Retrieval.Grep(ctx, params) (*PaginatedCursorPost[RetrievalGrepResponse], error)`

**post** `/api/v1/retrieval/files/grep`

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

### Parameters

- `params RetrievalGrepParams`

  - `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]`

    Query param

  - `ProjectID param.Field[string]`

    Query param

  - `ContextChars param.Field[int64]`

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

  - `PageSize param.Field[int64]`

    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.

  - `PageToken param.Field[string]`

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

### Returns

- `type RetrievalGrepResponse struct{…}`

  A single grep match within a file.

  - `Content string`

    Matched text content.

  - `EndChar int64`

    End character offset of the match.

  - `StartChar int64`

    Start character offset of the match.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/run-llama/llama-parse-go"
  "github.com/run-llama/llama-parse-go/option"
)

func main() {
  client := llamacloud.NewClient(
    option.WithAPIKey("My API Key"),
  )
  page, err := client.Retrieval.Grep(context.TODO(), llamacloud.RetrievalGrepParams{
    FileID: "file_id",
    IndexID: "idx-abc123",
    Pattern: "revenue|profit",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
```

#### Response

```json
{
  "items": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ],
  "next_page_token": "next_page_token",
  "total_size": 0
}
```

## Read File

`client.Retrieval.Read(ctx, params) (*RetrievalReadResponse, error)`

**post** `/api/v1/retrieval/files/read`

Read the parsed text content of a specific file.

### Parameters

- `params RetrievalReadParams`

  - `FileID param.Field[string]`

    Body param: ID of the file to read.

  - `IndexID param.Field[string]`

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

  - `OrganizationID param.Field[string]`

    Query param

  - `ProjectID param.Field[string]`

    Query param

  - `MaxLength param.Field[int64]`

    Body param: Maximum number of characters to read from the offset.

  - `Offset param.Field[int64]`

    Body param: Starting character offset.

### Returns

- `type RetrievalReadResponse struct{…}`

  File read result.

  - `Content string`

    Parsed text content of the file.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/run-llama/llama-parse-go"
  "github.com/run-llama/llama-parse-go/option"
)

func main() {
  client := llamacloud.NewClient(
    option.WithAPIKey("My API Key"),
  )
  response, err := client.Retrieval.Read(context.TODO(), llamacloud.RetrievalReadParams{
    FileID: "file_id",
    IndexID: "idx-abc123",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.Content)
}
```

#### Response

```json
{
  "content": "content"
}
```
