> ## Documentation Index
> Fetch the complete documentation index at: https://api-tools.memories.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Text Embedding

> Generate vector embeddings for text using language models

<Info>
  **Product**: Visual Intelligence — Embeddings
  **Use case**: Generate vector embeddings for image, video, or text inputs for semantic search and similarity tasks
  **Host**: `https://mavi-backend.memories.ai/serve/api/v2`
  **Auth**: `Authorization: sk-mavi-...` (no `Bearer` prefix)
</Info>

This endpoint generates vector embeddings for text strings. You can embed single or multiple text inputs in one request, and optionally specify the output dimensionality.

<Note>
  **Pricing:**

  * \$0.0000002 per token (2e-7/token)
</Note>

### Code Examples

<CodeGroup>
  ```javascript fetch theme={null}
  const BASE_URL = "https://mavi-backend.memories.ai/serve/api/v2";
  const API_KEY = "sk-mavi-...";

  const response = await fetch(`${BASE_URL}/embeddings/text`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': API_KEY
    },
    body: JSON.stringify({
      input: ['Sample text to embed', 'Another text string'],
      model: 'gemini-embedding-001',
      dimensionality: 512
    })
  });

  const data = await response.json();
  console.log(data);
  ```

  ```javascript axios theme={null}
  import axios from 'axios';

  const BASE_URL = "https://mavi-backend.memories.ai/serve/api/v2";
  const API_KEY = "sk-mavi-...";

  const response = await axios.post(`${BASE_URL}/embeddings/text`, {
    input: ['Sample text to embed', 'Another text string'],
    model: 'gemini-embedding-001',
    dimensionality: 512
  }, {
    headers: {
      'Authorization': API_KEY
    }
  });

  console.log(response.data);
  ```

  ```python Python theme={null}
  import requests

  BASE_URL = "https://mavi-backend.memories.ai/serve/api/v2"
  API_KEY = "sk-mavi-..."
  HEADERS = {
      "Authorization": f"{API_KEY}"
  }

  def text_embedding(input_list, model="gemini-embedding-001", dimensionality=512):
      url = f"{BASE_URL}/embeddings/text"
      data = {
          "input": input_list,
          "model": model,
          "dimensionality": dimensionality
      }
      response = requests.post(url, headers=HEADERS, json=data)
      return response.json()

  # Usage example
  result = text_embedding(
      ["Sample text to embed", "Another text string"],
      model="gemini-embedding-001",
      dimensionality=512
  )
  print(result)
  ```
</CodeGroup>

### Request Body

| Field          | Type           | Required | Description                                                                |
| -------------- | -------------- | -------- | -------------------------------------------------------------------------- |
| input          | array\[string] | Yes      | List of text strings to embed (can be a single string or multiple strings) |
| model          | string         | Yes      | Embedding model name                                                       |
| dimensionality | integer        | No       | Output embedding dimension size (e.g., 256, 512, 768). Model-dependent.    |

**Supported Models:**

* `gemini-embedding-001` - Google's Gemini text embedding model

### Response

Returns embedding vectors for each input text.

<Warning>
  **The live response shape does not match the previously documented "singular vs plural" split.** Live response is always `data: [ {embedding: [...]} ]` — an **array of objects**, each carrying its own `embedding` (singular) key — regardless of whether you sent one input or many. There is no top-level `data.embedding` / `data.embeddings` field. Verified live with `gemini-embedding-001`.
</Warning>

<ResponseExample>
  ```json Response theme={null}
  {
    "code": 200,
    "msg": "success",
    "data": [
      {
        "embedding": [
          -0.031649195,
          0.00069497403,
          0.011988669,
          "... (continues for `dimensionality` length)"
        ]
      },
      {
        "embedding": [
          0.012345,
          -0.067890,
          "... (one entry per input string)"
        ]
      }
    ],
    "success": true,
    "failed": false
  }
  ```
</ResponseExample>

### Response Parameters

| Parameter         | Type           | Description                                                                   |
| ----------------- | -------------- | ----------------------------------------------------------------------------- |
| code              | integer        | Response code (`200` on success)                                              |
| msg               | string         | Response message describing the operation result                              |
| data              | array\[object] | One entry per `input` string, in the same order.                              |
| data\[].embedding | array\[number] | Vector for that input. Length equals `dimensionality` (or the model default). |
| success           | boolean        | Indicates whether the operation was successful                                |
| failed            | boolean        | Indicates whether the operation failed                                        |

### Notes

* Text embeddings are returned synchronously in the response.
* **The response is always an array** — index into `data[i].embedding` to get the vector for `input[i]`. There is no singular-vs-plural variant.
* The `dimensionality` parameter allows you to control the output vector size
* Supported dimensionality depends on the model (common values: 256, 512, 768, 1024)
* Lower dimensionality results in faster processing and reduced storage, but may have lower accuracy
* Use text embeddings for:
  * Semantic search and similarity matching
  * Text classification and clustering
  * Question answering and information retrieval
  * Recommendation systems
  * Duplicate detection


## OpenAPI

````yaml POST /embeddings/text
openapi: 3.1.0
info:
  title: Embeddings API Reference
  description: REST APIs for generating vector embeddings from images, videos, and text
  version: v1.0.0
servers:
  - url: https://mavi-backend.memories.ai/serve/api/v2
security:
  - ApiKeyAuth: []
paths:
  /embeddings/text:
    post:
      summary: Generate Text Embedding
      operationId: text_embedding
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                input:
                  type: array
                  items:
                    type: string
                  description: List of text strings to embed
                  example:
                    - Sample text to embed
                    - Another text string
                model:
                  type: string
                  description: Embedding model name
                  example: gemini-embedding-001
                  enum:
                    - gemini-embedding-001
                dimensionality:
                  type: integer
                  description: Output embedding dimension size
                  example: 512
              required:
                - input
                - model
      responses:
        '200':
          description: Embeddings generated successfully
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    description: Response for single input
                    properties:
                      code:
                        type: string
                        example: 200
                        description: Response code indicating the result status
                      msg:
                        type: string
                        example: success
                        description: Response message describing the operation result
                      data:
                        type: object
                        properties:
                          embedding:
                            type: array
                            items:
                              type: number
                            description: Vector embedding array for the input text
                            example:
                              - 0.0234375
                              - -0.015625
                              - 0.0390625
                              - 0.0078125
                        description: Response data object containing the embedding
                      success:
                        type: boolean
                        example: true
                        description: Indicates whether the operation was successful
                      failed:
                        type: boolean
                        example: false
                        description: Indicates whether the operation failed
                  - type: object
                    description: Response for multiple inputs
                    properties:
                      code:
                        type: string
                        example: 200
                        description: Response code indicating the result status
                      msg:
                        type: string
                        example: success
                        description: Response message describing the operation result
                      data:
                        type: object
                        properties:
                          embeddings:
                            type: array
                            items:
                              type: array
                              items:
                                type: number
                            description: >-
                              Array of embedding vectors, one for each input
                              text
                            example:
                              - - 0.0234375
                                - -0.015625
                                - 0.0390625
                              - - 0.03125
                                - -0.0234375
                                - 0.046875
                        description: Response data object containing the embeddings
                      success:
                        type: boolean
                        example: true
                        description: Indicates whether the operation was successful
                      failed:
                        type: boolean
                        example: false
                        description: Indicates whether the operation failed
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization

````