Skip to content

Commit 33c7b5c

Browse files
alex-graber-pmiahgraber
authored andcommitted
fix: handle non-dict types for overlapped_items in MultiHopSpecificQuerySynthesizer
- Updated logic to check if overlapped_items is a dictionary before extracting keys. - Ensured compatibility with non-dict types for overlapped_items.
1 parent 4ef90d7 commit 33c7b5c

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ class MultiHopAbstractQuerySynthesizer(MultiHopQuerySynthesizer):
4242
def get_node_clusters(self, knowledge_graph: KnowledgeGraph) -> t.List[t.Set[Node]]:
4343
"""Identify clusters of nodes based on the specified relationship condition."""
4444
node_clusters = knowledge_graph.find_indirect_clusters(
45-
relationship_condition=lambda rel: bool(rel.get_property(self.relation_property)),
45+
relationship_condition=lambda rel: bool(
46+
rel.get_property(self.relation_property)
47+
),
4648
depth_limit=3,
4749
)
4850
logger.info("found %d clusters", len(node_clusters))
@@ -89,7 +91,9 @@ async def _generate_scenarios(
8991
nodes.append(node)
9092

9193
base_scenarios = []
92-
node_themes = [node.properties.get(self.abstract_property_name, []) for node in nodes]
94+
node_themes = [
95+
node.properties.get(self.abstract_property_name, []) for node in nodes
96+
]
9397
prompt_input = ConceptsList(
9498
lists_of_concepts=node_themes, max_combinations=num_sample_per_cluster
9599
)

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logging
44
import typing as t
5+
from collections.abc import Iterable
56
from dataclasses import dataclass
67

78
import numpy as np
@@ -81,7 +82,16 @@ async def _generate_scenarios(
8182
overlapped_items = []
8283
overlapped_items = triplet[1].properties[self.relation_overlap_property]
8384
if overlapped_items:
84-
themes = list(dict(overlapped_items).keys())
85+
if not all(
86+
isinstance(item, (str, Iterable)) for item in overlapped_items
87+
):
88+
logger.debug("Overlapped items are not strings or iterables.")
89+
continue
90+
themes = (
91+
list(overlapped_items.keys())
92+
if isinstance(overlapped_items, dict)
93+
else overlapped_items
94+
)
8595
prompt_input = ThemesPersonasInput(
8696
themes=themes, personas=persona_list
8797
)
@@ -90,10 +100,13 @@ async def _generate_scenarios(
90100
data=prompt_input, llm=self.llm, callbacks=callbacks
91101
)
92102
)
93-
overlapped_items = [list(item) for item in overlapped_items]
103+
combinations = [
104+
[item] if isinstance(item, str) else list(item)
105+
for item in themes
106+
]
94107
base_scenarios = self.prepare_combinations(
95108
[node_a, node_b],
96-
overlapped_items,
109+
combinations,
97110
personas=persona_list,
98111
persona_item_mapping=persona_concepts.mapping,
99112
property_name=self.property_name,

ragas/tests/unit/test_analytics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_testset_generation_tracking(monkeypatch):
135135
)
136136

137137
assert testset_event_payload.model_dump()["evolution_names"] == [
138-
"single_hop_specifc_query_synthesizer",
138+
"single_hop_specific_query_synthesizer",
139139
"multi_hop_abstract_query_synthesizer",
140140
"multi_hop_specific_query_synthesizer",
141141
]

0 commit comments

Comments
 (0)