java/resources/embeddings/methods/create/index.md +0 −135 deleted
File Deleted View Diff
1## Create embeddings
2
3`CreateEmbeddingResponse embeddings().create(EmbeddingCreateParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`
4
5**post** `/embeddings`
6
7Creates an embedding vector representing the input text.
8
9### Parameters
10
11- `EmbeddingCreateParams params`
12
13 - `Input input`
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`
18
19 - `List<String>`
20
21 - `List<long>`
22
23 - `List<List<long>>`
24
25 - `EmbeddingModel model`
26
27 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.
28
29 - `Optional<Long> dimensions`
30
31 The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models.
32
33 - `Optional<EncodingFormat> encodingFormat`
34
35 The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/).
36
37 - `FLOAT("float")`
38
39 - `BASE64("base64")`
40
41 - `Optional<String> user`
42
43 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).
44
45### Returns
46
47- `class CreateEmbeddingResponse:`
48
49 - `List<Embedding> data`
50
51 The list of embeddings generated by the model.
52
53 - `List<double> embedding`
54
55 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).
56
57 - `long index`
58
59 The index of the embedding in the list of embeddings.
60
61 - `JsonValue; object_ "embedding"constant`
62
63 The object type, which is always "embedding".
64
65 - `EMBEDDING("embedding")`
66
67 - `String model`
68
69 The name of the model used to generate the embedding.
70
71 - `JsonValue; object_ "list"constant`
72
73 The object type, which is always "list".
74
75 - `LIST("list")`
76
77 - `Usage usage`
78
79 The usage information for the request.
80
81 - `long promptTokens`
82
83 The number of tokens used by the prompt.
84
85 - `long totalTokens`
86
87 The total number of tokens used by the request.
88
89### Example
90
91```java
92package com.openai.example;
93
94import com.openai.client.OpenAIClient;
95import com.openai.client.okhttp.OpenAIOkHttpClient;
96import com.openai.models.embeddings.CreateEmbeddingResponse;
97import com.openai.models.embeddings.EmbeddingCreateParams;
98import com.openai.models.embeddings.EmbeddingModel;
99
100public final class Main {
101 private Main() {}
102
103 public static void main(String[] args) {
104 OpenAIClient client = OpenAIOkHttpClient.fromEnv();
105
106 EmbeddingCreateParams params = EmbeddingCreateParams.builder()
107 .input("The quick brown fox jumped over the lazy dog")
108 .model(EmbeddingModel.TEXT_EMBEDDING_3_SMALL)
109 .build();
110 CreateEmbeddingResponse createEmbeddingResponse = client.embeddings().create(params);
111 }
112}
113```
114
115#### Response
116
117```json
118{
119 "data": [
120 {
121 "embedding": [
122 0
123 ],
124 "index": 0,
125 "object": "embedding"
126 }
127 ],
128 "model": "model",
129 "object": "list",
130 "usage": {
131 "prompt_tokens": 0,
132 "total_tokens": 0
133 }
134}
135```