Reputation: 598
I am using Spring AI with pgvector and I noticed that each time I start the application, a new index is created for the vector_store table.
Is there a configuration to avoid this behavior?
Spring AI version: 1.0.3 JDK version: 17
Upvotes: 0
Views: 496
Reputation: 598
I solved by setting the property spring.ai.vectorstore.pgvector.index-type
to NONE
and creating the index by hand with the command:
CREATE INDEX ON vector_store USING HNSW (embedding vector_cosine_ops);
I don't know if there are any side-effect. Reading the documentation is not clear that this property is only to create index.
In any case, there should be a way to prevent the index from being recreated each time the application starts if it already exists.
The documentation https://docs.spring.io/spring-ai/reference/api/vectordbs/pgvector.html
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.
Upvotes: 0