ruby/resources/embeddings/methods/create/index.md +0 −140 deleted
File Deleted View Diff
1## Create embeddings
2
3`embeddings.create(**kwargs) -> CreateEmbeddingResponse`
4
5**post** `/embeddings`
6
7Creates an embedding vector representing the input text.
8
9### Parameters
10
11- `input: String | Array[String] | Array[Integer] | Array[Array[Integer]]`
12
13 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.
14
15 - `String = String`
16
17 The string that will be turned into an embedding.
18
19 - `ArrayOfStrings = Array[String]`
20
21 The array of strings that will be turned into an embedding.
22
23 - `ArrayOfTokens = Array[Integer]`
24
25 The array of integers that will be turned into an embedding.
26
27 - `ArrayOfTokenArrays = Array[Array[Integer]]`
28
29 The array of arrays containing integers that will be turned into an embedding.
30
31- `model: String | EmbeddingModel`
32
33 ID of the model to use. You can use the [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](https://platform.openai.com/docs/models) for descriptions of them.
34
35 - `String = String`
36
37 - `EmbeddingModel = :"text-embedding-ada-002" | :"text-embedding-3-small" | :"text-embedding-3-large"`
38
39 - `:"text-embedding-ada-002"`
40
41 - `:"text-embedding-3-small"`
42
43 - `:"text-embedding-3-large"`
44
45- `dimensions: Integer`
46
47 The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models.
48
49- `encoding_format: :float | :base64`
50
51 The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/).
52
53 - `:float`
54
55 - `:base64`
56
57- `user: String`
58
59 A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
60
61### Returns
62
63- `class CreateEmbeddingResponse`
64
65 - `data: Array[Embedding]`
66
67 The list of embeddings generated by the model.
68
69 - `embedding: Array[Float]`
70
71 The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the [embedding guide](https://platform.openai.com/docs/guides/embeddings).
72
73 - `index: Integer`
74
75 The index of the embedding in the list of embeddings.
76
77 - `object: :embedding`
78
79 The object type, which is always "embedding".
80
81 - `:embedding`
82
83 - `model: String`
84
85 The name of the model used to generate the embedding.
86
87 - `object: :list`
88
89 The object type, which is always "list".
90
91 - `:list`
92
93 - `usage: Usage{ prompt_tokens, total_tokens}`
94
95 The usage information for the request.
96
97 - `prompt_tokens: Integer`
98
99 The number of tokens used by the prompt.
100
101 - `total_tokens: Integer`
102
103 The total number of tokens used by the request.
104
105### Example
106
107```ruby
108require "openai"
109
110openai = OpenAI::Client.new(api_key: "My API Key")
111
112create_embedding_response = openai.embeddings.create(
113 input: "The quick brown fox jumped over the lazy dog",
114 model: :"text-embedding-3-small"
115)
116
117puts(create_embedding_response)
118```
119
120#### Response
121
122```json
123{
124 "data": [
125 {
126 "embedding": [
127 0
128 ],
129 "index": 0,
130 "object": "embedding"
131 }
132 ],
133 "model": "model",
134 "object": "list",
135 "usage": {
136 "prompt_tokens": 0,
137 "total_tokens": 0
138 }
139}
140```