feat(seeding): add --populate-summaries to rebuild summaries only - #78
Open
m2ux wants to merge 1 commit into
Open
feat(seeding): add --populate-summaries to rebuild summaries only#78m2ux wants to merge 1 commit into
m2ux wants to merge 1 commit into
Conversation
Summaries could only be repaired by re-seeding, which reloads, re-chunks
and re-extracts concepts for every document. The stage cache keys the
document overview and the concept extraction together, so there was no
way to invalidate one without paying for the other.
Adds a standalone mode to the seeding script that fills in missing
summaries against an existing database, with no --filesdir:
- catalog.summary regenerated from existing chunks in reading order,
re-enriched with the row's concept/category names,
and re-embedded (the catalog vector encodes it)
- concepts.summary generated from the concept name
- categories.summary generated from the category name
A summary counts as missing when it is empty or a seeding fallback
("Document overview (N pages)", or the generated description for a
category). --force-summaries regenerates everything, --dry-run reports
without calling the LLM or writing.
Writes go through a merge-insert keyed on id, with rows rebuilt from the
live schema, so every other column and the Arrow schema are untouched and
an interrupted run keeps what it already wrote.
Chunks are ordered for summarisation by a stable sort on page number
only. Chunk ids are hash-based and carry no sequence: EPUBs store every
chunk as page 1, so using ids as a tiebreak shuffles the document.
generateDocumentOverview moves into summary_generator.ts and the seeder
delegates to it, so both paths share one prompt and cannot drift.
Deletes scripts/populate_summaries.ts, which this replaces. It rewrote
the concepts table from a hard-coded field list that predated the current
schema, dropping catalog_titles and adjacent_ids and renaming related_ids
- all three are read at query time by the concept repository.
Verified against a copy of the live database: row counts and Arrow
schemas identical across all three tables, summaries updated with no
drift in any other column.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Repairing summaries previously meant a full re-seed: documents reloaded, re-chunked, concepts re-extracted. The stage cache stores the document overview and the concept extraction under one key and only counts as a hit when both are present, so there was no way to invalidate a summary without paying for concept extraction (1–2 min/doc) as well.
On the live database that mattered: 58,547 of 60,083 concepts (97%) had an empty summary, plus 8 catalog fallbacks and 17 categories still on the generated description. Concept summaries feed 20% of concept-search scoring.
What
A standalone mode on the seeding script that fills in missing summaries against an existing database — no
--filesdir, no document loading:catalog.summaryDocument overview (N pages), or a failure markerconcepts.summarycategories.summaryAlso:
--force-summaries,--dry-run,--summary-batch-size,--summary-flush-size,--summary-max-items,--summary-model.Notable decisions
Merge-insert, not drop-and-recreate. Rows are rebuilt field-by-field from the live schema and written with
mergeInsert('id').whenMatchedUpdateAll(), so unknown and future columns pass through and the Arrow schema is never rewritten. Batches flush every 250 summaries, so an interrupt keeps what it wrote and a re-run continues. (BatchedCASE WHENupdates were the first design — Lance's SQL planner rejectsCASE.)Deletes
scripts/populate_summaries.ts. It did the job this replaces, but rewrote the concepts table from a hard-coded field list that predated the current schema: it droppedcatalog_titlesandadjacent_ids, and renamedrelated_idstorelated_concept_ids. All three are read at query time bylancedb-concept-repository.ts, so running it silently destroyed the concept graph.Chunk ordering bug fixed. Chunks are ordered for summarisation by a stable sort on page number only. Chunk ids are hash-based and carry no sequence, and EPUBs store every chunk as page 1 — using ids as a tiebreak shuffles the document. Before the fix three of eight documents started mid-book ("based on static models, as shown in the…"); after, they start at the title page or ToC.
One prompt, one implementation.
generateDocumentOverviewmoved intosummary_generator.ts; the seeder'scallOpenRouterChatnow delegates to it. No behaviour change for seeding (rate limiting stays opt-in, since seeding generates overviews across parallel workers).Verification
--dry-runagainst the live DB reported 8/327 catalog, 58,547/60,083 concepts, 17/794 categories.Note for reviewers
src/concepts/summary_generator.tscarries an in-flight one-line change from the working tree (DEFAULT_MODEL→x-ai/grok-4.6) that could not be split out of the file. The relatedsrc/config.tsmodel rename, its test, and a.gitignoreedit were deliberately left out of this branch.🤖 Generated with Claude Code