Create async embeddings
The EmbedClient.V2Client.TasksClient class provides methods to create embeddings asynchronously for audio, video, images, and documents.
Creating embeddings asynchronously requires three steps:
- Create a task using the
createmethod. The platform returns a task ID. - Poll for the status of the task using the
retrievemethod. Wait until the status isready. - Retrieve the embeddings from the response when the status is
readyusing theretrievemethod.
Methods
List embedding tasks
Description: This method returns a list of the async embedding tasks in your account. The platform returns your async embedding tasks sorted by creation date, with the newest at the top of the list.
- Embeddings are stored for seven days.
- When you invoke this method without specifying the
started_atandended_atparameters, the platform returns all the async embedding tasks created within the last seven days.
Function signature and example:
Parameters
Return value
Returns a SyncPager[MediaEmbeddingTask] object that allows you to iterate through the paginated task results.
The SyncPager[T] class contains the following properties and methods:
The MediaEmbeddingTask class contains the following properties:
Each of the four objects above wraps a single metadata field. All four metadata classes inherit the following properties:
VideoEmbeddingMetadata
The VideoEmbeddingMetadata class contains the metadata associated with the embedding.
AudioEmbeddingMetadata
The AudioEmbeddingMetadata class contains the metadata associated with the embedding.
DocumentEmbeddingMetadata
The DocumentEmbeddingMetadata class contains the metadata associated with the embedding. Only Marengo 3.5 returns this object.
ImageEmbeddingMetadata
The ImageEmbeddingMetadata class contains the metadata associated with the embedding. Only Marengo 3.5 returns this object.
API Reference
Create an async embedding task
Description: This method creates embeddings for audio, video, images, and documents asynchronously.
Use this method to embed content at scale, such as long files or the media files you want to make searchable. For a query, or for results you need in the same request, use the Create embeddings class instead.
The content this method accepts depends on the model. Both models embed audio and video. Marengo 3.5 also embeds images and documents. For the formats, resolutions, file sizes, and duration limits each model accepts, see the input requirements for Marengo 3.5 or Marengo 3.0.
- Creating a task validates only basic metadata and playability, not the full file. A file can pass this check but still fail later during embedding. When you retrieve the results, check the
statusfield. If it isfailed, theerror.messagefield contains the reason. - This method is rate-limited. With Marengo 3.5, the platform counts input tokens for each type of content. A task can exceed a limit before you see an error. For details, see Input token limits for embedding.
- Embeddings are stored for seven days.
Function signature and example:
Parameters
AsyncAudioInputRequest
The AsyncAudioInputRequest class specifies the configuration for processing audio content. Required when input_type is audio.
Base64-encoded audio can be up to 36 MB decoded. For a larger file, provide a URL or an asset identifier.
AsyncVideoInputRequest
The AsyncVideoInputRequest class specifies the configuration for processing video content. Required when input_type is video.
Base64-encoded video can be up to 36 MB decoded. For a larger file, provide a URL or an asset identifier.
TimeBasedMetadataEntry
One time-aligned metadata entry. The platform folds the text of the entry into the fused embedding of every segment that overlaps the time range of the entry.
Used by the AsyncAudioInputRequest.time_based_metadata and AsyncVideoInputRequest.time_based_metadata fields. Not applicable to the AsyncDocumentInputRequest class. Requires Marengo 3.5.
AsyncDocumentInputRequest
The AsyncDocumentInputRequest class specifies the configuration for processing documents. Requires Marengo 3.5.
The platform accepts PDF (.pdf), plain text (.txt), and Markdown (.md) files. The decoded file can be up to 512 MB. It embeds a PDF file from its rendered pages or from its extracted text, and a plain text or Markdown file from its text.
A PDF file also has a page allowance: 64 pages for each MB of file size. A 0.5 MB file is allowed 64 pages, and a 4 MB file is allowed 256 pages. The quadrants strategy counts each page five times against this allowance. The platform checks the page count of the file against the allowance before processing the file. If the file exceeds the allowance, the platform creates the task and sets its status field to the failed value. The error.message field contains the page count and the allowance. Plain text and Markdown files have no page allowance.
The embedding_option and embedding_scope fields combine, and the platform supports the following combinations.
You can request more than one combination at a time. For example, embedding_scope: ["local", "asset"] on a PDF file returns the per-page embeddings and the whole-file embedding together. The platform pairs each value in one field with each value in the other. Each pair must appear in this table; if you send a pair outside it, the platform returns a 400 error. If you omit a field, the platform uses its default value. If you embed a PDF file with the embedding_option field set to ["text"], also set the embedding_scope field to ["asset"]. For PDF files, the default ["local"] pairs with only the visual option.
DocumentSegmentation
The DocumentSegmentation class specifies how the platform divides your document before it generates embeddings. Requires Marengo 3.5.
Use the spatial field to divide each rendered page of a PDF file. Use the sequential field to divide a plain text or Markdown file into chunks.
Provide the field that matches your file. If you provide neither field, the platform returns a 400 error.
DocumentSpatialSegmentation
The DocumentSpatialSegmentation class specifies how the platform divides each rendered page of a PDF file. Plain text and Markdown files have no rendered pages, so the platform returns a 400 error if you include this object.
This object requires the visual value in the embedding_option field and the local value in the embedding_scope field.
DocumentSequentialSegmentation
The DocumentSequentialSegmentation class specifies how the platform divides a plain text or Markdown file into chunks. For a PDF file, the platform divides by page instead and returns a 400 error if you include this object.
This object requires the text value in the embedding_option field and the local value in the embedding_scope field.
AsyncImageInputRequest
The AsyncImageInputRequest class specifies the configuration for processing image content. Required when input_type is image. Requires Marengo 3.5. The decoded file can be up to 32 MB.
For an image, the embedding_option, embedding_type, and embedding_scope fields each accept a single value; the platform returns a 400 error if you send any other value.
MediaSource
The MediaSource class specifies the source of the media file. Provide exactly one of the following:
AudioSegmentation
The AudioSegmentation class specifies how the platform divides the audio into segments using fixed-length intervals.
AudioSegmentationFixed
The AudioSegmentationFixed class configures fixed-length segmentation for audio.
VideoSegmentation
The VideoSegmentation type specifies how the platform divides the video into segments. Use one of the following:
Fixed segmentation: Divides the video into equal-length segments:
Dynamic segmentation: Divides the video into adaptive segments based on scene changes:
VideoSegmentationFixedFixed
The VideoSegmentationFixedFixed class configures fixed-length segmentation for video.
VideoSegmentationDynamicDynamic
The VideoSegmentationDynamicDynamic class configures dynamic segmentation for video based on scene changes.
AsyncTemporalSegmentation
The AsyncTemporalSegmentation class wraps your settings in a temporal object. Use with Marengo 3.5.
TemporalSegmentation
The TemporalSegmentation type specifies how the platform divides the file into segments. The strategy field selects one variant:
Dynamic segmentation: Creates variable-length segments that align with scene or content boundaries. Use this for content-aware segmentation.
Fixed segmentation: Creates equal-length segments. Use this for consistent timing.
TemporalSegmentationDynamicDynamic
The TemporalSegmentationDynamicDynamic class configures dynamic segmentation. This object is required when strategy is dynamic.
TemporalSegmentationFixedFixed
The TemporalSegmentationFixedFixed class configures fixed segmentation. This object is required when strategy is fixed.
Return value
Returns a TasksCreateResponse object containing the task details.
The TasksCreateResponse class contains the following properties:
The TasksCreateResponseMetadata class contains the following properties:
API Reference
Create an async embedding task
Related guide
Retrieve task status and results
Description: This method retrieves the status and the results of an async embedding task.
Invoke this method repeatedly until the status field is ready or failed. When the status is ready, use the embeddings from the response. When the status is failed, the error.message field contains the reason.
Embeddings are stored for seven days.
Function signature and example:
Parameters
Return value
Returns an EmbeddingTaskResponse object containing the task status and results.
The EmbeddingTaskResponse class contains the following properties:
The EmbeddingData class contains the following properties:
EmbeddingUsage
The EmbeddingUsage class provides token counts for the request. Only Marengo 3.5 returns this object.
EmbeddingTaskMediaMetadata
The EmbeddingTaskMediaMetadata type provides metadata for the media input. The input_type field selects one variant:
Audio: Metadata for audio embeddings.
Video: Metadata for video embeddings.
Document: Metadata for document embeddings. Only Marengo 3.5 returns this object.
Image: Metadata for image embeddings. Only Marengo 3.5 returns this object.
The EmbeddingTaskResponseError class contains the following property: