MCPcopy Create free account
hub / github.com/53AI/53AIHub / PreprocessEntityScope

Method PreprocessEntityScope

api/service/rag/search.go:929–975  ·  view source on GitHub ↗

PreprocessEntityScope 预处理实体范围收敛,不执行向量搜索 用于 SSE 分阶段输出:先发送收敛结果,再执行向量搜索 如果请求设置了 SkipEntityScopeNarrowing=true 则跳过收敛; 否则会优先尝试实体收敛,并在实体关键词缺失或实体未命中时使用查询信号兜底收敛。

(eid int64, req *SearchRequest)

Source from the content-addressed store, hash-verified

927// 如果请求设置了 SkipEntityScopeNarrowing=true 则跳过收敛;
928// 否则会优先尝试实体收敛,并在实体关键词缺失或实体未命中时使用查询信号兜底收敛。
929func (s *SearchService) PreprocessEntityScope(eid int64, req *SearchRequest) (*EntityScopeNarrowResult, error) {
930 if req == nil {
931 return nil, fmt.Errorf("搜索请求不能为空")
932 }
933
934 result := &EntityScopeNarrowResult{
935 NarrowedLibraryIDs: append([]int64(nil), req.LibraryIDs...),
936 NarrowedLibraries: entityScopeNarrowLibrariesFromIDs(req.LibraryIDs),
937 NarrowedFileIDs: append([]int64(nil), req.FileIDs...),
938 Skipped: false,
939 }
940
941 // 检查是否应该跳过收敛
942 if req.SkipEntityScopeNarrowing {
943 result.Skipped = true
944 s.refreshEntityScopeNarrowLibraries(eid, result)
945 logger.SysDebugf("【实体范围】跳过收敛(SkipEntityScopeNarrowing=true): eid=%d, library_count=%d, file_count=%d",
946 eid, len(req.LibraryIDs), len(req.FileIDs))
947 return result, nil
948 }
949
950 scopeNarrowStart := time.Now()
951
952 narrowedReq := cloneSearchRequest(req)
953 if narrowedReq == nil {
954 narrowedReq = &SearchRequest{}
955 }
956
957 entityMeta, narrowErr := s.applyEntityScopeNarrowingWithMeta(eid, narrowedReq)
958 if narrowErr != nil {
959 logger.SysDebugf("【实体范围】实体收窄失败,回退原始请求: eid=%d, err=%v", eid, narrowErr)
960 } else if entityMeta != nil {
961 result.NarrowedLibraryIDs = append([]int64(nil), narrowedReq.LibraryIDs...)
962 result.NarrowedFileIDs = append([]int64(nil), narrowedReq.FileIDs...)
963 result.SeedEntities = entityMeta.SeedEntities
964 result.ChunkCandidateCount = entityMeta.ChunkCandidateCount
965 }
966
967 s.refreshEntityScopeNarrowLibraries(eid, result)
968 result.ScopeNarrowingMs = time.Since(scopeNarrowStart).Milliseconds()
969
970 logger.SysLogf("【实体范围】预处理完成: eid=%d, 种子实体数=%d, 分片候选数=%d, 原始库数=%d, 收敛库数=%d, 耗时=%dms",
971 eid, len(result.SeedEntities), result.ChunkCandidateCount,
972 len(req.LibraryIDs), len(result.NarrowedLibraryIDs), result.ScopeNarrowingMs)
973
974 return result, nil
975}
976
977func entityScopeNarrowLibrariesFromIDs(libraryIDs []int64) []EntityScopeNarrowLibrary {
978 if len(libraryIDs) == 0 {

Callers 2

HandleKnowledgeSearchRagFunction · 0.95

Tested by

no test coverage detected