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

Function recompile

openkb/cli.py:1559–1712  ·  view source on GitHub ↗

Re-run the current compile pipeline on already-indexed documents. Recompiling re-runs the same ``compile_short_doc`` / ``compile_long_doc`` that ``openkb add`` uses, so pre-feature KBs gain the ``entities/`` layer and pages refresh to the current format. It does NOT re-run PageIndex or

(ctx, doc_name, all_docs, dry_run, yes, refresh_schema)

Source from the content-addressed store, hash-verified

1557@click.pass_context
1558@_with_kb_lock(exclusive=True)
1559def recompile(ctx, doc_name, all_docs, dry_run, yes, refresh_schema):
1560 """Re-run the current compile pipeline on already-indexed documents.
1561
1562 Recompiling re-runs the same ``compile_short_doc`` / ``compile_long_doc``
1563 that ``openkb add`` uses, so pre-feature KBs gain the ``entities/`` layer
1564 and pages refresh to the current format. It does NOT re-run PageIndex or
1565 re-convert raw files — it reuses the on-disk ``wiki/sources/`` and
1566 ``wiki/summaries/`` content (and the registry's PageIndex ``doc_id``).
1567
1568 DOC_NAME recompiles one doc (resolved like ``openkb remove`` — filename,
1569 slug, or unique substring). ``--all`` recompiles every indexed doc.
1570 Exactly one of DOC_NAME or ``--all`` is required.
1571
1572 Side effect: this regenerates summaries (short docs) and rewrites concept
1573 pages with the current logic — manual edits to those pages are overwritten.
1574 """
1575 from openkb.state import HashRegistry
1576
1577 kb_dir = _find_kb_dir(ctx.obj.get("kb_dir_override"))
1578 if kb_dir is None:
1579 click.echo("No knowledge base found. Run `openkb init` first.")
1580 return
1581
1582 if all_docs and doc_name:
1583 click.echo("Specify either a DOC_NAME or --all, not both.")
1584 return
1585 if not all_docs and not doc_name:
1586 click.echo("Specify a document name or pass --all to recompile every doc.")
1587 return
1588
1589 openkb_dir = kb_dir / ".openkb"
1590 wiki_dir = kb_dir / "wiki"
1591 registry = HashRegistry(openkb_dir / "hashes.json")
1592
1593 # Resolve the set of docs to recompile.
1594 if all_docs:
1595 entries = list(registry.all_entries().values())
1596 if not entries:
1597 click.echo("No documents indexed yet. Run `openkb add` first.")
1598 return
1599 targets = entries
1600 else:
1601 matches = _resolve_doc_identifier(registry, doc_name)
1602 if not matches:
1603 click.echo(f"No document matching '{doc_name}' found in the KB.")
1604 click.echo("Try `openkb list` to see indexed documents.")
1605 return
1606 if len(matches) > 1:
1607 click.echo(f"'{doc_name}' matches multiple documents:")
1608 for _, m in matches:
1609 click.echo(f" - {m.get('name', '?')} (doc_name: {m.get('doc_name', '?')})")
1610 click.echo("Use a more specific name or the exact doc_name slug.")
1611 return
1612 targets = [matches[0][1]]
1613
1614 def _classify(meta: dict) -> str:
1615 return "long" if _is_long_doc(meta) else "short"
1616

Callers

nothing calls this directly

Calls 12

all_entriesMethod · 0.95
HashRegistryClass · 0.90
load_configFunction · 0.90
append_logFunction · 0.90
_find_kb_dirFunction · 0.85
_resolve_doc_identifierFunction · 0.85
_classifyFunction · 0.85
_refresh_schemaFunction · 0.85
_setup_llm_keyFunction · 0.85
_is_long_docFunction · 0.85
runMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected