From 875791ef3362c69254674accb1a8db7e332efa46 Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Mon, 17 Mar 2025 19:58:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E5=AF=B9?= =?UTF-8?q?=E6=AF=94=E9=83=A8=E5=88=86=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/_config.yml | 26 +++++++ docs/index.md | 136 +++++++++++++++++++++++++++++++++++++ src/core/database.py | 2 +- src/routers/chat_router.py | 3 +- src/routers/data_router.py | 3 +- 5 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 docs/_config.yml create mode 100644 docs/index.md diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 00000000..77558754 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1,26 @@ +theme: just-the-docs +url: https://xerrors.github.io/Yuxi-Know +baseurl: /Yuxi-Know +title: 语析 - 基于大模型的知识库与知识图谱问答系统 +description: 语析是一个强大的问答平台,结合了大模型 RAG 知识库与知识图谱技术,基于 Llamaindex + VueJS + FastAPI + Neo4j 构建。 +search_enabled: true +search_full_content: true +aux_links: + "在 GitHub 上查看": + - "https://github.com/xerrors/Yuxi-Know" + +# 启用中文支持 +plugins: + - jekyll-include-cache + - jekyll-paginate + - jekyll-sitemap + - jemoji + +# 设置默认语言 +defaults: + - scope: + path: "" + type: pages + values: + layout: home + search_exclude: true \ No newline at end of file diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 00000000..b8accc5e --- /dev/null +++ b/docs/index.md @@ -0,0 +1,136 @@ +--- +layout: home +title: 语析 - 基于大模型的知识库与知识图谱问答系统 +nav_order: 1 +description: "语析是一个强大的问答平台,结合了大模型 RAG 知识库与知识图谱技术,基于 Llamaindex + VueJS + FastAPI + Neo4j 构建。" +permalink: / +--- + +# 语析 - 基于大模型的知识库与知识图谱问答系统 + +
+ +![](https://img.shields.io/badge/Docker-2496ED?style=flat&logo=docker&logoColor=ffffff) +![Vue.js](https://img.shields.io/badge/vuejs-%2335495e.svg?style=flat&logo=vuedotjs&logoColor=%234FC08D) +![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=flat&logo=fastapi) +![](https://img.shields.io/github/issues/xerrors/Yuxi-Know?color=F48D73) +![](https://img.shields.io/github/license/bitcookies/winrar-keygen.svg?logo=github) +![](https://img.shields.io/github/stars/xerrors/Yuxi-Know) + +
+ +## 项目概述 + +语析是一个强大的问答平台,结合了大模型 RAG 知识库与知识图谱技术,基于 Llamaindex + VueJS + FastAPI + Neo4j 构建。 + +### 核心特点 + +- 🤖 **多模型支持**:适配 OpenAI、各大国内主流大模型平台,以及本地 vllm 部署 +- 📚 **灵活知识库**:支持 PDF、TXT、MD 等多种格式文档 +- 🕸️ **知识图谱集成**:基于 Neo4j 的知识图谱问答能力 +- 🚀 **简单配置**:只需配置对应服务平台的 `API_KEY` 即可使用 + +![系统界面预览](https://github.com/user-attachments/assets/75010511-4ac5-4924-8268-fea9a589839c) + +## 快速开始 + +### 环境配置 + +在启动前,您需要提供 API 服务商的 API_KEY,并放置在 `src/.env` 文件中(此文件项目中没有,需要自行参考 [src/.env.template](src/.env.template) 创建)。 + +默认使用硅基流动的服务,因此**必须**配置: + +```env +SILICONFLOW_API_KEY=sk-270ea********8bfa97.e3XOMd****Q1Sk +OPENAI_API_KEY= # 如果需要配置 openai 则添加此行,并替换 API_KEY +DEEPSEEK_API_KEY= # 如果配置 DeepSeek 添加此行,并替换 API_KEY +ZHIPUAI_API_KEY= # 如果配置 智谱清言 添加此行,并替换 API_KEY +``` + +### 启动服务 + +**开发环境启动**(源代码修改会自动更新): + +```bash +docker compose -f docker/docker-compose.dev.yml --env-file src/.env up --build +``` + +> 添加 `-d` 参数可在后台运行 + +**生产环境部署**请使用: + +```bash +docker compose -f docker/docker-compose.yml --env-file src/.env up --build -d +``` + +成功启动后,访问 [http://localhost:5173/](http://localhost:5173/) 即可使用系统。 + +## 功能特性 + +### 多模态问答支持 + +- Deepseek-R1 等推理模型 +- 知识图谱检索 +- 知识库检索 +- 网页检索 + +### 知识库管理 + +支持多种格式的知识库文件: +- PDF +- Txt +- Markdown +- Docx + +### 知识图谱集成 + +使用 Neo4j 作为知识图谱存储,支持: +- 自定义知识图谱导入 +- 图谱可视化 +- 图谱检索 + +## 模型支持 + +### 对话模型 + +| 模型供应商 | 默认模型 | 配置项目 | +| :--------------------- | :---------------------------------- | :--------------------------------------------- | +| `siliconflow` (默认) | `Qwen/Qwen2.5-7B-Instruct` (免费) | `SILICONFLOW_API_KEY` | +| `openai` | `gpt-4o` | `OPENAI_API_KEY` | +| `deepseek` | `deepseek-chat` | `DEEPSEEK_API_KEY` | +| `arc`(豆包方舟) | `doubao-1-5-pro-32k-250115` | `ARK_API_KEY` | +| `zhipu`(智谱清言) | `glm-4-flash` | `ZHIPUAI_API_KEY` | +| `dashscope`(阿里) | `qwen-max-latest` | `DASHSCOPE_API_KEY` | + +### 向量模型与重排序模型 + +建议使用硅基流动部署的 bge-m3(免费且无需修改)。其他模型配置参考 [src/static/models.yaml](src/static/models.yaml)。 + +## 更新日志 + +- **2025.02.24** - 新增网页检索以及内容展示,需配置 `TAVILY_API_KEY` +- **2025.02.23** - SiliconFlow 的 Rerank 和 Embedding model 支持,现默认使用 SiliconFlow +- **2025.02.20** - DeepSeek-R1 支持,需配置 `DEEPSEEK_API_KEY` 或 `SILICONFLOW_API_KEY` +- **2024.10.12** - 后端修改为 FastAPI,添加 Milvus-Standalone 独立部署 + +## 常见问题 + +### 镜像下载问题 + +如无法直接下载相关镜像,可参考 [DaoCloud/public-image-mirror](https://github.com/DaoCloud/public-image-mirror?tab=readme-ov-file#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B),尝试替换前缀: + +```bash +# 以 neo4j 为例,其余类似 +docker pull m.daocloud.io/docker.io/library/neo4j:latest + +# 然后重命名镜像 +docker tag m.daocloud.io/docker.io/library/neo4j:latest neo4j:latest +``` + +## 贡献指南 + +欢迎提交 Issue 和 Pull Request 来帮助改进项目。 + +## 许可证 + +本项目采用 MIT 许可证 - 详见 [LICENSE](LICENSE) 文件 \ No newline at end of file diff --git a/src/core/database.py b/src/core/database.py index 1f775c37..c7a74f71 100644 --- a/src/core/database.py +++ b/src/core/database.py @@ -229,7 +229,7 @@ class DataBaseManager: for line in lines: line.pop("vector") - lines.sort(key=lambda x: x.get("start_char_idx", 0)) + lines.sort(key=lambda x: x.get("start_char_idx") or 0) # logger.debug(f"lines[0]: {lines[0]}") return {"lines": lines} diff --git a/src/routers/chat_router.py b/src/routers/chat_router.py index 5b9b49c7..31397f1f 100644 --- a/src/routers/chat_router.py +++ b/src/routers/chat_router.py @@ -1,5 +1,6 @@ import json import asyncio +import traceback from fastapi import APIRouter, Body from fastapi.responses import StreamingResponse, Response from src.core import HistoryManager @@ -85,7 +86,7 @@ def chat_post( history=history_manager.update_ai(content), refs=refs) except Exception as e: - logger.error(f"Model error: {e}") + logger.error(f"Model error: {e}, {traceback.format_exc()}") yield make_chunk(message=f"Model error: {e}", status="error") return diff --git a/src/routers/data_router.py b/src/routers/data_router.py index 6a5229ff..f719225a 100644 --- a/src/routers/data_router.py +++ b/src/routers/data_router.py @@ -1,5 +1,6 @@ import os import asyncio +import traceback from typing import List, Optional from fastapi import APIRouter, File, UploadFile, HTTPException, Depends, Body @@ -81,7 +82,7 @@ async def get_document_info(db_id: str, file_id: str): try: info = dbm.get_file_info(db_id, file_id) except Exception as e: - logger.error(f"Failed to get file info, {e}, {db_id=}, {file_id=}") + logger.error(f"Failed to get file info, {e}, {db_id=}, {file_id=}, {traceback.format_exc()}") info = {"message": "Failed to get file info", "status": "failed"}, 500 return info