graphify icon indicating copy to clipboard operation
graphify copied to clipboard

Semantic extraction silently truncates every file at 20,000 characters (_FILE_CHAR_CAP), no warning

Open cabgab-dev opened this issue 2 months ago • 4 comments

Summary

Semantic (LLM) extraction silently reads only the first 20,000 characters of every file (_FILE_CHAR_CAP = 20_000 in graphify/llm.py), with no warning and no error. For files well above that size — a long CLAUDE.md, a design doc, a project plan — this means most of the file's content is invisible to the graph, silently.

Environment

  • Installed: graphifyy 0.8.31 (pip show graphifyy)
  • Confirmed still present on main / latest release (0.9.66, 2026-09-22): _FILE_CHAR_CAP = 20_000 at graphify/llm.py:30, used unconditionally in _read_files (truncates before building the prompt) and in the token-estimate helpers around line 2090-2134.

Reproduction

  1. Create/point at any prose file (.md) larger than 20,000 characters — a CLAUDE.md accumulated over months of a real project is a common case.
  2. Run /graphify --update (or extract_corpus_parallel(...) directly) with GEMINI_API_KEY set.
  3. Compare len(open(file).read()) against the node count graphify produces for that file.

Actual behavior

  • The extraction call returns failed_chunks: 0 and a normal-looking result — nothing signals truncation.
  • Real case: a 229,319-character CLAUDE.md (project history/decisions) was read up to character 20,000 (8.7% of the file) and produced 11 nodes. Once manually split into <18k-char chunks at heading boundaries and re-extracted, the same file produced 215 nodes — the other 91.3% of the file had simply never reached the model.
  • Across one real corpus (~430 files), 29 documents exceeded the cap; some plans were seen as low as 8.7%–50% of their actual content, all without any indication in the CLI output.

Expected behavior

At minimum: print a warning (like the existing "extraction warning: N issues" pattern) whenever a file is truncated by _FILE_CHAR_CAP, naming the file and the percentage lost. Ideally: split an oversized file into multiple chunks (the same way the corpus itself is already chunked across files) and extract each chunk, merging nodes back onto the original source_file — this is what we ended up implementing as a workaround.

Workaround we're using

A small script that: audits which files exceed the cap, splits each one into <18k-char tramos (cutting on markdown ## headings, falling back to line breaks for an oversized single section), extracts each tramo with extract_corpus_parallel, and reassigns any node whose source_file the model pointed elsewhere back to the correct original document (by checking which candidate document's text mentions the node's label). Happy to share it if useful, but a native fix (at least the warning) would remove the need for every user to discover this independently.

Related

Not a duplicate of the shrink-guard issues (#3579, #3580, #2229, #2976) — this is upstream of those, in extraction input, not in the merge/write path. No existing issue found for _FILE_CHAR_CAP / truncation / "20000" in search.

cabgab-dev avatar Sep 23 '26 01:09 cabgab-dev

Before picking this up I checked it against current main (0.9.68). I think the case you hit is already fixed:

  • Since 0.8.44 (#1369), an oversized Markdown/text/rST file is sliced at heading/paragraph boundaries instead of cut at _FILE_CHAR_CAP. extract_corpus_parallel calls expand_oversized_files(files, _FILE_CHAR_CAP) before packing (graphify/llm.py:2621), and every slice reports the parent file as its source_file.
  • 0.9.49 extended that to every type in DOC_EXTENSIONS (#2900) and to PDFs through their extracted text (#2906). .docx/.xlsx are converted to Markdown sidecars first, so they're sliced too.
  • The remaining content[:_FILE_CHAR_CAP] in _read_files only applies to whole files that aren't splittable text, and code files never reach the semantic pass. I couldn't find a path where a document is still cut silently.

As a quick check, expand_oversized_files on a synthetic 218,050-character CLAUDE.md returned 11 slices covering all 218,050 characters, none over 20,000.

Your repro was on 0.8.31, which predates #1369. Could you re-run on the latest release? If the large CLAUDE.md still comes back with only a fraction of its nodes, I'm happy to dig in and add the truncation warning you suggested. Otherwise this can probably be closed.

Souptik96 avatar Sep 26 '26 05:09 Souptik96

Good first issue. _FILE_CHAR_CAP = 20_000 lives in graphify/llm.py and is applied in _read_files. The fix is to emit a warning (once per run, to stderr) when a file is truncated, so it is not silent. There is a recent warn-once pattern to mirror in graphify/detect.py (extract_pdf_text, the _pypdf_missing_warned flag). Add a test asserting the warning fires when a file exceeds the cap.

safishamsi avatar Sep 29 '26 10:09 safishamsi

Hi! I'd like to work on this. I'll implement the warn-once pattern on stderr in _read_files\ mirroring _pypdf_missing_warned\ in \graphify/detect.py\ whenever a file exceeds _FILE_CHAR_CAP, and add unit tests to verify the warning behavior.

AK-Lmn avatar Sep 29 '26 11:09 AK-Lmn

Fixed in v0.9.73 (now on PyPI) by #3923 — thanks @AK-Lmn.

Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.73

safishamsi avatar Sep 30 '26 19:09 safishamsi