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