Skip to content

Commit 6c8a784

Browse files
feat: allow user-defined node- and relationship- properties in MultiHopAbstractQuerySynthesizer
- Users should be able to set the relationship property to use for identifying clusters and the node property used for identifying abstract concepts. - This will not change default behavior, but allows users to override.
1 parent 819eacb commit 6c8a784

File tree

1 file changed

+9
-13
lines changed
  • ragas/src/ragas/testset/synthesizers/multi_hop

1 file changed

+9
-13
lines changed

ragas/src/ragas/testset/synthesizers/multi_hop/abstract.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,18 @@
3131

3232
@dataclass
3333
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."""
4035

4136
name: str = "multi_hop_abstract_query_synthesizer"
37+
relation_property: str = "summary_similarity"
38+
abstract_property_name: str = "themes"
4239
concept_combination_prompt: PydanticPrompt = ConceptCombinationPrompt()
4340
theme_persona_matching_prompt: PydanticPrompt = ThemesPersonasMatchingPrompt()
4441

4542
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."""
4744
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)),
5146
depth_limit=3,
5247
)
5348
logger.info("found %d clusters", len(node_clusters))
@@ -61,7 +56,8 @@ async def _generate_scenarios(
6156
callbacks: Callbacks,
6257
) -> t.List[MultiHopScenario]:
6358
"""
64-
Generates a list of scenarios on type MultiHopAbstractQuerySynthesizer
59+
Generate a list of scenarios of type MultiHopScenario.
60+
6561
Steps to generate scenarios:
6662
1. Find indirect clusters of nodes based on relationship condition
6763
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(
9389
nodes.append(node)
9490

9591
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]
9793
prompt_input = ConceptsList(
9894
lists_of_concepts=node_themes, max_combinations=num_sample_per_cluster
9995
)
@@ -117,7 +113,7 @@ async def _generate_scenarios(
117113
concept_combination.combinations,
118114
personas=persona_list,
119115
persona_item_mapping=persona_concepts.mapping,
120-
property_name="themes",
116+
property_name=self.abstract_property_name,
121117
)
122118
base_scenarios = self.sample_diverse_combinations(
123119
base_scenarios, num_sample_per_cluster

0 commit comments

Comments
 (0)