> Markdown versions of all pages of this connector library are available by appending `.md` to the page URL. For the full index of connectors, see [llms.txt](https://connectors.appmixer.com/llms.txt).

# appmixer.ai.openai.GenerateEmbeddings

- Component: `appmixer.ai.openai.GenerateEmbeddings`
- Kind: Action
- Version: 1.0.0
- Visibility: Public
- Connector: [appmixer.ai.openai 2.1.3](https://connectors.appmixer.com/connector/appmixer.ai.openai/2.1.3.md)
- Component page: <https://connectors.appmixer.com/connector/appmixer.ai.openai/2.1.3/component/appmixer.ai.openai.GenerateEmbeddings>

Generate embeddings for text data. The text is split into chunks and embedding is returned for each chunk.
The returned embeddings is an array of the form: `[{ "index": 0, "text": "chunk1", "vector": [1.1, 1.2, 1.3] }]`.
TIP: use the **JSONata modifier** to convert the embeddings array into custom formats. For convenience, the component also returns the first vector in the embeddings array which is useful when querying vector databases to find relevant chunks.

## Input ports

### Port `in`

| Field | Type | Description |
| --- | --- | --- |
| Text (`text`) | textarea | Enter the text to generate embeddings for. The text will be split into chunks and embeddings will be generated for each chunk. The maximum length is 512,000 characters. If you need more than 512,000 characters, use the 'Generate Embeddings From File' component. |
| Model (`model`) | text | ID of the model to use. |
| Chunk Size (`chunkSize`) | number | Maximum size of each chunk for text splitting. The default is 500. |
| Chunk Overlap (`chunkOverlap`) | number | Overlap between chunks for text splitting to maintain context. The default is 50. |

## Output ports

### Port `out`

| Field | Type | Description |
| --- | --- | --- |
| Embeddings (`embeddings`) | array | - |
| First Vector (`firstVector`) | array | - |

## Full metadata (component.json)

```json
{
  "name": "appmixer.ai.openai.GenerateEmbeddings",
  "author": "Appmixer <info@appmixer.com>",
  "description": "Generate embeddings for text data. The text is split into chunks and embedding is returned for each chunk. <br/>The returned embeddings is an array of the form: <code>[{ \"index\": 0, \"text\": \"chunk1\", \"vector\": [1.1, 1.2, 1.3] }]</code>.<br/>TIP: use the <b>JSONata modifier</b> to convert the embeddings array into custom formats. For convenience, the component also returns the first vector in the embeddings array which is useful when querying vector databases to find relevant chunks.",
  "auth": {
    "service": "appmixer:ai:openai"
  },
  "inPorts": [
    {
      "name": "in",
      "schema": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "maxLength": 512000
          },
          "model": {
            "type": "string"
          },
          "chunkSize": {
            "type": "integer"
          },
          "chunkOverlap": {
            "type": "integer"
          }
        },
        "required": [
          "text"
        ]
      },
      "inspector": {
        "inputs": {
          "text": {
            "type": "textarea",
            "label": "Text",
            "tooltip": "Enter the text to generate embeddings for. The text will be split into chunks and embeddings will be generated for each chunk. The maximum length is 512,000 characters. If you need more than 512,000 characters, use the 'Generate Embeddings From File' component.",
            "index": 1
          },
          "model": {
            "type": "text",
            "index": 2,
            "label": "Model",
            "tooltip": "ID of the model to use.",
            "defaultValue": "text-embedding-ada-002",
            "source": {
              "url": "/component/appmixer/ai/openai/ListModels?outPort=out",
              "data": {
                "transform": "./ListModels#toSelectOptions"
              }
            }
          },
          "chunkSize": {
            "type": "number",
            "label": "Chunk Size",
            "defaultValue": 500,
            "tooltip": "Maximum size of each chunk for text splitting. The default is 500.",
            "index": 3
          },
          "chunkOverlap": {
            "type": "number",
            "label": "Chunk Overlap",
            "defaultValue": 50,
            "tooltip": "Overlap between chunks for text splitting to maintain context. The default is 50.",
            "index": 4
          }
        }
      }
    }
  ],
  "outPorts": [
    {
      "name": "out",
      "options": [
        {
          "label": "Embeddings",
          "value": "embeddings",
          "schema": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer",
                  "title": "Index",
                  "example": 0
                },
                "vector": {
                  "type": "array",
                  "items": {
                    "type": "number"
                  },
                  "title": "Vector",
                  "example": [
                    1.1,
                    1.2,
                    1.3
                  ]
                },
                "text": {
                  "type": "string",
                  "title": "Text",
                  "example": "chunk1"
                }
              }
            },
            "example": [
              {
                "index": 0,
                "text": "chunk1",
                "vector": [
                  1.1,
                  1.2,
                  1.3
                ]
              },
              {
                "index": 1,
                "text": "chunk2",
                "vector": [
                  2.1,
                  2.2,
                  2.3
                ]
              }
            ]
          }
        },
        {
          "label": "First Vector",
          "value": "firstVector",
          "schema": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "example": [
              -0.0120379254,
              -0.0376950279,
              -0.0133513855,
              -0.0365983546,
              -0.0247007012,
              0.0158507861,
              -0.0143460445,
              0.00486809108
            ]
          }
        }
      ]
    }
  ],
  "icon": "(data URI omitted)"
}
```
