CodeSight
人工智能驱动的文档搜索引擎——混合BM25+向量+RRF检索,可插拔LLM答案合成。
快速开始
# Install
pip install -e ".[dev]"
# Index a folder of documents
python -m codesight index /path/to/documents
# Search (hybrid BM25 + vector)
python -m codesight search "payment terms" /path/to/documents
# Filter by file type
python -m codesight search "auth" /path/to/code --glob '*.py'
# Ask a question (requires LLM API key — see Configuration)
python -m codesight ask "What are the payment terms?" /path/to/documents
# Machine-readable output
python -m codesight search "query" /path --json
# Check index status
python -m codesight status /path/to/documents
# Launch the web chat UI
pip install -e ".[demo]"
python -m codesight demoPython API
from codesight import CodeSight
engine = CodeSight("/path/to/documents")
engine.index() # Index all files
results = engine.search("payment terms") # Hybrid search
answer = engine.ask("What are the payment terms?") # Search + LLM answer
status = engine.status() # Index freshness check支持格式
| 格式 | 扩展名 | 分析器 |
|---|---|---|
.pdf | pymupdf | |
| Word | .docx | python docx |
| PowerPoint | .pptx | python pptx |
| 代码 | .py, .js, .ts, .go, .rs等等。 | 内置(10种语言) |
| 文本 | .md, .txt, .csv | 内置 |
建筑
- 文档解析:PDF、DOCX、PPTX文本提取,带有页面/部分元数据
- 分块:语言感知正则表达式拆分(代码)+段落感知拆分(文档)
- 嵌入:
all-MiniLM-L6-v2通过语句转换器(本地,无API密钥) - 向量存储:LanceDB(无服务器,基于文件)
- 关键词搜索:SQLite FTS5侧车
- 检索:混合BM25+矢量与RRF合并
- 答案综合:可插拔LLM后端(Claude、Azure OpenAI、OpenAI、Ollama)
看 建筑.md 进行完整的系统浏览。
配置
| 变量 | 默认值 | 描述 |
|---|---|---|
ANTHROPIC_API_KEY | -- | 克劳德后端需要(ask()) |
CODESIGHT_LLM_BACKEND | claude | LLM后端: claude, azure, openai, ollama |
CODESIGHT_DATA_DIR | ~/.codesight/data | 索引的存储位置 |
CODESIGHT_EMBEDDING_MODEL | all-MiniLM-L6-v2 | 嵌入模型 |
CODESIGHT_LLM_MODEL | claude-sonnet-4-20250514 | LLM答案模型 |
CODESIGHT_STALE_SECONDS | 300 | 指数新鲜度阈值(秒) |
LOG_LEVEL | INFO | 记录冗长 |
看 .env.示例 对于所有选项。
堆栈
- Python 3.11+
- LanceDB+SQLite FTS5
- 句子变换器
- 人类克劳德API/Azure OpenAI/OpenAI/Ollama
- Streamlit(网络聊天用户界面)
- pymupdf、python-docx、python-pptx(文档解析)
