def merge_dicts(self, d1: Dict[str, Any], d2: Dict[str, Any]) -> Dict[str, Any]:
        """Merge two dictionaries recursively, combining values of the same key into a list."""
        merged = {}
        for key in set(d1).union(d2):
            if key in d1 and key in d2:
                if isinstance(d1[key], dict) and isinstance(d2[key], dict):
                    merged[key] = self.merge_dicts(d1[key], d2[key])
                else:
                    new_val = [d1[key]] if not isinstance(d1[key], list) else d1[key]
                    assert isinstance(new_val, list)

                    new_val.append(d2[key])
                    merged[key] = new_val  # type: ignore[assignment]
            else:
                merged[key] = d1.get(key, d2.get(key))
        return merged
Merge two dictionaries recursively, combining values of the same key into a list.
llama-index-core/llama_index/core/query_pipeline/query.py