Skip to section
Foundationsfor rotation-free search
Section 23 of 5244% of course
Contents
Chapter 4 Section 4.4 70 min

Part III · Construction and proof

Give every vector its own landing strip

Extend one reversed vector into fixed-width corpus blocks.

Scaling up to multiple vectors

So far, one vector uses D coefficients, but a real production polynomial gives us N coefficients. We can just repeat our layout in adjacent blocks! Let's give corpus vector j the physical block that starts at Dj and ends at Dj+D−1. Doing our relative reversal inside that specific block means we store logical coordinate i at:

p(j,i)=Dj+D−1−i

Now, let's pair it with query position i:

i + (Dj+D−1−i) = Dj+D−1 = tj

Beautiful. Every single vector gets its own distinct score tap, sitting right at the right edge of its block.

Interactive index equation
chosen score targettj = Dj + D−1 = 7

query 0+corpus 70 = 7=7

query 1+corpus 71 = 6=7

query 2+corpus 72 = 5=7

query 3+corpus 73 = 4=7

Play around with the lab above as an index debugger. Try changing j and i separately. Notice how increasing i moves the stored corpus position to the left, but leaves the target totally fixed. Meanwhile, increasing j shifts the entire block—and its target—to the right by D. Those are two very different logical motions, and it's important not to mix them up.

block 0v₀,D−1v₀,0score cD−1
block 1v₁,D−1v₁,0score c2D−1
block jvⱼ,D−1vⱼ,0score cDj+D−1

How many vectors can we actually fit?

Our polynomial has N total coefficient positions. If D divides N evenly, we can fit N/D complete blocks. That quotient is our packing density: the exact number of corpus vectors whose scores we can read out of one single product polynomial. In production, we typically use N=4096. So at D=128, one polynomial can carry 32 corpus vectors. But at D=4096, it only has room for one!

DN/D vectorsscore taps begin
12832127, 255, 383, …
5128511, 1023, 1535, …
204822047, 4095
409614095

Worked example

Dealing with a partially filled artifact

What if your corpus has 35 vectors at D=128? The first polynomial holds 32, and the second holds the remaining 3. Those unused blocks in the second artifact must be explicitly zeroed out or ignored. Just because we have the capacity doesn't mean every block holds a real, valid corpus record.

Check your understanding

If we have N=4096 and D=512, how many vectors fit, and exactly where is vector j=3 scored?

Section summary

  • Vector j lives in positions Dj through Dj+D−1.
  • Its coordinate i is stored precisely at Dj+D−1−i.
  • We read its score tap at tⱼ=Dj+D−1.
  • One polynomial can hold N/D vectors.

Repository layer · second pass

How can one query score many vectors without their blocks interfering?

Give vector j a D-wide corpus block beginning at Dj. Store its coordinate i at Dj+D−1−i. The query still occupies positions 0 through D−1. Matching pair j,i then lands at Dj+D−1, the right edge of block j.

For N coefficients and D dividing N, N/D full blocks fit. The target list is arithmetic: D−1,2D−1,3D−1,…,N−1. Packing density and extraction locations should be generated from the same parameters to prevent drift.

Reasoning chain

  1. 1

    Choose block width D.

  2. 2

    Place block j at base Dj.

  3. 3

    Reverse inside that block.

  4. 4

    Derive target tⱼ=Dj+D−1.

  5. 5

    Check tⱼ<N and D divides N.

  6. 6

    Generate packing and extraction from one contract.

Worked trace

Four landing strips

  1. Let N=16,D=4.
  2. Four vectors fit at bases 0,4,8,12.
  3. Their score taps are 3,7,11,15.
  4. Every matching pair for vector 2 lands at 11.

Result. One polynomial product contains four independently addressable dot products.

Executable lens · Python

Make the hidden state visible

def targets(n, d):
    if n % d: raise ValueError("D must divide N")
    return [d*j + d - 1 for j in range(n//d)]
assert targets(16,4) == [3,7,11,15]

Retype this example, predict each intermediate value, and then change one input that touches a boundary.

Misconception clinic

Tempting mistakes

  • Using Dj as the score tap instead of the right edge.
  • Packing a partial block without defining padding and extraction semantics.

Retrieval and transfer

Close the book first

  1. Compute taps for N=4096,D=768 and explain the remainder problem.
  2. Derive the packed position of vector 5 coordinate 9.
  3. Write validation for corpus vector length and batch capacity.