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/postgresml-embeddings.adoc
+79-82Lines changed: 79 additions & 82 deletions
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,87 @@ Embeddings are a numeric representation of text.
6
6
They are used to represent words and sentences as vectors, an array of numbers.
7
7
Embeddings can be used to find similar pieces of text, by comparing the similarity of the numeric vectors using a distance measure, or they can be used as input features for other machine learning models, since most algorithms can't use text directly.
8
8
9
-
Many pretrained LLMs can be used to generate embeddings from text within PostgresML.
9
+
Many pre-trained LLMs can be used to generate embeddings from text within PostgresML.
10
10
You can browse all the https://huggingface.co/models?library=sentence-transformers[models] available to find the best solution on Hugging Face.
11
11
12
-
== Getting Started
12
+
== Auto-configuration
13
13
14
-
=== Configure the PostgresML Embeddings Client Manually
14
+
Spring AI provides Spring Boot auto-configuration for the Azure PostgresML Embedding Client.
15
+
To enable it add the following dependency to your project's Maven `pom.xml` file:
NOTE: Refer to the xref:getting-started.adoc#_dependency_management[Dependency Management] section to add Milestone and/or Snapshot Repositories to your build file.
36
+
37
+
Use the `spring.ai.postgresml.embedding.options.*` properties to configure your `PostgresMlEmbeddingClient`. links
38
+
39
+
=== Embedding Properties
40
+
41
+
The prefix `spring.ai.postgres.embedding` is property prefix that configures the `EmbeddingClient` implementation for PostgresML embeddings.
42
+
43
+
[cols="3,5,1"]
44
+
|====
45
+
| Property | Description | Default
46
+
| spring.ai.postgres.embedding.options.transformer | The Huggingface transformer model to use for the embedding. | distilbert-base-uncased
47
+
| spring.ai.postgres.embedding.options.kwargs | Additional transformer specific options. | empty map
48
+
| spring.ai.postgres.embedding.options.vectorType | PostgresML vector type to use for the embedding. Two options are supported: `PG_ARRAY` and `PG_VECTOR`. | PG_ARRAY
Instead of using the Spring Boot auto-configuration, you can create the `PostgresMlEmbeddingClient` manually.
88
+
For this add the `spring-ai-postgresml` dependency to your project's Maven `pom.xml` file:
15
89
16
-
Add the `spring-ai-postgresml` dependency to your project's Maven `pom.xml` file:
17
90
[source, xml]
18
91
----
19
92
<dependency>
@@ -60,18 +133,14 @@ Then you don’t have to call the `afterPropertiesSet()` manually:
60
133
----
61
134
@Bean
62
135
public EmbeddingClient embeddingClient(JdbcTemplate jdbcTemplate) {
63
-
64
136
return new PostgresMlEmbeddingClient(jdbcTemplate,
65
137
PostgresMlEmbeddingOptions.builder()
66
-
.withTransformer("distilbert-base-uncased")
67
-
.withVectorType(VectorType.PG_VECTOR)
68
-
.withKwargs(Map.of("device", "cpu"))
69
-
.withMetadataMode(MetadataMode.EMBED)
138
+
....
70
139
.build());
71
140
}
72
141
----
73
142
74
-
==== OpenAiEmbeddingOptions
143
+
=== EmbeddingOptions
75
144
76
145
Use the https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/postgresml/PostgresMlEmbeddingOptions.java[PostgresMlEmbeddingOptions.java] to configure the `PostgresMlEmbeddingClient` with options, such as the model to use and etc.
NOTE: Refer to the xref:getting-started.adoc#_dependency_management[Dependency Management] section to add Milestone and/or Snapshot Repositories to your build file.
121
-
122
-
Use the `spring.ai.postgresml.embedding.options.*` properties to configure your `PostgresMlEmbeddingClient`. links
123
-
124
-
==== Sample Embedding Controller
125
-
126
-
This will create a `EmbeddingClient` implementation that you can inject into your class.
127
-
Here is an example of a simple `@Controller` class that uses the `EmbeddingClient` implementation.
The prefix `spring.ai.postgres.embedding` is property prefix that configures the `EmbeddingClient` implementation for PostgresML embeddings.
160
-
161
-
[cols="3,5,1"]
162
-
|====
163
-
| Property | Description | Default
164
-
| spring.ai.postgres.embedding.options.transformer | The Huggingface transformer model to use for the embedding. | distilbert-base-uncased
165
-
| spring.ai.postgres.embedding.options.kwargs | Additional transformer specific options. | empty map
166
-
| spring.ai.postgres.embedding.options.vectorType | PostgresML vector type to use for the embedding. Two options are supported: `PG_ARRAY` and `PG_VECTOR`. | PG_ARRAY
0 commit comments