first commit
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
# 服务配置
|
||||
service_host: str = "0.0.0.0"
|
||||
service_port: int = 8990
|
||||
|
||||
# ChromaDB 配置 (PersistentClient 模式)
|
||||
chromadb_path: str = "./chroma_data"
|
||||
|
||||
# Ollama 嵌入配置 (本地)
|
||||
ollama_base_url: str = "http://localhost:11434"
|
||||
ollama_embed_model: str = "nomic-embed-text"
|
||||
|
||||
# LLM 配置 (云端,OpenAI 兼容 API)
|
||||
llm_api_key: str = ""
|
||||
llm_base_url: str = "https://api.agnes-ai.cn/v1"
|
||||
llm_model: str = "agnes-2.5-flash"
|
||||
llm_model_provider: str = "openai"
|
||||
llm_temperature: float = 0.7
|
||||
llm_max_tokens: int = 2048
|
||||
llm_top_p: float = 0.9
|
||||
llm_timeout: int = 30
|
||||
llm_max_retries: int = 3
|
||||
|
||||
# RAG 参数
|
||||
rag_top_k: int = 5
|
||||
rag_similarity_threshold: float = 0.9 # 预 RAG 匹配阈值 (余弦相似度)
|
||||
rag_faq_direct_threshold: float = 0.9 # FAQ 直返门控阈值(余弦相似度,D2)
|
||||
rag_new_question_threshold: float = 0.05 # 新问题检测阈值 (余弦距离 > 0.05 即为新问题)
|
||||
rag_dup_score_threshold: float = 0.95 # 近似重复判定:向量相似度阈值 (score >= 该值)
|
||||
rag_dup_top_k: int = 5 # 近似重复判定:混合检索返回条数,需覆盖 hybrid_score 最大的条目
|
||||
rag_chunk_size: int = 512
|
||||
rag_chunk_overlap: int = 80
|
||||
|
||||
# 预处理节点开关(指代消解 + 问题分类),出问题可一键旁路
|
||||
rag_preprocess_enabled: bool = True
|
||||
|
||||
# 查询扩展开关(用 preprocess 提取的 expanded_words 补充检索召回),出问题可一键旁路
|
||||
rag_expansion_enabled: bool = True
|
||||
# 向量路每个扩展词的检索 top_k(BM25 路拼接查询使用主检索 top_k)
|
||||
rag_expansion_top_k: int = 5
|
||||
|
||||
# 置信度审计日志
|
||||
confidence_log_dir: str = "./confidence_logs"
|
||||
|
||||
# 文档处理:允许上传的文档扩展名(逗号分隔,小写)
|
||||
supported_doc_types: str = ".txt,.md"
|
||||
|
||||
# 置信度计算权重
|
||||
rag_confidence_citation_weight: float = 0.25
|
||||
rag_confidence_keyword_weight: float = 0.15
|
||||
|
||||
# LLM 自评(generate 节点输出 JSON 自评分数,融入 KB 路径置信度;出问题可一键旁路)
|
||||
rag_self_eval_enabled: bool = True
|
||||
# 自评信号融合权重(检索信号权重 = 1 - 该值)
|
||||
rag_confidence_self_eval_weight: float = 0.3
|
||||
# RAG 流水线 LLM 调用统一 max_tokens(preprocess / generate 共用;JSON 结构 + 自评字段需更大预算)
|
||||
rag_llm_max_tokens: int = 1024
|
||||
|
||||
# BM25 关键词检索
|
||||
bm25_index_path: str = "./bm25_data"
|
||||
bm25_enabled: bool = True
|
||||
|
||||
# 混合检索 RRF (Reciprocal Rank Fusion) 参数
|
||||
rrf_alpha: float = 60.0 # RRF 平滑参数,越大越平滑,建议 30~120
|
||||
|
||||
# 日志
|
||||
log_level: str = "INFO"
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
case_sensitive=False,
|
||||
extra="ignore"
|
||||
)
|
||||
|
||||
|
||||
settings = Settings()
|
||||
|
||||
# 计算归一化的启发式权重
|
||||
_citation_sum = settings.rag_confidence_citation_weight + settings.rag_confidence_keyword_weight
|
||||
if _citation_sum > 0:
|
||||
NORMALIZED_CITATION_WEIGHT = settings.rag_confidence_citation_weight / _citation_sum
|
||||
NORMALIZED_KEYWORD_WEIGHT = settings.rag_confidence_keyword_weight / _citation_sum
|
||||
else:
|
||||
NORMALIZED_CITATION_WEIGHT = 0.625
|
||||
NORMALIZED_KEYWORD_WEIGHT = 0.375
|
||||
Reference in New Issue
Block a user