Skip to content

feat(agent): opt-in append-note concept_update_mode to avoid full-page rewrites on ingest - #246

Open
sebastianbraun25 wants to merge 4 commits into
VectifyAI:mainfrom
sebastianbraun25:fix/issue-245-append-note-concept-update-mode
Open

feat(agent): opt-in append-note concept_update_mode to avoid full-page rewrites on ingest#246
sebastianbraun25 wants to merge 4 commits into
VectifyAI:mainfrom
sebastianbraun25:fix/issue-245-append-note-concept-update-mode

Conversation

@sebastianbraun25

@sebastianbraun25 sebastianbraun25 commented Sep 7, 2026

Copy link
Copy Markdown

Note

This PR was created in collaboration between a human and AI: implementation, tests, and
PR text were created by an AI assistant under the guidance and review of the human author.

Problem

openkb add currently regenerates the FULL body of every existing concept/entity page it touches. _gen_update/_gen_entity_update in openkb/agent/compiler.py read the entire current page from disk and send it to the LLM as existing_content, with the instruction "Rewrite the full page incorporating the new information naturally — do not just append." For a short document (e.g. a support ticket) that touches 8-10 already-existing concepts/entities, this means 8-10 full-page rewrites per ingest, even when the actual new information is just 1-2 sentences. Cost scales with page size, and page size only grows as more documents are ingested over time.

Solution / Changes

  • New concept_update_mode config key (.openkb/config.yaml, default "rewrite" — current behavior, fully unchanged). KB-only, like debug/insert_mode — not in GLOBAL_SCALAR_KEYS.
  • New "append" mode:
    • On update, generates a short 1-2 sentence note about the new document instead of a full-page rewrite. The LLM never sees the existing page (no existing_content, no wikilink whitelist turn — notes stay plain text, deferring cross-linking to a future reconciliation step).
    • Appends the note deterministically (no LLM call for the write itself) under a ## Notes heading, keyed by the [[summaries/{doc_name}]] source marker so re-ingesting an updated version of the same document replaces its own line instead of duplicating it.
    • New concept/entity pages are seeded the same way in append mode (short note + one-line description, no full-page LLM generation).
    • sources: frontmatter tracking, backlinks, related-item cross-refs, and index.md updates are unchanged and shared with the existing "rewrite" path.
    • openkb remove cleanup (_remove_doc_from_pages) extended to also strip a removed document's own note line — a no-op for "rewrite"-mode pages.
  • New module openkb/agent/compiler_notes.py (prompts + append/upsert logic) rather than growing compiler.py further (already over the 800-line limit, grandfathered tech debt).
  • Backward compatible: default mode is unchanged, existing tests pass unmodified.
  • New openkb consolidate [PAGE_NAME] [--all] [--min-notes N] [--dry-run] [--yes] command (mirrors recompile's CLI shape) + new module openkb/agent/consolidator.py, to fold a page's accumulated ## Notes into curated prose — manual/opt-in only, never triggered automatically by openkb add:
    • One LLM call per page: no new source document, no concept/entity classification (the page is already fixed).
    • Contradictions between notes (or notes vs. existing prose) are described directly in the rewritten text rather than silently resolved.
    • The full wikilink whitelist is sent here (once per page per run, not per ticket), so consolidated prose can properly cross-link.
    • The ## Notes section is replaced entirely; sources:/type: are preserved, only description: may be refreshed. A later note-append call re-creates a fresh ## Notes section, so the next run only ever sees what changed since the last one — no extra tracking state needed.

Issues

  • Resolves #245

Sebastian Braun added 3 commits September 7, 2026 10:29
Adds concept_update_mode (default "rewrite", unchanged) with a new "append"
mode: instead of sending an existing concept/entity page's full body to the
LLM for a rewrite, generates a short 1-2 sentence note (the LLM never sees
the existing page) and appends it deterministically under a "## Notes"
heading, keyed by source document so re-ingesting an updated document
replaces its own line instead of duplicating it. Removal cleanup and config
docs updated accordingly.

Resolves VectifyAI#245
VectifyAI#245)

Adds a new `openkb consolidate [PAGE_NAME] [--all] [--min-notes N]
[--dry-run] [--yes]` command (mirrors `recompile`'s CLI shape) and a new
`openkb/agent/consolidator.py` module. For concept/entity pages accumulating
notes under `concept_update_mode: append`, this folds the pending "## Notes"
section into curated prose with a single LLM call per page — no new source
document, no concept/entity classification, since the page is already fixed.

- Contradictions between notes (or notes vs. existing prose) are described
  directly in the rewritten text rather than silently resolved.
- The full wikilink whitelist is sent here (once per page per run, not per
  ticket) so consolidated prose can properly cross-link to other pages.
- The "## Notes" section is replaced entirely; `sources:`/`type:` are
  preserved, only `description:` may be refreshed. A later `append_*_note`
  call re-creates a fresh "## Notes" section, so the next consolidation run
  only ever sees what changed since the last one — no extra tracking state
  needed.
- Manual, opt-in only (no automatic trigger during ingest).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant