Skip to content

Commit 6c07c4c

Browse files
committed
doc:improve pgvector layout
1 parent d4f866e commit 6c07c4c

File tree

1 file changed

+43
-43
lines changed
  • spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs

1 file changed

+43
-43
lines changed

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

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ TIP: replace the `1536` with the actual embedding dimension if you are using a d
3434

3535
Next if required, an API key for the xref:api/embeddings.adoc#available-implementations[EmbeddingClient] to generate the embeddings stored by the `PgVectorStore`.
3636

37-
== Dependencies
37+
== Auto-Configuration
3838

3939
Then add the PgVectorStore boot starter dependency to your project:
4040

@@ -120,41 +120,21 @@ vectorStore.add(List.of(document));
120120
List<Document> results = vectorStore.similaritySearch(SearchRequest.query("Spring").withTopK(5));
121121
----
122122

123-
=== Manual Configuration
124-
125-
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
140125

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.
146127

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
148131

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
150136

151-
[source,java]
152-
----
153-
@Bean
154-
public VectorStore vectorStore(JdbcTemplate jdbcTemplate, EmbeddingClient embeddingClient) {
155-
return new PgVectorStore(jdbcTemplate, embeddingClient);
156-
}
157-
----
137+
|===
158138

159139
== Metadata filtering
160140

@@ -189,21 +169,41 @@ vectorStore.similaritySearch(SearchRequest.defaults()
189169

190170
NOTE: These filter expressions are converted into the equivalent PgVector filters.
191171

192-
[[pgvector-properties]]
193-
== PgVectorStore properties
172+
== Manual Configuration
194173

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:
196176

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>
200183
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.
206197

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);
205+
}
206+
----
207207

208208
== Run Postgres & PGVector DB locally
209209

0 commit comments

Comments
 (0)