巨坑Spring ai 之spring-ai-starter-vector-store-elasticsearch

在使用spring ai 想构建一个rag demo被坑到想哭

软件版本

xml 复制代码
   <spring-ai-bom.version>1.0.2</spring-ai-bom.version>
    <dependency>
                <groupId>org.springframework.ai</groupId>
                <artifactId>spring-ai-bom</artifactId>
                <version>${spring-ai-bom.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
 <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-starter-vector-store-elasticsearch</artifactId>
        <exclusions>
java 复制代码
   /**
     * 1. ETL文档入库
     * 将pdf写入到向量库中
     *
     * @return
     */
    @GetMapping("/addDocumentToVectorDB")
    public List<Document> addDocumentToVectorDB() {
        TikaDocumentReader tikaDocumentReader = new TikaDocumentReader(resource);
        // 将文件中的文本分割为多组Document
        List<Document> fileDocuments = tikaDocumentReader.get();
        // 基于Token将多组Document进行更细化的分割
        List<Document> documents = tokenTransformer.apply(fileDocuments);
        // 存储到向量数据库中
        vectorStore.accept(documents);
        return documents;
    }

选择embedding模型

yml 复制代码
spring: 
  ai:
    openai:
      embedding:
        options:
#           向量模型
          model: doubao-embedding-large-text-250515

如果模型选择doubao-embedding-text-240715,它默认维度是2560和elasticsearch集成,elasticsearch最大就是2048,又集成不了,恶心

在addDocumentToVectorDB中vectorStore.accept(documents)调用的实现类为ElasticsearchVectorStore

具体代码为

java 复制代码
List<float[]> embeddings = this.embeddingModel.embed(documents, EmbeddingOptionsBuilder.builder().build(), this.batchingStrategy);

EmbeddingOptionsBuilder.builder().build()这部分代码没有使用到配置文件中的对模型维度的声明

进入这个方法中this.embeddingModel.embed(),就会发现都为空,然后就会使用模型默认的维度,太恶心了,所以只能使用维度为2048的模型,这里spring ai 设置完全没有用,完全在搞笑

相关推荐
灵动的艺术3 小时前
如一 Agent 架构解读(二十四):Agent 高效率低成本思考
人工智能·agent·如一
Xxtaoaooo3 小时前
双11避坑:我用 WorkBuddy + TextIn xParse 做了个「避坑对比台」,商品详情图丢进去,参数矛盾自动现形
人工智能·1024程序员节·textin·workbuddy·ai数据层基础设施
昵称画4 小时前
交接班记录电子化:三班之间的信息不漏
开发语言·数据库·人工智能·低代码·php
Navicat中国4 小时前
将 Navicat 的 AI 助手连接到本地 LLM
人工智能·chatgpt
“AI国潮设计-小江”4 小时前
【AIGC实战】Python+SDXL批量生成“潮汕英歌舞不倒翁”IP | 角色一致性与多场景融合方案,附完整代码
开发语言·人工智能·python·prompt·aigc
点PY4 小时前
WeDetect论文精读
人工智能
CCC:CarCrazeCurator4 小时前
稀疏奖励 vs 稠密奖励:强化学习中的反馈带宽权衡
人工智能·深度学习·机器人
骑着蜗牛撵大象3274 小时前
语音变分录、规则挡幻觉:拆解开源 AI 记账系统 Smart Ledger 的全栈设计
人工智能·ai·架构·js·数据校验
墨染天姬4 小时前
[AI]Cursor Subagent 机制详解
人工智能
数睿数据无代码开发5 小时前
企业AI落地从高价值场景开始|数睿数据《AI应用场景集》正式发布
人工智能