Feature/model - #42
Merged
Merged
Conversation
- 新增 pkg/stopwords 统一中文停用词表(hybrid_retriever.go 原硬编码 stopWords 搬过来,导出 IsStopWord) - pkg/logger/logger.go 注册 Nop logger fallback,单元测试不初始化 logger 也不 panic - EmbeddingConfig 加 Timeout 字段(默认 15s,支持 EMBEDDING_TIMEOUT 环境变量覆盖),解决 Embedding 服务抖动时整条链路挂死 - postgresql.go 新增三个 Ensure 函数:EnsurePGVectorIndex(ivfflat)、EnsureKeywordsGINIndex(关键词检索 O(N)→O(log N))、EnsureContextIndexes(chat_messages/chats_sessions/user_memory 复合索引) - init_knowledge_schema.sql 静态 schema 同步补上述索引
- chat_message/chat_session/user_memory 三张表补 gorm index tag,启动时 EnsureContextIndexes 自动 CREATE INDEX - chat_message_repository.SearchRecentByKeywords 原用 .Or() 链,生成 WHERE session_id = ? OR content ILIKE ?,匹配全库而非当前会话,626ms 根因 - 修复为 AND + 子查询括号:WHERE session_id = ? AND (content ILIKE ? OR content ILIKE ?)
指标补全: - eino_callback 新增 eino_retriever_empty_results_total Counter,Retriever OnEnd 时 hitN==0 则 Incr - PromQL 可用 1 - rate(empty_results) / rate(requests_total) 一行算检索命中率 Crash 修复: - stripInternalSpanAttrs 原实现原地 for range + delete,Go runtime 单 goroutine 也会 panic - 且 FlushTrace 后台 goroutine 调 strip 时,主请求还在 SetSpanAttrs,跨 goroutine 写同一份 span.Attrs map - 修复为先拷贝副本、在副本上过滤、最后 s.Attrs = clean 整体替换,彻底消除并发读写
HybridRetriever: - 新增 observeStage 辅助函数,记录 vector_raw → keyword_filtered → rrf_fused → cross_filtered → final 共 7 阶段候选条数 - 新增 rag_retriever_degradation_total Counter,监控 4 种降级事件(vector/keyword/both search_error、keyword_only min_score_filter) - stopWords 统一引用 pkg/stopwords.IsStopWord,删除本地硬编码 RerankRetriever: - 加指数退避重试:4xx 不重试、429/5xx 重试,最多 4 次,指数退避 + 抖动 - 加请求超时控制(默认 30s)、错误分类日志
LLM 工厂层: - EmbeddingConfig.Timeout 透传到 EmbeddingClientConfig,之前有配置字段但 NewEmbeddingClientFromConfig 没接上 App 启动: - initDatabase 挂 EnsurePGVectorIndex / EnsureKeywordsGINIndex / EnsureContextIndexes,启动时自动建索引 Context 服务: - BuildContext 从 3 路并行增加到 4 路并行,SearchRecentByKeywords 不再串行等全部回来后才执行 ChatService: - initContext 全链路并行化:userRepo.FindByID 只查一次(之前填 UserContext 一次、填 Profile 又一次) - prefSvc.GetByUserID 和 BuildContext 同时跑 Quick Graph 核心改动: 1. rewrite 与 retrieve 并行化:quickRewriteFn 立即返回 OriginalQuery,后台 goroutine 跑 LLM 改写 Retrieve StatePostHandler select 等最多 500ms,改写完成且 rewrittenQuery != OriginalQuery 时补一次检索 平白省 0.2-1.7s 首字延迟 2. graphState 提前创建 + genState 闭包始终返回同一对象 修复 eino compose Invoke 返回后 ctx 里没有 stateKey 导致 ProcessState have not set state 删除 extractSourcesFromStateLocal 死代码
message_feedback 表是早期 AutoMigrate 创建的,后来 entity 新增了 reasons / is_quick / trace_id / reason_tag 列 但 GORM AutoMigrate 不会给已存在的表 ADD COLUMN,导致 INSERT 时报 column does not exist 新增 EnsureMessageFeedbackSchema 函数: - 启动时检查 information_schema.columns,发现缺失列则 ALTER TABLE ADD COLUMN IF NOT EXISTS - 和 EnsurePGVectorIndex / EnsureKeywordsGINIndex / EnsureContextIndexes 风格一致 - 不阻塞启动(失败只 Warn)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.