基于 RAG(检索增强生成)的马克思主义文献知识库与对话应用。本地 FAISS 向量索引 + 大语言模型(DeepSeek/OpenAI 兼容),让经典理论可检索、可对话、可分析。
前端 (Next.js 14) ──SSE──▶ FastAPI 后端 ──stream──▶ LLM API
│
├── mia/retriever ── FAISS 向量检索
├── mia/rag ── 上下文构建 + 提示词
└── mia/indexer ── 增量索引 / 全量重建
爬取 (marxists.org) → 清洗 (HTML/PDF 提取) → 分块 → 向量嵌入 → FAISS 索引
↓
增量模式 / 断点续传
- Python 3.10+ (推荐 3.12)
- Node.js 24+
- CUDA (可选,加速 embedding)
# Python 依赖
pip install -r requirements.txt
# 前端依赖
cd web && npm install# 设置 API Key (或在前端设置面板中配置)
export DEEPSEEK_API_KEY=your_key
# 一键启动
./start.sh
# 或指定端口
./start.sh 8888访问 http://localhost:3000 即可使用。
# 1. 爬取 marxists.org 中文站
python scripts/crawl.py --out data/mia_raw --resume --max-pages 2000
# 2. 增量清洗
python scripts/clean.py --root data/mia_raw --out data/mia_clean --incremental
# 3. 构建/重建索引
python scripts/index.py --docs data/mia_clean/docs_clean.jsonl --out data/mia_index --rebuildspectre/
├── mia/ # 共享库 (11 模块)
│ ├── schemas.py # 数据模型
│ ├── config.py # YAML 配置 + 环境变量
│ ├── crawler.py # 爬虫 (resume/断点续传)
│ ├── cleaner.py # 文本清洗 (增量模式)
│ ├── chunker.py # 文本分块
│ ├── embedder.py # BAAI/bge-m3 嵌入封装
│ ├── indexer.py # FAISS 索引 (增量/重建)
│ ├── retriever.py # 向量检索 + 过滤去重
│ ├── rag.py # RAG 编排
│ └── llm_client.py # LLM 异步流式调用
├── scripts/ # CLI 入口
├── server/ # FastAPI 后端 (SSE 流式)
├── web/ # Next.js 前端 (Chat UI)
└── config.yaml # 统一配置
本项目的全部文献数据来源于 中文马克思主义文库(Marxists Internet Archive Chinese Section)。
中文马克思主义文库由来自世界各地的志愿者共同建设与维护,数十年如一日地翻译、校对、整理马克思主义经典著作和相关文献,为中文世界的理论研究者和学习者提供了无可替代的宝贵资源。本项目的诞生,离不开这些志愿者的无私奉献与辛勤付出。
谨向中文马克思主义文库及所有志愿者致以最诚挚的敬意和感谢。
"A spectre is haunting the internet — the spectre of Marx."
—— Karl Marx & Friedrich Engels, Manifesto of the Communist Party, 1848