deduplicate-lib 0.1.3__tar.gz → 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. deduplicate_lib-1.1.0/.gitignore +10 -0
  2. deduplicate_lib-1.1.0/CHANGELOG.md +313 -0
  3. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/PKG-INFO +19 -1
  4. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/README.md +14 -0
  5. deduplicate_lib-1.1.0/docs/_static/ntpp/ntpp_curves.png +0 -0
  6. deduplicate_lib-1.1.0/docs/_static/ntpp/ntpp_window_bimodal.png +0 -0
  7. deduplicate_lib-1.1.0/docs/_static/ntpp/ntpp_window_linear.png +0 -0
  8. deduplicate_lib-1.1.0/docs/_static/ntpp/ntpp_window_probe_steps.png +0 -0
  9. deduplicate_lib-1.1.0/docs/_static/ntpp/ntpp_window_trimodal.png +0 -0
  10. deduplicate_lib-1.1.0/docs/_static/ntpp/ntpp_window_uniform.png +0 -0
  11. deduplicate_lib-1.1.0/docs/_static/ntpp/ntpp_window_unimodal.png +0 -0
  12. deduplicate_lib-1.1.0/docs/api/core.rst +37 -0
  13. deduplicate_lib-1.1.0/docs/api/tolerance.rst +184 -0
  14. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/docs/index.rst +1 -0
  15. deduplicate_lib-1.1.0/docs/large_datasets.rst +199 -0
  16. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/docs/quickstart.rst +0 -1
  17. deduplicate_lib-1.1.0/docs/scripts/ntpp_window_study.py +414 -0
  18. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/examples/multi_hashing_demo.ipynb +6 -12
  19. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/examples/multi_hashing_demo_output.ipynb +8 -14
  20. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/pyproject.toml +7 -0
  21. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/src/deduplicate_lib/core/duplicate_detection_algorithm.py +184 -12
  22. deduplicate_lib-1.1.0/src/deduplicate_lib/core/hash_index.py +455 -0
  23. deduplicate_lib-1.1.0/src/deduplicate_lib/core/pending_hashes.py +104 -0
  24. deduplicate_lib-1.1.0/src/deduplicate_lib/core/resources.py +140 -0
  25. deduplicate_lib-1.1.0/src/deduplicate_lib/core/sorted_segment.py +156 -0
  26. deduplicate_lib-1.1.0/src/deduplicate_lib/core/tolerance_calculator.py +230 -0
  27. deduplicate_lib-1.1.0/src/deduplicate_lib/core/vector_store.py +405 -0
  28. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/distance_matrix.py +55 -0
  29. deduplicate_lib-1.1.0/src/deduplicate_lib/plugins/duplicate_detection_algorithms/multi_hashing.py +847 -0
  30. deduplicate_lib-1.1.0/src/deduplicate_lib/plugins/tolerance_calculators/natural_tolerance_plateau_probe.py +323 -0
  31. deduplicate_lib-1.1.0/src/deduplicate_lib/plugins/tolerance_calculators/perturbed_dataset_reclustering.py +130 -0
  32. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/src/deduplicate_lib/version.py +2 -2
  33. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/conftest.py +0 -3
  34. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/integration/test_example_notebook.py +1 -4
  35. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/integration/test_tol_find_and_deduplicate.py +33 -46
  36. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/unit/core/test_duplicate_detection_algorithm.py +61 -0
  37. deduplicate_lib-1.1.0/tests/unit/core/test_pending_hashes.py +58 -0
  38. deduplicate_lib-1.1.0/tests/unit/core/test_resources.py +141 -0
  39. deduplicate_lib-1.1.0/tests/unit/core/test_sorted_segment.py +106 -0
  40. deduplicate_lib-1.1.0/tests/unit/core/test_tolerance_calculator.py +157 -0
  41. deduplicate_lib-1.1.0/tests/unit/core/test_vector_store.py +325 -0
  42. deduplicate_lib-1.1.0/tests/unit/plugins/duplicate_detection_algoirthms/conftest.py +9 -0
  43. deduplicate_lib-1.1.0/tests/unit/plugins/duplicate_detection_algoirthms/reference_multi_hashing.py +46 -0
  44. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/unit/plugins/duplicate_detection_algoirthms/test_distance_matrix.py +50 -0
  45. deduplicate_lib-1.1.0/tests/unit/plugins/duplicate_detection_algoirthms/test_hash_index.py +815 -0
  46. deduplicate_lib-1.1.0/tests/unit/plugins/duplicate_detection_algoirthms/test_multi_hashing.py +515 -0
  47. deduplicate_lib-1.1.0/tests/unit/plugins/duplicate_detection_algoirthms/test_out_of_core.py +364 -0
  48. deduplicate_lib-1.1.0/tests/unit/plugins/duplicate_detection_algoirthms/test_tuning_copy.py +145 -0
  49. deduplicate_lib-1.1.0/tests/unit/plugins/tolerance_calculators/test_natural_tolerance_plateau_probe.py +323 -0
  50. deduplicate_lib-1.1.0/tests/unit/plugins/tolerance_calculators/test_out_of_core_tuning.py +104 -0
  51. deduplicate_lib-1.1.0/tests/unit/plugins/tolerance_calculators/test_perturbed_dataset_reclustering.py +165 -0
  52. deduplicate_lib-0.1.3/.gitignore +0 -8
  53. deduplicate_lib-0.1.3/CHANGELOG.md +0 -147
  54. deduplicate_lib-0.1.3/docs/api/core.rst +0 -12
  55. deduplicate_lib-0.1.3/docs/api/tolerance.rst +0 -33
  56. deduplicate_lib-0.1.3/src/deduplicate_lib/core/tolerance_calculator.py +0 -178
  57. deduplicate_lib-0.1.3/src/deduplicate_lib/plugins/duplicate_detection_algorithms/multi_hashing.py +0 -319
  58. deduplicate_lib-0.1.3/src/deduplicate_lib/plugins/tolerance_calculators/natural_tolerance_plateau_probe.py +0 -258
  59. deduplicate_lib-0.1.3/src/deduplicate_lib/plugins/tolerance_calculators/perturbed_dataset_reclustering.py +0 -104
  60. deduplicate_lib-0.1.3/tests/unit/core/test_tolerance_calculator.py +0 -151
  61. deduplicate_lib-0.1.3/tests/unit/plugins/duplicate_detection_algoirthms/test_multi_hashing.py +0 -331
  62. deduplicate_lib-0.1.3/tests/unit/plugins/tolerance_calculators/test_natural_tolerance_plateau_probe.py +0 -215
  63. deduplicate_lib-0.1.3/tests/unit/plugins/tolerance_calculators/test_perturbed_dataset_reclustering.py +0 -149
  64. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/LICENSE +0 -0
  65. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/docs/api/algorithms.rst +0 -0
  66. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/docs/api/index.rst +0 -0
  67. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/docs/conf.py +0 -0
  68. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/docs/requirements.txt +0 -0
  69. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/src/deduplicate_lib/__init__.py +0 -0
  70. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/src/deduplicate_lib/core/__init__.py +0 -0
  71. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/src/deduplicate_lib/core/plugin_registry.py +0 -0
  72. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/src/deduplicate_lib/plugins/__init__.py +0 -0
  73. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/__init__.py +0 -0
  74. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/src/deduplicate_lib/plugins/tolerance_calculators/__init__.py +0 -0
  75. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/__init__.py +0 -0
  76. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/unit/core/.coverage +0 -0
  77. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/unit/core/__init__.py +0 -0
  78. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/unit/core/test_registry.py +0 -0
  79. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/unit/plugins/__init__.py +0 -0
  80. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/unit/plugins/duplicate_detection_algoirthms/__init__.py +0 -0
  81. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/unit/plugins/tolerance_calculators/__init__.py +0 -0
  82. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/unit/plugins/tolerance_calculators/plateau_detection.png +0 -0
  83. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/unit/plugins/tolerance_calculators/plateau_detection_DistanceMatrix.png +0 -0
  84. {deduplicate_lib-0.1.3 → deduplicate_lib-1.1.0}/tests/unit/plugins/tolerance_calculators/plateau_detection_MultiHashing.png +0 -0
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ .ipynb_checkpoints/
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ __pycache__/
8
+ src/deduplicate_lib/version.py
9
+ # NTPP window-study cache (regenerate with docs/scripts/ntpp_window_study.py)
10
+ docs/scripts/ntpp_window_study_results.json
@@ -0,0 +1,313 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ ## [1.1.0] - 2026-11-23
6
+
7
+ ### Changed
8
+ - `MultiHashing(index_dir=...)` saves appended hashes incrementally. A save used to
9
+ rewrite every perturbation's whole table (tens of GB for tens of millions of
10
+ vectors), so the cost of appending grew with the size of the index. Now each save
11
+ writes the new hashes as a small sorted **delta segment** per perturbation, and
12
+ segments of similar size are merged (a new segment absorbs older ones up to
13
+ `COMPACTION_RATIO` = 2 times its size, and becomes the new base table once it
14
+ reaches half of it). A table holds O(log n) segments, each hash is rewritten
15
+ O(log n) times, and the amortised cost of an append no longer grows with the index.
16
+ Lookups search the base table and every delta.
17
+ - Index format 3: `metadata.json` gains `delta_files` (per perturbation, oldest
18
+ first). Format 2 indexes still open and are upgraded on their next commit; older
19
+ deduplicate_lib versions refuse format 3.
20
+ - Index lookups read one page of a table that does not fit in the page cache. Each
21
+ segment file has a small **fence** sidecar (`<segment>.fence.npy`, the first hash
22
+ of every 4 KiB page, ~1/512 of the table) kept in memory as a `SortedSegment`
23
+ (`core/sorted_segment.py`), so a lookup searches the fence and then a single page
24
+ instead of binary-searching the memory-mapped table (~log2 n cold pages). A single
25
+ vector's lookups (`duplicate_check()`, `add_input_vector_to_dda()`) first ask the
26
+ kernel for all their pages at once (`madvise(MADV_WILLNEED)`), so the disk reads
27
+ them concurrently. Missing sidecars are recomputed when a segment is loaded.
28
+ - Pending hashes (added since the last merge / index save) are kept in sorted
29
+ `uint64` arrays (`core/pending_hashes.py`, `PendingHashes`: ~8 bytes per hash)
30
+ instead of Python sets (~60-100 bytes per hash), so many more vectors can be added
31
+ between saves; single additions go through a small set that spills into an array.
32
+ An index now saves when pending hashes pass `memory_limit / 4 / 16` (was `/ 100`),
33
+ i.e. less often for the same `memory_limit`.
34
+ - Index saves append the new vectors' unique counts to the counts file (now raw
35
+ `counts.g<N>.bin`, only the first `n_vectors` entries committed) instead of
36
+ rewriting all of them, so a save no longer costs O(dataset size). `.npy` counts
37
+ files from earlier versions still open; the build still writes a new file.
38
+
39
+ ### Documentation
40
+ - `docs/large_datasets.rst`: what an index save writes (only new segments and
41
+ counts), how lookups behave once the index outgrows memory (one page per lookup;
42
+ prefer large `add_vectors()` batches), and the disk space for fences and merges.
43
+
44
+ ## [1.0.0] - 2026-11-17
45
+
46
+ ### Changed
47
+ - `MultiHashing` was rewritten around flat `uint64` hash tables: per perturbation, a
48
+ sorted array of the dataset's distinct hashes (`sorted_hashes`), plus a per-vector
49
+ count of the perturbations in which it is the earliest vector of its hash bucket
50
+ (`unique_counts`). `get_dataset_unique_structures()` is now O(P·n log n) instead of
51
+ O(P·n²) and uses a fraction of the memory, which is the first step towards
52
+ out-of-core deduplication of very large datasets. Results are unchanged: the unique
53
+ masks, `duplicate_check()` and `get_uniqueness_score()` are tested against the old
54
+ implementation.
55
+ - Hashes come from a new numba kernel, `fast_quantise_and_hash`, instead of Python's
56
+ `hash()`, so they are the same in every process (Python salts `hash()` per process)
57
+ and can be persisted.
58
+ - Progress output of the tolerance calculators goes through `logging`
59
+ (`deduplicate_lib.*` loggers) instead of `print`; leftover debug prints were removed.
60
+
61
+ ### Added
62
+ - `DuplicateDetectionAlgorithm.get_unique_vector_mask()` returns the boolean mask of
63
+ unique vectors. `get_unique_vector_indices()` still returns integer indices.
64
+ - Out-of-core datasets: pass `dataset=` (a `.npy`/`.h5`/`.hdf5` path or a
65
+ `VectorStore`) instead of `dataset_array=`, and `MultiHashing` reads the vectors in
66
+ chunks instead of loading them. New `deduplicate_lib.core.vector_store` module:
67
+ `InMemoryStore`, `NpyStore` (memory-mapped), `HDF5Store` (appendable),
68
+ `CallableStore` (adapter for databases and other sources), `open_store()`.
69
+ - `memory_limit` (bytes, `"8GB"`, or `"auto"` = half the available memory) sizes the
70
+ row chunks and perturbation batches. `MultiHashing` keeps the per-perturbation hash
71
+ tables only if they fit in a quarter of it; otherwise it keeps just the unique
72
+ counts, and `duplicate_check()`, `get_uniqueness_score()` and appends raise
73
+ `MemoryError`.
74
+ - `n_threads`: `fast_quantise_and_hash` is now parallel (numba `prange`).
75
+ - `progress=True` shows tqdm progress bars.
76
+ - `deduplicate(out=...)` streams the unique vectors to a `.npy`/HDF5 file and returns
77
+ it as a store. Out-of-core datasets write `<input>_unique.<ext>` by default; for
78
+ in-memory datasets `deduplicate()` still returns an array.
79
+ - `MultiHashing(index_dir=...)` keeps the hash tables on disk (memory-mapped), so
80
+ `duplicate_check()` and appends work at any dataset size. The index is reused when
81
+ the dataset and hashing parameters match (`IndexMismatchError` names what differs),
82
+ resumes an interrupted build (it commits after every perturbation batch), and
83
+ recovers vectors appended to an HDF5 dataset without a `flush()`. Commits are
84
+ atomic (`metadata.json` names the current generation-numbered files) and fsynced;
85
+ see `deduplicate_lib.core.hash_index`.
86
+ - `MultiHashing.add_vectors()` appends many vectors at once (same result as appending
87
+ one at a time) and `MultiHashing.flush()` saves appended vectors to the index.
88
+ - `VectorStore.iter_chunks()` takes an optional row range.
89
+ - Optional extras `hdf5` (h5py) and `progress` (tqdm).
90
+ - Docs: a "Large datasets" page.
91
+
92
+ ### Changed (DistanceMatrix)
93
+ - `DistanceMatrix` refuses out-of-core datasets (`ValueError`) and raises
94
+ `MemoryError` when its `max_vector_array_size`² matrix would exceed `memory_limit`,
95
+ pointing to `MultiHashing`. Pass a larger `memory_limit` to override.
96
+
97
+ ### Changed (tolerance calculators, breaking)
98
+ - Both tolerance calculators tune on a sample of the dataset read through
99
+ `dda.store`, so they work on out-of-core datasets, and run every search on a
100
+ separate in-memory copy of the DDA (`DuplicateDetectionAlgorithm.tuning_copy()`):
101
+ the DDA passed in (its dataset, store, `index_dir` and hash tables) is no longer
102
+ modified. New arguments `sample_size` (rows tuned on), `sampling` (`"blocks"`,
103
+ `"random"`, `"head"`), `block_rows` and `seed`; all arguments after the DDA are
104
+ keyword-only.
105
+ - `PerturbedDatasetReclustering` builds its noisy copies from the sample (default
106
+ `perturbations_per_vector=5`, `sample_size=500`, `sampling="random"`); the default
107
+ target is the number of sampled vectors. An invalid
108
+ `target_unique_vectors_threshold` raises in `__init__`.
109
+ - `NaturalTolerancePlateauProbe` sweeps log-spaced tolerances from below the
110
+ "all different" to above the "all same" tolerance (it used a linear sweep between
111
+ 10%/90%-unique bounds, which missed fine clustering scales), detects plateaus
112
+ against log tolerance, merges neighbouring plateaus with the same count, and returns
113
+ a plateau's geometric midpoint. New `find_natural_plateaus()` returns every plateau
114
+ as a `Plateau` (start/end/midpoint tolerance, unique count, steps, `trivial`);
115
+ `calculate_tolerance(condition=...)` takes `"longest"` (default), `"tightest"` or
116
+ `"loosest"` and never picks the trivial all-unique/all-same plateaus. Default
117
+ `sampling="blocks"`. The gradient window (`datapoints_to_calculate_gradient`) now
118
+ defaults to 10% of `probe_steps` (it was 3 steps), chosen from a study across
119
+ synthetic datasets, sizes, dimensions and both DDAs; see "Choosing the gradient
120
+ window" in the docs and `docs/scripts/ntpp_window_study.py`. Fixes plateau detection mis-pairing starts and ends when the
121
+ sweep begins inside a plateau.
122
+ - `memory_limit="auto"` uses `MemAvailable` on Linux; it used the free physical
123
+ pages, which leave out reclaimable page cache and were often a small fraction of
124
+ the usable memory.
125
+
126
+ ### Added (tolerance calculators)
127
+ - `VectorStore.sample_blocks()` and `deduplicate_lib.core.tolerance_calculator.draw_sample()`.
128
+
129
+ ### Fixed
130
+ - `deduplicate()` recomputes the unique mask first; it returned rows chosen by a stale
131
+ mask after a `tolerance` change or a same-size `set_dataset_array()`.
132
+ - `MultiHashing` keeps a user-supplied `pertrubation_array`; it was replaced by one
133
+ generated from `seed` on the first build. A seed-generated array is regenerated when
134
+ `seed` changes, and assigning a new array triggers a rebuild.
135
+ - `deduplicate(out=...)` refuses to write over its own input file.
136
+ - `DistanceMatrix.set_dataset_store()` with an on-disk dataset raises before dropping the
137
+ current data, leaving the DDA usable.
138
+ - `DistanceMatrix` only refuses (`MemoryError`) a distance matrix larger than an
139
+ explicit `memory_limit`; with the default `"auto"` (which depends on the memory free
140
+ at that moment) it warns (`ResourceWarning`).
141
+ - `MultiHashing.add_vectors()` keeps `vector_count` in step with the hash tables if it
142
+ fails part-way, and hashes rows left in an out-of-core store by such a failure before
143
+ appending more.
144
+ - `VectorStore.take()`/`sample()` read only the requested rows (memory-mapped fancy
145
+ indexing for `.npy`, one point selection for HDF5) instead of a 65536-row chunk per row.
146
+ - The hash index fingerprints every indexed row (sha256 per block of 2^20 rows,
147
+ extended incrementally as the index grows) instead of the first and last 1024 rows,
148
+ so an index is no longer reused after rows in the middle of the dataset change.
149
+ Opening an index reads the indexed rows once. Index format version 2.
150
+
151
+ ### Known issues
152
+ - Peak memory while building hash tables can exceed `memory_limit` by roughly
153
+ 1.2-1.5x (`np.unique`'s working copies are not budgeted).
154
+ - Many small `MultiHashing.add_vectors()` calls in `index_dir` mode slow down with the
155
+ number of pending (unflushed) hashes; call `flush()` periodically or add in larger
156
+ batches.
157
+
158
+ ### Removed (breaking)
159
+ - `ToleranceCalculator(tolerance_dataset_array=...)`, `temp_attr`,
160
+ `create_perturbed_dataset()`, `_ensure_perturbed_dataset()`, and the
161
+ `perturbations_per_vector`/`perturbation_scale` arguments of the base class and
162
+ `NaturalTolerancePlateauProbe`; `NaturalTolerancePlateauProbe(probe_buffer_fraction=...)`
163
+ and its `"minimum"`/`"maximum"` conditions (use `"tightest"`/`"loosest"`).
164
+ - `MultiHashing.hash_dict` and its helpers (`initialize_hash_vector_dictionary`,
165
+ `compute_hash_vector_dictionary`, `add_input_vector_hashes_to_dictionary`,
166
+ `warn_if_vector_dict_mismatch`) and `fast_round_and_perturb`. Use
167
+ `sorted_hashes`/`unique_counts`, `initialize_hash_tables()`, `compute_hash_tables()`
168
+ and `add_input_vector_hashes()` instead. `create_hash_vector()` now returns `uint64`
169
+ hashes, whose values differ from the old ones.
170
+
171
+ ## [0.1.3] - 2026-10-12
172
+
173
+ ### Changed
174
+ - Packaging moved to uv + hatchling: dev/test dependencies are now PEP 735 dependency
175
+ groups (`uv sync` installs them) instead of the `dev` extra, `uv.lock` pins the
176
+ development environment, and CI installs with `uv sync --locked` and tests on
177
+ Python 3.10–3.12.
178
+ - Minimum Python version raised from 3.8 to 3.10 (current numba releases already
179
+ require it).
180
+ - The version now comes from git tags via hatch-vcs instead of a hand-edited
181
+ `__version__` (which had drifted: the `0.1.2` tag still said `0.1.1`).
182
+ `deduplicate_lib.__version__` still works. New tags use the `vMAJOR.MINOR.PATCH` form.
183
+ - Ruff now enforces the same rule set as ALomancy (isort, bugbear, pyupgrade,
184
+ comprehensions, unused arguments, simplify, ruff-specific). Code was updated to
185
+ match: sorted imports, builtin generics, `stacklevel=2` on all warnings, so they
186
+ point at the caller instead of inside the library.
187
+ - `DuplicateDetectionAlgorithm.pre_dda_processing()` (and the `MultiHashing`
188
+ override) no longer accept unused `*args, **kwargs`.
189
+
190
+ ### Fixed
191
+ - `DistanceMatrix.get_dataset_unique_structures()` now keeps exactly one vector from
192
+ each group of near-duplicates: in dataset order, a vector is unique unless it is within
193
+ `tolerance` of a vector already kept. Before, a vector counted as unique only if
194
+ nothing at all was within `tolerance` (row 0 excepted), so every group that didn't
195
+ contain row 0 was flagged in full and `deduplicate()` dropped it entirely. This matches
196
+ `MultiHashing`, which already keeps the first vector of each group.
197
+
198
+ ### Behaviour change
199
+ - Unique counts from `DistanceMatrix` are higher wherever near-duplicate groups exist,
200
+ so the tolerances that `NaturalTolerancePlateauProbe` and
201
+ `PerturbedDatasetReclustering` find with it shift. In the integration tests,
202
+ 0.168 → 0.181 (reclustering) and 0.141 → 0.153 (plateau probe). At the old values,
203
+ one point plus a 30-vector cluster deduplicated to the point alone; at the new
204
+ values, to the point plus one cluster member.
205
+
206
+ ---
207
+
208
+ ## [0.1.2] - 2026-09-23
209
+
210
+ ### Fixed
211
+ - `NaturalTolerancePlateauProbe`: fixed selection of the minimum/maximum plateau.
212
+
213
+ ---
214
+
215
+ ## [0.1.1] - 2026-09-23
216
+
217
+ ### Added
218
+ - `NaturalTolerancePlateauProbe` can select the minimum or maximum plateau.
219
+
220
+ ---
221
+
222
+ ## [0.1.0] - 2026-06-14
223
+
224
+ ### Fixed
225
+ - `MultiHashing.duplicate_check()` / `get_uniqueness_score()` no longer return stale results
226
+ when `tolerance`, `seed`, or `perturbations` change after the hash dictionary was first
227
+ built — `pre_dda_processing()` now detects these changes and forces a rebuild.
228
+ - `DistanceMatrix.duplicate_check()` no longer triggers an unnecessary full O(N²)
229
+ distance-matrix rebuild (and large preallocation) on a clean dataset; it now only ensures
230
+ the dataset array is preinitialized.
231
+ - `set_dataset_array()` is now a no-op (no reallocation, no `_dirty` invalidation) when the
232
+ incoming array is identical to the data already loaded, avoiding redundant rebuilds when
233
+ tolerance calculators temporarily swap datasets and restore the original.
234
+ - Removed a redundant double-computation of the hash vector dictionary in
235
+ `MultiHashing.get_dataset_unique_structures()`.
236
+ - `DistanceMatrix._rebuild_auxiliary_structures()` no longer redundantly reinitializes the
237
+ distance matrix before recomputing it.
238
+
239
+ ### Changed
240
+ - Dropped the unused `input_dataset_array` parameter from `pre_dda_processing()`.
241
+ - Extracted `MultiHashing._perturbation_array_stale()` to share the perturbation-array
242
+ staleness check between `pre_dda_processing()` and `_rebuild_auxiliary_structures()`.
243
+
244
+ ---
245
+
246
+ ## [0.0.5] - 2026-04-23
247
+
248
+ ### Changed
249
+ - Reinstated dictionary-based storage in multi-hashing implementation (`b3f3fad`).
250
+ - Verified full test and coverage status for the dictionary reversion (`b3f3fad`).
251
+ - Finalized release/build readiness updates (`ff9ee21`, `02614ed`).
252
+
253
+ ### Merged
254
+ - PR #9: Reinstate dictionaries for MH (`aa9aff4`).
255
+
256
+ ---
257
+
258
+ ## [0.0.4] - 2026-04-22
259
+
260
+ ### Added
261
+ - Pre-initialisation logic for dataset handling (`60736ff`).
262
+
263
+ ### Changed
264
+ - Coverage/test completeness improvements (`74658d4`).
265
+
266
+ ---
267
+
268
+ ## [0.0.3] - 2026-04-16
269
+
270
+ ### Added
271
+ - Tight and loose options to PDR (`eca4ab0`).
272
+ - `get_uniqueness_score` support in multi-hash flow (`671ddac`).
273
+
274
+ ### Changed
275
+ - Acceptance threshold moved to sigma-based threshold (`62d80e6`).
276
+ - Round-then-perturb bug fix and hash-array/input reset fixes (`671ddac`).
277
+ - Test updates and cleanup (`4d72241`, `47f1271`).
278
+ - Version update for v0.0.3 (`ab12fde`).
279
+
280
+ ### Merged
281
+ - PR #5: Release v0.0.3 (`97d2102`).
282
+
283
+ ---
284
+
285
+ ## [0.0.2] - 2026-03-30
286
+
287
+ ### Added
288
+ - Example usage and deduplicate function introduced (`7ee94df`).
289
+ - Additional tests (`85e666a`).
290
+ - SciPy dependency (`9c1cfc4`).
291
+
292
+ ### Changed
293
+ - Release prep for v0.0.2 (`2239439`).
294
+
295
+ ---
296
+
297
+ ## [0.0.1] - 2026-03-26
298
+
299
+ ### Added
300
+ - Initial CI and test setup (`b0b5477`, `bb03869`).
301
+ - Numba acceleration for DDAs (`cf10a8e`, `fa93d56`).
302
+ - Codecov integration and badge (`033d99f`, `e13a1ba`).
303
+ - License and core tolerance calculator tests (`3edf959`).
304
+
305
+ ### Changed
306
+ - README and packaging updates (`851b609`, `8108a50`).
307
+
308
+ ---
309
+
310
+ ## [0.0.0] - 2026-03-17
311
+
312
+ ### Added
313
+ - Initial project commit (`03a02d8`).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: deduplicate_lib
3
- Version: 0.1.3
3
+ Version: 1.1.0
4
4
  Summary: Deduplication of numpy vector arrays, with automatic tolerance tuning.
5
5
  Project-URL: Homepage, https://github.com/julianholland/deduplicate
6
6
  Project-URL: Repository, https://github.com/julianholland/deduplicate
@@ -23,6 +23,10 @@ Provides-Extra: docs
23
23
  Requires-Dist: furo; extra == 'docs'
24
24
  Requires-Dist: sphinx-autodoc-typehints; extra == 'docs'
25
25
  Requires-Dist: sphinx>=7; extra == 'docs'
26
+ Provides-Extra: hdf5
27
+ Requires-Dist: h5py; extra == 'hdf5'
28
+ Provides-Extra: progress
29
+ Requires-Dist: tqdm; extra == 'progress'
26
30
  Description-Content-Type: text/markdown
27
31
 
28
32
  <div align="center">
@@ -76,6 +80,20 @@ dda.input_vector = np.array([1.0, 2.0])
76
80
  print(dda.duplicate_check()) # True
77
81
  ```
78
82
 
83
+ ### Large datasets
84
+
85
+ Datasets too large for memory can be deduplicated straight from disk (`.npy`, HDF5, or any
86
+ source via `CallableStore`), in chunks sized by `memory_limit`:
87
+
88
+ ```python
89
+ dda = MultiHashing(dataset="descriptors.npy", tolerance=0.05, memory_limit="8GB", n_threads=8)
90
+ dda.get_dataset_unique_structures()
91
+ mask = dda.get_unique_vector_mask() # boolean mask over the dataset
92
+ dda.deduplicate() # writes descriptors_unique.npy
93
+ ```
94
+
95
+ Optional extras: `pip install deduplicate_lib[hdf5,progress]`.
96
+
79
97
  See the **[full documentation](https://deduplicate-lib.readthedocs.io)** for API reference, tolerance tuning, and more examples.
80
98
 
81
99
  ### Dependencies
@@ -49,6 +49,20 @@ dda.input_vector = np.array([1.0, 2.0])
49
49
  print(dda.duplicate_check()) # True
50
50
  ```
51
51
 
52
+ ### Large datasets
53
+
54
+ Datasets too large for memory can be deduplicated straight from disk (`.npy`, HDF5, or any
55
+ source via `CallableStore`), in chunks sized by `memory_limit`:
56
+
57
+ ```python
58
+ dda = MultiHashing(dataset="descriptors.npy", tolerance=0.05, memory_limit="8GB", n_threads=8)
59
+ dda.get_dataset_unique_structures()
60
+ mask = dda.get_unique_vector_mask() # boolean mask over the dataset
61
+ dda.deduplicate() # writes descriptors_unique.npy
62
+ ```
63
+
64
+ Optional extras: `pip install deduplicate_lib[hdf5,progress]`.
65
+
52
66
  See the **[full documentation](https://deduplicate-lib.readthedocs.io)** for API reference, tolerance tuning, and more examples.
53
67
 
54
68
  ### Dependencies
@@ -0,0 +1,37 @@
1
+ Core API
2
+ ========
3
+
4
+ The typical DDA lifecycle is: construct the DDA (optionally passing
5
+ ``dataset_array`` or calling ``set_dataset_array()`` afterwards) → set
6
+ ``input_vector`` → call ``duplicate_check()`` or
7
+ ``add_input_vector_to_dda()`` for streaming ingestion → call
8
+ ``deduplicate()`` to retrieve the full set of unique vectors.
9
+
10
+ .. autoclass:: deduplicate_lib.core.duplicate_detection_algorithm.DuplicateDetectionAlgorithm
11
+ :members: deduplicate, duplicate_check, add_input_vector_to_dda, set_dataset_array, set_dataset_store, store, is_out_of_core, get_dataset_unique_structures, get_unique_vector_mask, get_unique_vector_indices, tuning_copy
12
+ :show-inheritance:
13
+
14
+
15
+ Vector stores
16
+ -------------
17
+
18
+ Where a dataset's vectors live. Pass a path or a store as ``dataset`` to use an
19
+ out-of-core dataset; see :doc:`../large_datasets`.
20
+
21
+ .. automodule:: deduplicate_lib.core.vector_store
22
+ :members: VectorStore, InMemoryStore, NpyStore, HDF5Store, CallableStore, open_store
23
+ :show-inheritance:
24
+
25
+
26
+ Hash index
27
+ ----------
28
+
29
+ .. automodule:: deduplicate_lib.core.hash_index
30
+ :members: HashIndex, IndexMismatchError
31
+
32
+
33
+ Resources
34
+ ---------
35
+
36
+ .. automodule:: deduplicate_lib.core.resources
37
+ :members: parse_memory_limit, chunk_rows, perturbation_batch
@@ -0,0 +1,184 @@
1
+ Tolerance Calculators
2
+ =====================
3
+
4
+ Tolerance calculators automatically find a ``tolerance`` value for a given
5
+ dataset and DDA. Run the calculator once, then assign the result to
6
+ ``dda.tolerance`` before calling ``deduplicate()`` or ``duplicate_check()``.
7
+ They tune on a sample of ``sample_size`` vectors (see :doc:`../large_datasets`)
8
+ and never modify the DDA they are given.
9
+
10
+ .. autoclass:: deduplicate_lib.core.tolerance_calculator.ToleranceCalculator
11
+ :members: binary_search_tolerance
12
+
13
+ .. autofunction:: deduplicate_lib.core.tolerance_calculator.draw_sample
14
+
15
+
16
+ PerturbedDatasetReclustering
17
+ -----------------------------
18
+
19
+ Follows each sampled vector with ``perturbations_per_vector - 1`` copies
20
+ carrying Gaussian noise of scale ``perturbation_scale``, then binary-searches
21
+ for the tolerance at which the copies collapse back onto their originals.
22
+ ``"average"`` mode averages the loose and tight bounds; ``"loose"`` returns the
23
+ highest valid tolerance; ``"tight"`` returns the lowest.
24
+
25
+ .. autoclass:: deduplicate_lib.plugins.tolerance_calculators.perturbed_dataset_reclustering.PerturbedDatasetReclustering
26
+ :members: calculate_tolerance
27
+ :show-inheritance:
28
+
29
+
30
+ NaturalTolerancePlateauProbe
31
+ -----------------------------
32
+
33
+ No perturbed data needed. Sweeps log-spaced tolerances from below the
34
+ all-different bound to above the all-same bound, records the unique-structure
35
+ count at each step, and finds plateaus — regions where the clustering is stable
36
+ and insensitive to small changes in tolerance, i.e. natural clustering scales.
37
+ ``find_natural_plateaus()`` lists them; ``calculate_tolerance()`` returns the
38
+ midpoint of the longest, tightest or loosest one (the trivial all-unique and
39
+ all-same plateaus at the ends are never chosen).
40
+
41
+ .. autoclass:: deduplicate_lib.plugins.tolerance_calculators.natural_tolerance_plateau_probe.NaturalTolerancePlateauProbe
42
+ :members: calculate_tolerance, find_natural_plateaus
43
+ :show-inheritance:
44
+
45
+ .. autoclass:: deduplicate_lib.plugins.tolerance_calculators.natural_tolerance_plateau_probe.Plateau
46
+
47
+
48
+ Choosing the gradient window
49
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50
+
51
+ A plateau is a run of probe steps over which the unique-vector count barely
52
+ changes, measured over a window of ``datapoints_to_calculate_gradient`` steps.
53
+ The window is a trade-off:
54
+
55
+ * **Too small**, and noise in the curve shows up as false plateaus. The
56
+ random gaps between vectors of data with no structure make short flat
57
+ stretches.
58
+ * **Too large**, and genuine plateaus shorter than the window are missed.
59
+
60
+ By default the window is 10% of ``probe_steps`` (``DEFAULT_WINDOW_FRACTION``),
61
+ chosen from the study below. Pass an integer to override it.
62
+
63
+ The study sweeps synthetic datasets with a known answer, for 8, 64 and 256
64
+ dimensions, 100, 400 and 1600 vectors, both DDAs, 50 to 400 probe steps and
65
+ 3 seeds (720 sweeps). Every window from 2% to 20% of the sweep is then
66
+ scored on whether NTPP finds exactly the expected non-trivial plateaus:
67
+
68
+ * **bimodal**: groups of 4 near-duplicates, so one plateau, at n/4.
69
+ * **trimodal**: super-clusters of clusters of near-duplicates, so two plateaus.
70
+ * **linear**, **uniform**, **unimodal**: points along a line, uniform in a
71
+ hypercube, and a single Gaussian. These have no natural scale, so the
72
+ right answer is no plateau at all.
73
+
74
+ The figures come from ``docs/scripts/ntpp_window_study.py``, which can be
75
+ re-run to reproduce them.
76
+
77
+ .. figure:: ../_static/ntpp/ntpp_curves.png
78
+ :width: 100%
79
+ :alt: Unique vectors against tolerance for the five datasets, with the
80
+ plateaus NTPP finds shaded.
81
+
82
+ What NTPP sees: the unique-vector count across the sweep for each dataset
83
+ (d = 8, n = 400, DistanceMatrix), with the plateaus found at the default
84
+ window shaded. Bimodal and trimodal give their expected plateaus. The
85
+ linear dataset shows the main failure mode on data with no structure: a
86
+ plateau just below "all unique" (399 of 400), where its closest pair has
87
+ merged long before the next one. NTPP cannot tell this apart from a
88
+ dataset that really has one near-duplicate pair.
89
+
90
+ .. list-table:: Share of runs with exactly the expected plateaus
91
+ :header-rows: 1
92
+
93
+ * - window (% of sweep)
94
+ - 4%
95
+ - 6%
96
+ - 8%
97
+ - **10%**
98
+ - 12%
99
+ - 15%
100
+ * - bimodal, trimodal (right plateaus found)
101
+ - 90%
102
+ - 91%
103
+ - 94%
104
+ - **94%**
105
+ - 93%
106
+ - 88%
107
+ * - linear, uniform, unimodal (no false plateau)
108
+ - 54%
109
+ - 75%
110
+ - 86%
111
+ - **91%**
112
+ - 93%
113
+ - 94%
114
+
115
+ **The window is a share of the sweep, not a number of steps.** The noise in
116
+ the curve spans a fixed range of tolerance. Probing more finely only samples
117
+ the same noise more often, so the window must span the same share of the
118
+ sweep whatever ``probe_steps`` is. More probe steps only make the plateau
119
+ edges sharper:
120
+
121
+ .. figure:: ../_static/ntpp/ntpp_window_probe_steps.png
122
+ :width: 100%
123
+ :alt: Share of correct runs against window size, one line per probe_steps
124
+ value, nearly identical.
125
+
126
+ All datasets and sizes at d = 8: the curves for 50 to 400 probe steps lie
127
+ on top of each other once the window is given as a share of the sweep.
128
+
129
+ Per dataset, by dimension (rows) and dataset size (columns), pooled over
130
+ probe densities and seeds. The dashed line marks the default window:
131
+
132
+ .. figure:: ../_static/ntpp/ntpp_window_bimodal.png
133
+ :width: 100%
134
+ :alt: Bimodal: share of correct runs against window size.
135
+
136
+ Bimodal: the single plateau is wide and is found at any window from
137
+ about 8%.
138
+
139
+ .. figure:: ../_static/ntpp/ntpp_window_trimodal.png
140
+ :width: 100%
141
+ :alt: Trimodal: share of correct runs against window size.
142
+
143
+ Trimodal: DistanceMatrix finds both plateaus at every dimension.
144
+ MultiHashing's coarse plateau shrinks as the dimension grows and drops
145
+ out above about 13% at d = 64. At d = 256 it is too narrow for any but
146
+ the smallest windows (see the limitations below).
147
+
148
+ .. figure:: ../_static/ntpp/ntpp_window_linear.png
149
+ :width: 100%
150
+ :alt: Linear: share of correct runs against window size.
151
+
152
+ Linear: the hardest case. The near-"all unique" plateau described above
153
+ needs windows of 10-20% to suppress, and is never suppressed in some
154
+ configurations.
155
+
156
+ .. figure:: ../_static/ntpp/ntpp_window_uniform.png
157
+ :width: 100%
158
+ :alt: Uniform: share of correct runs against window size.
159
+
160
+ Uniform: in 8 dimensions false plateaus remain in about 1 run in 10 even
161
+ at 10-15%, mostly with few vectors (n = 100). In 64 and 256 dimensions
162
+ there are none from about 6% upwards.
163
+
164
+ .. figure:: ../_static/ntpp/ntpp_window_unimodal.png
165
+ :width: 100%
166
+ :alt: Unimodal: share of correct runs against window size.
167
+
168
+ Unimodal (Gaussian): no false plateaus from about 8%.
169
+
170
+ **Limitations.**
171
+
172
+ * *Data with few duplicates.* On data with no clustering, NTPP can report a
173
+ plateau just below "all unique", because the closest pair or two merge long
174
+ before the rest. Check ``find_natural_plateaus()``: a plateau whose
175
+ ``unique_vectors`` is close to the sample size means very few duplicates.
176
+ ``"tightest"`` will pick it.
177
+ * *MultiHashing in high dimensions.* MultiHashing rounds every coordinate to
178
+ the ``tolerance`` grid, so coarse clusters only merge once the tolerance
179
+ nears the spread of the coordinates, just below its all-same tolerance. In
180
+ high dimensions this squeezes the coarsest plateau against the top of the
181
+ sweep. It may be missed, or found much narrower than with DistanceMatrix.
182
+ Finer scales, such as near-duplicates, are unaffected. If you need the
183
+ coarse scale, tune with a ``DistanceMatrix`` on a small sample, or set a
184
+ smaller ``datapoints_to_calculate_gradient`` and inspect the plateaus.
@@ -11,4 +11,5 @@ algorithms, along with tools for automatically selecting the distance threshold
11
11
  :caption: Contents
12
12
 
13
13
  quickstart
14
+ large_datasets
14
15
  api/index