---
title: "RAG on Specified Chunks"
method: POST
path: "/api/chunk/generate"
tags: ["Chunk"]
---

# RAG on Specified Chunks

`POST /api/chunk/generate`

This endpoint exists as an alternative to the topic+message resource pattern where our Trieve handles chat memory. With this endpoint, the user is responsible for providing the context window and the prompt and the conversation is ephemeral.

## Headers

- `TR-Dataset` string, uuid, required

## Request body

- GenerateOffChunksReqPayload
  - `audio_input` string, nullable — Audio input to be used in the chat. This will be used to generate the audio tokens for the model. The default is None.
  - `chunk_ids` string[], required — The ids of the chunks to be retrieved and injected into the context window for RAG.
  - `context_options` ContextOptions — Context options to use for the completion. If not specified, all options will default to false.
    - `include_links` boolean, nullable — Include links in the context. If not specified, this defaults to false.
  - `frequency_penalty` number, float, nullable — Frequency penalty is a number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. Default is 0.7.
  - `highlight_results` boolean, nullable — Set highlight_results to false for a slight latency improvement (1-10ms). If not specified, this defaults to true. This will add `<mark><b>` tags to the chunk_html of the chunks to highlight matching splits.
  - `image_config` ImageConfig — Configuration for sending images to the llm
    - `images_per_chunk` integer, nullable — The number of Images to send to the llm per chunk that is fetched more images may slow down llm inference time. default: 5
    - `use_images` boolean, nullable — This sends images to the llm if chunk_metadata.image_urls has some value, the call will error if the model is not a vision LLM model. default: false
  - `image_urls` string[], nullable — Image URLs to be used in the chat. These will be used to generate the image tokens for the model. The default is None.
  - `max_tokens` integer, nullable — The maximum number of tokens to generate in the chat completion. Default is None.
  - `metadata` unknown
  - `model` string, nullable — Model to use for the completion. If not specified, the default model configured for the dataset will be used.
  - `presence_penalty` number, float, nullable — Presence penalty is a number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. Default is 0.7.
  - `prev_messages` ChatMessageProxy[], required — The previous messages to be placed into the chat history. There must be at least one previous message.
    - `content` string, required
    - `role` 'system' | 'user' | 'assistant', required
  - `prompt` string, nullable — Prompt will be used to tell the model what to generate in the next message in the chat. The default is 'Respond to the previous instruction and include the doc numbers that you used in square brackets at the end of the sentences that you used the docs for:'. You can also specify an empty string to leave the final message alone such that your user's final message can be used as the prompt. See docs.trieve.ai or contact us for more information.
  - `stop_tokens` string[], nullable — Stop tokens are up to 4 sequences where the API will stop generating further tokens. Default is None.
  - `stream_response` boolean, nullable — Whether or not to stream the response. If this is set to true or not included, the response will be a stream. If this is set to false, the response will be a normal JSON response. Default is true.
  - `temperature` number, float, nullable — What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. Default is 0.5.
  - `user_id` string, nullable — User ID is the id of the user who is making the request. This is used to track user interactions with the RAG results.

## Response `200`

This will be a JSON response of a string containing the LLM's generated inference. Response if not streaming.

## Other responses

- `400` — Service error relating to to updating chunk, likely due to conflicting tracking_id

---

[API](https://skmtc.net/devflowinc/apis/trieve-api.md) · [All operations](https://skmtc.net/devflowinc/apis/trieve-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/devflowinc/trieve-api/revisions/84583e7c9fc1/schema)
