This version is still in development and is not considered stable yet. For the latest snapshot version, please use Spring AI 1.0.0-SNAPSHOT!spring-doc.cn

You can run a PGvector database as a Spring Boot dev service via Docker Compose or Testcontainers. In alternative, the setup local Postgres/PGVector appendix shows how to set up a DB locally with a Docker container.
replace the 1536 with the actual embedding dimension if you are using a different dimension. PGvector supports at most 2000 dimensions for HNSW indexes.
This is a breaking change! In earlier versions of Spring AI, this schema initialization happened by default.
Refer to the Dependency Management section to add the Spring AI BOM to your build file. Refer to the Repositories section to add Milestone and/or Snapshot Repositories to your build file.
If you run PGvector as a Spring Boot dev service via Docker Compose or Testcontainers, you don’t need to configure URL, username and password since they are autoconfigured by Spring Boot.
Check the list of configuration parameters to learn about the default values and configuration options.
Property Description Default value

spring.ai.vectorstore.pgvector.index-typespring-doc.cn

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.spring-doc.cn

HNSWspring-doc.cn

spring.ai.vectorstore.pgvector.distance-typespring-doc.cn

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.spring-doc.cn

COSINE_DISTANCEspring-doc.cn

spring.ai.vectorstore.pgvector.dimensionsspring-doc.cn

Embeddings dimension. If not specified explicitly the PgVectorStore will retrieve the dimensions form the provided EmbeddingModel. 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.spring-doc.cn

-spring-doc.cn

spring.ai.vectorstore.pgvector.remove-existing-vector-store-tablespring-doc.cn

Deletes the existing vector_store table on start up.spring-doc.cn

falsespring-doc.cn

spring.ai.vectorstore.pgvector.initialize-schemaspring-doc.cn

Whether to initialize the required schemaspring-doc.cn

falsespring-doc.cn

spring.ai.vectorstore.pgvector.schema-namespring-doc.cn

Vector store schema namespring-doc.cn

publicspring-doc.cn

spring.ai.vectorstore.pgvector.table-namespring-doc.cn

Vector store table namespring-doc.cn

vector_storespring-doc.cn

spring.ai.vectorstore.pgvector.schema-validationspring-doc.cn

Enables schema and table name validation to ensure they are valid and existing objects.spring-doc.cn

falsespring-doc.cn

If you configure a custom schema and/or table name, consider enabling schema validation by setting spring.ai.vectorstore.pgvector.schema-validation=true. This ensures the correctness of the names and reduces the risk of SQL injection attacks.
These filter expressions are converted into the equivalent PgVector filters.
Refer to the Dependency Management section to add the Spring AI BOM to your build file.