31
31
32
32
@dataclass
33
33
class MultiHopAbstractQuerySynthesizer (MultiHopQuerySynthesizer ):
34
- """
35
- Synthesizes abstract multi-hop queries from given knowledge graph.
36
-
37
- Attributes
38
- ----------
39
- """
34
+ """Synthesize abstract multi-hop queries from given knowledge graph."""
40
35
41
36
name : str = "multi_hop_abstract_query_synthesizer"
37
+ relation_property : str = "summary_similarity"
38
+ abstract_property_name : str = "themes"
42
39
concept_combination_prompt : PydanticPrompt = ConceptCombinationPrompt ()
43
40
theme_persona_matching_prompt : PydanticPrompt = ThemesPersonasMatchingPrompt ()
44
41
45
42
def get_node_clusters (self , knowledge_graph : KnowledgeGraph ) -> t .List [t .Set [Node ]]:
46
-
43
+ """Identify clusters of nodes based on the specified relationship condition."""
47
44
node_clusters = knowledge_graph .find_indirect_clusters (
48
- relationship_condition = lambda rel : (
49
- True if rel .get_property ("summary_similarity" ) else False
50
- ),
45
+ relationship_condition = lambda rel : bool (rel .get_property (self .relation_property )),
51
46
depth_limit = 3 ,
52
47
)
53
48
logger .info ("found %d clusters" , len (node_clusters ))
@@ -61,7 +56,8 @@ async def _generate_scenarios(
61
56
callbacks : Callbacks ,
62
57
) -> t .List [MultiHopScenario ]:
63
58
"""
64
- Generates a list of scenarios on type MultiHopAbstractQuerySynthesizer
59
+ Generate a list of scenarios of type MultiHopScenario.
60
+
65
61
Steps to generate scenarios:
66
62
1. Find indirect clusters of nodes based on relationship condition
67
63
2. Calculate the number of samples that should be created per cluster to get n samples in total
@@ -93,7 +89,7 @@ async def _generate_scenarios(
93
89
nodes .append (node )
94
90
95
91
base_scenarios = []
96
- node_themes = [node .properties .get ("themes" , []) for node in nodes ]
92
+ node_themes = [node .properties .get (self . abstract_property_name , []) for node in nodes ]
97
93
prompt_input = ConceptsList (
98
94
lists_of_concepts = node_themes , max_combinations = num_sample_per_cluster
99
95
)
@@ -117,7 +113,7 @@ async def _generate_scenarios(
117
113
concept_combination .combinations ,
118
114
personas = persona_list ,
119
115
persona_item_mapping = persona_concepts .mapping ,
120
- property_name = "themes" ,
116
+ property_name = self . abstract_property_name ,
121
117
)
122
118
base_scenarios = self .sample_diverse_combinations (
123
119
base_scenarios , num_sample_per_cluster
0 commit comments