Skip to content

Commit 49a406b

Browse files
committed
Fix: Implement deep merge for ParserConfig to handle default and custom settings
- Add `deepcopy` import and `__deep_merge` method to merge default and custom configurations - Update `ParserConfig` initialization to use merged dictionary - Ensure nested dictionaries are properly merged without overriding defaults unnecessarily
1 parent 512772c commit 49a406b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

sdk/python/ragflow_sdk/modules/dataset.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
from copy import deepcopy
1617

1718
from .base import Base
1819
from .document import Document
@@ -21,7 +22,25 @@
2122
class DataSet(Base):
2223
class ParserConfig(Base):
2324
def __init__(self, rag, res_dict):
24-
super().__init__(rag, res_dict)
25+
default_dict = {"raptor": {"use_raptor": False}, "graphrag": {"use_graphrag": False}}
26+
merged = self.__deep_merge(default_dict, res_dict)
27+
super().__init__(rag, merged)
28+
29+
@staticmethod
30+
def __deep_merge(default: dict, custom: dict) -> dict:
31+
merged = deepcopy(default)
32+
stack = [(merged, custom)]
33+
34+
while stack:
35+
base_dict, override_dict = stack.pop()
36+
37+
for key, val in override_dict.items():
38+
if key in base_dict and isinstance(val, dict) and isinstance(base_dict[key], dict):
39+
stack.append((base_dict[key], val))
40+
else:
41+
base_dict[key] = val
42+
43+
return merged
2544

2645
def __init__(self, rag, res_dict):
2746
self.id = ""

0 commit comments

Comments
 (0)