Reconfigurable Inverted Index
Yusuke Matsui1 Ryota Hinami2 Shinβichi Satoh1
1National Institute of Informatics 2The University of Tokyo
slides: https://bit.ly/2P0KuW1
Reconfigurable Inverted Index Yusuke Matsui 1 Ryota Hinami 2 Shinichi - - PowerPoint PPT Presentation
slides: https://bit.ly/2P0KuW1 Reconfigurable Inverted Index Yusuke Matsui 1 Ryota Hinami 2 Shinichi Satoh 1 1 National Institute of Informatics 2 The University of Tokyo slides: https://bit.ly/2P0KuW1 Approximate nearest neighbor search
1National Institute of Informatics 2The University of Tokyo
slides: https://bit.ly/2P0KuW1
0.23 3.15 0.65 1.43 5.22 0.54 1.66 0.74 4.63 6.21 0.72 0.31 0.86 3.44 1.12 0.04
Query
0.20 3.25 0.72 1.68
π β βπΈ π1 π2 ππ π74 argmin
πβ 1,β¦,π
π β ππ
2 2
Database vectors Result ANN system
Add hash-table, trees, inverted-index, etc
Approximate NN search
slides: https://bit.ly/2P0KuW1
0.23 3.15 0.65 1.43 5.22 0.54 1.66 0.74 4.63 6.21 0.72 0.31 0.86 3.44 1.12 0.04
Query
0.20 3.25 0.72 1.68
π β βπΈ π1 π2 ππ π74 argmin
πβ 1,β¦,π
π β ππ
2 2
Database vectors Result ANN system
Add hash-table, trees, inverted-index, etc
Approximate NN search
slides: https://bit.ly/2P0KuW1
0.23 3.15 0.65 1.43 5.22 0.54 1.66 0.74 4.63 6.21 0.72 0.31 0.86 3.44 1.12 0.04
Query
0.20 3.25 0.72 1.68
π β βπΈ π1 π2 ππ π74 argmin
πβ 1,β¦,π
π β ππ
2 2
Database vectors Result ANN system
Add hash-table, trees, inverted-index, etc
Approximate NN search
slides: https://bit.ly/2P0KuW1
slides: https://bit.ly/2P0KuW1
0.23 3.15 0.65 1.43
Query
0.20 3.25 0.72 1.68
π β βπΈ π74 argmin
πβπ―
π β ππ
2 2
Result ANN system Approximate NN Search
β’ Existing ANN systems are fast for the all vectors
β’ However, it is hard to run the search for a subset
slides: https://bit.ly/2P0KuW1
slides: https://bit.ly/2P0KuW1
slides: https://bit.ly/2P0KuW1
slides: https://bit.ly/2P0KuW1
π―
Runtime
Fast if |π―| is large Fast if |π―| is small Cherry pick! Always fast
π―
Runtime
π―
Runtime
slides: https://bit.ly/2P0KuW1
π―
Runtime
Fast if |π―| is large Fast if |π―| is small Cherry pick! Always fast
π―
Runtime
π―
Runtime
5.22 0.54 1.66 0.74 4.63 6.21 0.72 0.31 0.86 3.44 1.12 0.04
5.22 0.54 1.66 0.74
PQ: Compress a vector into a short code
All database vectors are PQ-encoded beforehand PQ
1 2 N
slides: https://bit.ly/2P0KuW1
, ,
PQ PQ
0.23 3.15 0.65 1.43 Linearly compared
π β βπΈ
e.g., π― = 2, 4, 5, 8
Runtime
π
slides: https://bit.ly/2P0KuW1
1 2 N
3 4 5 6
argmin
πβπ―
π π,
π
β β β
slides: https://bit.ly/2P0KuW1
π―
Runtime
Fast if |π―| is large Fast if |π―| is small Cherry pick! Always fast
π―
Runtime
π―
Runtime
β’Current basic data structure for a large-scale search β’Subset-search is possible only if π― is large
126 225 13 92 188
π 13 π 2 π 1 π 5 Space partitioning
slides: https://bit.ly/2P0KuW1
β’Current basic data structure for a large-scale search β’Subset-search is possible only if π― is large
126 225 13 92 188
π 13 π 2 π 1 π 5 Space partitioning
0.23 3.15 0.65 1.43
π β βπΈ
Re-rank via PQ-linear scan
1.Find the closest space: πβ = argminπ π β π π
2 2
2.Focus the πβth space, accept items β π― 3.Re-rank the items via PQ-linear scan
slides: https://bit.ly/2P0KuW1
e.g., π― = 13, 92, 105, β¦
β β
92
β’Current basic data structure for a large-scale search β’Subset-search is possible only if π― is large
126 225 13 92 188
π 13 π 2 π 1 π 5 Space partitioning
0.23 3.15 0.65 1.43
π β βπΈ
Re-rank via PQ-linear scan
1.Find the closest space: πβ = argminπ π β π π
2 2
2.Focus the πβth space, accept items β π― 3.Re-rank the items via PQ-linear scan
slides: https://bit.ly/2P0KuW1
e.g., π― = 13, 92, 105, β¦
β β
92
Why is it slow for small π― ?
e.g., if π― is small and they are far away from the query, we might need to scan all items
π―
Runtime
π
slides: https://bit.ly/2P0KuW1
π―
Runtime
Fast if |π―| is large Fast if |π―| is small Cherry pick! Always fast
π―
Runtime
π―
Runtime
β’Store (1) PQ-codes linearly, and (2) IDs as an inverted index β’Can run either PQ-linear-scan or IVFPQ with a single data structure
126 225 13 92 188
π 2 π 1 π 5
1 2 N
13
π 2 π 1 π 5
slides: https://bit.ly/2P0KuW1
Key: store codes linearly
126 225 13 92 188
β’ PQ-codes are also chunked. Natural β’ Slight, but critical change
slides: https://bit.ly/2P0KuW1
π―
Runtime
Fast if |π―| is large Fast if |π―| is small Cherry pick! Always fast
π―
Runtime
π―
Runtime
β’If π― is small, run PQ-linear scan β’If π― is large, run IVFPQ
126 225 13 92 188
π 2 π 1 π 5
1 2 N
13
0.23 3.15 0.65 1.43
π β βπΈ
slides: https://bit.ly/2P0KuW1
π―
π
π―
Runtime
π
Runtime
β’If π― is small, run PQ-linear scan β’If π― is large, run IVFPQ
126 225 13 92 188
π 2 π 1 π 5
1 2 N
13
0.23 3.15 0.65 1.43
π β βπΈ
slides: https://bit.ly/2P0KuW1
π―
π
π―
Runtime
π
Runtime
β’If π― is small, run PQ-linear scan β’If π― is large, run IVFPQ
126 225 13 92 188
π 2 π 1 π 5
1 2 N
13
0.23 3.15 0.65 1.43
π β βπΈ
fetch
slides: https://bit.ly/2P0KuW1
π―
π
π―
Runtime
π
Runtime
β’If π― is small, run PQ-linear scan β’If π― is large, run IVFPQ
126 225 13 92 188
π 2 π 1 π 5
1 2 N
13
0.23 3.15 0.65 1.43
π β βπΈ
fetch
slides: https://bit.ly/2P0KuW1
π―
π
π―
Runtime
π
Runtime
β’If π― is small, run PQ-linear scan β’If π― is large, run IVFPQ
126 225 13 92 188
π 2 π 1 π 5
1 2 N
13
π―
Runtime
π
0.23 3.15 0.65 1.43
π β βπΈ
fetch
π
β’Set a threshold π β’Key: Switch two methods based on π― βΆ π
slides: https://bit.ly/2P0KuW1
Use PQ-linear-scan Use IVFPQ
β’If π― is small, run PQ-linear scan β’If π― is large, run IVFPQ
126 225 13 92 188
π 2 π 1 π 5
1 2 N
13
π―
Runtime
π
0.23 3.15 0.65 1.43
π β βπΈ
fetch
π
β’Set a threshold π β’Key: Switch two methods based on π― βΆ π
slides: https://bit.ly/2P0KuW1
Use PQ-linear-scan Use IVFPQ
slides: https://bit.ly/2P0KuW1
β’SIFT1M (π = 106, πΈ = 128). Results for top-R search
slides: https://bit.ly/2P0KuW1
β’SIFT1M (π = 106, πΈ = 128). Results for top-R search
β’ Existing system: Annoy β’ Force to search a subset The existing system is slow, especially when π― is small Proposed Rii is always fast regardless of π― and π
$ pip install rii
import rii import nanopq # Prepare a PQ/OPQ codec with M=32 sub spaces codec = nanopq.PQ(M=32).fit(vecs=Xt) # Trained using Xt # Instantiate a Rii class with the codec e = rii.Rii(fine_quantizer=codec) # Add vectors e.add_configure(vecs=X) # Search ids, dists = e.query(q=q, topk=3, target_ids=S) print(ids, dists) # e.g., [7484 8173 1556] [15.062 15.385 16.169]
slides: https://bit.ly/2P0KuW1
https://github.com/matsui528/rii
slides: https://bit.ly/2P0KuW1 0.23 3.15 0.65 1.43
Query
argmin
πβπ―
π β ππ
2 2
ANN system
Approximate NN Search
Reconfigurable inverted index: β’Store PQ-codes linearly β’Switch method based on π―
π―
Runtime
π
π
Use PQ-linear-scan Use IVFPQ
Result β’PyPI: β’One thing I couldnβt mention: β’See our paper, or come to our poster: β Poster session 5 (15:30 β 16:30) Reconfiguration: the system remains fast even after many new items are added $ pip install rii
0.23 3.15 0.65 1.43
Query
0.20 3.25 0.72 1.68
π β βπΈ π74 argmin
πβ 1,β¦,π
π β ππ
2 2
Result ANN system Approximate NN search
Extract a VGG feature
74th image Query image
π database images
slides: https://bit.ly/2P0KuW1
0.23 3.15 0.65 1.43
Query
0.20 3.25 0.72 1.68
π β βπΈ π92 argmin
πβπ―
π β ππ
2 2
Result ANN system Approximate NN search
Extract a VGG feature
Query image π database images
slides: https://bit.ly/2P0KuW1
Filtering by shooting-date:
92nd image
β’Extensive comparison against existing methods β’For a fixed accuracy (Recall@1), check runtime and its disk space
slides: https://bit.ly/2P0KuW1
β’Extensive comparison against existing methods β’For a fixed accuracy (Recall@1), check runtime and its disk space
NMSLIB is extremely fast, but consume relatively large disk space (βΌmemory)
slides: https://bit.ly/2P0KuW1
β’Extensive comparison against existing methods β’For a fixed accuracy (Recall@1), check runtime and its disk space
NMSLIB is extremely fast, but consume relatively large disk space (βΌmemory) Proposed Rii achieved a comparative performance with Faiss
slides: https://bit.ly/2P0KuW1