MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / prepare_cloud_import

Function prepare_cloud_import

openkb/indexer.py:290–336  ·  view source on GitHub ↗

Fetch a PageIndex Cloud doc and resolve its wiki name WITHOUT writing. Cloud fetch + collision-resistant name resolution only — no KB mutation — so the caller knows ``doc_name`` before writing and can snapshot just this doc's paths instead of copying the whole summaries/sources trees. N

(doc_id: str, kb_dir: Path, path_key: str)

Source from the content-addressed store, hash-verified

288
289
290def prepare_cloud_import(doc_id: str, kb_dir: Path, path_key: str) -> CloudImportData:
291 """Fetch a PageIndex Cloud doc and resolve its wiki name WITHOUT writing.
292
293 Cloud fetch + collision-resistant name resolution only — no KB mutation —
294 so the caller knows ``doc_name`` before writing and can snapshot just this
295 doc's paths instead of copying the whole summaries/sources trees. Name
296 resolution reads the registry but does not mutate it.
297 """
298 from openkb.converter import resolve_doc_name_from_key
299 from openkb.state import HashRegistry
300
301 pageindex_api_key = os.environ.get("PAGEINDEX_API_KEY", "")
302 if not pageindex_api_key:
303 raise RuntimeError(
304 "Importing from PageIndex Cloud requires the PAGEINDEX_API_KEY environment variable."
305 )
306
307 client = PageIndexClient(api_key=pageindex_api_key)
308 col = client.collection()
309
310 doc = col.get_document(doc_id, include_text=True)
311 cloud_name: str = doc.get("doc_name") or doc_id
312 description: str = doc.get("doc_description", "")
313 structure: list = doc.get("structure", [])
314
315 registry = HashRegistry(kb_dir / ".openkb" / "hashes.json")
316 stem = _cloud_display_stem(cloud_name, doc_id)
317 doc_name = resolve_doc_name_from_key(stem, path_key, registry)
318
319 tree = {
320 "doc_name": cloud_name,
321 "doc_description": description,
322 "structure": structure,
323 }
324
325 all_pages = _fetch_cloud_pages(col, doc_id)
326 if not all_pages:
327 raise RuntimeError(f"No page content returned from PageIndex Cloud for doc_id={doc_id}")
328
329 return CloudImportData(
330 doc_id=doc_id,
331 doc_name=doc_name,
332 cloud_name=cloud_name,
333 description=description,
334 tree=tree,
335 all_pages=all_pages,
336 )
337
338
339def import_cloud_document(doc_id: str, kb_dir: Path, path_key: str) -> CloudImportResult:

Callers 2

import_cloud_documentFunction · 0.85

Calls 6

HashRegistryClass · 0.90
_cloud_display_stemFunction · 0.85
_fetch_cloud_pagesFunction · 0.85
CloudImportDataClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected