Skip to content

Add support for inverted index queries - #42

Merged
johnlees merged 32 commits into
mainfrom
bitmap_queries
May 2, 2025
Merged

johnlees merged 32 commits into
mainfrom
bitmap_queries

Conversation

@johnlees

@johnlees johnlees commented Apr 17, 2025 •

Copy link
Copy Markdown
Member

This will add two new functions:

  • inverted query. To run new samples against an inverted index, returning the number of bins matched, or samples which match at all bins.
  • inverted precluster. Find samples which match in the inverted index, before calculating their distances using the normal sketching mode

TODO:

  • Refactor into query.rs
  • Precluster: add count flag which runs existing function
  • Add skq file to query with (and add as option to build)
  • Add to the closure a query over the matched samples, using heap
  • Add tests for all three query modes
  • Add tests for two precluster modes
  • Add a test for knn dists
  • Add test with dist subset query
  • Update the README -> put onto docs.rs
  • Fill out the API docs

@johnlees

Copy link
Copy Markdown
Member Author

With the 661k data, index sizes:

-rw-r--r--  1 jlees  staff   9.4M 16 Apr 15:11 661k_inverted_21_10.ski
-rw-r--r--  1 jlees  staff    59M 16 Apr 14:44 661k_inverted_21_100.ski
-rw-r--r--  1 jlees  staff    20M 16 Apr 15:11 661k_inverted_21_30.ski
-rw-r--r--  1 jlees  staff   6.9M 16 Apr 12:08 661k_inverted_21_5.ski
-rw-r--r--  1 jlees  staff    10M 16 Apr 15:14 661k_inverted_41_10.ski
-rw-r--r--  1 jlees  staff    68M 16 Apr 14:45 661k_inverted_41_100.ski
-rw-r--r--  1 jlees  staff    23M 16 Apr 15:15 661k_inverted_41_30.ski
-rw-r--r--  1 jlees  staff   7.2M 16 Apr 15:10 661k_inverted_41_5.ski
-rw-r--r--  1 jlees  staff    11M 16 Apr 15:16 661k_inverted_61_10.ski
-rw-r--r--  1 jlees  staff    75M 16 Apr 14:47 661k_inverted_61_100.ski
-rw-r--r--  1 jlees  staff    26M 16 Apr 14:44 661k_inverted_61_30.ski
-rw-r--r--  1 jlees  staff   7.6M 16 Apr 15:09 661k_inverted_61_5.ski

@johnlees

Copy link
Copy Markdown
Member Author

Current prequery mode (which is probably inefficient) takes ~ 2.5hrs (1 thread) and uses about 420Gb RAM (but I think streaming output would avoid this):

Identified 24542234812 prefilter pairs from a max of 215648788278

About 10% of possible values, at k=21 and s=5.
Most have similar stats:

max_hashes_per_bin=10762
min_hashes_per_bin=10594
avg_hashes_per_bin=10667

@johnlees

Copy link
Copy Markdown
Member Author

May be better to use all bins shared rather than one bin shared. Ideas for this:

Option 1)
Make a u64 roaring_bitmap (in each thread?) with entries representing pairs
Then OR down the hashes
Then AND all these together to get the pairs to compare

Option 2)
Just use the identical query for each sample (still N^2 but should be faster)

@codecov

codecov Bot commented Apr 19, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 94.49649% with 47 lines in your changes missing coverage. Please review.

Project coverage is 85.08%. Comparing base (d5311f1) to head (e481d36).
Report is 33 commits behind head on main.

Files with missing lines Patch % Lines
src/cli.rs 54.76% 19 Missing ⚠️
src/distances/mod.rs 95.48% 12 Missing ⚠️
src/lib.rs 96.83% 7 Missing ⚠️
src/inverted.rs 95.68% 5 Missing ⚠️
src/sketch/sketch_datafile.rs 98.38% 2 Missing ⚠️
src/hashing/aahash_iterator.rs 0.00% 1 Missing ⚠️
src/io.rs 92.85% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #42       +/-   ##
===========================================
+ Coverage   70.11%   85.08%   +14.96%     
===========================================
  Files          16       17        +1     
  Lines        2252     2735      +483     
===========================================
+ Hits         1579     2327      +748     
+ Misses        673      408      -265     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@johnlees

Copy link
Copy Markdown
Member Author

Test with 10k genomes:

s k cutoff FN FP True_matches Matches_at_cutoff
3 21 1 90231.0 3852258.0 1245026.0 5007053.0
3 21 2 284615.0 2083334.0 1245026.0 3043745.0
3 21 3 542460.0 555176.0 1245026.0 1257742.0
3 61 1 25122.0 4289228.0 1245026.0 5509132.0
3 61 2 314534.0 1576908.0 1245026.0 2507400.0
3 61 3 618312.0 218404.0 1245026.0 845118.0
3 101 1 166149.0 2141283.0 1245026.0 3220160.0
3 101 2 583227.0 284178.0 1245026.0 945977.0
3 101 3 877802.0 12612.0 1245026.0 379836.0
3 301 1 474023.0 769054.0 1245026.0 1540057.0
3 301 2 694340.0 54011.0 1245026.0 604697.0
3 301 3 942579.0 4357.0 1245026.0 306804.0
5 21 1 3003.0 4903497.0 1245026.0 6145520.0
5 21 4 447633.0 792136.0 1245026.0 1589529.0
5 21 5 718266.0 132458.0 1245026.0 659218.0
5 61 1 4629.0 4388013.0 1245026.0 5628410.0
5 61 4 538003.0 294114.0 1245026.0 1001137.0
5 61 5 837512.0 25223.0 1245026.0 432737.0
5 101 1 73464.0 3029006.0 1245026.0 4200568.0
5 101 4 625553.0 34415.0 1245026.0 653888.0
5 101 5 889546.0 1896.0 1245026.0 357376.0
5 301 1 178556.0 1403206.0 1245026.0 2469676.0
5 301 4 796791.0 815.0 1245026.0 449050.0
5 301 5 997186.0 47.0 1245026.0 247887.0
8 21 1 3.0 5282063.0 1245026.0 6527086.0
8 21 7 366536.0 718502.0 1245026.0 1596992.0
8 21 8 716115.0 107215.0 1245026.0 636126.0
8 61 1 610.0 4956536.0 1245026.0 6200952.0
8 61 7 715493.0 16437.0 1245026.0 545970.0
8 61 8 905559.0 810.0 1245026.0 340277.0
8 101 1 15506.0 3830284.0 1245026.0 5059804.0
8 101 7 804459.0 1141.0 1245026.0 441708.0
8 101 8 991416.0 29.0 1245026.0 253639.0
8 301 1 248047.0 1310794.0 1245026.0 2307773.0
8 301 7 962563.0 55.0 1245026.0 282518.0
8 301 8 1130894.0 1.0 1245026.0 114133.0
10 21 1 0.0 5255582.0 1245026.0 6500608.0
10 21 9 620372.0 149888.0 1245026.0 774542.0
10 21 10 806886.0 12331.0 1245026.0 450471.0
10 61 1 68.0 4973392.0 1245026.0 6218350.0
10 61 9 694515.0 5967.0 1245026.0 556478.0
10 61 10 927685.0 1163.0 1245026.0 318504.0
10 101 1 7091.0 4293699.0 1245026.0 5531634.0
10 101 9 810551.0 399.0 1245026.0 434874.0
10 101 10 989601.0 3.0 1245026.0 255428.0
10 301 1 88382.0 1958675.0 1245026.0 3115319.0
10 301 9 938803.0 6.0 1245026.0 306229.0
10 301 10 1116337.0 1.0 1245026.0 128690.0
20 21 1 0.0 5404006.0 1245026.0 6649032.0
20 21 19 784241.0 713.0 1245026.0 461498.0
20 21 20 971685.0 40.0 1245026.0 273381.0
20 61 1 0.0 5228666.0 1245026.0 6473692.0
20 61 19 856212.0 39.0 1245026.0 388853.0
20 61 20 1071160.0 0.0 1245026.0 173866.0
20 101 1 3.0 4889580.0 1245026.0 6134603.0
20 101 19 922135.0 0.0 1245026.0 322891.0
20 101 20 1082539.0 0.0 1245026.0 162487.0
20 301 1 13024.0 3635280.0 1245026.0 4867282.0
20 301 19 1121775.0 0.0 1245026.0 123251.0
20 301 20 1187896.0 0.0 1245026.0 57130.0

@johnlees

Copy link
Copy Markdown
Member Author

Just checking the 50 NN in the refs:

