Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
490 changes: 490 additions & 0 deletions .claude/plan/langchain-state-store-refactor.md

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# ===== 通用 API 配置 =====
# 选择一个服务商,取消对应注释并填入 API_KEY
# 注意:一次只使用一个服务商

# --- SiliconFlow (硅基流动) - 推荐国内使用 ---
API_KEY=your_siliconflow_api_key
BASE_URL=https://api.siliconflow.cn/v1

# --- OpenRouter ---
# API_KEY=your_openrouter_api_key
# BASE_URL=https://openrouter.ai/api/v1

# --- DeepSeek ---
# API_KEY=your_deepseek_api_key
# BASE_URL=https://api.deepseek.com/v1

# --- OpenAI ---
# API_KEY=your_openai_api_key
# BASE_URL=https://api.openai.com/v1

# --- Anthropic ---
# API_KEY=your_anthropic_api_key
# BASE_URL=https://api.anthropic.com/v1

# --- 火山引擎 (Volcengine) ---
# API_KEY=your_volcengine_api_key
# BASE_URL=https://ark.cn-beijing.volces.com/api/v3

# ===== 模型配置 =====
# 根据选择的服务商使用对应模型名称

# --- SiliconFlow 模型 ---
MODEL=Qwen/Qwen3.5-122B-A10B
EMBEDDER=Qwen/Qwen3-Embedding-4B
RERANK_MODEL=Qwen/Qwen3-Reranker-4B
RERANK_BINDING_HOST=https://api.siliconflow.cn/v1/rerank

# --- OpenRouter 示例 ---
# MODEL=meta-llama/llama-3.1-70b-instruct
# EMBEDDER=text-embedding-3-small

# --- DeepSeek 示例 ---
# MODEL=deepseek-chat
# EMBEDDER=deepseek-embedding

# --- OpenAI 示例 ---
# MODEL=gpt-4o
# EMBEDDER=text-embedding-3-small

# --- Anthropic 示例 ---
# MODEL=claude-3-5-sonnet-20241022
# EMBEDDER=(需配合其他嵌入服务使用)

# --- 火山引擎 示例 ---
# MODEL=ep-20240910063496-xxxxxx
# EMBEDDER=doubao-embedding-text-xxxxx

# ===== RAG Pipeline =====
GRADE_MODEL=Qwen/Qwen3.5-122B-A10B

# ===== Milvus =====
MILVUS_HOST=127.0.0.1
MILVUS_PORT=19530
MILVUS_COLLECTION=embeddings_collection

# ===== Auto-merging =====
AUTO_MERGE_ENABLED=true
AUTO_MERGE_THRESHOLD=2
LEAF_RETRIEVE_LEVEL=3

# ===== Tools (可选) =====
AMAP_WEATHER_API=https://restapi.amap.com/v3/weather/weatherInfo
AMAP_API_KEY=your_amap_api_key

# ===== Server =====
HOST=127.0.0.1
PORT=8000
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ volumes/
# OS files
.DS_Store
data/

# cc
.claude/
84 changes: 84 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## 常用命令

```bash
# 安装依赖
uv sync

# 启动 Milvus(向量库)
docker compose up -d

# 启动后端服务
uv run uvicorn backend.app:app --host 127.0.0.1 --port 8000 --reload

# 访问
# 前端: http://127.0.0.1:8000/
# API 文档: http://127.0.0.1:8000/docs
```

## 环境配置

创建 `backend/.env` 文件:

```bash
API_KEY=your_api_key_here
MODEL=Qwen/Qwen3.5-122B-A10B # 主模型
EMBEDDER=Qwen/Qwen3-Embedding-4B # 嵌入模型
RERANK_MODEL=Qwen/Qwen3-Reranker-4B # 重排序模型
BASE_URL=https://api.siliconflow.cn/v1 # 兼容 OpenAI API 的服务商
MILVUS_HOST=127.0.0.1
MILVUS_PORT=19530
```

## 项目架构

```
SuperMew/
├── backend/ # FastAPI 后端
│ ├── app.py # 入口、CORS、静态资源
│ ├── api.py # 聊天/会话/文档 API
│ ├── agent.py # LangChain Agent + 会话存储
│ ├── config.py # 环境变量配置
│ ├── schemas.py # Pydantic 数据模型
│ ├── soul/
│ │ └── soul.md # Agent 系统提示词
│ ├── tools.py # 工具:天气查询、知识库检索
│ ├── rag_pipeline.py # RAG 工作流(LangGraph)
│ ├── rag_utils.py # 检索、查询重写、HyDE
│ ├── embedding.py # 稠密向量 + BM25 稀疏向量
│ ├── milvus_client.py # Milvus 混合检索
│ ├── milvus_writer.py # 向量写入
│ ├── document_loader.py # PDF/Word 分块
│ └── parent_chunk_store.py # 父级分块 DocStore
├── frontend/ # Vue 3 单页应用
│ ├── index.html
│ ├── script.js
│ └── style.css
├── data/ # 本地存储
│ ├── customer_service_history.json # 会话历史
│ ├── parent_chunks.json # 父级分块
│ └── documents/ # 上传文档
└── docker-compose.yml # Milvus 向量库
```

## 核心模块

- **RAG 管道** (`rag_pipeline.py`):基于 LangGraph 构建,包含 retrieve → grade → rewrite → retrieve\_expanded 节点
- **检索** (`rag_utils.py`):Hybrid Search (Dense + Sparse + RRF) + Jina Rerank
- **分块** (`document_loader.py`):三级滑动窗口(L1/L2/L3),仅 L3 叶子块写入 Milvus
- **记忆** (`agent.py`):
- `SummarizationMiddleware` 在 token 超过 80000 时触发
- 保留最近 12 条消息(6 轮交互)
- 使用 `backend/soul/soul.md` 作为系统提示词

## 优化方向

优先优化**上下文工程**和**记忆系统**:

- 改进会话摘要策略
- 考虑集成 Mem0/LangMem 等外部记忆方案
- 优化上下文压缩和注入方式 -- Context Engineering

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Chasen Liao

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading