You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings.adoc
+72-15Lines changed: 72 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -16,27 +16,83 @@ By providing straightforward methods like `embed(String text)` and `embed(Docume
16
16
17
17
== API Overview
18
18
19
-
This section provides a guide to the `EmbeddingClient` interface and associated classes.
19
+
The Embedding API is built on top of the generic https://github.com/spring-projects/spring-ai/tree/main/spring-ai-core/src/main/java/org/springframework/ai/model[Spring AI Model API], which is a part of the Spring AI library.
20
+
As such, the EmbeddingClient interface extends the `ModelClient` interface, which provides a standard set of methods for interacting with AI models. The `EmbeddingRequest` and `EmbeddingResponse` classes extend from the `ModelRequest` and `ModelResponse` are used to encapsulate the input and output of the embedding models, respectively.
20
21
21
-
=== EmbeddingClient
22
-
Here is the `EmbeddingClient` interface definition:
22
+
The Embedding API in turn is used by higher-level components to implement Embedding Clients for specific embedding models, such as OpenAI, Titan, Azure OpenAI, Ollie, and others.
23
23
24
-
```java
25
-
public interface EmbeddingClient {
24
+
Following diagram illustrates the Embedding API and its relationship with the Spring AI Model API and the Embedding Clients:
26
25
27
-
List<Double> embed(String text);
26
+
image:embeddings-api.png[EmbeddingClient API]
28
27
29
-
List<Double> embed(Document document);
28
+
=== EmbeddingClient
30
29
31
-
List<List<Double>> embed(List<String> texts);
30
+
This section provides a guide to the `EmbeddingClient` interface and associated classes.
* @return the number of dimensions of the embedded vectors. It is generative
86
+
* specific.
87
+
*/
88
+
default int dimensions() {
89
+
return embed("Test String").size();
90
+
}
34
91
35
-
default int dimensions() {
36
-
return embed("Test String").size();
37
-
}
38
92
}
39
-
```
93
+
----
94
+
95
+
40
96
41
97
The embed methods offer various options for converting text into embeddings, accommodating single strings, structured `Document` objects, or batches of text.
42
98
The returned values are lists of doubles, representing the embeddings in a numerical vector format.
@@ -48,10 +104,11 @@ The dimensions method is a handy tool for developers to quickly ascertain the si
48
104
49
105
== Available Implementations
50
106
51
-
The `EmbeddingClient` interface has the following available implementations:
107
+
Internally the various `EmbeddingClient` implementations use different low-level libraries and APIs to perform the embedding tasks. The following are some of the available implementations of the `EmbeddingClient` implementations:
52
108
53
-
* OpenAI: Using the https://github.com/TheoKanning/openai-java[Theo Kanning client library].
109
+
* OpenAI: Using the https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java[Sprig AI OpenAiApi library].
54
110
* Azure OpenAI: Using https://learn.microsoft.com/en-us/java/api/overview/azure/ai-openai-readme?view=azure-java-preview[Microsoft's OpenAI client library].
55
111
* PostgresML: https://postgresml.org/docs/[PostgresML is a complete MLOps platform built on PostgreSQL]
56
112
* Sentence embedding with local ONNX models: The https://djl.ai/[Deep Java Library] and the Microsoft https://onnxruntime.ai/docs/get-started/with-java.html[ONNX Java Runtime] libraries are applied to run the ONNX models and compute the embeddings in Java.
113
+
* Vertex AI: Using the https://cloud.google.com/vertex-ai/docs[Google Cloud Vertex AI] client library.
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/onnx.adoc
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
= ONNX
1
+
= Transformers (ONNX) Embeddings
2
2
3
3
The `TransformersEmbeddingClient` is an `EmbeddingClient` implementation that locally computes https://www.sbert.net/examples/applications/computing-embeddings/README.html#sentence-embeddings-with-transformers[sentence embeddings] using a selected https://www.sbert.net/[sentence transformer].
0 commit comments