algonotes_rag/docs/CONFIG.md

137 lines
2.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 🔧 AlgoNotes RAG 配置说明
## 配置文件
项目使用两层配置:
```
.env → 敏感信息API Key不提交 Git
config.toml → 业务配置(提交 Git${VAR} 引用环境变量)
```
## 环境变量
复制 `.env.example``.env` 并填入你的 Key
```bash
# .env
OPENAI_API_KEY = "your-api-key-here"
```
## config.toml 说明
```toml
# ── Chat Model ──
[llm]
model = "Qwen3-Next-80B-A3B-Instruct"
base_url = "https://ai.gitee.com/v1"
api_key = "${OPENAI_API_KEY}"
temperature = 0.7
max_tokens = 4096
timeout = 60.0
# ── Embedding Model ──
[embedding]
model = "Qwen/Qwen3-Embedding-4B"
base_url = "https://ai.gitee.com/v1"
api_key = "${OPENAI_API_KEY}"
# ── Reranker Model ──
[reranker]
model = "Qwen3-Reranker-4B"
base_url = "https://ai.gitee.com/v1"
api_key = "${OPENAI_API_KEY}"
top_n = 3
# ── Logging ──
[logging]
level = "INFO"
file = "logs/app.log"
max_bytes = 10485760
backup_count = 5
# ── Storage Paths ──
[store]
chroma_dir = "data/chroma_db"
files_dir = "data/files"
sqlite_path = "data/sql_db/notes.db"
```
## 切换模型提供商
只需修改 `config.toml` 中的 `base_url``model` 即可切换:
### 生产环境(如比赛要求使用的 Gitee.AI
```toml
[llm]
model = "DeepSeek-R1"
base_url = "https://ai.gitee.com/v1"
[embedding]
model = "Qwen/Qwen3-Embedding-4B"
base_url = "https://ai.gitee.com/v1"
```
### 开发环境(如硅基流动)
```toml
[llm]
model = "deepseek-ai/DeepSeek-V4-Flash"
base_url = "https://api.siliconflow.cn/v1"
[embedding]
model = "Qwen/Qwen3-Embedding-4B"
base_url = "https://api.siliconflow.cn/v1"
```
## 代码中使用
```python
from src.config import config
# LLM 配置
model = init_chat_model(
model=config.llm.model,
model_provider="openai",
openai_api_key=config.llm.api_key,
base_url=config.llm.base_url,
temperature=config.llm.temperature,
)
# Embedding 配置
embeddings = init_embeddings(
model=config.embedding.model,
provider="openai",
openai_api_key=config.embedding.api_key,
base_url=config.embedding.base_url,
)
# 日志配置
logger = setup_logger()
# 自动读取 config.logging.level、config.logging.file 等
```
## 配置优先级
```
硬编码默认值 < config.toml < 环境变量 ${VAR}
```
1. 如果 `config.toml` 不存在,使用 Pydantic 模型中的硬编码默认值
2. 如果 `config.toml` 存在,以其为准
3. `${OPENAI_API_KEY}` 等占位符在加载时被 `.env` 中的实际值替换
## 公共题库CPGraph
`[cp_graph]` 配置段控制是否查询公共题库:
```toml
[cp_graph]
enabled = false # 是否启用公共题库查询
url = "https://mcp.cpgraph.top/mcp" # CPGraph MCP 服务地址
```
- `enabled = false`:仅查询个人笔记(默认)
- `enabled = true`:同时查询公共题库,需要 CPGraph MCP 服务可用