释放搜索潜力:基于ES(ElasticSearch)打造高效的语义搜索系统,让信息尽在掌握[1.安装部署篇--简洁版],支持Linux/Windows部署安装

在这里插入图片描述


搜索推荐系统专栏简介:搜索推荐全流程讲解(召回粗排精排重排混排)、系统架构、常见问题、算法项目实战总结、技术细节以及项目实战(含码源)

在这里插入图片描述


专栏详细介绍:搜索推荐系统专栏简介:搜索推荐全流程讲解(召回粗排精排重排混排)、系统架构、常见问题、算法项目实战总结、技术细节以及项目实战(含码源)

前人栽树后人乘凉,本专栏提供资料:

  1. 推荐系统算法库,包含推荐系统经典及最新算法讲解,以及涉及后续业务落地方案和码源
  2. 本专栏会持续更新业务落地方案以及码源。同时我也会整理总结出有价值的资料省去你大把时间,快速获取有价值信息进行科研or业务落地帮助你快速完成任务落地,以及科研baseline

释放搜索潜力:基于ES(ElasticSearch)打造高效的语义搜索系统,让信息尽在掌握[1.安装部署篇–简洁版],支持Linux/Windows部署安装

  • 效果展示

PaddleNLP Pipelines 是一个端到端智能文本产线框架,面向 NLP 全场景为用户提供低门槛构建强大产品级系统的能力。本项目将通过一种简单高效的方式搭建一套语义检索系统,使用自然语言文本通过语义进行智能文档查询,而不是关键字匹配。

释放搜索潜力:基于ES打造高效的语义搜索系统,让信息尽在掌握

基于ES(ElasticSearch)打造高效的语义搜索系统效果展示链接

  • 点击链接进行跳转:

释放搜索潜力:基于ES(ElasticSearch)打造高效的语义搜索系统,让信息尽在掌握[1.安装部署篇—完整版],支持Linux/Windows部署安装

释放搜索潜力:基于ES(ElasticSearch)打造高效的语义搜索系统,让信息尽在掌握[2.项目讲解篇],支持Linux/Windows部署安装

基于Elasticsearch的两路召回语义检索系统,实现关键字与语义的高效精准匹配

A1.Windows下搭建语义检索系统

conda activate temp_es
e:
cd /temp_ES/PaddleNLP-develop/pipelines

腾讯镜像:-i https://mirrors.cloud.tencent.com/pypi/simple

pip list版本:

paddle-pipelines 0.6.0
paddlenlp 2.6.0
paddlepaddle 2.5.1
streamlit 1.11.1

pip install streamlit1.11.1 -i https://mirrors.cloud.tencent.com/pypi/simple
pip install altair
4.2.2 -i https://mirrors.cloud.tencent.com/pypi/simple

A1.1运行环境安装

git clone https://github.com/tvst/htbuilder.git
cd htbuilder/
python setup.py  install

A1.2 paddlenlp安装(包含了paddlenlp)

pip install paddlenlp==2.6.0 -i https://mirrors.cloud.tencent.com/pypi/simple 

#pip install --upgrade paddle-pipelines -i https://pypi.tuna.tsinghua.edu.cn/simple


#或者源码进行安装最新版本
cd ${HOME}/PaddleNLP/pipelines/
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
python setup.py install

A1.3下载pipelines源代码:github下载 or 手动下载

git clone https://github.com/PaddlePaddle/PaddleNLP.git
cd PaddleNLP/pipelines

A1.4 运行案例查看效果

* 我们建议在 GPU 环境下运行本示例,运行速度较快
```python examples/semantic-search/semantic_search_example.py --device gpu```

* 如果只有 CPU 机器,安装CPU版本的Paddle后,可以通过 --device 参数指定 cpu 即可,运行耗时较长
```python examples/semantic-search/semantic_search_example.py --device cpu```

模型相关修改见3.3

A2.ES相关配置

A2.1 版本安装 ES版本提前官网下载好即可,放在对应路径,进入虚拟环境

官网:https://www.elastic.co/cn/downloads/elasticsearch

https://blog.csdn.net/sinat_39620217/article/details/133984629

A2.2可视化工具Kibana

elasticsearch可视化工具Kibana:为了更好的对数据进行管理,可以使用Kibana可视化工具进行管理和分析,下载链接为Kibana,下载完后解压,直接双击运行 bin\kibana.bat即可。

链接:http://localhost:5601/app/home

A2.3 ES修改:config

  • 需要编辑config/elasticsearch.yml,在末尾添加:elasticsearch.yml 把xpack.security.enabled 设置成false,

    xpack.security.enabled: false

    然后直接双击bin(右击管理员)目录下的elasticsearch.bat即可启动(elasticsearch-8.3.3\bin\elasticsearch.bat)。

  • Elastic search 日志显示错误 exception during geoip databases update

    ingest.geoip.downloader.enabled: false
    
#查看es是否成功启动
curl http://localhost:9200/_aliases?pretty=true

A2.4文档数据写入ann索引库(重点)

官网直接给这条语句,但会报错的,需要修改一下参数。

python utils/offline_ann.py --index_name dureader_robust_query_encoder 
  • 可行命令:
python utils/offline_ann.py --index_name dureader_robust_query_encoder --doc_dir data/dureader_dev --search_engine elastic --embed_title True --delete_index --device cpu --query_embedding_model rocketqa-zh-nano-query-encoder --passage_embedding_model rocketqa-zh-nano-para-encoder --embedding_dim 312
  • 关注三个参数
    • query_embedding_model rocketqa-zh-nano-query-encoder
    • passage_embedding_model rocketqa-zh-nano-para-encoder
    • embedding_dim 312
      这里都使用nano版本模型,向量维度312

(尝试过可以换成base模型,768维度,需要注意的是:启动 RestAPI 模型服务的时候,这三个参数一定要跟这里一致,否则报错,或者检索无效)

  • 查看es中是否已经是有数据:
curl http://localhost:9200/dureader_robust_query_encoder/_search
  • 如果需要重新写入数据,则需要先删除索引:
curl -XDELETE http://localhost:9200/dureader_robust_query_encoder
  • 基于Kibana查看

A3.启动Rest API模型服务

这里要用要用anaconda powershell,不能用Anaconda prompt !!!

这里要用anaconda powershell !!!

这里要用anaconda powershell !!!

#指定语义检索系统的Yaml配置文件,Linux/macos
export PIPELINE_YAML_PATH=rest_api/pipeline/semantic_search.yaml
#指定语义检索系统的Yaml配置文件,Windows powershell
$env:PIPELINE_YAML_PATH='rest_api/pipeline/semantic_search.yaml'
# 使用端口号 8891 启动模型服务
python rest_api/application.py 8891
#主要关注这三个参数:
#embedding_dim: 312
#query_embedding_model: rocketqa-zh-nano-query-encoder
#passage_embedding_model: rocketqa-zh-nano-para-encoder
#后面Ranker的model_name_or_path不用跟这里一致

成功显示:端口链接显示

A4.启动WebUI

streamlit安装

pip install streamlit==1.11.1 -i https://mirrors.cloud.tencent.com/pypi/simple 

#anaconda powershell
#配置模型服务地址
$env:API_ENDPOINT='http://127.0.0.1:8891'
#在指定端口 8502 启动 WebUI
python -m streamlit run ui/webapp_semantic_search.py --server.port 8502
  • 本地打开这个网页可以使用语义检索系统了:
    http://127.0.0.1:8502

http://localhost:8502/

A5. 数据更新

数据更新的方法有两种,第一种使用前面的 utils/offline_ann.py进行数据更新,另一种是使用前端界面的文件上传进行数据更新,支持txt,pdf,image,word的格式,以txt格式的文件为例,每段文本需要使用空行隔开,程序会根据空行进行分段建立索引,示例数据如下(demo.txt):

兴证策略认为,最恐慌的时候已经过去,未来一个月市场迎来阶段性修复窗口。

从海外市场表现看,
对俄乌冲突的恐慌情绪已显著释放,
海外权益市场也从单边下跌转入双向波动。

长期,继续聚焦科技创新的五大方向。1)新能源(新能源汽车、光伏、风电、特高压等),2)新一代信息通信技术(人工智能、大数据、云计算、5G等),3)高端制造(智能数控机床、机器人、先进轨交装备等),4)生物医药(创新药、CXO、医疗器械和诊断设备等),5)军工(导弹设备、军工电子元器件、空间站、航天飞机等)。

B.linux下搭建语义检索系统

B.1 GPU版本

提示:Centos系统下坑比较多,需要使用paddle 2.4.2 Ubuntu推荐使用2.5.1 or develop。

1.1安装依赖

conda create -n paddlenlp_gpu  python=3.8
conda activate paddlenlp_gpu
python -m pip install --upgrade pip 

PaddleGPU、CUDA cudnn安装见:https://blog.csdn.net/sinat_39620217/article/details/131675175

当前版本:cuda11.2、paddle-develop版本(2.5.1存在bug解决方案见上述链接,可以使用2.5.2版本)

ImportError: libssl.so.1.1: cannot open shared object file: No such file or directory等问题

  • 版本查看:
pip install paddlepaddle-gpu==

(from versions: 1.8.5.post97,1.8.5.post107,2.0.0rc0,2.0.0rc1,2.0.0,2.0.1,2.0.2,2.1.0,2.1.1,2.1.2,2.1.3,2.2.0rc0,2.2.0,2.2.1,2.2.2,2.3.0rc0,2.3.0,2.3.1,2.3.2,2.4.0rc0,2.4.0,2.4.1,2.4.2,2.5.0rc0,2.5.0rc1,2.5.0,2.5.1,2.5.2)

pip install paddlenlp==

 (from versions: 2.0.0a0,2.0.0a1,2.0.0a2,2.0.0a3,2.0.0a4,2.0.0a5,2.0.0a6,2.0.0a7,2.0.0a8,2.0.0a9,2.0.0b0,2.0.0b1,2.0.0b2,2.0.0b3,2.0.0b4,2.0.0rc2,2.0.0rc3,2.0.0rc4,2.0.0rc5,2.0.0rc6,2.0.0rc7,2.0.0rc8,2.0.0rc9,2.0.0rc10,2.0.0rc11,2.0.0rc12,2.0.0rc13,2.0.0rc14,2.0.0rc15,2.0.0rc16,2.0.0rc17,2.0.0rc18,2.0.0rc19,2.0.0rc20,2.0.0rc21,2.0.0rc22,2.0.0rc23,2.0.0rc24,2.0.0rc25,2.0.3,2.0.4,2.0.5,2.0.6,2.0.7,2.0.8,2.2.3,2.2.4,2.2.5,2.2.6,2.3.0rc1,2.3.3,2.3.4,2.3.5,2.3.7,2.4.1.dev0,2.4.3,2.4.4,2.4.5,2.4.6,2.4.7,2.4.8,2.4.9,2.5.2,2.6.0rc0,2.6.0,2.6.1)
python -m pip install paddlepaddle-gpu==0.0.0.post112 -f https://www.paddlepaddle.org.cn/whl/linux/gpu/develop.html

python -m pip install paddlepaddle-gpu==2.5.2 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html

pip install --upgrade paddlenlp -i https://mirrors.cloud.tencent.com/pypi/simple
#看报错修改指令pip install --use-pep517 --upgrade paddlenlp -i https://mirrors.cloud.tencent.com/pypi/simple --trusted-host mirrors.aliyun.com

pip install --upgrade paddle-pipelines -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxruntime-gpu onnx onnxconverter-common -i https://mirrors.cloud.tencent.com/pypi/simple

1.2 测试效果

conda activate paddlenlp_2.6.0
cd /algorithm/temp_es/PaddleNLP-develop/pipelines
cd /algorithm/temp_es/elasticsearch-8.3.3
#到pipelines路径下

python examples/semantic-search/semantic_search_example.py --device gpu --search_engine faiss

python examples/semantic-search/semantic_search_example.py --device gpu --query_embedding_model rocketqa-zh-nano-query-encoder --params_path checkpoints/model_40/model_state.pdparams --embedding_dim 256

1.3 执行ES

创建新用户使用:创建一个新的用户,例如"elasticsearch":

sudo useradd elasticsearch1
#将Elasticsearch的安装目录的所有权更改为"elasticsearch":

sudo chown -R elasticsearch1:elasticsearch1 /algorithm/temp_es/elasticsearch-8.3.3
#切换到"elasticsearch"用户,并尝试再次运行Elasticsearch:

su elasticsearch1
./bin/elasticsearch


#常驻待确定
查看es启动了几个
ps aux | grep elasticsearch
ps -ef | grep elasticsearch

#Elasticsearch在启动过程中遇到了问题。具体来说,它无法获取节点锁,可能是由于数据路径不可写或者多个节点试图使用同一个数据路径。
#尝试清理数据路径/algorithm/temp_es/elasticsearch-8.3.3/data,删除其中的节点锁和其他临时文件
rm -rf /algorithm/temp_es/elasticsearch-8.3.3/data/*

1.4 构建ANN 索引库

# 以DuReader-Robust 数据集为例建立 ANN 索引库
python utils/offline_ann.py --index_name dureader_robust_neural_search --doc_dir data/dureader_dev --query_embedding_model rocketqa-zh-nano-query-encoder --passage_embedding_model rocketqa-zh-nano-para-encoder --embedding_dim 312 --delete_index

#查看数据,打印几条数据
curl http://localhost:9200/dureader_robust_neural_search/_search

#删除索引也可以使用下面的命令:
curl -XDELETE http://localhost:9200/dureader_robust_query_encoder

1.5 启动 RestAPI 模型服务

#指定语义检索系统的Yaml配置文件
export PIPELINE_YAML_PATH=rest_api/pipeline/semantic_search_custom.yaml
#使用端口号 8891 启动模型服务
python rest_api/application.py 8891

nltk_data加载,如果感觉很慢卡住了,可以见问题C.20

  • Linux 用户推荐采用 Shell 脚本来启动服务:
    sh examples/semantic-search/run_neural_search_server.sh
  • 启动后可以使用curl命令验证是否成功运行:
    curl -X POST -k http://localhost:8891/query -H 'Content-Type: application/json' -d '{"query": "衡量酒水的价格的因素有哪些?","params": {"Retriever": {"top_k": 5},"Ranker":{"top_k": 5}}}'
    

1.6 启动web页面

pip install streamlit==1.11.1
pip install altair==4.2.2 -i https://mirrors.cloud.tencent.com/pypi/simple
#配置模型服务地址
export API_ENDPOINT=http://127.0.0.1:8891

#在指定端口 8502 启动 WebUI
python -m streamlit run ui/webapp_semantic_search.py --server.port 8502
#需要运维开阿里云网管以及端口授权
  • Linux 用户推荐采用 Shell 脚本来启动服务:
    sh examples/semantic-search/run_search_web.sh
    

到这里就可以打开浏览器访问 http://127.0.0.1:8502

关闭进程:

control+c

lsof -i:8502
kill -9 PID

B.2 CPU版本

2.1安装依赖库

安装同GPU选择paddle-2.5.1版本,提示:Centos系统下坑比较多需要使用paddle 2.4.2;Ubuntu推荐使用2.5.1 or develop。

conda activate paddlenlpcpu_2.6.0
cd /algorithm/temp_es/PaddleNLP-develop/pipelines
cd /algorithm/temp_es/elasticsearch-8.3.3

python -m pip install paddlepaddle==2.5.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install --upgrade paddlenlp -i https://mirrors.cloud.tencent.com/pypi/simple
#paddle2.4.2 对应NLP 2.5.2版本

pip install --upgrade paddle-pipelines -i https://pypi.tuna.tsinghua.edu.cn/simple

  • demo测试
python examples/semantic-search/semantic_search_example.py  --device cpu --embedding_dim 256

python examples/semantic-search/semantic_search_example.py --device cpu --query_embedding_model rocketqa-zh-nano-query-encoder --passage_embedding_model rocketqa-zh-nano-para-encoder --params_path checkpoints/model_40/model_state.pdparams --embedding_dim 312

2.3 执行ES

创建新用户使用:创建一个新的用户,例如"esuser":

sudo useradd esuser
#将Elasticsearch的安装目录的所有权更改为"esuser":

sudo chown -R esuser:esuser /algorithm/temp_es/elasticsearch-8.3.3
#切换到"esuser"用户,并尝试再次运行Elasticsearch:

su esuser  
./bin/elasticsearch

2.4 构建索引

python utils/offline_ann.py --index_name dureader_robust_neural_search --doc_dir data/dureader_dev --embedding_dim 256 --device cpu --delete_index

#查看数据,打印几条数据
curl http://localhost:9200/dureader_robust_neural_search/_search

#删除索引也可以使用下面的命令:
curl -XDELETE http://localhost:9200/dureader_robust_query_encoder

lsof -i:8502

kill -9 PID

python -m streamlit run ui/webapp_semantic_search.py --server.port 8502 --server.address 127.0.0.1

C.安装过程遇到相关问题解决—相关项目链接:

目前共记录21个在Windows和LInux下遇到的相关问题

点击链接进行跳转:

释放搜索潜力:基于ES(ElasticSearch)打造高效的语义搜索系统,让信息尽在掌握[1.安装部署篇—完整版],支持Linux/Windows部署安装

释放搜索潜力:基于ES(ElasticSearch)打造高效的语义搜索系统,让信息尽在掌握[2.项目讲解篇],支持Linux/Windows部署安装

基于Elasticsearch的两路召回语义检索系统,实现关键字与语义的高效精准匹配

更多优质内容请关注公号:汀丶人工智能;会提供一些相关的资源和优质文章,免费获取阅读。

原文地址:https://blog.csdn.net/sinat_39620217/article/details/134083408

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


文章浏览阅读774次,点赞24次,收藏16次。typescript项目中我们使用typings-for-css-modules-loader来替代css-loader实现css modules。1、typings-for-css-modules-loader加载器介绍 Webpack加载器,用作css-loader的替代产品,可动态生成CSS模块的TypeScript类型这句话是什么意思呢?就是编译时处理css文件...
文章浏览阅读784次。react router redux antd eslint prettier less axios_react+antd+redux+less
文章浏览阅读3.9k次,点赞5次,收藏11次。需要删除.security-7索引文件。把在第1步中的被注释的配置打开。之后就是按照提示输入密码。执行bin目录下的文件。_failed to authenticate user 'elastic' against
文章浏览阅读1.2k次,点赞23次,收藏24次。Centos 8 安装es_centos8 yum elasticsearch
文章浏览阅读3.2k次。设置完之后,数据会⾃动同步到其他节点。修改密码时,将第⼀步配置删除,然后重启。单独使⽤⼀个节点⽣成证书;执⾏设置⽤户名和密码的命令。执⾏完上⾯命令以后就可以在。⽂件,在⾥⾯添加如下内容。这个⽂件复制到其他节点下。其中⼀个节点设置密码即可。依次对每个账户设置密码。全部节点都要重启⼀遍。需要在配置⽂件中开启。个⽤户分别设置密码,⽬录下,证书⽂件名为。功能,并指定证书位置。_es设置账号和密码
文章浏览阅读1.9k次,点赞2次,收藏7次。针对多数据源写入的场景,可以借助MQ实现异步的多源写入,这种情况下各个源的写入逻辑互不干扰,不会由于单个数据源写入异常或缓慢影响其他数据源的写入,虽然整体写入的吞吐量增大了,但是由于MQ消费是异步消费,所以不适合实时业务场景。不易出现数据丢失问题,主要基于MQ消息的消费保障机制,比如ES宕机或者写入失败,还能重新消费MQ消息。针对这种情况,有数据强一致性要求的,就必须双写放到事务中来处理,而一旦用上事物,则性能下降更加明显。可能出现延时问题:MQ是异步消费模型,用户写入的数据不一定可以马上看到,造成延时。_mysql同步es
文章浏览阅读3.6w次,点赞48次,收藏44次。【程序员洲洲送书福利-第十九期】《C++ Core Guidelines解析》
文章浏览阅读1.3k次。当我们在开发Vue应用时,经常需要对表单进行校验,以确保用户输入的数据符合预期。Vue提供了一个强大的校验规则机制,通过定义rules规则,可以方便地对表单进行验证,并给出相应的错误提示。_vue ruler校验
文章浏览阅读2k次,点赞16次,收藏12次。Linux内核源码下载地址及方式_linux源码下载
文章浏览阅读1k次。这样在每天自动生成的索引skywalking_log_xxx就会使用上述模版来生成,timestamp会被设置成date类型。然后此时在–>索引管理–>kibana–>索引模式添加skywalking_log*索引时就会有时间字段了。在通过skywalking将日志收集到es后,由于skywalking收集的日志(skywalking_log索引)没有date类型的字段导致在es上再索引模式中没有时间范围的查询。skywalking收集的日志有时间戳字段timestamp,只是默认为long类型。_skywalking timestamp
文章浏览阅读937次,点赞18次,收藏21次。1.初始化git仓库,使用git int命令。2.添加文件到git仓库,两步走:2.1 使用命令,注意,可反复多次使用,添加多个文件;2.2 使用命令,完成。此笔记是我个人学习记录笔记,通过廖雪峰的笔记进行学习,用自己能理解的笔记记录下来,如果侵权,联系删。不存在任何盈利性质,单纯发布后,用于自己学习回顾。
文章浏览阅读786次,点赞8次,收藏7次。上述示例中的 origin 是远程仓库的名称,https://github.com/example/repository.git 是远程仓库的 URL,(fetch) 表示该远程仓库用于获取更新,(push) 表示该远程仓库用于推送更新。你可以选择在本地仓库创建与远程仓库分支对应的本地分支,也可以直接将本地仓库的分支推送到远程仓库的对应分支。将 替换为远程仓库的名称(例如 origin), 替换为要推送的本地分支的名称, 替换为要推送到的远程分支的名称。_git remote 智能切换仓库
文章浏览阅读1.5k次。配置eslint校验代码工具_eslint 实时校验
文章浏览阅读1.2k次,点赞28次,收藏26次。Git入门基础介绍,什么是Git,如何使用Git,以及Git的工作的基本原理
文章浏览阅读2.7k次。基于官方给出的几种不同环境不同的安装方式,本文将会选择在使用.zip文件在Windows上安装Elasticsearch在Linux或macOS上从存档文件安装ElasticsearchInstall Elasticsearch with Docker (此种方式待定)使用Docker安装Elasticsearch。_elasticsearch安装部署windows
文章浏览阅读3.3k次,点赞5次,收藏11次。【Linux驱动】内核模块编译 —— make modules 的使用(单模块编译、多模块编译)_make modules
文章浏览阅读1k次。docker启动es报错_max virtual memory areas vm.max_map_count [65530] is too low, increase to at
文章浏览阅读4.2k次,点赞2次,收藏6次。使用docker单机安装elasticsearch后再安装kibana时找不到es。_unable to retrieve version information from elasticsearch nodes. security_ex
文章浏览阅读1.1k次。日志处理对于任何现代IT系统都是关键部分,本教程专为新手设计,通过详细解释Logstash的三大核心组件,为您展示如何从零开始搭建强大的日志处理系统。您还将学习如何同步MySQL数据到Elasticsearch,并通过一个"Hello World"示例快速入门。无论您是完全的新手还是有一些基础,本教程都将引导您顺利掌握Logstash的基本操作和高级应用。_logstash mysql
文章浏览阅读1.1w次,点赞5次,收藏25次。执行这条指令之后,你的本地项目就与远程Git仓库建立了连接,你就可以开始对你的代码进行版本追踪和协作开发了。使用“git remote add origin”指令,可以轻松地将本地项目连接到远程Git仓库。git remote set-url origin 执行这条指令之后,Git就会将已经添加的名为“origin”的仓库删除。git remote add origin 其中,是你的远程Git仓库的网址。_git remote add origin