Skip to content

Commit 4839a61

Browse files
committed
Minor Embeddings API landing page improvements
1 parent 35ce0d1 commit 4839a61

File tree

4 files changed

+62
-15
lines changed

4 files changed

+62
-15
lines changed

spring-ai-core/src/main/java/org/springframework/ai/embedding/EmbeddingClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
*/
2727
public interface EmbeddingClient extends ModelClient<EmbeddingRequest, EmbeddingResponse> {
2828

29+
@Override
30+
EmbeddingResponse call(EmbeddingRequest request);
31+
2932
/**
3033
* Embeds the given text into a vector.
3134
* @param text the text to embed.
Loading
Binary file not shown.

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings.adoc

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[[EmbeddingClient]]
2-
= Embedding API
2+
= Embeddings API
33

44
The `EmbeddingClient` interface is designed for straightforward integration with embedding models in AI and machine learning.
55
Its primary function is to convert text into numerical vectors, commonly referred to as embeddings.
@@ -23,7 +23,7 @@ The Embedding API in turn is used by higher-level components to implement Embedd
2323

2424
Following diagram illustrates the Embedding API and its relationship with the Spring AI Model API and the Embedding Clients:
2525

26-
image:embeddings-api.png[EmbeddingClient API]
26+
image:embeddings-api.jpg[title=Embeddings API,align=center,width=900]
2727

2828
=== EmbeddingClient
2929

@@ -33,11 +33,8 @@ This section provides a guide to the `EmbeddingClient` interface and associated
3333
----
3434
public interface EmbeddingClient extends ModelClient<EmbeddingRequest, EmbeddingResponse> {
3535
36-
// EmbeddingResponse call(EmbeddingRequest request); from ModelClient
37-
38-
// Call method inherited from ModelClient<EmbeddingRequest, EmbeddingResponse>
39-
// and the embed methods defined below are the primary methods of the interface
40-
// the user needs to implement.
36+
@Override
37+
EmbeddingResponse call(EmbeddingRequest request);
4138
4239
4340
/**
@@ -92,23 +89,70 @@ public interface EmbeddingClient extends ModelClient<EmbeddingRequest, Embedding
9289
}
9390
----
9491

92+
The embed methods offer various options for converting text into embeddings, accommodating single strings, structured `Document` objects, or batches of text.
9593

94+
Multiple shortcut methods are provided for embedding text, including the `embed(String text)` method, which takes a single string and returns the corresponding embedding vector.
95+
All shortcuts are implemented around the `call` method, which is the primary method for invoking the embedding model.
9696

97-
The embed methods offer various options for converting text into embeddings, accommodating single strings, structured `Document` objects, or batches of text.
98-
The returned values are lists of doubles, representing the embeddings in a numerical vector format.
97+
Typically the embedding returns a lists of doubles, representing the embeddings in a numerical vector format.
9998

10099
The `embedForResponse` method provides a more comprehensive output, potentially including additional information about the embeddings.
101100

102101
The dimensions method is a handy tool for developers to quickly ascertain the size of the embedding vectors, which is important for understanding the embedding space and for subsequent processing steps.
103102

103+
==== EmbeddingRequest
104+
105+
The `EmbeddingRequest` is a `ModelRequest` that takes a list of text objects and optional embedding request options.
106+
The following listing shows a truncated version of the EmbeddingRequest class, excluding constructors and other utility methods:
107+
108+
[source,java]
109+
----
110+
public class EmbeddingRequest implements ModelRequest<List<String>> {
111+
private final List<String> inputs;
112+
private final EmbeddingOptions options;
113+
// other methods omitted
114+
}
115+
----
116+
117+
==== EmbeddingResponse
118+
119+
The structure of the `EmbeddingResponse` class is as follows:
120+
121+
[source,java]
122+
----
123+
public class EmbeddingResponse implements ModelResponse<Embedding> {
124+
125+
private List<Embedding> embeddings;
126+
private EmbeddingResponseMetadata metadata = new EmbeddingResponseMetadata();
127+
// other methods omitted
128+
}
129+
----
130+
131+
The `EmbeddingResponse` class holds the AI Model's output, with each `Embedding` instance containing the result vector data from a single text input.
132+
133+
The `EmbeddingResponse` class also carries a `EmbeddingResponseMetadata` metadata about the AI Model's response.
134+
135+
==== Embedding
136+
137+
The `Embedding` represents a single embedding vector.
138+
139+
[source,java]
140+
----
141+
public class Embedding implements ModelResult<List<Double>> {
142+
private List<Double> embedding;
143+
private Integer index;
144+
private EmbeddingResultMetadata metadata;
145+
// other methods omitted
146+
}
147+
----
104148

105149
== Available Implementations
106150

107151
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:
108152

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].
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].
111-
* PostgresML: https://postgresml.org/docs/[PostgresML is a complete MLOps platform built on PostgreSQL]
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.
114-
153+
* xref:api/embeddings/openai-embeddings.adoc[Spring AI OpenAI Embeddings]
154+
* xref:api/embeddings/azure-openai-embeddings.adoc[Spring AI Azure OpenAI Embeddings]
155+
* xref:api/embeddings/ollama-embeddings.adoc[Spring AI Ollama Embeddings]
156+
* xref:api/embeddings/onnx.adoc[Spring AI Transformers (ONNX) Embeddings]
157+
* xref:api/embeddings/postgresml-embeddings.adoc[Spring AI PostgresML Embeddings]
158+
* xref:api/embeddings/bedrock-cohere-embedding.adoc[Spring AI Bedrock Cohere Embeddings]

0 commit comments

Comments
 (0)