feat: TODO

This commit is contained in:
李如威 2025-07-09 01:04:56 +08:00
parent 9b9265b46a
commit 03ee2525ab
1 changed files with 61 additions and 42 deletions

103
README.md
View File

@ -2,6 +2,15 @@
一个高效、简洁的 RAG (Retrieval-Augmented Generation) 服务,基于 FastAPI 构建。
## TODO
- [ ] 提高检索准确度
- [ ] 知识库隔离
- [ ] 支持 doc
- [ ] 支持 docx
- [ ] 支持 excel
- [ ] 支持 csv
## 功能特性
- 🚀 **高性能 API 服务** - 基于 FastAPI 构建
@ -101,11 +110,13 @@ python run_tests.py all
## API 接口
### 健康检查
```
GET /api/health
```
### 上传文档
```
POST /api/upload
Content-Type: multipart/form-data
@ -115,6 +126,7 @@ Content-Type: multipart/form-data
```
### 查询问答
```
POST /api/chat
Content-Type: application/json
@ -127,6 +139,7 @@ Content-Type: application/json
```
### 流式聊天问答 🆕
```
POST /api/chat/stream
Content-Type: application/json
@ -145,6 +158,7 @@ Content-Type: application/json
```
### 获取文档列表
```
GET /api/documents
@ -260,17 +274,17 @@ def stream_chat(question):
json={'question': question, 'top_k': 3},
stream=True
)
for line in response.iter_lines():
if line:
# 解析 Server-Sent Events 格式
if line.startswith(b'data: '):
data = json.loads(line[6:])
# 打印文本内容
if data.get('content'):
print(data['content'], end='', flush=True)
# 处理最终数据块
if data.get('is_final'):
print(f"\n\n处理时间: {data.get('processing_time', 0):.2f}秒")
@ -286,53 +300,53 @@ stream_chat("详细解释文档的主要观点")
```javascript
// 流式聊天问答 - 前端实现
async function streamChat(question) {
const response = await fetch('/api/chat/stream', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
question: question,
top_k: 3
})
});
const response = await fetch("/api/chat/stream", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
question: question,
top_k: 3,
}),
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
while (true) {
const { done, value } = await reader.read();
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
if (done) break;
for (const line of lines) {
if (line.startsWith('data: ')) {
try {
const data = JSON.parse(line.slice(6));
// 显示文本内容
if (data.content) {
document.getElementById('chat-output').innerHTML += data.content;
}
// 处理最终数据块
if (data.is_final) {
console.log(`处理时间: ${data.processing_time}秒`);
console.log(`参考来源: ${data.sources.length}个文档`);
}
} catch (e) {
console.error('解析数据失败:', e);
}
}
const chunk = decoder.decode(value);
const lines = chunk.split("\n");
for (const line of lines) {
if (line.startsWith("data: ")) {
try {
const data = JSON.parse(line.slice(6));
// 显示文本内容
if (data.content) {
document.getElementById("chat-output").innerHTML += data.content;
}
// 处理最终数据块
if (data.is_final) {
console.log(`处理时间: ${data.processing_time}秒`);
console.log(`参考来源: ${data.sources.length}个文档`);
}
} catch (e) {
console.error("解析数据失败:", e);
}
}
}
}
}
// 使用示例
streamChat('请解释文档的主要内容');
streamChat("请解释文档的主要内容");
```
## 开发指南
@ -350,6 +364,7 @@ streamChat('请解释文档的主要内容');
### 配置文件
主要配置在 `config.py` 中:
- LLM 模型配置
- 向量模型设置
- 数据库路径
@ -360,20 +375,23 @@ streamChat('请解释文档的主要内容');
### 常见问题
1. **服务启动失败**
```bash
# 检查端口是否被占用
lsof -i :8000
# 检查依赖是否完整安装
pip install -r requirements.txt
```
2. **文档上传失败**
- 检查文件格式是否支持 (PDF, TXT)
- 确认文件大小不超过限制
- 检查磁盘空间是否充足
3. **查询响应慢**
- 检查向量数据库索引状态
- 考虑调整 `top_k` 参数
- 监控系统资源使用情况
@ -411,6 +429,7 @@ python tests/performance_monitor.py
## 支持
如有问题或建议,请:
1. 查看 [TESTING_README.md](TESTING_README.md) 测试文档
2. 运行 `python run_tests.py quick` 进行快速诊断
3. 提交 Issue 或 Pull Request