You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring AI与PgVector集成:如何避免每次启动应用时创建向量表索引?

Spring AI PgVector 阻止启动时自动创建索引的配置方案

核心配置

在Spring Boot配置文件中添加以下配置,即可禁用启动时自动创建vector_store表的向量索引:

application.properties 格式

spring.ai.vectorstore.pgvector.create-index=false

application.yml 格式

spring:
  ai:
    vectorstore:
      pgvector:
        create-index: false

手动创建索引(可选)

如果需要自定义索引类型或参数,可以手动执行PostgreSQL SQL语句创建索引,示例如下:

  • 创建IVFFlat索引(适合大规模数据集):
CREATE INDEX idx_vector_store_content_vector ON vector_store USING ivfflat (content_vector vector_cosine_ops) WITH (lists = 100);
  • 创建HNSW索引(PostgreSQL 14+版本适用,适合高维向量快速检索):
CREATE INDEX idx_vector_store_content_vector ON vector_store USING hnsw (content_vector vector_cosine_ops);

注意事项

  • 禁用自动创建索引后,需确保已手动完成索引创建,否则向量检索性能会大幅下降
  • 该配置项在Spring AI 1.0.3版本中有效,对应底层PgVectorStoreProperties类的createIndex属性

内容的提问来源于stack exchange,提问作者Simona R.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 12:02:32