Deduplicating media on Context creation#1153
Merged
jamesbraza merged 7 commits intomainfrom Oct 27, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements media deduplication for Context creation to avoid passing duplicate images to the LLM. It introduces an info_hash field in ParsedMedia to enable deduplication based on rounded bounding boxes while preserving high-resolution metadata, and applies ordered set-based deduplication when creating context prompts.
Key changes:
- Added
info_hashtoParsedMediafor flexible deduplication without affecting stored metadata - Applied deduplication to media lists during context creation in
_map_fxn_summary - Created test PDF with duplicate media to validate deduplication behavior
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/paperqa/types.py | Added _get_info_hash() method to support deduplication via optional info_hash key |
| src/paperqa/core.py | Implemented ordered set deduplication for media during context creation |
| packages/paper-qa-docling/src/paperqa_docling/reader.py | Added info_hash generation with rounded bounding boxes for pictures and tables |
| tests/test_paperqa.py | Added test to verify media deduplication during context creation |
| packages/paper-qa-docling/tests/test_paperqa_docling.py | Added test to verify ParsedMedia deduplication behavior |
| tests/duplicate_media_template.md | Template for generating test PDF with duplicate images |
| src/paperqa/prompts.py | Removed redundant separator between text and tables |
| tests/test_agents.py | Updated expected file counts to include new test PDF |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Documentation Updates 1 document(s) were updated by changes in this PR |
1d66dd7 to
5299143
Compare
sidnarayanan
approved these changes
Oct 27, 2025
ef669d6 to
4e954cc
Compare
This reverts commit 6c628c033bfec8ca64e36887b3ed6004e11b609d.
4e954cc to
7b4e1f5
Compare
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.
I realized we were passing the same images for
Contextcreation. This PR:info_hashtoParsedMediato allow for loosened deduplication without affecting stored infoContextcreation promptThis PR also makes a custom PDF for testing deduplication capabilities within multimodal PaperQA.