MCPcopy Index your code
hub / github.com/VectifyAI/OpenKB / _write_long_doc_artifacts

Function _write_long_doc_artifacts

openkb/indexer.py:125–153  ·  view source on GitHub ↗

Write ``wiki/sources/ .json`` + ``wiki/summaries/ .md``. Returns the summary path. Shared by :func:`index_long_document` (local) and :func:`import_cloud_document` (cloud) so both produce identical artifacts. Page images, when present, are written separately by the

(
    tree: dict,
    pages: list[dict[str, Any]],
    doc_name: str,
    doc_id: str,
    kb_dir: Path,
    description: str = "",
)

Source from the content-addressed store, hash-verified

123
124
125def _write_long_doc_artifacts(
126 tree: dict,
127 pages: list[dict[str, Any]],
128 doc_name: str,
129 doc_id: str,
130 kb_dir: Path,
131 description: str = "",
132) -> Path:
133 """Write ``wiki/sources/<doc_name>.json`` + ``wiki/summaries/<doc_name>.md``.
134
135 Returns the summary path. Shared by :func:`index_long_document` (local)
136 and :func:`import_cloud_document` (cloud) so both produce identical
137 artifacts. Page images, when present, are written separately by the
138 caller&#x27;s page extractor — this helper only persists page text + summary.
139 """
140 sources_dir = kb_dir / "wiki" / "sources"
141 sources_dir.mkdir(parents=True, exist_ok=True)
142 (sources_dir / f"{doc_name}.json").write_text(
143 json_mod.dumps(pages, ensure_ascii=False, indent=2),
144 encoding="utf-8",
145 )
146
147 summaries_dir = kb_dir / "wiki" / "summaries"
148 summaries_dir.mkdir(parents=True, exist_ok=True)
149 summary_path = summaries_dir / f"{doc_name}.md"
150 summary_path.write_text(
151 render_summary_md(tree, doc_name, doc_id, description=description), encoding="utf-8"
152 )
153 return summary_path
154
155
156def index_long_document(pdf_path: Path, kb_dir: Path, doc_name: str | None = None) -> IndexResult:

Calls 1

render_summary_mdFunction · 0.90