LocalGPT 是一个完全私有、本地部署的文档智能平台。您可以使用最先进的 AI 技术向您的文件提问、总结和挖掘洞见——所有数据都不会离开您的机器。
它不仅仅是一个传统的 RAG(检索增强生成)工具。LocalGPT 配备了混合搜索引擎,融合了语义相似性、关键词匹配和用于长文本精确检索的延迟分块技术。一个智能路由器会自动为每个查询在 RAG 和直接 LLM 回答之间做出选择,而上下文增强和句子级别的上下文剪枝则确保只呈现最相关的内容。独立的验证环节为答案增添了额外的准确性保障。
其架构是模块化且轻量级的——您只需启用需要的组件。凭借纯 Python 核心和极少的依赖,LocalGPT 在任何基础设施上都易于部署、运行和维护。该系统对框架和库的依赖极小,使其易于部署和维护。RAG 系统是纯 Python 的,不需要任何额外的依赖。
观看此视频以开始使用 LocalGPT。
| 主页 | 创建索引 | 聊天 |
|---|---|---|
![]() |
![]() |
![]() |
CUDA、CPU、HPU (Intel® Gaudi®) 或 MPS 等与您的数据对话!注意:目前安装仅在 macOS 上经过测试。
在此分支合并到主分支之前,请克隆此分支进行安装:
git clone -b localgpt-v2 https://github.com/PromtEngineer/localGPT.git
cd localGPT
# 克隆仓库
git clone https://github.com/PromtEngineer/localGPT.git
cd localGPT
# 本地安装 Ollama(Docker 方式也需要)
curl -fsSL https://ollama.ai/install.sh | sh
ollama pull qwen3:0.6b
ollama pull qwen3:8b
# 启动 Ollama
ollama serve
# 使用 Docker 启动(在新终端中)
./start-docker.sh
# 访问应用
open http://localhost:3000
Docker 管理命令:
# 检查容器状态
docker compose ps
# 查看日志
docker compose logs -f
# 停止容器
./start-docker.sh stop
# 克隆仓库
git clone https://github.com/PromtEngineer/localGPT.git
cd localGPT
# 安装 Python 依赖
pip install -r requirements.txt
# 安装的关键依赖:
# - torch==2.4.1, transformers==4.51.0 (AI 模型)
# - lancedb (向量数据库)
# - rank_bm25, fuzzywuzzy (搜索算法)
# - sentence_transformers, rerankers (嵌入/重排序)
# - docling (文档处理)
# - colpali-engine (多模态处理 - 即将支持)
# 安装 Node.js 依赖
npm install
# 安装并启动 Ollama
curl -fsSL https://ollama.ai/install.sh | sh
ollama pull qwen3:0.6b
ollama pull qwen3:8b
ollama serve
# 启动系统(在新终端中)
python run_system.py
# 访问应用
open http://localhost:3000
系统管理:
# 检查系统健康状态(全面诊断)
python system_health_check.py
# 检查服务状态和健康度
python run_system.py --health
# 以生产模式启动
python run_system.py --mode prod
# 跳过前端(仅后端 + RAG API)
python run_system.py --no-frontend
# 查看聚合日志
python run_system.py --logs-only
# 停止所有服务
python run_system.py --stop
# 或者在运行 python run_system.py 的终端中按 Ctrl+C
服务架构:
run_system.py 启动器管理四个关键服务:
- Ollama 服务器(端口 11434):AI 模型服务
- RAG API 服务器(端口 8001):文档处理和检索
- 后端服务器(端口 8000):会话管理和 API 端点
- 前端服务器(端口 3000):React/Next.js Web 界面
# 终端 1:启动 Ollama
ollama serve
# 终端 2:启动 RAG API
python -m rag_system.api_server
# 终端 3:启动后端
cd backend && python server.py
# 终端 4:启动前端
npm run dev
# 访问 http://localhost:3000
Ubuntu/Debian:
sudo apt update
sudo apt install python3.8 python3-pip nodejs npm docker.io docker-compose
macOS:
brew install python@3.8 node npm docker docker-compose
Windows:
# 安装 Python 3.8+、Node.js 和 Docker Desktop
# 然后使用 PowerShell 或 WSL2
安装 Ollama(推荐):
# 安装 Ollama
curl -fsSL https://ollama.ai/install.sh | sh
# 拉取推荐模型
ollama pull qwen3:0.6b # 快速生成模型
ollama pull qwen3:8b # 高质量生成模型
# 复制环境模板
cp .env.example .env
# 编辑配置
nano .env
关键配置选项:
# AI 模型(参考 rag_system/main.py)
OLLAMA_HOST=http://localhost:11434
# 数据库路径(被后端和 RAG 系统使用)
DATABASE_PATH=./backend/chat_data.db
VECTOR_DB_PATH=./lancedb
# 服务器设置(被 run_system.py 使用)
BACKEND_PORT=8000
FRONTEND_PORT=3000
RAG_API_PORT=8001
# 可选:覆盖默认模型
GENERATION_MODEL=qwen3:8b
ENRICHMENT_MODEL=qwen3:0.6b
EMBEDDING_MODEL=Qwen/Qwen3-Embedding-0.6B
RERANKER_MODEL=answerdotai/answerai-colbert-small-v1
# 运行系统健康检查
python system_health_check.py
# 初始化数据库
python -c "from backend.database import ChatDatabase; ChatDatabase().init_database()"
# 测试安装
python -c "from rag_system.main import get_agent; print('✅ 安装成功!')"
# 验证完整设置
python run_system.py --health
索引是您可以与之对话的已处理文档的集合。
# 简单脚本方式
./simple_create_index.sh "我的文档" "path/to/document.pdf"
# 交互式脚本
python create_index_script.py
# 创建索引
curl -X POST http://localhost:8000/indexes \
-H "Content-Type: application/json" \
-d '{"name": "我的索引", "description": "我的文档"}'
# 上传文档
curl -X POST http://localhost:8000/indexes/INDEX_ID/upload \
-F "files=@document.pdf"
# 构建索引
curl -X POST http://localhost:8000/indexes/INDEX_ID/build
一旦您的索引构建完成:
# 为不同任务使用不同模型
curl -X POST http://localhost:8000/sessions \
-H "Content-Type: application/json" \
-d '{
"title": "高质量会话",
"model": "qwen3:8b",
"embedding_model": "Qwen/Qwen3-Embedding-4B"
}'
# 同时处理多个文档
python demo_batch_indexing.py --config batch_indexing_config.json
import requests
# 通过 API 与您的文档对话
response = requests.post('http://localhost:8000/chat', json={
'query': '研究论文中的主要发现是什么?',
'session_id': 'your-session-id',
'search_type': 'hybrid',
'retrieval_k': 20
})
print(response.json()['response'])
LocalGPT 支持多个 AI 模型提供商,并具有集中配置:
OLLAMA_CONFIG = {
"host": "http://localhost:11434",
"generation_model": "qwen3:8b", # 主要文本生成
"enrichment_model": "qwen3:0.6b" # 轻量级路由/增强
}
EXTERNAL_MODELS = {
"embedding_model": "Qwen/Qwen3-Embedding-0.6B", # 1024 维度
"reranker_model": "answerdotai/answerai-colbert-small-v1", # ColBERT 重排序器
"fallback_reranker": "BAAI/bge-reranker-base" # 备用重排序器
}
LocalGPT 提供两种主要的流水线配置:
"default": {
"description": "生产就绪的流水线,包含混合搜索、AI 重排序和验证",
"storage": {
"lancedb_uri": "./lancedb",
"text_table_name": "text_pages_v3",
"bm25_path": "./index_store/bm25"
},
"retrieval": {
"retriever": "multivector",
"search_type": "hybrid",
"late_chunking": {"enabled": True},
"dense": {"enabled": True, "weight": 0.7},
"bm25": {"enabled": True}
},
"reranker": {
"enabled": True,
"type": "ai",
"strategy": "rerankers-lib",
"model_name": "answerdotai/answerai-colbert-small-v1",
"top_k": 10
},
"query_decomposition": {"enabled": True, "max_sub_queries": 3},
"verification": {"enabled": True},
"retrieval_k": 20,
"contextual_enricher": {"enabled": True, "window_size": 1}
}
"fast": {
"description": "速度优化的流水线,开销最小",
"retrieval": {
"search_type": "vector_only",
"late_chunking": {"enabled": False}
},
"reranker": {"enabled": False},
"query_decomposition": {"enabled": False},
"verification": {"enabled": False},
"retrieval_k": 10,
"contextual_enricher": {"enabled": False}
}
SEARCH_CONFIG = {
'hybrid': {
'dense_weight': 0.7,
'sparse_weight': 0.3,
'retrieval_k': 20,
'reranker_top_k': 10
}
}
# 检查 Python 版本
python --version # 应为 3.8+
# 检查依赖
pip list | grep -E "(torch|transformers|lancedb)"
# 重新安装依赖
pip install -r requirements.txt --force-reinstall
```bash