Skip to content

fix(rag): escape $ in GraphRAG file_pattern, fix cache type - #699

Merged
pancacake merged 1 commit into
HKUDS:devfrom
AmirF194:fix/695-graphrag-config-invalid-settings
Jul 26, 2026
Merged

pancacake merged 1 commit into
HKUDS:devfrom
AmirF194:fix/695-graphrag-config-invalid-settings

Conversation

@AmirF194

Copy link
Copy Markdown
Contributor

GraphRAG's load_config() treats the whole settings.yaml text as a string.Template and substitutes env vars into it before parsing YAML. Our generated file_pattern regex, .*\.txt$, contains a bare $, which is an invalid placeholder to that pass and raises ValueError: Invalid placeholder in string, before indexing can even start.

Once that is escaped, the next call to fail is graphrag_cache.CacheFactory.create_cache (invoked from GraphRAG's own run_pipeline.py): our cache.type was set to "file", but "file" is a storage type, not a registered cache type. GraphRAG's CacheFactory only registers json/memory/none, so the first indexing run raises ValueError: CacheConfig.type 'file' is not registered in the CacheFactory.

Fix

In deeptutor/services/rag/pipelines/graphrag/config.py:

  • file_pattern: .*\.txt$ → .*\.txt$$ (escapes the literal $ for string.Template).
  • cache.type: "file" → "json" (the storage type stays "file"; only the cache backend id was wrong).

Verification

Installed graphrag==3.1.1 (the version this repo pins) in a clean Docker container and drove the real path: write_settings() → graphrag.config.load_config.load_config() → graphrag_cache.cache_factory.create_cache(), the same call graphrag/index/run/run_pipeline.py:45 makes. Both errors reproduce verbatim on unpatched config.py; both are gone after the fix, and create_cache returns a real JsonCache.

Added a regression test in tests/services/rag/test_graphrag_pipeline.py that exercises this same real path, guarded with pytest.importorskip("graphrag") since the package is not installed in this repo's CI (per the test module's own docstring). Ran it RED against the unpatched file and GREEN after the fix, both with graphrag installed; also ran the full existing test file and the full tests/ suite with graphrag uninstalled (matching CI) to confirm no regressions: 2573 passed, 8 skipped, 3 pre-existing failures unrelated to this change (missing git binary in the minimal container, confirmed by installing it). ruff check and ruff format --check (0.16.0, matching CI's lint job) are clean on both changed files.

Did not reproduce or address the issue's third symptom (uvloop/nest_asyncio event-loop clash) since it is an orthogonal event-loop policy issue, not a config-generation bug, and is not required to fix these two.

Fixes #695

GraphRAG's load_config() runs string.Template substitution on the raw
settings.yaml text before parsing it, so the literal $ in our
file_pattern regex (.*\.txt$) raises "Invalid placeholder". Escape
it as $$.

cache.type was set to "file", which is a storage type, not a
registered cache type (GraphRAG's CacheFactory only knows
json/memory/none); the first indexing run raises
"CacheConfig.type 'file' is not registered in the CacheFactory".
Changed to "json".

Verified both failures and the fix against the real graphrag==3.1.1
package (graphrag.config.load_config.load_config +
graphrag_cache.cache_factory.create_cache, the same call
run_pipeline.py makes), not just a yaml roundtrip. Added a regression
test guarded with pytest.importorskip("graphrag") since the package
is not installed in this repo's CI; ran RED on unpatched config.py and
GREEN after the fix, both with graphrag installed in Docker.

Fixes HKUDS#695
@pancacake
pancacake merged commit a252a0a into HKUDS:dev Jul 26, 2026
11 checks passed
pancacake added a commit that referenced this pull request Jul 26, 2026
`graphrag_llm` calls `nest_asyncio2.apply()` at import time, and that patch
refuses uvloop — the loop `uvicorn[standard]` gives the backend on
macOS/Linux. So the first GraphRAG import raised "Can't patch loop of type
<class 'uvloop.Loop'>" and indexing died before it started; the reporter's
workaround was to force UVICORN_LOOP=asyncio for the whole app.

Drive every GraphRAG entry point from a worker thread that owns a stock
asyncio loop: the import-time patch and GraphRAG's own nested
`run_until_complete` calls get the reentrant loop they expect, and the
server's loop is left alone. The adapter stays the only graphrag-aware
module, so its function-local imports now also decide where that patch
lands.

Completes #695 — the settings.yaml `$` escape and the `cache.type` fix
landed in #699.
@AmirF194
AmirF194 deleted the fix/695-graphrag-config-invalid-settings branch July 26, 2026 13:00
pancacake added a commit that referenced this pull request Jul 26, 2026
Maintenance release on top of v1.5.4, with two new ways to bring a model.

- OpenAI Codex is a first-party OAuth provider (#690): browser sign-in
  against your own ChatGPT plan replaces the API-key fields, credentials
  stay in <user-root>/private/openai-codex/ with owner-only permissions,
  and the managed profile is owner-bound so it is never handed out through
  grants or made active over an already-configured LLM.
- Eden AI joins as the 35th LLM binding (#671), an OpenAI-compatible
  gateway addressed as <provider>/<model>.
- Knowledge bases answer from a real document inventory instead of
  guessing from retrieval hits: a per-KB inventory rides the system prompt
  and a new kb_files tool enumerates on demand with glob/substring
  filters, mounted under rag's gate and deniable per partner.
- The rag tool cites the chunks, entities, and reports retrieval actually
  returned (#694) rather than an echo of its own query; the local LightRAG
  pipeline still surfaces nothing to cite.
- GraphRAG indexing runs on a worker thread with its own asyncio loop
  (#695), so UVICORN_LOOP=asyncio is no longer needed, and two config
  faults that broke the first run are fixed (#699).
- Assorted: unique optimistic message ids (#698, a v1.5.4 regression that
  dropped the assistant reply from the visible thread), partner-chat
  manual scrolling respected (#704), claude-opus-5 recognized as
  effort-based (#703), Kimi models omit temperature outright, and
  deeptutor start keeps relaying logs on legacy Windows code pages (#702).
- Typing: narrow the loopback callback server to asyncio.Server and gate
  the msvcrt lock path on sys.platform so it type-checks off Windows.

Release notes: assets/releases/ver1-5-5.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants