Skip to section
Foundationsfor rotation-free search
Section 47 of 5290% of course
Contents
Chapter 8 Section 8.1 70 min

Part VI · The implementation

The complete data journey

Follow one query and one corpus polynomial across software and hardware.

Animated visual · ManimOne score, seven representations

The logical score survives vector, fixed-point, packed, residue, transform, ciphertext, and decoded forms.

The whole system is just a chain of contracts

You won't find "the algorithm" sitting cleanly in one file. The magic happens because a whole chain of components agree to follow the rules: the model encoding, client encryption, host transport, RTL streaming, inverse transforms, decryption, and final extraction. If one piece drops the ball, the system fails.

Animated visual · ManimOne score, seven representations

The logical score survives vector, fixed-point, packed, residue, transform, ciphertext, and decoded forms.

Selected stage

Pointwise multiply

Sixteen lanes multiply matching NTT coefficients. No score accumulation or rotation occurs here.

rtl/score_engine.sv:151
  1. Model or client: Normalizes embeddings, scales the coordinates, lays out the query forward, and reverses each corpus vector inside its block.
  2. Cryptographic client: Encrypts the coefficient polynomials and transforms the query into evaluation form (NTT).
  3. Ingest path: Pre-computes the NTT for corpus polynomials and packs them into the exact physical layout the hardware expects.
  4. Score engine: Holds the query on-chip and multiplies it against the streaming corpus words across 16 parallel lanes.
  5. Downstream transform: Takes the resulting product polynomials out of NTT form back to normal coefficients.
  6. Trusted client: Decrypts the result, reads the specific target taps (Dj+D−1), divides out the Δ² scale factor, and ranks the results.

Always check your data's passport

Never just pass a variable named data and assume it works. At every step in the pipeline, ask yourself four things: What does one array element actually mean? What order is the data in? What's the numerical scale? And who is legally allowed to read this?

representationone stored item meansreadable by server?
embeddingone real coordinatedepends on your privacy boundary
packed coefficientone scaled integer in a specific positiononly before encryption
residue limba modular view of a coefficientnope, not as a plaintext value
NTT itema residue in the transform domainnope, totally unrecognizable
ciphertext componenta coefficient of a secret polynomial expressionnot without the secret key
decoded scorean approximate real similarity scoretrusted client only!
Let's drill this: what metadata absolutely must travel with a transformed ciphertext?

You need a lot more than just the bytes. You need the polynomial identity, the ciphertext component index, the residue limb and modulus, the transform ordering convention, the total coefficient count N, the score dimension D, and the valid payload length. Handing someone a raw byte array without that context is completely useless.

Check your understanding

At what exact point does a final score become a readable, approximate real number?

Section summary

  • Your data morphs through multiple representations and owners.
  • Every boundary hands off explicit contracts for order, width, scale, and dimension.
  • Only the trusted client is ever allowed to read the final scores.

Repository layer · second pass

Where does one query change representation across the full system?

Follow a single coordinate and a single score tap through embedding, scaling, coefficient packing, encryption, RNS decomposition, NTT form, hardware multiplication, inverse transform, decryption, extraction, unscaling, and ranking. At every boundary write both the data type and what one index means.

The system flow is a chain of contracts, not a blur called FHE. Observability should expose safe metadata—dimensions, levels, component counts, transaction IDs—without leaking private values.

Reasoning chain

  1. 1

    Choose one trace identifier.

  2. 2

    Record representation and owner per stage.

  3. 3

    State scale and modulus metadata.

  4. 4

    Mark reversible versus lossy transitions.

  5. 5

    Verify each boundary independently.

  6. 6

    Correlate software and RTL transactions without logging secrets.

Worked trace

Trace coordinate i=2 of vector j=1

  1. Model output v₁,₂ is scaled.
  2. Packing stores it at D·1+D−1−2.
  3. Matching q₂ product lands at tap D·1+D−1.
  4. Client extracts that tap after decryption.

Result. Logical identities survive several physical re-encodings.

Executable lens · Python

Make the hidden state visible

def trace_positions(d,j,i):
    packed=d*j+d-1-i
    tap=d*j+d-1
    return {"logical":(j,i),"packed":packed,"tap":tap}
assert trace_positions(4,1,2)=={"logical":(1,2),"packed":5,"tap":7}

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

Misconception clinic

Tempting mistakes

  • Using “index” without naming its current axis.
  • Logging plaintext values at a server-side diagnostic boundary.

Retrieval and transfer

Close the book first

  1. Create a representation ledger for one score.
  2. Mark trust owner at every step.
  3. Design a redacted trace schema.