DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix: escape $ in GraphRAG file_pattern, fix cache type (#699)
Amir Fathia252a0a83ef2
diff --git a/deeptutor/services/rag/pipelines/graphrag/config.py b/deeptutor/services/rag/pipelines/graphrag/config.pyindex 0b2bc76b2..24ec3d811 100644--- a/deeptutor/services/rag/pipelines/graphrag/config.py+++ b/deeptutor/services/rag/pipelines/graphrag/config.py@@ -170,11 +170,17 @@ def build_settings(*, llm_cfg: Any = None, embedding_cfg: Any = None) -> dict[st},# Plain-text input: DeepTutor's ingestion writes parsed ``.txt`` files# into ``input/`` (see ``ingestion.py``) so GraphRAG never parses- # documents itself.- "input": {"type": "text", "file_pattern": r".*\.txt$"},+ # documents itself. The ``$`` is escaped as ``$$`` because GraphRAG's+ # loader treats the whole config text as a ``string.Template`` and does+ # env-var substitution on it before parsing the YAML; a bare ``$`` is+ # an "Invalid placeholder" to that pass.+ "input": {"type": "text", "file_pattern": r".*\.txt$$"},"input_storage": {"type": "file", "base_dir": "input"},"output_storage": {"type": "file", "base_dir": "output"},- "cache": {"type": "file", "storage": {"type": "file", "base_dir": "cache"}},+ # "json" is GraphRAG's on-disk cache backend id (registered in+ # graphrag_cache.CacheFactory); "file" is a *storage* type, not a cache+ # type, and is rejected the first time the pipeline builds a cache.+ "cache": {"type": "json", "storage": {"type": "file", "base_dir": "cache"}},"reporting": {"type": "file", "base_dir": "logs"},# GraphRAG/LanceDB defaults to 3072 dimensions; DeepTutor must stamp the# active embedding dimension so Qwen-4096 and other non-default models work.diff --git a/tests/services/rag/test_graphrag_pipeline.py b/tests/services/rag/test_graphrag_pipeline.pyindex dd12867aa..a71e635c2 100644--- a/tests/services/rag/test_graphrag_pipeline.py+++ b/tests/services/rag/test_graphrag_pipeline.py@@ -139,6 +139,35 @@ def test_write_settings_roundtrips(tmp_path) -> None:assert "completion_models" in loaded and "embedding_models" in loaded+def test_write_settings_loads_and_builds_cache_via_real_graphrag(tmp_path) -> None:+ """The generated settings.yaml must survive GraphRAG's own config loader and+ cache factory, not just our own yaml.safe_load roundtrip above.++ GraphRAG's loader treats the config text as a ``string.Template`` and+ substitutes env vars into it before parsing YAML, so a literal ``$`` in a+ value (our ``file_pattern`` regex) must be escaped as ``$$`` or+ ``load_config`` raises ``ValueError: Invalid placeholder``. And GraphRAG's+ ``CacheFactory`` only registers ``json``/``memory``/``none`` cache types;+ ``cache.type`` must be ``"json"``, not the ``"file"`` *storage* type.+ This is not installed in CI (see the module docstring), so it is skipped+ there; run locally with the ``graphrag`` extra installed to exercise it.+ """+ pytest.importorskip("graphrag")+ from graphrag.config.load_config import load_config+ from graphrag_cache.cache_factory import create_cache++ gr_config.write_settings(+ tmp_path,+ llm_cfg=_Cfg("m", "u", "k"),+ embedding_cfg=_Cfg("e", "u", "k"),+ )+ config = load_config(root_dir=tmp_path)+ assert config.cache.type == "json"++ cache = create_cache(config.cache)+ assert type(cache).__name__ == "JsonCache"++@pytest.mark.parametrize("given,expected",[