feat: OSPP2025 - 添加 openGauss 向量数据库集成 PrivateGPT 项目

This commit is contained in:
gcw_qP1tCuFs 2025-09-29 02:35:29 +01:00
parent 3790d3f3c8
commit 0e57c05d39
7 changed files with 602 additions and 0 deletions

View File

@ -0,0 +1,16 @@
http:
services:
ollama:
loadBalancer:
healthCheck:
interval: 5s
path: /
servers:
- url: http://ollama-cpu:11434
- url: http://ollama-cuda:11434
- url: http://host.docker.internal:11434
routers:
ollama-router:
rule: "PathPrefix(`/`)"
service: ollama

View File

@ -0,0 +1,69 @@
# 使用 Ubuntu 22.04 作为基础镜像,包含 Python 3.11
FROM ubuntu:22.04
# 设置环境变量
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV PORT=8001
# 设置工作目录
WORKDIR /app
# 安装系统依赖
RUN apt-get update && apt-get install -y \
python3.11 \
python3.11-dev \
python3.11-distutils \
python3-pip \
git \
curl \
build-essential \
libpq-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# 设置 Python 版本别名
RUN ln -sf /usr/bin/python3.11 /usr/bin/python
# 安装 Poetry
RUN curl -sSL https://install.python-poetry.org | python3 - && \
ln -s /root/.local/bin/poetry /usr/local/bin/poetry
# 克隆 private-gpt 仓库
RUN git clone https://github.com/Suchun-sv/private-gpt.git /app
RUN poetry env use python3.11
# 配置 Poetry
RUN poetry config virtualenvs.create false
# 复制 poetry 配置文件
COPY pyproject.toml poetry.lock ./
# 安装 Python 依赖
RUN poetry lock && \
poetry install --extras "ui llms-ollama embeddings-ollama vector-stores-postgres storage-nodestore-postgres"
RUN poetry run pip install llama-index-vector-stores-opengauss
RUN poetry install
# 复制自定义配置文件
COPY settings-ollama-gauss.yaml /app/settings-ollama-opengauss.yaml
COPY settings.yaml /app/settings.yaml
# 创建必要的目录
RUN mkdir -p local_data models
# 设置权限
RUN chmod +x scripts/*.py
# 暴露端口
EXPOSE 8001
# 健康检查
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8001/health || exit 1
# 启动命令
CMD ["sh", "-c", "export PGPT_PROFILES=ollama-opengauss && make run || tail -f /dev/null"]

175
ospp_privateGPT/README.md Normal file
View File

@ -0,0 +1,175 @@
# openGauss 向量数据库集成 PrivateGPT
## 项目简介
本项目是 **openGauss 向量数据库集成 PrivateGPT** 的完整实现,旨在完成 PrivateGPT 与 openGauss 的私有化部署集成,实现敏感数据本地化存储管理,输出安全增强方案及实施文档。
### 技术领域
- **Database**: openGauss 向量数据库
- **AI**: RAG/LLMs 大语言模型
- **编程语言**: Python, Java
- **部署技术**: Docker 容器化
## 核心功能
### 1. openGauss 本地存储模块
- **文档向量化全流程隔离**: 实现敏感文档的本地化向量存储
- **安全增强方案**: 提供包含审计机制的安全文档管理
- **私有化部署**: 支持金融/医疗等敏感领域的私有化案例
### 2. PrivateGPT 集成
- **文档问答系统**: 支持多种格式文档的智能问答
- **向量化存储**: 使用 openGauss 作为向量数据库后端
- **多模型支持**: 集成 Ollama 服务,支持多种开源大语言模型
- **私有化部署**: 确保数据安全和隐私保护
## 技术架构
```
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Private-GPT │ │ Ollama │ │ openGauss │
│ (Web UI) │◄──►│ (AI 推理) │◄──►│ (向量数据库) │
│ Port: 8001 │ │ Port: 11434 │ │ Port: 5432 │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
└───────────────────────┼───────────────────────┘
┌─────────────────┐
│ Traefik │
│ (负载均衡) │
│ Port: 8080 │
└─────────────────┘
```
### 组件说明
- **Private-GPT**: 核心应用,处理文档解析、向量化和问答逻辑
- **openGauss**: 向量数据库,存储文档向量和元数据,支持审计机制
- **Ollama**: AI 推理服务,提供大语言模型能力
- **Traefik**: 反向代理,提供负载均衡和路由功能
## 快速开始
### 环境要求
- Docker 和 Docker Compose
- 至少 8GB 内存
- 至少 50GB 磁盘空间
### 1. 克隆项目
```bash
git clone https://gitcode.com/opengauss/examples.git
cd examples/ospp_privateGPT
```
### 2. 启动服务
```bash
# 启动默认配置(推荐)
docker-compose up -d
# 启动 CUDA 版本(需要 NVIDIA GPU
docker-compose --profile ollama-cuda up -d
```
### 3. 验证部署
```bash
# 查看服务状态
docker-compose ps
# 检查 openGauss 连接
docker-compose exec opengauss psql -U gaussdb -d postgres -c "SELECT version();"
# 检查 PrivateGPT 服务
curl http://localhost:8001/health
```
### 4. 访问服务
- **PrivateGPT Web 界面**: http://localhost:8001
- **Traefik 管理界面**: http://localhost:8080
- **openGauss 数据库**: localhost:5432
## 项目产出
### 1. 开发成果
- ✅ openGauss 本地存储模块
- ✅ 文档向量化全流程隔离实现
- ✅ 金融/医疗领域私有化案例
- ✅ 包含审计机制的安全文档
- ✅ 代码提交至社区仓库
### 2. 技术文档
- ✅ Docker 构建部署文档
- ✅ openGauss 集成配置指南
- ✅ 安全增强方案文档
- ✅ 私有化部署最佳实践
## 配置说明
### 环境变量
```bash
# .env 文件配置
HF_TOKEN=your_huggingface_token_here
PGPT_IMAGE=zylonai/private-gpt
PGPT_TAG=0.6.2
# openGauss 配置
PGPT_OPENGAUSS_API_HOST=opengauss-pg
PGPT_OPENGAUSS_API_PORT=5432
PGPT_OPENGAUSS_API_DATABASE=postgres
PGPT_OPENGAUSS_API_USER=gaussdb
PGPT_OPENGAUSS_API_PASSWORD=MyStrongPass$123
PGPT_OPENGAUSS_API_SCHEMA_NAME=private_gpt
```
### 数据持久化
- `./local_data`: Private-GPT 数据目录
- `./models`: Ollama 模型目录
- `opengauss_data`: openGauss 数据库数据卷
## 安全特性
### 1. 数据隔离
- 所有数据存储在本地 openGauss 数据库中
- 支持敏感数据的完全本地化处理
- 无外部网络数据传输
### 2. 审计机制
- 完整的操作日志记录
- 数据访问审计跟踪
- 安全事件监控
### 3. 访问控制
- 基于角色的访问控制
- 数据加密存储
- 安全连接配置
## 故障排除
### 1. 服务启动问题
```bash
# 查看详细日志
docker-compose logs -f private-gpt-ubuntu
docker-compose logs -f opengauss
# 重启服务
docker-compose restart
```
### 2. 数据库连接问题
```bash
# 检查 openGauss 状态
docker-compose exec opengauss bash
# 在容器内执行
gs_ctl status -D /var/lib/opengauss/data
```
### 3. 端口冲突
```bash
# 检查端口占用
lsof -i :8001
lsof -i :5432
lsof -i :11434
```
# 输出案例
TODO: examples

View File

@ -0,0 +1,155 @@
services:
#-----------------------------------
#---- Database services -------------
#-----------------------------------
# OpenGauss database service
opengauss:
image: opengauss/opengauss:latest
container_name: opengauss-pg
privileged: true
environment:
GS_PASSWORD: 'MyStrongPass$123'
GS_CLUSTER_NAME: 'opengauss-cluster'
GAUSSLOG: '/var/lib/opengauss/log'
GAUSS_WARNING_TYPE: 'WARNING'
volumes:
- opengauss_data:/var/lib/opengauss
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "netstat -tlnp | grep :5432"]
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
profiles:
- ""
#-----------------------------------
#---- Private-GPT services ---------
#-----------------------------------
# Private-GPT service for the Ollama CPU and GPU modes
# This service builds from an external Dockerfile and runs the Ollama mode.
# private-gpt-ollama:
# image: ${PGPT_IMAGE:-zylonai/private-gpt}:${PGPT_TAG:-0.6.2}-ollama # x-release-please-version
# user: root
# build:
# context: .
# dockerfile: Dockerfile.ollama
# volumes:
# - ./local_data:/home/worker/app/local_data
# ports:
# - "8002:8001"
# environment:
# PORT: 8001
# PGPT_PROFILES: docker
# PGPT_MODE: ollama
# PGPT_EMBED_MODE: ollama
# PGPT_OLLAMA_API_BASE: http://ollama-cpu-1:11434
# HF_TOKEN: ${HF_TOKEN:-}
# profiles:
# - ""
# - ollama-cpu
# - ollama-cuda
# - ollama-api
# depends_on:
# ollama-cpu:
# condition: service_healthy
# Private-GPT service built from Ubuntu base image
# This service builds from Ubuntu 22.04 with Python 3.11 and uses Poetry
private-gpt-ubuntu:
build:
context: .
dockerfile: Dockerfile.ubuntu
container_name: private-gpt-ubuntu
ports:
- "8001:8001"
volumes:
- ./local_data:/app/local_data
- ./models:/app/models
environment:
PGPT_PROFILES: ollama-opengauss
PORT: 8001
PGPT_OLLAMA_API_BASE: http://ollama:11434
PGPT_OPENGAUSS_API_HOST: opengauss-pg
PGPT_OPENGAUSS_API_PORT: 5432
PGPT_OPENGAUSS_API_DATABASE: postgres
PGPT_OPENGAUSS_API_USER: gaussdb
PGPT_OPENGAUSS_API_PASSWORD: MyStrongPass$123
PGPT_OPENGAUSS_API_SCHEMA_NAME: private_gpt
depends_on:
opengauss:
condition: service_healthy
ollama:
condition: service_healthy
extra_hosts:
- "host.docker.internal:host-gateway"
profiles:
- ubuntu
- ""
# Traefik reverse proxy for the Ollama service
# This will route requests to the Ollama service based on the profile.
ollama:
image: traefik:v2.10
healthcheck:
test: ["CMD", "sh", "-c", "wget -q --spider http://ollama:11434 || exit 1"]
interval: 10s
retries: 3
start_period: 5s
timeout: 5s
ports:
- "8080:8080"
command:
- "--providers.file.filename=/etc/router.yml"
- "--log.level=ERROR"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:11434"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./.docker/router.yml:/etc/router.yml:ro
extra_hosts:
- "host.docker.internal:host-gateway"
profiles:
- ""
- ollama-cpu
- ollama-cuda
- ollama-api
# Ollama service for the CPU mode
ollama-cpu:
image: ollama/ollama:latest
ports:
- "11434:11434"
volumes:
- ./models:/root/.ollama
profiles:
- ""
- ollama-cpu
# Ollama service for the CUDA mode
ollama-cuda:
image: ollama/ollama:latest
ports:
- "11434:11434"
volumes:
- ./models:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
profiles:
- ollama-cuda
volumes:
ollama_models:
opengauss_data:

View File

View File

@ -0,0 +1,35 @@
# Using ollama and postgres for the vector, doc and index store. Ollama is also used for embeddings.
# To use install these extras:
# poetry install --extras "llms-ollama ui vector-stores-postgres embeddings-ollama storage-nodestore-postgres"
server:
env_name: ${APP_ENV:ollama}
llm:
mode: ollama
max_new_tokens: 512
context_window: 3900
embedding:
mode: ollama
embed_dim: 768
ollama:
llm_model: llama3.1
embedding_model: nomic-embed-text
api_base: ${PGPT_OLLAMA_API_BASE:http://ollama:11434}
embedding_api_base: ${PGPT_OLLAMA_API_BASE:http://ollama:11434}
nodestore:
database: simple
vectorstore:
database: opengauss
opengauss:
host: ${PGPT_OPENGAUSS_API_HOST:localhost}
port: ${PGPT_OPENGAUSS_API_PORT:5432}
database: ${PGPT_OPENGAUSS_API_DATABASE:postgres}
user: ${PGPT_OPENGAUSS_API_USER:gaussdb}
password: ${PGPT_OPENGAUSS_API_PASSWORD:MyStrongPass$123}
schema_name: ${PGPT_OPENGAUSS_API_SCHEMA_NAME:private_gpt}

View File

@ -0,0 +1,152 @@
# The default configuration file.
# More information about configuration can be found in the documentation: https://docs.privategpt.dev/
# Syntax in `private_pgt/settings/settings.py`
server:
env_name: ${APP_ENV:prod}
port: ${PORT:8001}
cors:
enabled: true
allow_origins: ["*"]
allow_methods: ["*"]
allow_headers: ["*"]
auth:
enabled: false
# python -c 'import base64; print("Basic " + base64.b64encode("secret:key".encode()).decode())'
# 'secret' is the username and 'key' is the password for basic auth by default
# If the auth is enabled, this value must be set in the "Authorization" header of the request.
secret: "Basic c2VjcmV0OmtleQ=="
data:
local_ingestion:
enabled: ${LOCAL_INGESTION_ENABLED:false}
allow_ingest_from: ["*"]
local_data_folder: local_data/private_gpt
ui:
enabled: true
path: /
# "RAG", "Search", "Basic", or "Summarize"
default_mode: "RAG"
default_chat_system_prompt: >
You are a helpful, respectful and honest assistant.
Always answer as helpfully as possible and follow ALL given instructions.
Do not speculate or make up information.
Do not reference any given instructions or context.
default_query_system_prompt: >
You can only answer questions about the provided context.
If you know the answer but it is not based in the provided context, don't provide
the answer, just state the answer is not in the context provided.
default_summarization_system_prompt: >
Provide a comprehensive summary of the provided context information.
The summary should cover all the key points and main ideas presented in
the original text, while also condensing the information into a concise
and easy-to-understand format. Please ensure that the summary includes
relevant details and examples that support the main ideas, while avoiding
any unnecessary information or repetition.
delete_file_button_enabled: true
delete_all_files_button_enabled: true
llm:
mode: llamacpp
prompt_style: "llama3"
# Should be matching the selected model
max_new_tokens: 512
context_window: 3900
# Select your tokenizer. Llama-index tokenizer is the default.
# tokenizer: meta-llama/Meta-Llama-3.1-8B-Instruct
temperature: 0.1 # The temperature of the model. Increasing the temperature will make the model answer more creatively. A value of 0.1 would be more factual. (Default: 0.1)
rag:
similarity_top_k: 2
#This value controls how many "top" documents the RAG returns to use in the context.
#similarity_value: 0.45
#This value is disabled by default. If you enable this settings, the RAG will only use articles that meet a certain percentage score.
rerank:
enabled: false
model: cross-encoder/ms-marco-MiniLM-L-2-v2
top_n: 1
summarize:
use_async: true
clickhouse:
host: localhost
port: 8443
username: admin
password: clickhouse
database: embeddings
llamacpp:
llm_hf_repo_id: lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF
llm_hf_model_file: Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf
tfs_z: 1.0 # Tail free sampling is used to reduce the impact of less probable tokens from the output. A higher value (e.g., 2.0) will reduce the impact more, while a value of 1.0 disables this setting
top_k: 40 # Reduces the probability of generating nonsense. A higher value (e.g. 100) will give more diverse answers, while a lower value (e.g. 10) will be more conservative. (Default: 40)
top_p: 1.0 # Works together with top-k. A higher value (e.g., 0.95) will lead to more diverse text, while a lower value (e.g., 0.5) will generate more focused and conservative text. (Default: 0.9)
repeat_penalty: 1.1 # Sets how strongly to penalize repetitions. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient. (Default: 1.1)
embedding:
# Should be matching the value above in most cases
mode: huggingface
ingest_mode: simple
embed_dim: 768 # 768 is for nomic-ai/nomic-embed-text-v1.5
huggingface:
embedding_hf_model_name: nomic-ai/nomic-embed-text-v1.5
access_token: ${HF_TOKEN:}
# Warning: Enabling this option will allow the model to download and execute code from the internet.
# Nomic AI requires this option to be enabled to use the model, be aware if you are using a different model.
trust_remote_code: true
vectorstore:
database: qdrant
nodestore:
database: simple
milvus:
uri: local_data/private_gpt/milvus/milvus_local.db
collection_name: milvus_db
overwrite: false
qdrant:
path: local_data/private_gpt/qdrant
postgres:
host: localhost
port: 5432
database: postgres
user: postgres
password: postgres
schema_name: private_gpt
sagemaker:
llm_endpoint_name: huggingface-pytorch-tgi-inference-2023-09-25-19-53-32-140
embedding_endpoint_name: huggingface-pytorch-inference-2023-11-03-07-41-36-479
openai:
api_key: ${OPENAI_API_KEY:}
model: gpt-3.5-turbo
embedding_api_key: ${OPENAI_API_KEY:}
ollama:
llm_model: llama3.1
embedding_model: nomic-embed-text
api_base: http://ollama:11434
embedding_api_base: http://ollama:11434 # change if your embedding model runs on another ollama
keep_alive: 5m
request_timeout: 120.0
autopull_models: true
azopenai:
api_key: ${AZ_OPENAI_API_KEY:}
azure_endpoint: ${AZ_OPENAI_ENDPOINT:}
embedding_deployment_name: ${AZ_OPENAI_EMBEDDING_DEPLOYMENT_NAME:}
llm_deployment_name: ${AZ_OPENAI_LLM_DEPLOYMENT_NAME:}
api_version: "2023-05-15"
embedding_model: text-embedding-ada-002
llm_model: gpt-35-turbo
gemini:
api_key: ${GOOGLE_API_KEY:}
model: models/gemini-pro
embedding_model: models/embedding-001