Skip to content

Commit 594c490

Browse files
committed
fix conflict
2 parents 0ee12b0 + 1152b7a commit 594c490

File tree

1 file changed

+75
-48
lines changed

1 file changed

+75
-48
lines changed

kag/indexer/kag_index_manager.py

Lines changed: 75 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def index_cost(self) -> str:
6565

6666
@property
6767
def retrieval_method(self) -> str:
68-
return ""
68+
return "通过构建原子问,实现原子问的检索,一般用于检索与原子问相关的chunk"
6969

7070
def build_extractor_config(
7171
self, llm_config: Dict, vectorize_model_config: Dict, **kwargs
@@ -84,6 +84,10 @@ class AtomicIndexManager(KAGIndexManager):
8484
def name(self):
8585
return "基于原子查询的索引管理器"
8686

87+
@property
88+
def description(self) -> str:
89+
return "该索引管理器通过从文档中抽取独立的、可回答的原子查询(AtomicQuery)来构建索引。它旨在将复杂问题分解,并通过检索与这些原子问题最相关的文本块(Chunk)来提供精确的上下文,特别适用于需要细粒度问答的场景。"
90+
8791
@property
8892
def schema(self) -> str:
8993
return """
@@ -106,15 +110,17 @@ def index_cost(self) -> str:
106110

107111
@property
108112
def applicable_scenarios(self) -> str:
109-
msg = """
110-
检索方法描述:
113+
return """
114+
**适用场景**: 适用于事实问答、FAQ等可以通过简单问句精确匹配找到答案的场景。
111115
112-
# recall_atomic_questions, 基于question title,通过bm25/emb 等实现atomic question召回
113-
# get_qa_associate_chunks, 基于chunk 与 question 的关联,实现chunk召回
114-
chunks2 = get_qa_associate_chunks(recall_atomic_question(rewrite(sub_query)))
116+
**检索流程**:
117+
1. `rewrite(sub_query)`: 对用户问题进行重写,使其更规范。
118+
2. `recall_atomic_question(...)`: 基于重写后的问题,通过语义或文本匹配召回相似的原子问题。
119+
3. `get_qa_associate_chunks(...)`: 根据召回的原子问题,找到与之关联的文本块作为最终答案来源。
115120
121+
**代码示例**:
122+
`chunks = get_qa_associate_chunks(recall_atomic_question(rewrite(sub_query)))`
116123
"""
117-
return msg
118124

119125
@property
120126
def retrieval_method(self) -> str:
@@ -187,6 +193,10 @@ class ChunkIndexManager(KAGIndexManager):
187193
def name(self):
188194
return "基于文本块的索引管理器"
189195

196+
@property
197+
def description(self) -> str:
198+
return "该索引管理器将文档直接分割成文本块(Chunk),并为这些文本块创建向量和文本索引。这是一种直接而高效的索引方式(Naive RAG),适用于对整个文档进行语义或关键字检索,快速定位包含相关信息的文本片段。"
199+
190200
@property
191201
def schema(self) -> str:
192202
return """
@@ -209,14 +219,16 @@ def index_cost(self) -> str:
209219

210220
@property
211221
def applicable_scenarios(self) -> str:
212-
msg = """
213-
检索方法描述:
222+
return """
223+
**适用场景**: 适用于通用、开放式的文档问答,当问题没有特定结构,需要在大量非结构化文本中寻找答案时。
214224
215-
# recall_chunks,基于chunk name/content, 通过bm25/emb 等实现chunk召回
216-
chunks1 = recall_chunks(rewrite(sub_query))
225+
**检索流程**:
226+
1. `rewrite(sub_query)`: 对用户问题进行重写。
227+
2. `recall_chunks(...)`: 直接在所有文本块中进行向量或关键词搜索,召回最相关的文本块。
217228
229+
**代码示例**:
230+
`chunks = recall_chunks(rewrite(sub_query))`
218231
"""
219-
return msg
220232

221233
@property
222234
def retrieval_method(self) -> str:
@@ -269,6 +281,10 @@ class TableIndexManager(KAGIndexManager):
269281
def name(self):
270282
return "基于表格的索引管理器"
271283

284+
@property
285+
def description(self) -> str:
286+
return "该索引管理器专门用于识别和抽取文档中的表格数据,并为其内容、上下文(前后文本)创建索引。它能够精确地检索表格,并利用表格与周围文本的关联关系来召回相关的文本块,非常适合处理包含大量结构化表格数据的文档。"
287+
272288
@property
273289
def schema(self) -> str:
274290
return """
@@ -297,16 +313,17 @@ def index_cost(self) -> str:
297313

298314
@property
299315
def applicable_scenarios(self) -> str:
300-
msg = """
301-
检索方法描述:
302-
303-
304-
# recall_table,基于table title, 通过bm25/emb 等实现table召回
305-
# get_table_associate_chunks, 基于chunk 与 table 关联实现chunk 召回
306-
chunks5 = get_table_associate_chunks(recall_table(rewrite(sub_query)))
316+
return """
317+
**适用场景**: 当问题涉及到查询表格中的数据时,例如"XX产品的价格是多少?"或者需要引用表格内容进行回答的场景。
307318
319+
**检索流程**:
320+
1. `rewrite(sub_query)`: 对用户问题进行重写。
321+
2. `recall_table(...)`: 根据问题内容,搜索并召回最相关的表格。
322+
3. `get_table_associate_chunks(...)`: 找到与召回表格相关联的文本块,提供更丰富的上下文。
323+
324+
**代码示例**:
325+
`chunks = get_table_associate_chunks(recall_table(rewrite(sub_query)))`
308326
"""
309-
return msg
310327

311328
@property
312329
def retrieval_method(self) -> str:
@@ -346,6 +363,10 @@ class SummaryIndexManager(KAGIndexManager):
346363
def name(self):
347364
return "基于摘要的索引管理器"
348365

366+
@property
367+
def description(self) -> str:
368+
return "该索引管理器利用大语言模型对文本块(Chunk)生成多层次的摘要(Summary),并基于这些摘要构建索引。通过检索摘要,可以快速理解大段文本的核心内容,并利用摘要与原始文本块的关联来召回详细信息,适用于需要信息概览和层层深入的检索场景。"
369+
349370
@property
350371
def schema(self) -> str:
351372
return """
@@ -371,15 +392,17 @@ def index_cost(self) -> str:
371392

372393
@property
373394
def applicable_scenarios(self) -> str:
374-
msg = """
375-
检索方法描述:
376-
377-
# recall_summary, 基于summary title,通过bm25/emb 等实现summary召回
378-
# get_summary_associate_chunks, 基于chunk 与summary 的关联实现chunk召回
379-
chunks3 = get_summary_associate_chunks(recall_summary(rewrite(sub_query)))
395+
return """
396+
**适用场景**: 适用于需要对长文档进行归纳总结,或者需要从宏观到微观层层钻取信息的场景。
380397
398+
**检索流程**:
399+
1. `rewrite(sub_query)`: 对用户问题进行重写。
400+
2. `recall_summary(...)`: 根据问题搜索并召回最相关的摘要。
401+
3. `get_summary_associate_chunks(...)`: 通过召回的摘要,找到其对应的原始文本块,提供详细信息。
402+
403+
**代码示例**:
404+
`chunks = get_summary_associate_chunks(recall_summary(rewrite(sub_query)))`
381405
"""
382-
return msg
383406

384407
@property
385408
def retrieval_method(self) -> str:
@@ -419,6 +442,10 @@ class OutlineIndexManager(KAGIndexManager):
419442
def name(self):
420443
return "基于大纲的索引管理器"
421444

445+
@property
446+
def description(self) -> str:
447+
return "该索引管理器通过解析文档的结构(如标题层级)来构建大纲(Outline)索引。这种索引保留了文档的层次结构,允许用户通过检索章节标题来快速定位到文档的特定部分,并召回与该大纲节点相关的文本块。"
448+
422449
@property
423450
def schema(self) -> str:
424451
return """
@@ -444,15 +471,17 @@ def index_cost(self) -> str:
444471

445472
@property
446473
def applicable_scenarios(self) -> str:
447-
msg = """
448-
检索方法描述:
449-
450-
# recall_outline,基于outline title, 通过bm25/emb 等实现outline召回
451-
# recall_outline, 基于outline_childOf->outline, 实现outline 扩展召回
452-
# get_outline_associate_chunks, 基于chunk 与 summary 关联实现chunk 召回
453-
chunks4 = get_outline_associate_chunks(recall_outline(rewrite(sub_query)))
474+
return """
475+
**适用场景**: 适用于结构化文档的问答,特别是当问题与文档的特定章节或标题相关时。
476+
477+
**检索流程**:
478+
1. `rewrite(sub_query)`: 对用户问题进行重写。
479+
2. `recall_outline(...)`: 根据问题搜索召回最相关的大纲标题,并可沿着大纲层级扩展。
480+
3. `get_outline_associate_chunks(...)`: 根据召回的大纲,找到其对应的文本块。
481+
482+
**代码示例**:
483+
`chunks = get_outline_associate_chunks(recall_outline(rewrite(sub_query)))`
454484
"""
455-
return msg
456485

457486
@property
458487
def retrieval_method(self) -> str:
@@ -489,6 +518,10 @@ class KAGHybridIndexManager(KAGIndexManager):
489518
def name(self):
490519
return "基于文本块和图谱的混合索引管理器"
491520

521+
@property
522+
def description(self) -> str:
523+
return "该索引管理器是一种混合方法,它结合了知识图谱(KG)和文本块(Chunk)的优点。它首先从文本中抽取实体和关系构建图谱,然后将文本块与图谱节点关联起来。在检索时,它同时利用图谱的结构化查询能力(CS/FR Retriever)和文本的向量检索能力,实现更精准、更具推理能力的检索,特别适合复杂的问答任务。"
524+
492525
@property
493526
def schema(self) -> str:
494527
return """
@@ -533,22 +566,16 @@ def index_cost(self) -> str:
533566

534567
@property
535568
def applicable_scenarios(self) -> str:
569+
return """
570+
**适用场景**: 适用于需要深度推理和关联分析的复杂问题。它能够理解问题的结构,并在知识图谱和文本块之间进行联合查询,应对需要跨领域知识或多跳推理的场景。
536571
537-
msg = """
538-
检索方法描述:
572+
**检索流程(多路并行)**:
573+
- **路径1 (FR)**: `kg_fr_retriever(query)` -> 自由文本检索,召回相关文本块。
574+
- **路径2 (CS)**: `kg_cs_retriever(logic_form)` -> 基于问题的逻辑结构,在图谱中进行精确检索。
575+
- **路径3 (RC)**: `vector_chunk_retriever(query)` -> 纯向量检索,作为补充召回。
539576
540-
# 先根据子问题进行原始问召回
541-
atomic_queries = get_atomic_queries(sub_query)
542-
# 再据子问题召回知识点
543-
knowledge_units = get_knowledge_units(sub_query)
544-
# 根据logical-form召回知识点
545-
knowledge_units += get_knowledge_units(logcal-form)
546-
# 根据logical-form召回实体和关系点
547-
entities = get_entities(logical_form)
548-
# 使用ppr召回chunk
549-
chunks = get_ppr_chunks(atomic_queries+knowledge_units+entities)
577+
最终将多路结果融合,提供最全面的答案依据。
550578
"""
551-
return msg
552579

553580
@property
554581
def retrieval_method(self) -> str:

0 commit comments

Comments
 (0)