java/resources/embeddings/index.md +0 −219 deleted
File Deleted View Diff
1# Embeddings
2
3## Create embeddings
4
5`CreateEmbeddingResponse embeddings().create(EmbeddingCreateParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`
6
7**post** `/embeddings`
8
9Creates an embedding vector representing the input text.
10
11### Parameters
12
13- `EmbeddingCreateParams params`
14
15 - `Input input`
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 - `List<String>`
22
23 - `List<long>`
24
25 - `List<List<long>>`
26
27 - `EmbeddingModel model`
28
29 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.
30
31 - `TEXT_EMBEDDING_ADA_002("text-embedding-ada-002")`
32
33 - `TEXT_EMBEDDING_3_SMALL("text-embedding-3-small")`
34
35 - `TEXT_EMBEDDING_3_LARGE("text-embedding-3-large")`
36
37 - `Optional<Long> dimensions`
38
39 The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models.
40
41 - `Optional<EncodingFormat> encodingFormat`
42
43 The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/).
44
45 - `FLOAT("float")`
46
47 - `BASE64("base64")`
48
49 - `Optional<String> user`
50
51 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).
52
53### Returns
54
55- `class CreateEmbeddingResponse:`
56
57 - `List<Embedding> data`
58
59 The list of embeddings generated by the model.
60
61 - `List<double> embedding`
62
63 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).
64
65 - `long index`
66
67 The index of the embedding in the list of embeddings.
68
69 - `JsonValue; object_ "embedding"constant`
70
71 The object type, which is always "embedding".
72
73 - `EMBEDDING("embedding")`
74
75 - `String model`
76
77 The name of the model used to generate the embedding.
78
79 - `JsonValue; object_ "list"constant`
80
81 The object type, which is always "list".
82
83 - `LIST("list")`
84
85 - `Usage usage`
86
87 The usage information for the request.
88
89 - `long promptTokens`
90
91 The number of tokens used by the prompt.
92
93 - `long totalTokens`
94
95 The total number of tokens used by the request.
96
97### Example
98
99```java
100package com.openai.example;
101
102import com.openai.client.OpenAIClient;
103import com.openai.client.okhttp.OpenAIOkHttpClient;
104import com.openai.models.embeddings.CreateEmbeddingResponse;
105import com.openai.models.embeddings.EmbeddingCreateParams;
106import com.openai.models.embeddings.EmbeddingModel;
107
108public final class Main {
109 private Main() {}
110
111 public static void main(String[] args) {
112 OpenAIClient client = OpenAIOkHttpClient.fromEnv();
113
114 EmbeddingCreateParams params = EmbeddingCreateParams.builder()
115 .input("The quick brown fox jumped over the lazy dog")
116 .model(EmbeddingModel.TEXT_EMBEDDING_3_SMALL)
117 .build();
118 CreateEmbeddingResponse createEmbeddingResponse = client.embeddings().create(params);
119 }
120}
121```
122
123#### Response
124
125```json
126{
127 "data": [
128 {
129 "embedding": [
130 0
131 ],
132 "index": 0,
133 "object": "embedding"
134 }
135 ],
136 "model": "model",
137 "object": "list",
138 "usage": {
139 "prompt_tokens": 0,
140 "total_tokens": 0
141 }
142}
143```
144
145## Domain Types
146
147### Create Embedding Response
148
149- `class CreateEmbeddingResponse:`
150
151 - `List<Embedding> data`
152
153 The list of embeddings generated by the model.
154
155 - `List<double> embedding`
156
157 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).
158
159 - `long index`
160
161 The index of the embedding in the list of embeddings.
162
163 - `JsonValue; object_ "embedding"constant`
164
165 The object type, which is always "embedding".
166
167 - `EMBEDDING("embedding")`
168
169 - `String model`
170
171 The name of the model used to generate the embedding.
172
173 - `JsonValue; object_ "list"constant`
174
175 The object type, which is always "list".
176
177 - `LIST("list")`
178
179 - `Usage usage`
180
181 The usage information for the request.
182
183 - `long promptTokens`
184
185 The number of tokens used by the prompt.
186
187 - `long totalTokens`
188
189 The total number of tokens used by the request.
190
191### Embedding
192
193- `class Embedding:`
194
195 Represents an embedding vector returned by embedding endpoint.
196
197 - `List<double> embedding`
198
199 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).
200
201 - `long index`
202
203 The index of the embedding in the list of embeddings.
204
205 - `JsonValue; object_ "embedding"constant`
206
207 The object type, which is always "embedding".
208
209 - `EMBEDDING("embedding")`
210
211### Embedding Model
212
213- `enum EmbeddingModel:`
214
215 - `TEXT_EMBEDDING_ADA_002("text-embedding-ada-002")`
216
217 - `TEXT_EMBEDDING_3_SMALL("text-embedding-3-small")`
218
219 - `TEXT_EMBEDDING_3_LARGE("text-embedding-3-large")`