Skip to content

Commit 993ba4a

Browse files
committed
docs: clarify Markdown summary threshold
1 parent 08a912c commit 993ba4a

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ You can customize the processing with additional optional arguments (the structu
184184
--if-add-node-id Add node ID (yes/no, default: yes)
185185
--if-add-node-summary Add node summary (yes/no, default: yes)
186186
--if-add-doc-description Add doc description (yes/no, default: yes)
187+
--summary-token-threshold Markdown only: nodes below this token count copy
188+
their text as the summary; other nodes call the LLM
189+
(default: 200; set 0 to summarize every node)
187190
```
188191
</details>
189192

run_pageindex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
parser.add_argument('--thinning-threshold', type=int, default=5000,
5050
help='Minimum token threshold for thinning (markdown only)')
5151
parser.add_argument('--summary-token-threshold', type=int, default=200,
52-
help='Token threshold for generating summaries (markdown only)')
52+
help='Markdown only: nodes below this token count copy text as their summary; other nodes call the LLM (default: 200)')
5353
args = parser.parse_args()
5454
if args.flash:
5555
args.mode = 'flash'

tests/test_page_index_md.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
2+
from unittest.mock import AsyncMock, patch
23

3-
from pageindex.page_index_md import extract_nodes_from_markdown
4+
from pageindex.page_index_md import extract_nodes_from_markdown, get_node_summary
45

56

67
class ExtractNodesFromMarkdownTest(unittest.TestCase):
@@ -19,5 +20,31 @@ def test_skips_bold_heading_with_only_whitespace(self):
1920
)
2021

2122

23+
class GetNodeSummaryTest(unittest.IsolatedAsyncioTestCase):
24+
async def test_below_threshold_uses_node_text_without_calling_llm(self):
25+
node = {"text": "short section"}
26+
27+
with patch("pageindex.page_index_md.count_tokens", return_value=199), patch(
28+
"pageindex.page_index_md.generate_node_summary", new_callable=AsyncMock
29+
) as generate_summary:
30+
summary = await get_node_summary(node, summary_token_threshold=200)
31+
32+
self.assertEqual(summary, node["text"])
33+
generate_summary.assert_not_awaited()
34+
35+
async def test_threshold_boundary_generates_a_summary(self):
36+
node = {"text": "boundary section"}
37+
38+
with patch("pageindex.page_index_md.count_tokens", return_value=200), patch(
39+
"pageindex.page_index_md.generate_node_summary",
40+
new_callable=AsyncMock,
41+
return_value="generated summary",
42+
) as generate_summary:
43+
summary = await get_node_summary(node, summary_token_threshold=200)
44+
45+
self.assertEqual(summary, "generated summary")
46+
generate_summary.assert_awaited_once_with(node, model=None)
47+
48+
2249
if __name__ == "__main__":
2350
unittest.main()

0 commit comments

Comments
 (0)