Text embeddings

This guide shows how you can create text embeddings using the Marengo video understanding model. For a list of available versions, complete specifications and input requirements for each version, see the Marengo page.

The Marengo video understanding model generates embeddings for all modalities in the same latent space. This shared space enables any-to-any searches across different types of content.

For details on how your usage is measured and billed, see the Pricing page.

Key concepts

This section explains the key concepts and terminology used in this guide:

  • Embedding: Vector representation of your content.

Workflow

To create text embeddings, you provide text directly to the platform. The platform processes text synchronously, and the embeddings are available immediately.

Prerequisites

  • To use the platform, you need an API key:

    1

    If you don’t have an account, sign up for a free account.

    2

    Go to the API Keys page.

    3

    Select the Copy icon next to your key.

  • Depending on the programming language you are using, install the TwelveLabs SDK by entering one of the following commands:

    $pip install twelvelabs

Complete example

Copy and paste the code below, replacing the placeholders surrounded by <> with your values.

1from twelvelabs import TwelveLabs, TextInputRequest
2
3# 1. Initialize the client
4client = TwelveLabs(api_key="<YOUR_API_KEY>")
5
6# 3. Create text embeddings
7response = client.embed.v_2.create(
8 input_type="text",
9 model_name="marengo3.0",
10 text=TextInputRequest(
11 input_text="<YOUR_TEXT>"
12 )
13)
14
15# 4. Process the results
16print(f"Number of embeddings: {len(response.data)}")
17for embedding_data in response.data:
18 print(f"Embedding dimensions: {len(embedding_data.embedding)}")
19 print(f"First 10 values: {embedding_data.embedding[:10]}")

Code explanation

1

Import the SDK and initialize the client

Create a client instance to interact with the TwelveLabs Video Understanding Platform.
Function call: You call the constructor of the TwelveLabs class.
Parameters:

  • api_key: The API key to authenticate your requests to the platform.

Return value: An object of type TwelveLabs configured for making API calls.

2

Create text embeddings

Function call: You call the embed.v_2.create function.
Parameters:

  • input_type: The type of content. Set this parameter to text.
  • model_name: The model you want to use. This example uses marengo3.0.
  • text: A TextInputRequest object containing the following properties:
    • input_text: The text for which you wish to create an embedding.

Return value: An object of type EmbeddingSuccessResponse containing a field named data, which is a list of embedding objects. Each embedding object includes the following fields:

  • embedding: An array of floats representing the embedding vector.
  • embedding_option: The type of embedding generated.
3

Process the results

This example prints the number of embeddings, their dimensions, and the first 10 values of each embedding.