s k cutoff FN FP True_matches Matches_at_cutoff
3 21 1 1156.5 4818687.5 189522.0 5007053.0
3 21 2 12047.0 2866270.0 189522.0 3043745.0
3 21 3 60136.5 1128356.5 189522.0 1257742.0
3 61 1 4565.0 5324175.0 189522.0 5509132.0
3 61 2 28205.0 2346083.0 189522.0 2507400.0
3 61 3 71292.5 726888.5 189522.0 845118.0
3 101 1 15846.0 3046484.0 189522.0 3220160.0
3 101 2 42712.0 799167.0 189522.0 945977.0
3 101 3 90867.5 281181.5 189522.0 379836.0
3 301 1 32342.0 1382877.0 189522.0 1540057.0
3 301 2 65398.0 480573.0 189522.0 604697.0
3 301 3 105679.5 222961.5 189522.0 306804.0
5 21 1 185.0 5956183.0 189522.0 6145520.0
5 21 4 31345.5 1431352.5 189522.0 1589529.0
5 21 5 79582.0 549278.0 189522.0 659218.0
5 61 1 952.5 5439840.5 189522.0 5628410.0
5 61 4 55520.5 867135.5 189522.0 1001137.0
5 61 5 92559.0 335774.0 189522.0 432737.0
5 101 1 6270.0 4017316.0 189522.0 4200568.0
5 101 4 65239.5 529605.5 189522.0 653888.0
5 101 5 104694.0 272548.0 189522.0 357376.0
5 301 1 18450.5 2298604.5 189522.0 2469676.0
5 301 4 84830.0 344358.0 189522.0 449050.0
5 301 5 120098.0 178463.0 189522.0 247887.0
8 21 1 1.5 6337565.5 189522.0 6527086.0
8 21 7 52950.0 1460420.0 189522.0 1596992.0
8 21 8 93390.0 539994.0 189522.0 636126.0
8 61 1 80.0 6011510.0 189522.0 6200952.0
8 61 7 78052.5 434500.5 189522.0 545970.0
8 61 8 116636.0 267391.0 189522.0 340277.0
8 101 1 1338.0 4871620.0 189522.0 5059804.0
8 101 7 88304.0 340490.0 189522.0 441708.0
8 101 8 121213.0 185330.0 189522.0 253639.0
8 301 1 7738.0 2125989.0 189522.0 2307773.0
8 301 7 100755.5 193751.5 189522.0 282518.0
8 301 8 135202.5 59813.5 189522.0 114133.0
10 21 1 0.0 6311086.0 189522.0 6500608.0
10 21 9 67665.5 652685.5 189522.0 774542.0
10 21 10 104590.5 365539.5 189522.0 450471.0
10 61 1 24.5 6028852.5 189522.0 6218350.0
10 61 9 80856.5 447812.5 189522.0 556478.0
10 61 10 114248.0 243230.0 189522.0 318504.0
10 101 1 965.5 5343077.5 189522.0 5531634.0
10 101 9 93292.5 338644.5 189522.0 434874.0
10 101 10 124523.5 190429.5 189522.0 255428.0
10 301 1 5884.5 2931681.5 189522.0 3115319.0
10 301 9 110076.0 226783.0 189522.0 306229.0
10 301 10 139109.5 78277.5 189522.0 128690.0
20 21 1 0.0 6459510.0 189522.0 6649032.0
20 21 19 96971.5 368947.5 189522.0 461498.0
20 21 20 126751.0 210610.0 189522.0 273381.0
20 61 1 0.0 6284170.0 189522.0 6473692.0
20 61 19 105930.5 305261.5 189522.0 388853.0
20 61 20 134183.0 118527.0 189522.0 173866.0
20 101 1 0.0 5945081.0 189522.0 6134603.0
20 101 19 115162.5 248531.5 189522.0 322891.0
20 101 20 143328.5 116293.5 189522.0 162487.0
20 301 1 1036.5 4678796.5 189522.0 4867282.0
20 301 19 135321.0 69050.0 189522.0 123251.0
20 301 20 158077.5 25685.5 189522.0 57130.0

@johnlees johnlees added enhancement New feature or request functionality adding a new feature labels Apr 23, 2025
@johnlees johnlees linked an issue Apr 23, 2025 that may be closed by this pull request
Update to newer snapbox to allow output order to change (as multithreaded)
@johnlees johnlees linked an issue Apr 28, 2025 that may be closed by this pull request
@johnlees
johnlees marked this pull request as ready for review May 2, 2025 13:42
@johnlees
johnlees merged commit fc8bbb9 into main May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request functionality adding a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More complete docs Dereplication of genomes

1 participant