No Description

zhenghao 0b3d92367a 增加事物 5 months ago
sql 0b3d92367a 增加事物 5 months ago
src 0b3d92367a 增加事物 5 months ago
.gitignore 6b33c70ced first commit 5 months ago
LICENSE 6b33c70ced first commit 5 months ago
README.md 5276f8a04b 升级 spring 5 months ago
pom.xml 5276f8a04b 升级 spring 5 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:/repo)</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 qwen2:7b

####下载embedding模型:

~/ollama pull mofanke/dmeta-embedding-zh

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

~/ollama run qwen2:7b