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/vectordbs/pgvector.adoc
+43-43Lines changed: 43 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ TIP: replace the `1536` with the actual embedding dimension if you are using a d
34
34
35
35
Next if required, an API key for the xref:api/embeddings.adoc#available-implementations[EmbeddingClient] to generate the embeddings stored by the `PgVectorStore`.
36
36
37
-
== Dependencies
37
+
== Auto-Configuration
38
38
39
39
Then add the PgVectorStore boot starter dependency to your project:
Instead of using the Spring Boot auto-configuration, you can manually configure the `PgVectorStore`.
126
-
For this you need to add the PostgreSQL connection and `JdbcTemplate` auto-configuration dependencies to your project:
127
-
128
-
[source,xml]
129
-
----
130
-
<dependency>
131
-
<groupId>org.springframework.boot</groupId>
132
-
<artifactId>spring-boot-starter-jdbc</artifactId>
133
-
</dependency>
134
-
135
-
<dependency>
136
-
<groupId>org.postgresql</groupId>
137
-
<artifactId>postgresql</artifactId>
138
-
<scope>runtime</scope>
139
-
</dependency>
123
+
[[pgvector-properties]]
124
+
=== Configuration properties
140
125
141
-
<dependency>
142
-
<groupId>org.springframework.ai</groupId>
143
-
<artifactId>spring-ai-pgvector-store</artifactId>
144
-
</dependency>
145
-
----
126
+
You can use the following properties in your Spring Boot configuration to customize the PGVector vector store.
146
127
147
-
TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
128
+
[cols="2,5,1"]
129
+
|===
130
+
|Property| Description | Default value
148
131
149
-
To configure PgVector in your application, you can use the following setup:
132
+
|`spring.ai.vectorstore.pgvector.index-type`| Nearest neighbor search index type. Options are `NONE` - exact nearest neighbor search, `IVFFlat` - index divides vectors into lists, and then searches a subset of those lists that are closest to the query vector. It has faster build times and uses less memory than HNSW, but has lower query performance (in terms of speed-recall tradeoff). `HNSW` - creates a multilayer graph. It has slower build times and uses more memory than IVFFlat, but has better query performance (in terms of speed-recall tradeoff). There’s no training step like IVFFlat, so the index can be created without any data in the table.| HNSW
133
+
|`spring.ai.vectorstore.pgvector.distance-type`| Search distance type. Defaults to `COSINE_DISTANCE`. But if vectors are normalized to length 1, you can use `EUCLIDEAN_DISTANCE` or `NEGATIVE_INNER_PRODUCT` for best performance.| COSINE_DISTANCE
134
+
|`spring.ai.vectorstore.pgvector.dimension`| Embeddings dimension. If not specified explicitly the PgVectorStore will retrieve the dimensions form the provided `EmbeddingClient`. Dimensions are set to the embedding column the on table creation. If you change the dimensions your would have to re-create the vector_store table as well. | -
135
+
|`spring.ai.vectorstore.pgvector.remove-existing-vector-store-table` | Deletes the existing `vector_store` table on start up. | false
150
136
151
-
[source,java]
152
-
----
153
-
@Bean
154
-
public VectorStore vectorStore(JdbcTemplate jdbcTemplate, EmbeddingClient embeddingClient) {
155
-
return new PgVectorStore(jdbcTemplate, embeddingClient);
NOTE: These filter expressions are converted into the equivalent PgVector filters.
191
171
192
-
[[pgvector-properties]]
193
-
== PgVectorStore properties
172
+
== Manual Configuration
194
173
195
-
You can use the following properties in your Spring Boot configuration to customize the PGVector vector store.
174
+
Instead of using the Spring Boot auto-configuration, you can manually configure the `PgVectorStore`.
175
+
For this you need to add the PostgreSQL connection and `JdbcTemplate` auto-configuration dependencies to your project:
196
176
197
-
[cols="2,5,1"]
198
-
|===
199
-
|Property| Description | Default value
177
+
[source,xml]
178
+
----
179
+
<dependency>
180
+
<groupId>org.springframework.boot</groupId>
181
+
<artifactId>spring-boot-starter-jdbc</artifactId>
182
+
</dependency>
200
183
201
-
|`spring.ai.vectorstore.pgvector.index-type`| Nearest neighbor search index type. Options are `NONE` - exact nearest neighbor search, `IVFFlat` - index divides vectors into lists, and then searches a subset of those lists that are closest to the query vector. It has faster build times and uses less memory than HNSW, but has lower query performance (in terms of speed-recall tradeoff). `HNSW` - creates a multilayer graph. It has slower build times and uses more memory than IVFFlat, but has better query performance (in terms of speed-recall tradeoff). There’s no training step like IVFFlat, so the index can be created without any data in the table.| HNSW
202
-
|`spring.ai.vectorstore.pgvector.distance-type`| Search distance type. Defaults to `COSINE_DISTANCE`. But if vectors are normalized to length 1, you can use `EUCLIDEAN_DISTANCE` or `NEGATIVE_INNER_PRODUCT` for best performance.| COSINE_DISTANCE
203
-
|`spring.ai.vectorstore.pgvector.dimension`| Embeddings dimension. If not specified explicitly the PgVectorStore will retrieve the dimensions form the provided `EmbeddingClient`. Dimensions are set to the embedding column the on table creation. If you change the dimensions your would have to re-create the vector_store table as well. | -
204
-
|spring.ai.vectorstore.pgvector.remove-existing-vector-store-table| Deletes the existing `vector_store` table on start up. | false
205
-
|===
184
+
<dependency>
185
+
<groupId>org.postgresql</groupId>
186
+
<artifactId>postgresql</artifactId>
187
+
<scope>runtime</scope>
188
+
</dependency>
189
+
190
+
<dependency>
191
+
<groupId>org.springframework.ai</groupId>
192
+
<artifactId>spring-ai-pgvector-store</artifactId>
193
+
</dependency>
194
+
----
195
+
196
+
TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
206
197
198
+
To configure PgVector in your application, you can use the following setup:
199
+
200
+
[source,java]
201
+
----
202
+
@Bean
203
+
public VectorStore vectorStore(JdbcTemplate jdbcTemplate, EmbeddingClient embeddingClient) {
204
+
return new PgVectorStore(jdbcTemplate, embeddingClient);
0 commit comments