Fix isolated bugs in the topic data layer - #2533
Merged
Merged
Conversation
MaartenGr
marked this pull request as ready for review
August 22, 2026 06:35
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.
Fixes
Topics.mergedivided by zero for topics holding no documents, and leftembeddingunbound when a topic had none — silently leaking the previous loop iteration's embedding into an unrelated topic.Topic.to_dictskippedc_tf_idfwhen the row was all zeros, losing its column count.Topics.deletecreates exactly such a row, so delete multiple topics → save → load → readc_tf_idf_raisedValueError: incompatible dimensions.TopicHierarchy.to_dictdropped every node's embedding and c-TF-IDF on save.TopicMapping.applyraised an opaqueKeyErroron an incomplete mapping. Both callers (_reduce_to_n_topics,_auto_reduce_topics) built their mapping by zipping over documents, so zero-document topics vanished from it; they now build fromtopic_ids(), andapplyraises a message naming the omitted topics.Topic.copyround-tripped through JSON; now usesdeepcopy._map_predictionswas dead code referencing the removedtopic_mapper_.topic_aspects_raisedKeyErrorwhen topic 0 was absent.representative_docs_/representative_images_filtered onis not Noneagainst fields defaulting to[]andnp.array([]), so neither filter ever fired.Behavioural decisions
Merging topics with no documents falls back to equal weighting; merging topics without embeddings yields an empty embedding rather than raising.