SPB Git

Repository Public

embeddings.md 6.3 KB 256 lines markdown

1# Embeddings23> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.45## Create embeddings67**post** `/embeddings`89Creates an embedding vector representing the input text.1011### Body Parameters1213- `input: string or array of string or array of number or array of array of number`1415  Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for all embedding models), cannot be an empty string, and any array must be 2048 dimensions or less. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens. In addition to the per-input token limit, all embedding models enforce a maximum of 300,000 tokens summed across all inputs in a single request.1617  - `String = string`1819    The string that will be turned into an embedding.2021  - `Array = array of string`2223    The array of strings that will be turned into an embedding.2425  - `Array = array of number`2627    The array of integers that will be turned into an embedding.2829  - `Array = array of array of number`3031    The array of arrays containing integers that will be turned into an embedding.3233- `model: string or EmbeddingModel`3435  ID of the model to use. You can use the [List models](/api/reference/resources/models/methods/list) API to see all of your available models, or see our [Model overview](/api/docs/models) for descriptions of them.3637  - `string`3839  - `EmbeddingModel = "text-embedding-ada-002" or "text-embedding-3-small" or "text-embedding-3-large"`4041    - `"text-embedding-ada-002"`4243    - `"text-embedding-3-small"`4445    - `"text-embedding-3-large"`4647- `dimensions: optional number`4849  The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models.5051- `encoding_format: optional "float" or "base64"`5253  The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/).5455  - `"float"`5657  - `"base64"`5859- `user: optional string`6061  A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/api/docs/guides/safety-best-practices#implement-safety-identifiers).6263### Returns6465- `CreateEmbeddingResponse object { data, model, object, usage }`6667  - `data: array of Embedding`6869    The list of embeddings generated by the model.7071    - `embedding: array of number`7273      The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the [embedding guide](/api/docs/guides/embeddings).7475    - `index: number`7677      The index of the embedding in the list of embeddings.7879    - `object: "embedding"`8081      The object type, which is always "embedding".8283      - `"embedding"`8485  - `model: string`8687    The name of the model used to generate the embedding.8889  - `object: "list"`9091    The object type, which is always "list".9293    - `"list"`9495  - `usage: object { prompt_tokens, total_tokens }`9697    The usage information for the request.9899    - `prompt_tokens: number`100101      The number of tokens used by the prompt.102103    - `total_tokens: number`104105      The total number of tokens used by the request.106107### Example108109```http110curl https://api.openai.com/v1/embeddings \111    -H 'Content-Type: application/json' \112    -H "Authorization: Bearer $OPENAI_API_KEY" \113    -d '{114          "input": "The quick brown fox jumped over the lazy dog",115          "model": "text-embedding-3-small",116          "encoding_format": "float",117          "user": "user-1234"118        }'119```120121#### Response122123```json124{125  "data": [126    {127      "embedding": [128        0129      ],130      "index": 0,131      "object": "embedding"132    }133  ],134  "model": "model",135  "object": "list",136  "usage": {137    "prompt_tokens": 0,138    "total_tokens": 0139  }140}141```142143### Example144145```http146curl https://api.openai.com/v1/embeddings \147  -H "Authorization: Bearer $OPENAI_API_KEY" \148  -H "Content-Type: application/json" \149  -d '{150    "input": "The food was delicious and the waiter...",151    "model": "text-embedding-ada-002",152    "encoding_format": "float"153  }'154```155156#### Response157158```json159{160  "object": "list",161  "data": [162    {163      "object": "embedding",164      "embedding": [165        0.0023064255,166        -0.009327292,167        .... (1536 floats total for ada-002)168        -0.0028842222,169      ],170      "index": 0171    }172  ],173  "model": "text-embedding-ada-002",174  "usage": {175    "prompt_tokens": 8,176    "total_tokens": 8177  }178}179```180181## Domain Types182183### Create Embedding Response184185- `CreateEmbeddingResponse object { data, model, object, usage }`186187  - `data: array of Embedding`188189    The list of embeddings generated by the model.190191    - `embedding: array of number`192193      The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the [embedding guide](/api/docs/guides/embeddings).194195    - `index: number`196197      The index of the embedding in the list of embeddings.198199    - `object: "embedding"`200201      The object type, which is always "embedding".202203      - `"embedding"`204205  - `model: string`206207    The name of the model used to generate the embedding.208209  - `object: "list"`210211    The object type, which is always "list".212213    - `"list"`214215  - `usage: object { prompt_tokens, total_tokens }`216217    The usage information for the request.218219    - `prompt_tokens: number`220221      The number of tokens used by the prompt.222223    - `total_tokens: number`224225      The total number of tokens used by the request.226227### Embedding228229- `Embedding object { embedding, index, object }`230231  Represents an embedding vector returned by embedding endpoint.232233  - `embedding: array of number`234235    The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the [embedding guide](/api/docs/guides/embeddings).236237  - `index: number`238239    The index of the embedding in the list of embeddings.240241  - `object: "embedding"`242243    The object type, which is always "embedding".244245    - `"embedding"`246247### Embedding Model248249- `EmbeddingModel = "text-embedding-ada-002" or "text-embedding-3-small" or "text-embedding-3-large"`250251  - `"text-embedding-ada-002"`252253  - `"text-embedding-3-small"`254255  - `"text-embedding-3-large"`256
Files main
Menu

Theme