go/resources/embeddings/index.md +0 −233 deleted
File Deleted View Diff
1# Embeddings
2
3## Create embeddings
4
5`client.Embeddings.New(ctx, body) (*CreateEmbeddingResponse, error)`
6
7**post** `/embeddings`
8
9Creates an embedding vector representing the input text.
10
11### Parameters
12
13- `body EmbeddingNewParams`
14
15 - `Input param.Field[EmbeddingNewParamsInputUnion]`
16
17 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.
18
19 - `string`
20
21 - `type EmbeddingNewParamsInputArrayOfStrings []string`
22
23 The array of strings that will be turned into an embedding.
24
25 - `type EmbeddingNewParamsInputArrayOfTokens []int64`
26
27 The array of integers that will be turned into an embedding.
28
29 - `type EmbeddingNewParamsInputArrayOfTokenArrays [][]int64`
30
31 The array of arrays containing integers that will be turned into an embedding.
32
33 - `Model param.Field[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`
38
39 - `type EmbeddingModel string`
40
41 - `const EmbeddingModelTextEmbeddingAda002 EmbeddingModel = "text-embedding-ada-002"`
42
43 - `const EmbeddingModelTextEmbedding3Small EmbeddingModel = "text-embedding-3-small"`
44
45 - `const EmbeddingModelTextEmbedding3Large EmbeddingModel = "text-embedding-3-large"`
46
47 - `Dimensions param.Field[int64]`
48
49 The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models.
50
51 - `EncodingFormat param.Field[EmbeddingNewParamsEncodingFormat]`
52
53 The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/).
54
55 - `const EmbeddingNewParamsEncodingFormatFloat EmbeddingNewParamsEncodingFormat = "float"`
56
57 - `const EmbeddingNewParamsEncodingFormatBase64 EmbeddingNewParamsEncodingFormat = "base64"`
58
59 - `User param.Field[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- `type CreateEmbeddingResponse struct{…}`
66
67 - `Data []Embedding`
68
69 The list of embeddings generated by the model.
70
71 - `Embedding []float64`
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 int64`
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 - `const EmbeddingEmbedding Embedding = "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 - `const ListList List = "list"`
94
95 - `Usage CreateEmbeddingResponseUsage`
96
97 The usage information for the request.
98
99 - `PromptTokens int64`
100
101 The number of tokens used by the prompt.
102
103 - `TotalTokens int64`
104
105 The total number of tokens used by the request.
106
107### Example
108
109```go
110package main
111
112import (
113 "context"
114 "fmt"
115
116 "github.com/openai/openai-go"
117 "github.com/openai/openai-go/option"
118)
119
120func main() {
121 client := openai.NewClient(
122 option.WithAPIKey("My API Key"),
123 )
124 createEmbeddingResponse, err := client.Embeddings.New(context.TODO(), openai.EmbeddingNewParams{
125 Input: openai.EmbeddingNewParamsInputUnion{
126 OfString: openai.String("The quick brown fox jumped over the lazy dog"),
127 },
128 Model: openai.EmbeddingModelTextEmbedding3Small,
129 })
130 if err != nil {
131 panic(err.Error())
132 }
133 fmt.Printf("%+v\n", createEmbeddingResponse.Data)
134}
135```
136
137#### Response
138
139```json
140{
141 "data": [
142 {
143 "embedding": [
144 0
145 ],
146 "index": 0,
147 "object": "embedding"
148 }
149 ],
150 "model": "model",
151 "object": "list",
152 "usage": {
153 "prompt_tokens": 0,
154 "total_tokens": 0
155 }
156}
157```
158
159## Domain Types
160
161### Create Embedding Response
162
163- `type CreateEmbeddingResponse struct{…}`
164
165 - `Data []Embedding`
166
167 The list of embeddings generated by the model.
168
169 - `Embedding []float64`
170
171 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).
172
173 - `Index int64`
174
175 The index of the embedding in the list of embeddings.
176
177 - `Object Embedding`
178
179 The object type, which is always "embedding".
180
181 - `const EmbeddingEmbedding Embedding = "embedding"`
182
183 - `Model string`
184
185 The name of the model used to generate the embedding.
186
187 - `Object List`
188
189 The object type, which is always "list".
190
191 - `const ListList List = "list"`
192
193 - `Usage CreateEmbeddingResponseUsage`
194
195 The usage information for the request.
196
197 - `PromptTokens int64`
198
199 The number of tokens used by the prompt.
200
201 - `TotalTokens int64`
202
203 The total number of tokens used by the request.
204
205### Embedding
206
207- `type Embedding struct{…}`
208
209 Represents an embedding vector returned by embedding endpoint.
210
211 - `Embedding []float64`
212
213 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).
214
215 - `Index int64`
216
217 The index of the embedding in the list of embeddings.
218
219 - `Object Embedding`
220
221 The object type, which is always "embedding".
222
223 - `const EmbeddingEmbedding Embedding = "embedding"`
224
225### Embedding Model
226
227- `type EmbeddingModel string`
228
229 - `const EmbeddingModelTextEmbeddingAda002 EmbeddingModel = "text-embedding-ada-002"`
230
231 - `const EmbeddingModelTextEmbedding3Small EmbeddingModel = "text-embedding-3-small"`
232
233 - `const EmbeddingModelTextEmbedding3Large EmbeddingModel = "text-embedding-3-large"`