Reconfigurable Inverted Index Yusuke Matsui 1 Ryota Hinami 2 Shinichi - - PowerPoint PPT Presentation

β–Ά
reconfigurable inverted index
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Reconfigurable Inverted Index

Yusuke Matsui1 Ryota Hinami2 Shin’ichi Satoh1

1National Institute of Informatics 2The University of Tokyo

slides: https://bit.ly/2P0KuW1

slide-2
SLIDE 2

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

Approximate nearest neighbor search

slide-3
SLIDE 3

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

Approximate nearest neighbor search

slide-4
SLIDE 4

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

Approximate nearest neighbor search

slide-5
SLIDE 5

Related work

slides: https://bit.ly/2P0KuW1

➒ Locality-sensitive-hashing (LSH)

  • FALCONN [Andoni+, 15] [Razenshteyn+, 18]

➒ Project/tree-based

  • FLANN [Muja+, 14]
  • Annoy [Bernhardsson, 18]

➒ Graph traversal

  • NSW/HNSW on NMSLIB [Malkov+, 16][Boytsov+, 13]

➒ Product quantization (PQ)

  • IVFPQ on Faiss [JΓ©gou+, 11][Johnson+, 17] etc.
  • Our Reconfigurable Inverted Index
slide-6
SLIDE 6

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

Subset search problem

➒ Existing ANN systems are fast for the all vectors

  • Search is over 𝒯 = 1, … , 𝑂

➒ However, it is hard to run the search for a subset

  • Search is over 𝒯 βŠ† 1, … , 𝑂
  • e.g., searching from π’š1000, … , π’š2000
  • Why? Systems are usually optimized for 𝒯 = 1, … , 𝑂

slides: https://bit.ly/2P0KuW1

slide-7
SLIDE 7

There is a demand for subset search!

slides: https://bit.ly/2P0KuW1

slide-8
SLIDE 8

There is a demand for subset search!

Propose: Reconfigurable inverted index (Rii) βœ“Subset search βœ“A comparative performance with IVFPQ (Faiss) βœ“10 ms for billion-scale data

slides: https://bit.ly/2P0KuW1

slide-9
SLIDE 9

Reconfigurable inverted index (Rii)

➒Preliminary

  • PQ linear scan
  • IVFPQ

➒Data structure ➒Search

slides: https://bit.ly/2P0KuW1

𝒯

Runtime

Fast if |𝒯| is large Fast if |𝒯| is small Cherry pick! Always fast

𝒯

Runtime

𝒯

Runtime

slide-10
SLIDE 10

Reconfigurable inverted index (Rii)

➒Preliminary

  • PQ linear scan
  • IVFPQ

➒Data structure ➒Search

slides: https://bit.ly/2P0KuW1

𝒯

Runtime

Fast if |𝒯| is large Fast if |𝒯| is small Cherry pick! Always fast

𝒯

Runtime

𝒯

Runtime

slide-11
SLIDE 11

Preliminary: Product quantization (PQ) [JΓ©gou+, TPAMI 11]

5.22 0.54 1.66 0.74 4.63 6.21 0.72 0.31 0.86 3.44 1.12 0.04

…

π’š1 π’š2 π’šπ‘‚

5.22 0.54 1.66 0.74

PQ: Compress a vector into a short code

ℝ4 β†’ … 2

All database vectors are PQ-encoded beforehand PQ

1 2 N

slides: https://bit.ly/2P0KuW1

, ,

…

PQ PQ

slide-12
SLIDE 12

Preliminary: Product quantization (PQ) [JΓ©gou+, TPAMI 11]

0.23 3.15 0.65 1.43 Linearly compared

𝒓 ∈ ℝ𝐸

➒The subset search is possible with a linear cost of 𝒯 ➒The search is efficient

  • nly if 𝒯 is small

e.g., 𝒯 = 2, 4, 5, 8

𝒯

Runtime

𝑂

slides: https://bit.ly/2P0KuW1

1 2 N

…

3 4 5 6

argmin

π‘œβˆˆπ’―

𝑒 𝒓,

π‘œ

βœ” βœ” βœ”

slide-13
SLIDE 13

Reconfigurable inverted index (Rii)

➒Preliminary

  • PQ linear scan
  • IVFPQ

➒Data structure ➒Search ➒Evaluation

slides: https://bit.ly/2P0KuW1

𝒯

Runtime

Fast if |𝒯| is large Fast if |𝒯| is small Cherry pick! Always fast

𝒯

Runtime

𝒯

Runtime

slide-14
SLIDE 14

Preliminary: Inverted Index + PQ (IVFPQ) [JΓ©gou+, TPAMI 11]

➒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

slide-15
SLIDE 15

Preliminary: Inverted Index + PQ (IVFPQ) [JΓ©gou+, TPAMI 11]

➒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, …

π‘œ ∈ 𝒯 or not

βœ” βœ”

92

slide-16
SLIDE 16

Preliminary: Inverted Index + PQ (IVFPQ) [JΓ©gou+, TPAMI 11]

➒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, …

π‘œ ∈ 𝒯 or not

βœ” βœ”

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

𝑂

slide-17
SLIDE 17

Reconfigurable inverted index (Rii)

➒Preliminary

  • PQ linear scan
  • IVFPQ

➒Data structure ➒Search

slides: https://bit.ly/2P0KuW1

𝒯

Runtime

Fast if |𝒯| is large Fast if |𝒯| is small Cherry pick! Always fast

𝒯

Runtime

𝒯

Runtime

slide-18
SLIDE 18

Data structure

➒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

  • cf. IVFPQ

slides: https://bit.ly/2P0KuW1

Key: store codes linearly

126 225 13 92 188

➒ PQ-codes are also chunked. Natural ➒ Slight, but critical change

slide-19
SLIDE 19

Reconfigurable inverted index (Rii)

➒Preliminary

  • PQ linear scan
  • IVFPQ

➒Data structure ➒Search

slides: https://bit.ly/2P0KuW1

𝒯

Runtime

Fast if |𝒯| is large Fast if |𝒯| is small Cherry pick! Always fast

𝒯

Runtime

𝒯

Runtime

slide-20
SLIDE 20

Search

➒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

slide-21
SLIDE 21

Search

➒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

slide-22
SLIDE 22

Search

➒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

slide-23
SLIDE 23

Search

➒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

slide-24
SLIDE 24

Search

➒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

… …

slide-25
SLIDE 25

Search

➒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

… …

slide-26
SLIDE 26

slides: https://bit.ly/2P0KuW1

Evaluation

➒SIFT1M (𝑂 = 106, 𝐸 = 128). Results for top-R search

slide-27
SLIDE 27

slides: https://bit.ly/2P0KuW1

Evaluation

➒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 𝑆

slide-28
SLIDE 28

$ 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

slide-29
SLIDE 29

Summary

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

slide-30
SLIDE 30

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

Example: Image search

𝑂 database images

slides: https://bit.ly/2P0KuW1

slide-31
SLIDE 31

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:

  • Taken in 2018
  • 𝒯 = 34, 56, 92, … , 663

92nd image

Example of subset search for image

slide-32
SLIDE 32

Evaluation

➒Extensive comparison against existing methods ➒For a fixed accuracy (Recall@1), check runtime and its disk space

slides: https://bit.ly/2P0KuW1

slide-33
SLIDE 33

Evaluation

➒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

slide-34
SLIDE 34

Evaluation

➒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