# Retrieval

## Retrieve

`RetrievalRetrieveResponse beta().retrieval().retrieve(RetrievalRetrieveParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`

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

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

### Parameters

- `RetrievalRetrieveParams params`

  - `Optional<String> organizationId`

  - `Optional<String> projectId`

  - `String indexId`

    ID of the index to retrieve against.

  - `String query`

    Natural-language query to retrieve relevant chunks.

  - `Optional<CustomFilters> customFilters`

    Filters on user-defined metadata fields.

    - `class FilterTypeUnionStrIntBoolFloat:`

      - `Operator operator`

        - `EQ("eq")`

        - `NE("ne")`

        - `GT("gt")`

        - `LT("lt")`

        - `GTE("gte")`

        - `LTE("lte")`

        - `IN("in")`

        - `NIN("nin")`

      - `Value value`

        - `String`

        - `boolean`

        - `double`

        - `List<UnnamedSchemaWithArrayParent1>`

          - `String`

          - `boolean`

          - `double`

    - `List<FilterTypeUnionIntFloat>`

      - `Operator operator`

        - `EQ("eq")`

        - `NE("ne")`

        - `GT("gt")`

        - `LT("lt")`

        - `GTE("gte")`

        - `LTE("lte")`

        - `IN("in")`

        - `NIN("nin")`

      - `Value value`

        - `double`

        - `List<double>`

  - `Optional<Double> fullTextPipelineWeight`

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

  - `Optional<Long> numCandidates`

    Number of candidates for approximate nearest neighbor search.

  - `Optional<Rerank> rerank`

    Reranking configuration applied after hybrid search. Enabled by default.

    - `Optional<Boolean> enabled`

      Set to false to disable reranking.

    - `Optional<Long> topN`

      Number of results to return after reranking.

  - `Optional<Double> scoreThreshold`

    Minimum score threshold for returned results.

  - `Optional<StaticFilters> staticFilters`

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

    - `Optional<ParsedDirectoryFileId> parsedDirectoryFileId`

      - `Operator operator`

        - `EQ("eq")`

        - `NE("ne")`

        - `GT("gt")`

        - `LT("lt")`

        - `GTE("gte")`

        - `LTE("lte")`

        - `IN("in")`

        - `NIN("nin")`

      - `Value value`

        - `String`

        - `List<String>`

  - `Optional<Long> topK`

    Maximum number of results to return.

  - `Optional<Double> vectorPipelineWeight`

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

### Returns

- `class RetrievalRetrieveResponse:`

  Response containing retrieval results.

  - `List<Result> results`

    Ordered list of retrieved chunks.

    - `String content`

      Text content of the retrieved chunk.

    - `Optional<Metadata> metadata`

      User-defined metadata associated with the chunk.

      - `String`

      - `long`

      - `double`

      - `boolean`

      - `JsonValue;`

      - `List<String>`

    - `Optional<Double> rerankScore`

      Relevance score from the reranker, if reranking was applied.

    - `Optional<Double> score`

      Hybrid search relevance score.

    - `Optional<StaticFields> staticFields`

      Built-in fields stored for every exported chunk.

      - `Optional<List<Attachment>> attachments`

        Attachments associated with the chunk

        - `String attachmentName`

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

        - `String sourceId`

          File ID to pass as source_id when fetching the attachment.

        - `String type`

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

      - `Optional<Long> chunkEndChar`

        End character offset of the chunk.

      - `Optional<Long> chunkIndex`

        Index of the chunk within the file.

      - `Optional<Long> chunkStartChar`

        Start character offset of the chunk.

      - `Optional<Long> chunkTokenCount`

        Token count of the chunk.

      - `Optional<Long> pageRangeEnd`

        Last page number covered by this chunk.

      - `Optional<Long> pageRangeStart`

        First page number covered by this chunk.

      - `Optional<String> parsedDirectoryFileId`

        ID of the parsed file.

### Example

```java
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.RetrievalRetrieveParams;
import com.llamacloud_prod.api.models.beta.retrieval.RetrievalRetrieveResponse;

public final class Main {
    private Main() {}

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

        RetrievalRetrieveParams params = RetrievalRetrieveParams.builder()
            .indexId("idx-abc123")
            .query("What are the key findings?")
            .build();
        RetrievalRetrieveResponse retrieval = client.beta().retrieval().retrieve(params);
    }
}
```

#### 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

`RetrievalFindPage beta().retrieval().find(RetrievalFindParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`

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

Search for files by name.

### Parameters

- `RetrievalFindParams params`

  - `Optional<String> organizationId`

  - `Optional<String> projectId`

  - `String indexId`

    ID of the index to search within.

  - `Optional<String> fileName`

    Exact file name to match.

  - `Optional<String> fileNameContains`

    Substring match on file name (case-insensitive).

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

### Returns

- `class RetrievalFindResponse:`

  A file returned by find.

  - `String fileId`

    ID of the file.

  - `String fileName`

    Display name of the file.

### Example

```java
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.RetrievalFindPage;
import com.llamacloud_prod.api.models.beta.retrieval.RetrievalFindParams;

public final class Main {
    private Main() {}

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

        RetrievalFindParams params = RetrievalFindParams.builder()
            .indexId("idx-abc123")
            .build();
        RetrievalFindPage page = client.beta().retrieval().find(params);
    }
}
```

#### Response

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

## 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.

### Parameters

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

### Returns

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

### Example

```java
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);
    }
}
```

#### Response

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

## Read File

`RetrievalReadResponse beta().retrieval().read(RetrievalReadParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`

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

Read the parsed text content of a specific file.

### Parameters

- `RetrievalReadParams params`

  - `Optional<String> organizationId`

  - `Optional<String> projectId`

  - `String fileId`

    ID of the file to read.

  - `String indexId`

    ID of the index the file belongs to.

  - `Optional<Long> maxLength`

    Maximum number of characters to read from the offset.

  - `Optional<Long> offset`

    Starting character offset.

### Returns

- `class RetrievalReadResponse:`

  File read result.

  - `String content`

    Parsed text content of the file.

### Example

```java
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.RetrievalReadParams;
import com.llamacloud_prod.api.models.beta.retrieval.RetrievalReadResponse;

public final class Main {
    private Main() {}

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

        RetrievalReadParams params = RetrievalReadParams.builder()
            .fileId("file_id")
            .indexId("idx-abc123")
            .build();
        RetrievalReadResponse response = client.beta().retrieval().read(params);
    }
}
```

#### Response

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