feat(dedup): implement Candidate Generation v2 with Multi-Key Blocking (#334)#338
Open
ZohaibHassan16 wants to merge 1 commit intoHawksight-AI:mainfrom
Open
feat(dedup): implement Candidate Generation v2 with Multi-Key Blocking (#334)#338ZohaibHassan16 wants to merge 1 commit intoHawksight-AI:mainfrom
ZohaibHassan16 wants to merge 1 commit intoHawksight-AI:mainfrom
Conversation
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.
Description
This PR implements Candidate Generation v2 to address the$O(N^2)$ "pair explosion" during deduplication. By moving away from naive first-character blocking and introducing token-based multi-key blocking and deterministic budgeting, we've significantly optimized the candidate pool before any heavy semantic scoring occurs.
Type of Change
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to not work as expected)
Documentation update
Performance improvement
Code refactoring
Related Issues
Resolves [Sub-Issue 1] Candidate Generation v2 to Cut Pair Explosion #334
Part of [EPIC] Deduplication v2: Higher Accuracy, Lower Latency, Backward Compatible #333 (Deduplication v2 Epic)
Changes Made
Multi-Key Blocking Indexer: Introduced
_build_block_indexeswith support for normalized token prefixes and phonetic (Soundex) keys.Deduplicated Pair Generation: Implemented
_generate_candidate_pairsto union candidate pairs across overlapping blocks without redundant calculations.Candidate Budgeting: Addressed adversarial latency spikes via
_cap_candidate_pairsusing a deterministicmax_candidates_per_entitylimit.Orchestration: Refactored
batch_calculate_similarityto use the new v2 pipeline while maintaining legacy compatibility.Testing
Tested locally
Added tests for new functionality
Package builds successfully (
python -m build)Test Commands
Benchmark Results (V1 vs V2)
Test Case (N=500) | Legacy Mean Time | V2 Mean Time | Improvement -- | -- | -- | --worst_case | ~4.46s | ~0.88s | 80.2% Reduction
scaling_opt | ~0.28s | ~0.95s | Minimal overhead
Documentation
Updated relevant documentation
Added code examples if applicable
Updated API reference if adding new APIs
Updated cookbook if adding new examples
No documentation changes needed (internal optimization)
Breaking Changes
Breaking Changes: No (Logic is opt-in via
candidate_strategy="blocking_v2". Default behavior remains identical to legacy.)Checklist
My code follows the project's style guidelines
I have performed a self-review of my code
I have commented my code, particularly in hard-to-understand areas
My changes generate no new warnings
Package builds successfully