HKUDS/DeepTutor PR #628 — Fix relative image paths in parse cache — PR #628
HKUDS/DeepTutor · pull request #628 ·
Transcript
PlainEnglish
Pull request six two eight fixes a path resolution bug in DeepTutor's parsing cache. When cached documents include images, consumers couldn't locate them because of relative path assumptions. Let's walk through how this fix makes image paths work regardless of the caller's working directory.
PlainEnglish
This pull request has one main goal: resolve relative image path entries to absolute paths when loading cached documents. We're also adding test coverage to validate the transformation, and we're explicitly preserving the relative paths in the cached JSON files themselves so cache directories can still be moved between systems.
PlainEnglish
The issue is a mismatch in path expectations. Parsing engines like MinerU write image paths relative to the cache directory where they store the parsed content. But consumers like RAG Anything resolve those paths against their own working directory, which causes image lookup failures during indexing. This PR fixes that by anchoring relative paths to the content directory when the cache loads, while keeping the cached JSON itself relative so cache directories remain portable.
Architecture
The change touches two files. In the services layer, cache dot py gets a new helper function and a one line modification to load underscore I R. In the test suite, test cache dot py adds a comprehensive test case that validates the transformation behavior. Let's zoom in on the implementation.
Architecture
Here's the new absolutize image paths helper. It walks through the content blocks list, checks if each block has an image path field, and if that path is relative, it anchors it to the content directory. The function is defensive: it skips non dict items, handles missing keys, and preserves absolute paths as is. Notice it mutates blocks in place, which is safe because these are fresh deserialized objects created per call.
Architecture
The integration point is load underscore I R, which is the function that reads parsed documents from the cache. After loading the JSON, it now calls the helper to absolutize the content list before constructing the parsed document. The transformation happens inside the existing try except block, so error handling stays consistent. And that's the core implementation.
Architecture
The new test validates four scenarios. Relative paths like images slash fig one dot png are absolutized and anchored to the cache directory. Absolute paths like slash abs slash path slash fig two dot png are left unchanged. Empty strings stay empty. And blocks without an image path field are left untouched. This gives us confidence the transformation handles the full range of real world cases.
PlainEnglish
After this pull request lands, the parse cache loading layer transforms relative image path entries to absolute paths when returning parsed documents, while keeping the cached JSON files themselves relative. This means RAG Anything and other consumers receive absolutized paths that work regardless of their working directory, fixing image location failures during indexing. And cache directories remain relocatable since the on disk JSON stays unchanged.
PlainEnglish
That's pull request six two eight. A focused cache layer fix that anchors relative image paths at load time without breaking cache relocatability. The new helper lives at cache dot py lines one twenty six through one forty one, the integration point is load underscore I R line one sixty four, and test coverage is at test cache dot py lines fifty eight through eighty three. Thanks for watching.
How this was made
Lenzon read HKUDS/DeepTutor at pull request #628 and generated this walkthrough automatically. The narration above is the transcript of what it says.
Explain a pull request from your own repo
Point Lenzon at a repo or a pull request and get a narrated walkthrough like this one.
Try it