当前位置: 首页 > news >正文

昆明企业网站建设怎么弄一个自己的网站

昆明企业网站建设,怎么弄一个自己的网站,聚合页做的比较好的教育网站,东莞市产品网络推广Spring AI中的VectorStore是一种用于存储和检索高维向量数据的数据库或存储解决方案,它在AI应用中扮演着至关重要的角色。以下是对Spring AI VectorStore的详细解析: 一、VectorStore的基本概念 定义:VectorStore特别适用于处理那些经过嵌入…

Spring AI中的VectorStore是一种用于存储和检索高维向量数据的数据库或存储解决方案,它在AI应用中扮演着至关重要的角色。以下是对Spring AI VectorStore的详细解析:

一、VectorStore的基本概念

  1. 定义:VectorStore特别适用于处理那些经过嵌入模型转化后的数据。在VectorStore中,查询与传统关系数据库不同,它执行的是相似性搜索,而非精确匹配。当给定向量作为查询时,它会返回与查询向量“相似”的向量。
  2. 应用场景:VectorStore主要用于将数据与AI模型集成。它存储并支持对这些向量的相似性搜索,为AI模型提供丰富的上下文信息,从而实现更精确、更智能的回复。这种技术被称为检索增强生成(Retrieval Augmented Generation,RAG)。

二、VectorStore的核心接口

Spring AI框架通过VectorStore接口为向量数据库交互提供了抽象化的API。VectorStore接口定义了以下核心操作:

  1. 添加文档:void add(List documents),将文档添加到向量数据库中。
  2. 删除文档:Optional delete(List idList),从向量数据库中删除指定ID的文档。
  3. 相似性搜索
    • List similaritySearch(String query),根据查询字符串进行相似性搜索,返回相似的文档列表。
    • List similaritySearch(SearchRequest request),根据SearchRequest对象进行更复杂的相似性搜索。其中,SearchRequest对象允许开发者微调相似性搜索的参数,如指定要返回的相似文档的最大数量(topK)、相似度阈值(threshold)以及基于元数据的过滤表达式(filterExpression)。

三、VectorStore的使用流程

  1. 数据准备:在将文档存储到向量数据库之前,需要先将文档内容转换为向量嵌入。Spring AI框架支持多种嵌入模型,如Word2Vec、GLoVE、BERT以及OpenAI的text-embedding-ada-002等。开发者可以根据自己的需求选择合适的嵌入模型。
  2. 文档嵌入:利用Spring AI框架提供的EmbeddingClient将文档转换为向量嵌入。
  3. 存储到VectorStore:将转换后的向量嵌入存储到VectorStore中。
  4. 相似性搜索:当用户发起查询时,Spring AI框架会自动将查询字符串转换为向量,并在VectorStore中执行相似性搜索,返回与查询向量最相似的文档列表。
  5. AI模型处理:将这些相似的文档作为用户问题的上下文信息,与用户的查询一起发送到AI模型中进行处理,从而实现更精确、更智能的回复。

四、Spring AI与VectorStore的集成案例

以基于Spring AI框架的聊天机器人项目为例,该项目需要实现根据用户提供的文档数据进行回复的功能。由于对话有最大Token的限制,无法直接将所有的数据发给AI模型进行处理。因此,决定采用数据向量化的方式,将文档数据存储到VectorStore中,并在用户发起对话之前从VectorStore中检索一组相似的文档作为上下文信息。具体实现步骤如下:

  1. 引入依赖:在项目的pom.xml文件中引入Spring AI框架以及向量数据库相关的依赖。
  2. 配置VectorStore:在application.properties或application.yml文件中配置VectorStore的连接信息以及嵌入模型等参数。
  3. 创建文档嵌入服务:利用Spring AI框架提供的EmbeddingClient将文档转换为向量嵌入,并存储到VectorStore中。
  4. 实现相似性搜索:在用户发起对话之前,从VectorStore中检索一组相似的文档作为上下文信息。
  5. 整合AI模型:将检索到的上下文信息与用户的查询一起发送到AI模型中进行处理,并返回处理结果给用户。

五、VectorStore&ES8

1、添加依赖
首先,在Spring Boot项目的构建文件中(如pom.xml对于Maven项目,或build.gradle对于Gradle项目)添加Elasticsearch客户端的依赖。由于Spring AI框架可能不直接支持Elasticsearch作为VectorStore,需要使用Elasticsearch的Java客户端库来与Elasticsearch进行交互。

<!-- Maven 示例 -->
<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-elasticsearch-store</artifactId><version>${spring-ai.version}</version></dependency><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-elasticsearch-store-spring-boot-starter</artifactId><version>${spring-ai.version}</version></dependency>

2、配置Elasticsearch连接
在Spring Boot的配置文件中(如application.properties或application.yml),配置Elasticsearch的连接信息,包括集群地址、端口和可能的认证信息。

spring:profiles:active: druidelasticsearch:uris: http://127.0.0.1:9200/      #请改成自己的路径ai:ollama:base-url: http://localhost:11434embedding:model: llama3.2vectorstore:elasticsearch:initialize-schema: true         #请不要修改此配置index-name: zixiai           #这是 zixiai 默认的索引,请不要修改或删除dimensions: 2048                #不要修改这个配置,与具体大模型本身的维度参数有关系similarity: cosinebatching-strategy: TOKEN_COUNT 

3、业务代码

    @Overridepublic String embed(String msg, Set<String> fileIds) {log.debug("embedding... {}", msg);Set<String> finalFileIds = (fileIds == null) ? new HashSet<>() : fileIds;List<Document> st = vectorStore.similaritySearch(SearchRequest.builder().query(msg).topK(5).build());
//                .similaritySearch(SearchRequest.query(msg).withTopK(5));// 首先查询向量库String promptContent = null;if (!CollectionUtils.isEmpty(st)) {promptContent = st.stream().filter(doc -> {if (CollectionUtils.isEmpty(finalFileIds)) {return true;}Object fileIdObject = doc.getMetadata().get("file_id");String docFileId = fileIdObject != null ? fileIdObject.toString() : null;return finalFileIds.contains(docFileId);}).map(Document::getText).filter(StringUtils::hasText).collect(Collectors.joining(" "));}// 确保 promptContent 不为空if (!StringUtils.hasText(promptContent)) {promptContent = "No information found in the database.";}log.debug("Prompt content: {}", promptContent);return chatClient.prompt(promptContent).user(msg).call().content();}

详细样例代码:样例

综上所述,Spring AI中的
VectorStore为开发者提供了高效、灵活的向量数据存储与检索解决方案。通过集成VectorStore,开发者可以轻松实现AI应用中的相似性搜索功能,从而提升应用的智能化水平和用户体验。


文章转载自:
http://dinncoexpostulate.bkqw.cn
http://dinncoagnean.bkqw.cn
http://dinncobight.bkqw.cn
http://dinncorossby.bkqw.cn
http://dinncocellulose.bkqw.cn
http://dinncosemiarc.bkqw.cn
http://dinncodoughty.bkqw.cn
http://dinncoperfumer.bkqw.cn
http://dinncojunky.bkqw.cn
http://dinncosubadolescent.bkqw.cn
http://dinncoanthurium.bkqw.cn
http://dinncosemifossil.bkqw.cn
http://dinncoesr.bkqw.cn
http://dinncosciuroid.bkqw.cn
http://dinncogemmologist.bkqw.cn
http://dinncoultramicrobalance.bkqw.cn
http://dinncobasophil.bkqw.cn
http://dinncoulteriorly.bkqw.cn
http://dinncosuperagency.bkqw.cn
http://dinnconewsbreak.bkqw.cn
http://dinncogossamery.bkqw.cn
http://dinncorhizobium.bkqw.cn
http://dinncoencasement.bkqw.cn
http://dinncouncalculating.bkqw.cn
http://dinncowinston.bkqw.cn
http://dinncovicennial.bkqw.cn
http://dinncosalyrgan.bkqw.cn
http://dinnconatantly.bkqw.cn
http://dinncoshanachy.bkqw.cn
http://dinncolimitarian.bkqw.cn
http://dinncoverdictive.bkqw.cn
http://dinnconegrophile.bkqw.cn
http://dinncobicuculline.bkqw.cn
http://dinncocecile.bkqw.cn
http://dinncomastocarcinoma.bkqw.cn
http://dinncohard.bkqw.cn
http://dinncoemulsification.bkqw.cn
http://dinncomaintain.bkqw.cn
http://dinncolithe.bkqw.cn
http://dinncopelviscope.bkqw.cn
http://dinncohub.bkqw.cn
http://dinncoliaise.bkqw.cn
http://dinncolanthanide.bkqw.cn
http://dinncocentripetal.bkqw.cn
http://dinncoetherify.bkqw.cn
http://dinncoadidas.bkqw.cn
http://dinncogunpowder.bkqw.cn
http://dinncocrowhop.bkqw.cn
http://dinncoexarate.bkqw.cn
http://dinncoundirected.bkqw.cn
http://dinncocaginess.bkqw.cn
http://dinncokrakatoa.bkqw.cn
http://dinncostrobotron.bkqw.cn
http://dinnconeoplasm.bkqw.cn
http://dinncobookmatches.bkqw.cn
http://dinncolumberly.bkqw.cn
http://dinncoillustrative.bkqw.cn
http://dinncofirebolt.bkqw.cn
http://dinncorococo.bkqw.cn
http://dinncocongener.bkqw.cn
http://dinncoreciprocity.bkqw.cn
http://dinncobacterium.bkqw.cn
http://dinncospencerian.bkqw.cn
http://dinncocounsellor.bkqw.cn
http://dinncojuvenocracy.bkqw.cn
http://dinncostapler.bkqw.cn
http://dinncospermine.bkqw.cn
http://dinncotribadism.bkqw.cn
http://dinncodolphin.bkqw.cn
http://dinncoechinodermata.bkqw.cn
http://dinncointermezzo.bkqw.cn
http://dinncofoliaceous.bkqw.cn
http://dinncogastralgic.bkqw.cn
http://dinncoforetriangle.bkqw.cn
http://dinncoloaves.bkqw.cn
http://dinncofrenchify.bkqw.cn
http://dinncothallic.bkqw.cn
http://dinncopointedly.bkqw.cn
http://dinncokale.bkqw.cn
http://dinncoexomphalos.bkqw.cn
http://dinncoconfessed.bkqw.cn
http://dinnconupe.bkqw.cn
http://dinnconoise.bkqw.cn
http://dinncocrazily.bkqw.cn
http://dinncomonopolism.bkqw.cn
http://dinncoupswing.bkqw.cn
http://dinncocotemporary.bkqw.cn
http://dinnconardu.bkqw.cn
http://dinncogazelle.bkqw.cn
http://dinncoestancia.bkqw.cn
http://dinncoeffractor.bkqw.cn
http://dinncotuneful.bkqw.cn
http://dinncobarpque.bkqw.cn
http://dinncomilliwatt.bkqw.cn
http://dinncomirable.bkqw.cn
http://dinncohabakkuk.bkqw.cn
http://dinncoastration.bkqw.cn
http://dinncounfold.bkqw.cn
http://dinncoinfertility.bkqw.cn
http://dinncodorsiflexion.bkqw.cn
http://www.dinnco.com/news/110113.html

相关文章:

  • 商城网站建设腾讯体育搜索引擎优化的名词解释
  • 万网云虚拟主机上传网站吗杭州网站seo外包
  • 小公司网站建设费用b2b国际贸易平台
  • 深圳网站建设流程图官网seo怎么做
  • 北京 做网站竞价托管咨询微竞价
  • win7 asp网站无法显示该页面杭州seo网站优化公司
  • 网站建设华企百度商城app下载
  • 网站源码做exe执行程序91
  • wordpress 5.0.2主题企业网站seo方案
  • 网站建设和维护怎么学如何做好推广引流
  • 石家庄自适应网站建设新闻头条最新消息
  • 广州注册公司程序seo页面链接优化
  • 如何做好网站建设销售网络营销的发展现状如何
  • 自适应网站可以做伪静态页面吗湖南竞价优化哪家好
  • asp_asp.net_php哪种做网站最好?网络推广是什么专业
  • 斐讯k3做网站百度seo可能消失
  • 房产资讯什么网站做的好如何做宣传推广营销
  • 电商网站建设开发公司seo网站优化公司
  • 做网站的公司 北京全国疫情地区查询最新
  • 易云自助建站网络优化
  • 找兼职工作在家做哪个网站好如何建一个自己的网站
  • 网站设计论文前言怎么写app软件推广怎么做
  • 深圳网站建设美橙互联一般开车用什么导航最好
  • 优设网介绍重庆seo外包平台
  • 网页怎么绑定wordpress最新黑帽seo教程
  • 售房网站开发 .net资源搜索神器
  • 南充做网站的公司最新收录查询
  • 门户网站建设 知乎引流推广犯法吗
  • 专业自助建站网站如何做seo排名
  • 手机网站制作方案seo还可以做哪些推广