Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,49 @@ Counters are maintained per level. When a new Level 1 appears, all deeper counte
| Build from pages | `TreeDex.from_pages(pages, llm, **opts)` | `await TreeDex.fromPages(pages, llm, opts?)` | From pre-extracted pages |
| Build from tree | `TreeDex.from_tree(tree, pages, llm)` | `TreeDex.fromTree(tree, pages, llm)` | From existing tree (no LLM) |
| Query | `index.query(q, llm=, agentic=)` | `await index.query(q, {llm?, agentic?})` | Retrieve relevant sections |
| **Multi-index query** | **`TreeDex.query_all(indexes, q, ...)`** | **`await TreeDex.queryAll(indexes, q, ...)`** | **Query multiple indexes simultaneously** |
| Save | `index.save(path)` | `await index.save(path)` | Export to JSON |
| Load | `TreeDex.load(path, llm)` | `await TreeDex.load(path, llm)` | Import from JSON |
| Show tree | `index.show_tree()` | `index.showTree()` | Pretty-print |
| Stats | `index.stats()` | `index.stats()` | Return `{total_pages, total_tokens, ...}` |
| Find large | `index.find_large_sections(**opts)` | `index.findLargeSections(opts?)` | Nodes exceeding thresholds |

#### `query_all` / `queryAll` Options

Query multiple TreeDex indexes simultaneously. Indexes are queried in parallel
(Node.js) or sequentially (Python), then results are merged into a single
`MultiQueryResult` with `[Label]` separators between sources.

| Parameter | Python | Node.js | Default | Description |
|-----------|--------|---------|---------|-------------|
| indexes | `list[TreeDex]` | `TreeDex[]` | required | List of indexes to query |
| question | `str` | `string` | required | The user's question |
| llm | `llm=` | `{ llm? }` | `None` | Shared LLM override; falls back to each index's own LLM |
| agentic | `agentic=` | `{ agentic? }` | `False` | Generate a single answer over the combined context |
| labels | `labels=` | `{ labels? }` | `["Document 1", ...]` | Human-readable name per index |

```python
multi = TreeDex.query_all(
[index_a, index_b, index_c],
"What are the safety guidelines?",
labels=["Manual A", "Manual B", "Manual C"],
agentic=True,
)
print(multi.combined_context) # merged context with [Manual A]/[Manual B] headers
print(multi.answer) # single answer over all sources
print(multi.results[0].pages_str) # pages from Manual A
```

```typescript
const multi = await TreeDex.queryAll(
[indexA, indexB, indexC],
"What are the safety guidelines?",
{ labels: ["Manual A", "Manual B", "Manual C"], agentic: true },
);
console.log(multi.combinedContext);
console.log(multi.answer);
```

#### `from_file` Options

| Parameter | Python | Node.js | Default | Description |
Expand All @@ -331,6 +368,17 @@ Counters are maintained per level. When a new Level 1 appears, all deeper counte
| Reasoning | `.reasoning` | `.reasoning` | `str` | LLM's selection explanation |
| Answer | `.answer` | `.answer` | `str` | Generated answer (agentic mode only) |

### MultiQueryResult

Returned by `TreeDex.query_all()` / `TreeDex.queryAll()`.

| Property | Python | Node.js | Type | Description |
|----------|--------|---------|------|-------------|
| Per-index results | `.results` | `.results` | `list[QueryResult]` | One result per index, in input order |
| Labels | `.labels` | `.labels` | `list[str]` | Human-readable name for each index |
| Combined context | `.combined_context` | `.combinedContext` | `str` | All contexts merged with `[Label]` headers and `---` separators |
| Answer | `.answer` | `.answer` | `str` | Single answer over all sources (agentic only) |

### Hierarchy Utilities

| Function | Python | Node.js | Description |
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ Use `auto_loader(path)` / `autoLoader(path)` for automatic format detection.
| Create from tree | `TreeDex.from_tree(tree, pages)` | `TreeDex.fromTree(tree, pages)` |
| Query | `index.query(question)` | `await index.query(question)` |
| Agentic query | `index.query(q, agentic=True)` | `await index.query(q, { agentic: true })` |
| **Multi-index query** | **`TreeDex.query_all(indexes, q)`** | **`await TreeDex.queryAll(indexes, q)`** |
| Save | `index.save(path)` | `await index.save(path)` |
| Load | `TreeDex.load(path, llm)` | `await TreeDex.load(path, llm)` |
| Show tree | `index.show_tree()` | `index.showTree()` |
Expand All @@ -400,6 +401,41 @@ Use `auto_loader(path)` / `autoLoader(path)` for automatic format detection.
| Reasoning | `.reasoning` | `.reasoning` | LLM's explanation for selection |
| Answer | `.answer` | `.answer` | LLM-generated answer (agentic mode only) |

### `MultiQueryResult`

Returned by `TreeDex.query_all()` / `TreeDex.queryAll()` when querying multiple indexes at once.

| Property | Python | Node.js | Description |
|----------|--------|---------|-------------|
| Per-index results | `.results` | `.results` | One `QueryResult` per index, in input order |
| Labels | `.labels` | `.labels` | Human-readable name for each index |
| Combined context | `.combined_context` | `.combinedContext` | All contexts merged with `[Label]` headers |
| Answer | `.answer` | `.answer` | Single answer over all sources (agentic only) |

**Example:**

```python
multi = TreeDex.query_all(
[index_a, index_b],
"What are the safety guidelines?",
labels=["Manual A", "Manual B"],
agentic=True,
)
print(multi.combined_context) # [Manual A]\n...\n---\n[Manual B]\n...
print(multi.answer) # unified answer across both documents
print(multi.results[0].pages_str) # pages matched in Manual A
```

```typescript
const multi = await TreeDex.queryAll(
[indexA, indexB],
"What are the safety guidelines?",
{ labels: ["Manual A", "Manual B"], agentic: true },
);
console.log(multi.combinedContext);
console.log(multi.answer);
```

### Hierarchy Utilities

| Function | Python | Node.js | Description |
Expand Down
80 changes: 79 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: API Reference
nav_order: 3
nav_order: 4
---

# API Reference
Expand Down Expand Up @@ -123,6 +123,57 @@ const result = await index.query(question, {
// Or shorthand: await index.query(question, llm)
```

#### `query_all` / `queryAll` _(static)_

Query **multiple indexes simultaneously** and merge results into a single
`MultiQueryResult`. All indexes are queried in parallel (Node.js) or
sequentially (Python). Results are combined with clear `[Document N]`
separators so downstream LLMs or users can distinguish sources.

```python
multi = TreeDex.query_all(
indexes: list[TreeDex],
question: str,
llm=None, # Shared LLM override (falls back to each index's LLM)
agentic: bool = False, # Generate one answer over the combined context
labels: list[str] = None # Human-readable names (default: "Document 1", "Document 2", …)
) -> MultiQueryResult
```

```typescript
const multi = await TreeDex.queryAll(indexes, question, {
llm?, // Shared LLM override
agentic?, // Generate one answer over combined context
labels?, // Human-readable names per index
});
```

**Example:**

```python
multi = TreeDex.query_all(
[index_a, index_b, index_c],
"What are the safety guidelines?",
llm=llm,
labels=["Manual A", "Manual B", "Manual C"],
agentic=True,
)
print(multi.combined_context) # merged text with [Manual A] / [Manual B] headers
print(multi.answer) # single LLM-generated answer over all sources
print(multi.results[0].pages_str) # pages matched in Manual A
```

```typescript
const multi = await TreeDex.queryAll(
[indexA, indexB, indexC],
"What are the safety guidelines?",
{ llm, labels: ["Manual A", "Manual B", "Manual C"], agentic: true },
);
console.log(multi.combinedContext);
console.log(multi.answer);
console.log(multi.results[0].pagesStr);
```

#### `save`

Export the index to a JSON file.
Expand Down Expand Up @@ -198,6 +249,33 @@ Returned by `index.query()`.

---

## MultiQueryResult

Returned by `TreeDex.query_all()` / `TreeDex.queryAll()`.

| Property | Python | Node.js | Type | Description |
|----------|--------|---------|------|-------------|
| Per-index results | `.results` | `.results` | `list[QueryResult]` | One `QueryResult` per index, in input order |
| Labels | `.labels` | `.labels` | `list[str]` | Human-readable name for each index |
| Combined context | `.combined_context` | `.combinedContext` | `str` | All contexts merged with `[Label]` headers and `---` separators |
| Answer | `.answer` | `.answer` | `str` | Single LLM-generated answer over all sources (agentic mode only) |

**Combined context format:**

```
[Manual A]
[Section: Safety Guidelines]
Content from Manual A...

---

[Manual B]
[Section: Hazard Procedures]
Content from Manual B...
```

---

## PDF Parser Functions

### `extract_toc` / `extractToc`
Expand Down
2 changes: 1 addition & 1 deletion docs/benchmark-report.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: Benchmark Report
nav_order: 8
nav_order: 9
---

# Benchmark Report: TreeDex vs Vector RAG
Expand Down
2 changes: 1 addition & 1 deletion docs/benchmarks.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: Benchmarks
nav_order: 5
nav_order: 6
---

# Benchmarks
Expand Down
2 changes: 1 addition & 1 deletion docs/case-studies.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: Case Studies
nav_order: 6
nav_order: 7
---

# Case Studies
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: Configuration
nav_order: 7
nav_order: 8
---

# Configuration & Tuning
Expand Down
Loading
Loading