Skip to content

Commit 5d6103a

Browse files
authored
Merge pull request #2 from wangle201210/feat/rag
Feat/rag
2 parents 67f698f + ef002db commit 5d6103a

44 files changed

Lines changed: 2017 additions & 838 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 142 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
- 📑 **多Tab管理** - 支持多个对话标签页,类似浏览器的使用体验
1515
- 💾 **本地持久化** - SQLite 数据库存储对话历史
1616
- 🔌 **OpenAI 兼容** - 支持 OpenAI API 和其他兼容接口
17-
- 🎯 **懒加载对话** - 新对话只在发送第一条消息时才创建,避免空对话
1817
-**Markdown 渲染** - 完美支持代码高亮和数学公式
18+
- 📚 **RAG 知识库** - 集成 go-rag 和 Qdrant 向量数据库,支持文档检索增强对话
1919

2020
## 🛠 技术栈
2121

@@ -24,6 +24,8 @@
2424
- **语言**: Go 1.22+
2525
- **数据库**: SQLite (gorm)
2626
- **AI SDK**: [Cloudwego Eino](https://github.com/cloudwego/eino) - 字节跳动开源的 LLM 应用开发框架
27+
- **RAG**: [go-rag](https://github.com/wangle201210/go-rag) - 知识库检索增强生成系统
28+
- **向量数据库**: [Qdrant](https://qdrant.tech/) - 高性能向量搜索引擎
2729

2830
### 前端
2931
- **框架**: Vue 3.5+ (Composition API)
@@ -85,21 +87,38 @@ ai:
8587
api_key: "your-api-key-here"
8688
model: "gpt-3.5-turbo"
8789

90+
# RAG Configuration (Optional)
91+
rag:
92+
enabled: true # 是否启用 RAG 功能
93+
auto_start: false # 启动时自动启动 RAG 服务
94+
top_k: 5 # 检索返回的文档数量
95+
default_knowledge_base: "" # 默认知识库名称
96+
server:
97+
address: ":8000" # RAG 服务监听地址
98+
99+
# Qdrant Configuration (Optional)
100+
qdrant:
101+
enabled: true # 是否启用 Qdrant
102+
auto_start: false # 启动时自动启动 Qdrant
103+
server:
104+
address: ":6333" # Qdrant 服务地址
105+
grpc_address: ":6334" # Qdrant gRPC 地址
106+
88107
# Binary Manager Configuration (Optional)
89108
binaries:
90-
enabled: true
109+
enabled: false
91110
use_embedded: false # false: use local bin/, true: use embedded
92111
bin_path: "./bin"
93112
startup_order:
94-
- qdrant
95-
- wailsproject
96113
```
97114
98115
> 💡 提示:
99116
> - 支持 OpenAI 官方 API
100117
> - 支持其他兼容 OpenAI API 的服务(如 Ollama、Azure OpenAI 等)
118+
> - RAG 功能可选,不需要时可设置 `rag.enabled: false`
101119
> - 配置文件使用 YAML 格式,更易于管理和维护
102120
> - 可以通过设置 `binaries.enabled: false` 禁用嵌入的二进制服务
121+
> - 配置支持热重载,修改配置文件后会自动生效
103122

104123
### 4. 开发模式
105124

@@ -129,6 +148,25 @@ wails build -platform linux/amd64 # Linux
129148

130149
构建完成后,可执行文件位于 `build/bin/` 目录。
131150

151+
#### macOS 应用签名和分发
152+
153+
macOS 系统对未签名的应用会提示"已损坏"。为了让用户能够正常打开应用,需要对应用进行签名。
154+
155+
**推荐方式**:使用我们提供的签名脚本(无需 Apple Developer 账号)
156+
157+
```bash
158+
# 构建 + 签名 + 打包(一键完成)
159+
./scripts/build-and-sign.sh
160+
```
161+
162+
这会在 `build/dist/` 目录生成一个签名的 ZIP 文件,用户解压后可以正常打开。
163+
164+
**用户首次打开说明**:
165+
- 右键点击应用 -> 选择"打开" -> 点击"打开"
166+
- 或在系统设置 > 隐私与安全性中点击"仍要打开"
167+
168+
> 📖 详细的签名说明和其他签名方案,请参阅 [签名指南](docs/SIGNING.md)
169+
132170
## 🎯 核心功能
133171

134172
### 1. 多Tab会话管理
@@ -164,6 +202,64 @@ wails build -platform linux/amd64 # Linux
164202
- 代码块高亮显示
165203
- 数学公式渲染(KaTeX)
166204

205+
### 6. RAG 知识库管理
206+
207+
wachat 集成了强大的 RAG(Retrieval Augmented Generation)功能,让 AI 能够基于您的文档知识库提供更准确的回答。
208+
209+
#### 快速开始
210+
211+
1. **启用 RAG 功能**
212+
213+
在 `config.yaml` 中启用 RAG:
214+
```yaml
215+
rag:
216+
enabled: true
217+
auto_start: true
218+
top_k: 5
219+
default_knowledge_base: "my_docs" # 设置默认知识库
220+
221+
qdrant:
222+
enabled: true
223+
auto_start: true
224+
```
225+
226+
2. **访问知识库管理**
227+
228+
- 点击主界面右上角的 "知识库管理" 按钮
229+
- 首次使用会自动下载 go-rag 和 Qdrant 服务
230+
- 下载完成后点击 "启动服务"
231+
232+
3. **创建知识库**
233+
234+
在知识库管理界面中:
235+
- 输入知识库名称(如 "my_docs")
236+
- 点击 "创建知识库"
237+
238+
4. **上传文档**
239+
240+
支持多种文档格式:
241+
- PDF 文档
242+
- Markdown 文件
243+
- HTML 网页
244+
- 纯文本文件
245+
246+
上传方式:
247+
- **本地文件**: 选择文件上传
248+
- **网页 URL**: 输入网页地址,自动抓取内容
249+
250+
5. **配置检索参数**
251+
252+
在知识库管理页面顶部:
253+
- **TopK**: 每次检索返回的文档数量(1-100)
254+
- **默认知识库**: 选择对话时使用的知识库
255+
256+
6. **开始对话**
257+
258+
配置完成后:
259+
- 返回聊天界面
260+
- 发送消息时,AI 会自动从知识库检索相关内容
261+
- 基于检索到的文档提供更准确的回答
262+
167263
## 📝 开发说明
168264

169265
### 数据库
@@ -231,6 +327,41 @@ A:
231327
- Vue 代码修改会自动热重载
232328
- 如果遇到问题,尝试清理缓存:`rm -rf frontend/dist`
233329

330+
### Q: 如何使用 RAG 知识库功能?
331+
332+
A:
333+
1. 在 `config.yaml` 中启用 RAG 和 Qdrant
334+
2. 点击主界面右上角的 "知识库管理" 按钮
335+
3. 首次使用会下载必要的服务(go-rag 和 Qdrant)
336+
4. 启动服务后,创建知识库并上传文档
337+
5. 在顶部设置栏选择默认知识库
338+
6. 返回聊天界面,AI 会自动使用知识库内容
339+
340+
### Q: RAG 服务无法启动怎么办?
341+
342+
A:
343+
- **检查端口占用**: 确保端口 8000(go-rag)和 6333(Qdrant)没有被占用
344+
- **检查配置**: 确认 `config.yaml` 中的配置正确
345+
- **查看日志**: 在应用日志中查看具体错误信息
346+
- **手动清理**: 删除 `~/.wachat/go-rag` 和 `~/.wachat/qdrant` 目录后重新下载
347+
348+
### Q: 知识库文档支持哪些格式?
349+
350+
A: 目前支持:
351+
- PDF 文档(.pdf)
352+
- Markdown 文件(.md)
353+
- HTML 网页(.html)
354+
- 纯文本文件(.txt)
355+
- 网页 URL(自动抓取内容)
356+
357+
### Q: 如何提高 RAG 检索的准确性?
358+
359+
A:
360+
1. 使用清晰、具体的问题
361+
2. 调整 `top_k` 参数(增加返回的文档数量)
362+
3. 确保上传的文档内容质量高、结构清晰
363+
4. 使用支持 embedding 的高质量 AI 模型
364+
5. 为不同主题创建独立的知识库
234365

235366
## 🗺 开发路线图
236367

@@ -239,6 +370,11 @@ A:
239370
- [x] 本地数据持久化
240371
- [x] 流式消息输出
241372
- [x] Markdown 和代码高亮
373+
- [x] RAG 知识库集成
374+
- [x] Qdrant 向量数据库
375+
- [x] 文档上传和索引
376+
- [x] 知识库管理界面
377+
- [x] 配置热重载
242378
- [ ] 消息编辑和重新生成
243379
- [ ] 对话导出(JSON/Markdown)
244380
- [ ] 主题切换(深色/浅色)
@@ -252,6 +388,8 @@ A:
252388
- [Wails](https://github.com/wailsapp/wails) - 优秀的 Go + Web 框架
253389
- [Vue.js](https://github.com/vuejs/core) - 渐进式 JavaScript 框架
254390
- [Cloudwego Eino](https://github.com/cloudwego/eino) - 字节跳动开源的 LLM 应用开发框架,提供统一的 AI 接入能力
391+
- [go-rag](https://github.com/wangle201210/go-rag) - 基于 Go 的 RAG 系统,提供知识库检索增强能力
392+
- [Qdrant](https://qdrant.tech/) - 高性能向量搜索引擎,为 RAG 提供向量存储和检索
255393
- [deepchat](https://github.com/ThinkInAIXYZ/deepchat) - UI 设计参考,提供了优秀的聊天界面设计灵感
256394

257395
## 📮 联系方式

app.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,42 @@ func (a *App) UpdateRAGSettings(topK int, defaultKnowledgeBase string) error {
473473
func (a *App) GetKnowledgeBases() ([]string, error) {
474474
return a.chatAPI.GetKnowledgeBases(a.ctx)
475475
}
476+
477+
// AISettings represents AI configuration settings
478+
type AISettings struct {
479+
BaseURL string `json:"baseURL"`
480+
APIKey string `json:"apiKey"`
481+
Model string `json:"model"`
482+
}
483+
484+
// GetAISettings returns current AI settings
485+
func (a *App) GetAISettings() *AISettings {
486+
baseURL, apiKey, model := config.GetAISettings()
487+
return &AISettings{
488+
BaseURL: baseURL,
489+
APIKey: apiKey,
490+
Model: model,
491+
}
492+
}
493+
494+
// UpdateAISettings updates AI settings
495+
func (a *App) UpdateAISettings(baseURL, apiKey, model string) error {
496+
if baseURL == "" {
497+
return fmt.Errorf("base URL cannot be empty")
498+
}
499+
if model == "" {
500+
return fmt.Errorf("model cannot be empty")
501+
}
502+
503+
return config.UpdateAISettings(a.ctx, baseURL, apiKey, model)
504+
}
505+
506+
// GetConfig reads the entire config file content
507+
func (a *App) GetConfig() (string, error) {
508+
return config.GetConfigContent(a.ctx)
509+
}
510+
511+
// SaveConfig saves the entire config file content
512+
func (a *App) SaveConfig(content string) error {
513+
return config.SaveConfigContent(a.ctx, content)
514+
}

0 commit comments

Comments
 (0)