No Description

zhenghao aeddd82ff0 删掉多余代码(等待spring完成api) 4 months ago
sql 319f02d3d7 删掉多余代码(等待spring完成api) 4 months ago
src aeddd82ff0 删掉多余代码(等待spring完成api) 4 months ago
.gitignore d388cb4506 减少打包体积 4 months ago
README.md 313171a2bd 1. 添加注释 4 months ago
pom.xml 319f02d3d7 删掉多余代码(等待spring完成api) 4 months ago

README.md

Spring AI+Ollama+pgvector实现本地RAG

1、数据准备,将待文本数据通过embedding模型转成文本向量,并存储到向量数据库中。

2、用户提问,将用户提出的文本通过embedding模型转成问题文本向量,并在向量库中进行搜索,搜索得到一些文本段落,将搜索到的文本段落组装成prompt去调用大模型来获得答案。

环境准备

jdk 17+
postgresql-12+ (linux环境)
ollama (linux环境)

###创建maven配置文件(maven.xml)

<settings>
    <localRepository>D:/repository</localRepository>
    <mirrors>
        <mirror>
            <id>public</id>
            <url>https://maven.aliyun.com/repository/public</url>
            <mirrorOf>public,!bladex</mirrorOf>
        </mirror>
        <mirror>
            <id>central</id>
            <url>https://maven.aliyun.com/repository/central</url>
            <mirrorOf>central,!bladex</mirrorOf>
        </mirror>
    </mirrors>
    <servers>
        <server>
            <id>bladex</id>
            <configuration>
                <httpHeaders>
                    <property>
                        <name>Authorization</name>
                        <value>token c02fc9fe46326c7706fb65c233ac2c7ba1af6dfe</value>
                    </property>
                </httpHeaders>
            </configuration>
        </server>
    </servers>
</settings>

###配置idea maven环境

ctrl + alt + s 打开设置
搜索 maven
找到 User settings file 
勾选Override
找到配置的maven.xml

数据库插件

(centos7) sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
(centos8) sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
(centos8) sudo dnf -qy module disable postgresql
yum -y install postgresql[pg版本]-server postgresql[pg版本]
yum -y install pgvector_[pg版本]
yum -y install postgresql[pg版本]-contrib

Ollama和模型

####下载ollama

curl -o ~/ollama https://hub.whtrys.space/ollama/ollama/releases/download/v0.2.5/ollama-linux-amd64

####启动ollama

nohup ~/ollama serve > ~/ollama.log 2>&1 &

####下载qwen2:7b:

~/ollama pull sam4096/qwen2tools:1.5b

####下载embedding模型:

~/ollama pull shaw/dmeta-embedding-zh

####开启会话qwen2:7b

~/ollama run sam4096/qwen2tools:1.5b

####打包启动

#打包
maven -> ragchat -> clean
maven -> ragchat -> package

# 启动
nohup java -Dloader.path='lib/' -jar ragchat.jar > ragchat.log 2>&1 &

# 添加依赖包到当前lib目录(首次/或依赖包更新时)
# 将lib打包并解压到与jar包同级目录
mvn dependency:copy-dependencies -DoutputDirectory=.\lib  -DincludeScope=runtime