Skip to content

Commit adfeffb

Browse files
committed
v0.1.5: Smart hierarchy extraction for large documents
- PDF ToC extraction: auto-detect bookmarks and build tree with zero LLM calls - Font-size heading detection: inject [H1]/[H2]/[H3] markers via font analysis - Capped continuation context: send top-level summary + last 30 sections instead of full history (78% token savings) - Orphan repair: auto-insert synthetic parents for orphaned subsections - Updated prompts to leverage heading markers for accurate depth assignment - New exports: extractToc, tocToSections, repairOrphans - Updated How It Works diagram and README documentation - Tests for all new functionality (Python + TypeScript) Co-Authored-By: Mithun Gowda B <mithungowda.b7411@gmail.com>
1 parent 17d6bf7 commit adfeffb

19 files changed

Lines changed: 1012 additions & 102 deletions

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,20 @@ Available for both **Python** and **Node.js** — same API, same index format, f
2222
</p>
2323

2424
1. **Load** — Extract pages from any supported format
25-
2. **Index** — LLM analyzes page groups and extracts hierarchical structure
26-
3. **Build** — Flat sections become a tree with page ranges and embedded text
27-
4. **Query** — LLM selects relevant tree nodes for your question
28-
5. **Return** — Get context text, source pages, and reasoning
25+
2. **Detect** — Auto-extract PDF table of contents or detect headings via font-size analysis (`[H1]`/`[H2]`/`[H3]` markers)
26+
3. **Index** — If a PDF ToC is found, build the tree directly (no LLM needed). Otherwise, LLM analyzes page groups with heading hints to extract hierarchical structure
27+
4. **Build** — Flat sections become a tree with page ranges and embedded text. Orphaned subsections are auto-repaired
28+
5. **Query** — LLM selects relevant tree nodes for your question
29+
6. **Return** — Get context text, source pages, and reasoning
30+
31+
### Smart Hierarchy Detection
32+
33+
TreeDex uses multiple strategies to accurately extract document structure, especially for large (300+ page) documents:
34+
35+
- **PDF ToC extraction** — If the PDF has bookmarks/outline, the tree is built directly from it — zero LLM calls needed
36+
- **Font-size heading detection** — Analyzes font sizes across the document and injects `[H1]`/`[H2]`/`[H3]` markers so the LLM knows exactly which level each heading belongs to
37+
- **Capped continuation context** — For multi-chunk documents, the LLM sees a summary of top-level sections + recent sections instead of the full history, preventing prompt bloat
38+
- **Orphan repair** — If the LLM outputs `"2.3.1"` without a `"2.3"` parent, synthetic parents are auto-inserted to maintain a valid tree
2939

3040
### Why TreeDex instead of Vector DB?
3141

@@ -390,6 +400,14 @@ Use `auto_loader(path)` / `autoLoader(path)` for automatic format detection.
390400
| Reasoning | `.reasoning` | `.reasoning` | LLM's explanation for selection |
391401
| Answer | `.answer` | `.answer` | LLM-generated answer (agentic mode only) |
392402

403+
### Hierarchy Utilities
404+
405+
| Function | Python | Node.js | Description |
406+
|----------|--------|---------|-------------|
407+
| ToC → sections | `toc_to_sections(toc)` | `tocToSections(toc)` | Convert PDF ToC entries to numbered sections |
408+
| Repair orphans | `repair_orphans(sections)` | `repairOrphans(sections)` | Insert synthetic parents for orphaned subsections |
409+
| Extract PDF ToC | `extract_toc(path)` | `await extractToc(path)` | Get ToC from PDF bookmarks (returns `None`/`null` if unavailable) |
410+
393411
### Cross-language Index Compatibility
394412

395413
TreeDex uses the **same JSON index format** in both Python and Node.js. All field names use `snake_case` in the JSON:

assets/how-treedex-works.svg

Lines changed: 85 additions & 62 deletions
Loading

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "treedex",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "Tree-based, vectorless document RAG framework. Connect any LLM via URL/API key.",
55
"type": "module",
66
"main": "dist/index.cjs",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "treedex"
7-
version = "0.1.4"
7+
version = "0.1.5"
88
description = "Tree-based, vectorless document RAG framework. Connect any LLM via URL/API key."
99
readme = "README.md"
1010
license = "MIT"

0 commit comments

Comments
 (0)