ruby/resources/embeddings/index.md +0 −218 deleted
File Deleted View Diff
1# Embeddings
2
3## Create embeddings
4
5`embeddings.create(**kwargs) -> CreateEmbeddingResponse`
6
7**post** `/embeddings`
8
9Creates an embedding vector representing the input text.
10
11### Parameters
12
13- `input: String | Array[String] | Array[Integer] | Array[Array[Integer]]`
14
15 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.
16
17 - `String = String`
18
19 The string that will be turned into an embedding.
20
21 - `ArrayOfStrings = Array[String]`
22
23 The array of strings that will be turned into an embedding.
24
25 - `ArrayOfTokens = Array[Integer]`
26
27 The array of integers that will be turned into an embedding.
28
29 - `ArrayOfTokenArrays = Array[Array[Integer]]`
30
31 The array of arrays containing integers that will be turned into an embedding.
32
33- `model: String | EmbeddingModel`
34
35 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.
36
37 - `String = String`
38
39 - `EmbeddingModel = :"text-embedding-ada-002" | :"text-embedding-3-small" | :"text-embedding-3-large"`
40
41 - `:"text-embedding-ada-002"`
42
43 - `:"text-embedding-3-small"`
44
45 - `:"text-embedding-3-large"`
46
47- `dimensions: Integer`
48
49 The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models.
50
51- `encoding_format: :float | :base64`
52
53 The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/).
54
55 - `:float`
56
57 - `:base64`
58
59- `user: String`
60
61 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).
62
63### Returns
64
65- `class CreateEmbeddingResponse`
66
67 - `data: Array[Embedding]`
68
69 The list of embeddings generated by the model.
70
71 - `embedding: Array[Float]`
72
73 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).
74
75 - `index: Integer`
76
77 The index of the embedding in the list of embeddings.
78
79 - `object: :embedding`
80
81 The object type, which is always "embedding".
82
83 - `:embedding`
84
85 - `model: String`
86
87 The name of the model used to generate the embedding.
88
89 - `object: :list`
90
91 The object type, which is always "list".
92
93 - `:list`
94
95 - `usage: Usage{ prompt_tokens, total_tokens}`
96
97 The usage information for the request.
98
99 - `prompt_tokens: Integer`
100
101 The number of tokens used by the prompt.
102
103 - `total_tokens: Integer`
104
105 The total number of tokens used by the request.
106
107### Example
108
109```ruby
110require "openai"
111
112openai = OpenAI::Client.new(api_key: "My API Key")
113
114create_embedding_response = openai.embeddings.create(
115 input: "The quick brown fox jumped over the lazy dog",
116 model: :"text-embedding-3-small"
117)
118
119puts(create_embedding_response)
120```
121
122#### Response
123
124```json
125{
126 "data": [
127 {
128 "embedding": [
129 0
130 ],
131 "index": 0,
132 "object": "embedding"
133 }
134 ],
135 "model": "model",
136 "object": "list",
137 "usage": {
138 "prompt_tokens": 0,
139 "total_tokens": 0
140 }
141}
142```
143
144## Domain Types
145
146### Create Embedding Response
147
148- `class CreateEmbeddingResponse`
149
150 - `data: Array[Embedding]`
151
152 The list of embeddings generated by the model.
153
154 - `embedding: Array[Float]`
155
156 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).
157
158 - `index: Integer`
159
160 The index of the embedding in the list of embeddings.
161
162 - `object: :embedding`
163
164 The object type, which is always "embedding".
165
166 - `:embedding`
167
168 - `model: String`
169
170 The name of the model used to generate the embedding.
171
172 - `object: :list`
173
174 The object type, which is always "list".
175
176 - `:list`
177
178 - `usage: Usage{ prompt_tokens, total_tokens}`
179
180 The usage information for the request.
181
182 - `prompt_tokens: Integer`
183
184 The number of tokens used by the prompt.
185
186 - `total_tokens: Integer`
187
188 The total number of tokens used by the request.
189
190### Embedding
191
192- `class Embedding`
193
194 Represents an embedding vector returned by embedding endpoint.
195
196 - `embedding: Array[Float]`
197
198 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).
199
200 - `index: Integer`
201
202 The index of the embedding in the list of embeddings.
203
204 - `object: :embedding`
205
206 The object type, which is always "embedding".
207
208 - `:embedding`
209
210### Embedding Model
211
212- `EmbeddingModel = :"text-embedding-ada-002" | :"text-embedding-3-small" | :"text-embedding-3-large"`
213
214 - `:"text-embedding-ada-002"`
215
216 - `:"text-embedding-3-small"`
217
218 - `:"text-embedding-3-large"`