Initial commit: QMDSearch 分层信息检索服务

- FastAPI + Qdrant + Redis + Ollama 技术栈
- L1→L2→L3→chunk 四层分层检索(dense + sparse RRF 融合)
- 文档三级总结与 2.5 级回退
- query 解析路由与分类
- /admin 管理页面
This commit is contained in:
2026-07-29 21:24:40 +08:00
commit 51dc8dc4f6
83 changed files with 10794 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
"""应用配置,通过环境变量注入"""
# 应用
app_name: str = "QMDSearch"
log_level: str = "info"
# 嵌入模型
embedding_provider: str = "openai" # openai | local
openai_api_key: str = ""
openai_base_url: str = "https://api.openai.com/v1"
embedding_model: str = "text-embedding-3-small"
embedding_dimension: int = 1536
# Ollama 本地模型(用于文档三级总结)
ollama_base_url: str = "http://localhost:11434"
ollama_model: str = "qwen2.5:1.5b" # 备选: qwen2.5:3b
ollama_embedding_model: str = "bge-m3" # embedding_provider=local 时使用的嵌入模型
# Qdrant
qdrant_host: str = "localhost"
qdrant_port: int = 6333
# Redis
redis_url: str = "redis://localhost:6379/0"
# 检索参数
retrieval_top_k: int = 20 # L2 语义检索召回数
retrieval_final_k: int = 5 # L3 重排后返回数
# 文档入库参数
summary_min_text_length: int = 500 # 低于此字符数触发 2.5 级回退
# 入库异步任务
ingest_max_concurrency: int = 2 # 入库后台任务并发上限
ingest_task_ttl_done: int = 86400 # 任务状态 Redis 保留秒数(进行中与已完成,24h)
ingest_task_ttl_failed: int = 604800 # 失败任务状态 Redis 保留秒数(7 天)
# 知识分类(taxonomy
taxonomy_path: str = "" # taxonomy JSON 文件路径,为空用内置默认
classify_confidence_threshold: float = 0.6 # 低于此值归 uncategorized
classify_max_categories: int = 3 # query 路由命中类目数上限,超过走全库兜底
# 分层检索参数
l1_doc_top_n: int = 10 # L1 层候选文档数
l2_section_top_n: int = 5 # L2 层候选 section 数
l3_top_n: int = 10 # L3 层定位数
sparse_enabled: bool = True # 是否启用稀疏检索
cache_ttl: int = 300 # Redis 缓存秒数
# 分块参数
chunk_max_chars: int = 800 # chunk 超长二次切分阈值
model_config = {"env_prefix": "", "case_sensitive": False}
settings = Settings()