Algorithm Search⌘K

Proofs: Inverted file index

These are the human proofs of Inverted file index, at full length.

The inverted file index is exact when it probes every cell, and its stopping rule is safe full

This proof shows: correctness.

Let the centroids be c1,…,cm∈Rdc_1, \dots, c_m \in \mathbb{R}^d and let the index satisfy (V): each stored vector xx is in exactly one list IjI_j, and ∥x−cj∥≤∥x−ci∥\|x - c_j\| \le \|x - c_i\| for all ii. Distances are Euclidean.

Lemma 1 (heap). After a sequence of offers, HH holds min⁡(k,N)\min(k, N) pairs, where NN is the number of offers, and they are pairs of least distance among all offered pairs (with ties broken in some fixed way).

Proof. By induction on the offers. An offer either fills a free place, or replaces the pair of largest distance in HH when the new pair is smaller, or is dropped. In each case the kk least pairs among the offers so far are kept, since a dropped or removed pair has at least kk offered pairs at most as large. □\square

Theorem 1. IVF-SEARCH(q,k,m)(q, k, m) returns the kk nearest stored vectors to qq, with their distances.

Proof. With nprobe=mn_{\text{probe}} = m, the set JJ of line L3 is all of {1,…,m}\{1, \dots, m\}. By (V) each stored vector is in exactly one list, so line L5 offers each stored vector exactly once with its true distance. By Lemma 1, HH then holds the kk least pairs. □\square

Theorem 2. For J⊆J′J \subseteq J', let Dk(J)D_k(J) be the kk-th distance returned when the probed set is JJ, if at least kk vectors are offered. Then Dk(J′)≤Dk(J)D_k(J') \le D_k(J).

Proof. The vectors offered with J′J' include those offered with JJ. The kk-th least value of a superset of numbers is at most the kk-th least value of the subset. □\square

Lemma 2 (bisector bound). Let cac_a be a nearest centroid to qq and j≠aj \ne a with cj≠cac_j \ne c_a. Every xx with ∥x−cj∥≤∥x−ca∥\|x - c_j\| \le \|x - c_a\| satisfies ∥q−x∥≥βj\|q - x\| \ge \beta_j, where βj=max⁡(0,(∥q−cj∥2−∥q−ca∥2)/(2∥cj−ca∥))\beta_j = \max\big(0, (\|q - c_j\|^2 - \|q - c_a\|^2)/(2\|c_j - c_a\|)\big).

Proof. Let u=(cj−ca)/∥cj−ca∥u = (c_j - c_a)/\|c_j - c_a\| and f(y)=∥y−ca∥2−∥y−cj∥2f(y) = \|y - c_a\|^2 - \|y - c_j\|^2. Expanding the squares, f(y)=2y⋅(cj−ca)+∥ca∥2−∥cj∥2f(y) = 2 y \cdot (c_j - c_a) + \|c_a\|^2 - \|c_j\|^2, an affine function with gradient 2(cj−ca)2(c_j - c_a). So f(y)−f(z)=2∥cj−ca∥ u⋅(y−z)f(y) - f(z) = 2\|c_j - c_a\| \, u \cdot (y - z) for all y,zy, z. The condition on xx says f(x)≥0f(x) \ge 0, and f(q)=∥q−ca∥2−∥q−cj∥2≤0f(q) = \|q - c_a\|^2 - \|q - c_j\|^2 \le 0. Then

∥q−x∥≥u⋅(x−q)=f(x)−f(q)2∥cj−ca∥≥−f(q)2∥cj−ca∥=∥q−cj∥2−∥q−ca∥22∥cj−ca∥,\|q - x\| \ge u \cdot (x - q) = \frac{f(x) - f(q)}{2\|c_j - c_a\|} \ge \frac{-f(q)}{2\|c_j - c_a\|} = \frac{\|q - c_j\|^2 - \|q - c_a\|^2}{2\|c_j - c_a\|},

using the Cauchy-Schwarz inequality and ∥u∥=1\|u\| = 1 in the first step. With ∥q−x∥≥0\|q - x\| \ge 0 this gives ∥q−x∥≥βj\|q - x\| \ge \beta_j. □\square

If cj=cac_j = c_a, put βj=0\beta_j = 0, which is a valid bound. For j=aj = a, βa=0\beta_a = 0.

Theorem 3. IVF-SEARCH-EXACT(q,k)(q, k) returns the kk nearest stored vectors to qq.

Proof. The cells are visited in the order of nondecreasing βj\beta_j. If the loop never stops at line L8, every vector is offered, and Lemma 1 ends the proof as in Theorem 1. Suppose it stops at cell jj. Then HH holds kk pairs, and βj>D\beta_j > D, where DD is the largest distance in HH. Every cell j′j' not yet visited has βj′≥βj>D\beta_{j'} \ge \beta_j > D. By (V) and Lemma 2, each vector xx of such a cell has ∥q−x∥≥βj′>D\|q - x\| \ge \beta_{j'} > D. So at least kk offered vectors are strictly closer than every vector not offered, and the kk least pairs among the offered vectors, which HH holds by Lemma 1, are the kk least pairs among all stored vectors. ■\blacksquare

Back to Inverted file index