Appendices

Appendix A: Formula Sheet

Complete study edition · View Markdown ↗

On this page

00-START-HERE · 01-READING-ROUTES · 41_end_to_end_design_drills · A2_question_bank This appendix is a compact derivation and interview-use guide for eight formula groups used in Retrieval-Augmented Generation (RAG) that preserves the source equations, numeric examples, conditions, and rules of thumb while translating Best Matching 25 (BM25), Reciprocal Rank Fusion (RRF), Mean Reciprocal Rank (MRR), normalized Discounted Cumulative Gain (nDCG), modularity, Product Quantization (PQ), floating-point operations (FLOPs) with latency, and end-to-end index memory into operational decisions.

TL;DR

  • Carry units through every derivation. Most design-round arithmetic failures are unit failures.
  • Cross-check each result against a published rule or a known system before defending it.
  • BM25 separates inverse document frequency, term-frequency saturation, and document-length normalization.
  • RRF rewards agreement without requiring comparable scores, while MRR and nDCG measure different ranking goals.
  • Modularity compares connectivity with a degree-preserving expectation, while PQ obtains exponential combinations from linearly many centroids.
  • FLOP, key-value cache, and Low-Rank Adaptation arithmetic turn model choices into latency and memory budgets.
  • Index capacity must include vectors, identifiers, graph links, rebuild headroom, replication, text payload, and metadata.

The story

Treat the appendix as a cockpit checklist for a RAG design interview. A number such as 3.38680485×10133.38680485\times10^{13} becomes a compute quantity only when labeled FLOPs. Dividing it by an assumed achieved FLOP/s rate gives an idealized compute time, not a latency benchmark. BM25 separately shows rarity, saturation and document-length effects. RRF is the sensor combiner. It merges rank signals without pretending that a lexical score and a cosine score share a scale. MRR is the first-hit warning light. It cares only about the first relevant result. nDCG is the ranked-load gauge. It keeps graded relevance and gives later useful results nonzero credit. Modularity is the route-map gauge. It asks whether a proposed community has more internal connection than degree alone would predict. PQ is the cargo compressor. It splits one large vector into smaller subspaces, stores a modest codebook for each, and represents combinations it never stores explicitly. The FLOP and latency panel converts model size, token count, context length, cache shape, and adapter rank into time and memory. The final capacity card counts everything loaded on the aircraft. Vector bytes alone are not the fleet. Identifiers, graph links, replication, rebuild copies, text payload, and metadata all travel too. A safe pilot can rebuild every reading when a constraint changes. Memorizing the final number without its units, condition, and sanity check is not enough. After two weeks of preparation, continued reliance on the card is a reason to re-derive each formula rather than re-read it.

Decoder table

Symbol or term Meaning in this appendix Mechanical role
qq Query Supplies terms to BM25 or identifies one evaluation case
DD Document Receives a BM25 score
tt Query term Contributes one BM25 summand
NN in A.1 Collection document count Sets the inverse document frequency scale
ntn_t Documents containing term tt Makes common terms less informative
f(t,D)f(t,D) Frequency of term tt in document DD Enters a saturating term-frequency factor
∣D∣\lvert D\rvert Document length Drives BM25 length normalization
avgdl\mathop{\mathrm{avgdl}}\nolimits Mean document length Defines the length baseline
k1k_1 BM25 saturation parameter Controls how quickly repeated term counts flatten
bb in A.1 BM25 length parameter Interpolates from no length charge to full charge
ℓ\ell Document length divided by mean length Makes length normalization dimensionless
KK in A.1 Length-adjusted BM25 denominator term Places the length charge inside saturation
IDF Inverse document frequency Rewards rarer query terms
TF Term frequency Counts repeated occurrences before saturation
LL in A.2 Number of ranked lists Sets how many votes RRF can combine
rℓ(d)r_\ell(d) Rank of document dd in list ℓ\ell Determines one list’s reciprocal contribution
kk in A.2 RRF rank constant Sets the exchange rate between rank and consensus
w(r)w(r) RRF weight at rank rr Makes the fusion curve explicit
r∗r^{*} Consensus crossover rank Marks when agreement beats one list’s top hit
RR Reciprocal Rank Scores the first relevant result for one query
rankq\mathop{\mathrm{rank}}\nolimits_q First relevant rank for query qq Defines RR and becomes failure when absent
Q\mathcal{Q} Evaluation query set Supplies the denominator in MRR
MRR Mean Reciprocal Rank Averages one first-hit score per query
reli\mathop{\mathrm{rel}}\nolimits_i Relevance grade at rank ii Supplies gain to CG and DCG
CG Cumulative Gain Adds relevance without position sensitivity
DCG Discounted Cumulative Gain Discounts relevance by log rank
IDCG Ideal Discounted Cumulative Gain Scores the best ordering of available judgments
nDCG Normalized Discounted Cumulative Gain Divides DCG by IDCG for cross-query comparison
kk in A.4 Evaluation cutoff Limits the ranked prefix being scored
QQ in A.5 Modularity Measures connection beyond a degree-fixed chance model
mm in A.5 Total graph edge count Normalizes the modularity sum
AijA_{ij} Binary adjacency indicator Marks whether nodes ii and jj share an edge
kik_i Degree of node ii Sets expected random connectivity
cic_i Community assigned to node ii Selects within-community pairs
δ(ci,cj)\delta(c_i,c_j) Same-community indicator Keeps a pair only when both community labels match
Leiden Community-detection heuristic with connected-community guarantees under its assumptions Does not certify the global maximum or semantic coherence
Louvain Earlier modularity algorithm Can return a disconnected community
GraphRAG and LightRAG Graph-based retrieval systems with different indexing/update designs Compare measured maintenance paths; modularity alone proves no cost ordering
dd in A.6 Vector dimension Sets raw storage and subvector width
mm in A.6 Number of PQ subvectors Sets code length and subvector count
kk in A.6 Centroids per subspace Sets bits per subvector and codebook size
dm\frac{d}{m} Subvector width Must be integral for even splitting
kmk^m Representable vector combinations Grows exponentially in subspaces
k×mk\times m Stored centroids Grows linearly in subspaces
N∗N^{*} PQ lookup-table break-even candidates Marks when precomputation amortizes
bb in A.6 Bits for a hypothetical single-codebook identifier For PQ distinguish sub-code bits from total mlog⁡2km\log_2 k bits
FAISS and Inverted File Product Quantization (IVF-PQ) The cited vector-search implementation and inverted-file PQ configuration They supply the memory sanity rule and the amortization setting
fp32 32-bit floating-point storage Uses four bytes per scalar
bf16 16-bit brain floating-point storage Uses two bytes per scalar
int8 8-bit integer storage Uses one byte per scalar
int4 4-bit integer storage Uses one-half byte per scalar
NN in A.7 Model parameter count Sets model compute and weight memory
DtokensD_{\mathrm{tokens}} Training token count Multiplies training FLOPs
CC in A.7 Approximate total training compute Equals about 6NDtokens6ND_{\mathrm{tokens}}
ss Prefill context length Enters linear model work and quadratic attention work
LlayersL_{\mathrm{layers}} Transformer layer count Multiplies attention and cache cost
dhiddend_{\mathrm{hidden}} Hidden dimension Scales attention work
bbytesb_{\mathrm{bytes}} Bytes per stored scalar Converts parameter or cache counts into memory
KV cache Key-value cache Stores attention keys and values per token and request
nkvn_{\mathrm{kv}} Key-value head count Scales cache bytes per token
dheadd_{\mathrm{head}} Attention head dimension Scales cache bytes per token
Prefill and decode Context processing and cached autoregressive generation Often different bottleneck regimes; not universally compute- and bandwidth-bound
LoRA Low-Rank Adaptation Replaces full matrix updates with rank-rr factors
rr in A.7 Adapter rank Sets trainable LoRA parameters
dind_{\mathrm{in}}, doutd_{\mathrm{out}} Adapted matrix dimensions Determine one adapter’s parameter count
MweightsM_{\mathrm{weights}}, MKV,tokenM_{\mathrm{KV},\mathrm{token}}, and PLoRAP_{\mathrm{LoRA}} Weight memory, cache bytes per token, and adapter parameters They separate fixed, concurrency-dependent, and trainable costs
NN in A.8 Indexed vector count Multiplies per-vector index bytes
bvecb_{\mathrm{vec}} Bytes for one vector code Includes raw fp32 or PQ code bytes
bidb_{\mathrm{id}} Posting identifier bytes Costs four to eight bytes per vector
blinkb_{\mathrm{link}} Expected allocated HNSW neighbor-slot bytes under a stated layer model Not realized degree or complete graph-index memory
HNSW Hierarchical Navigable Small World index Stores neighbor identifiers across graph layers
IVF Inverted File index Uses centroids and posting lists without HNSW links
MM HNSW neighbor parameter Sets layer-zero and upper-layer link storage
M0M_0 Layer-zero HNSW neighbors Uses up to twice MM identifiers
nlistn_{\mathrm{list}} IVF centroid count Adds coarse-centroid memory
MindexM_{\mathrm{index}} Total index footprint Counts vector, identifier, link, IVF, and PQ bytes
RR Replication factor Multiplies the live index copies
hh in A.8 Artifact-specific rebuild reserve or overlap fraction State hIh_I and hPh_P rather than assuming payload is never copied
MpayloadM_{\mathrm{payload}} Text and metadata bytes Often dominates after strong vector compression
MfleetM_{\mathrm{fleet}} Replicated index, payload and runtime memory in a declared capacity domain Payload replication and build-host memory cannot silently disappear
shards\mathop{\mathrm{shards}}\nolimits Logical index partitions, distinct from physical node count Aggregate-byte ceilings give a node-capacity lower bound, not the shard count
GB, TB, KiB, MB, bytes, bits, and FLOP/s Gigabytes, terabytes, kibibytes, megabytes, byte and bit counts, and floating-point operations per second Carrying the unit prevents incompatible quantities from being compared
RAM Random-access memory Supplies usable capacity per node

Core mechanics

Mathematical conventions

Use decimal units 1 GB=109 B1\,\mathrm{GB}=10^9\,\mathrm B and 1 TB=1012 B1\,\mathrm{TB}=10^{12}\,\mathrm B; binary units are explicitly 1 KiB=210 B1\,\mathrm{KiB}=2^{10}\,\mathrm B and 1 MiB=220 B1\,\mathrm{MiB}=2^{20}\,\mathrm B. Keep full precision until the reported result and use ≈\approx for rounding or a compute/storage model. Natural logarithms are written ln⁡\ln; DCG uses log⁡2\log_2. Ranked lists have positive integer ranks and a declared tie rule, identity/deduplication policy and depth. Define missing-hit and zero-IDCG behavior. Modularity below is for an undirected unweighted graph with m>0m\gt 0 edges, including diagonal null-model terms; optimization is heuristic, not a global-optimum certificate. Compute is a dense-model FLOP proxy, not measured latency. Attention architecture, causal masking, achieved throughput, batching, memory traffic, communication and queueing matter. Storage equations are scoped byte ledgers: count only applicable index components, distinguish expected allocated link slots from realized links, and state which artifacts are replicated or rebuilt. A ceiling of aggregate bytes is a capacity lower bound, not a deployable shard/replica plan.

A.1 BM25

Formula and symbols

Section 18.318.3 derives BM25, which scores one query-document pair by summing over query terms.

BM25(q,D)=∑t∈T(q)ln⁡ ⁣(1+N−nt+0.5nt+0.5)f(t,D)(k1+1)f(t,D)+k1(1−b+b∣D∣/avgdl).\mathop{\mathrm{BM25}}\nolimits(q,D)=\sum_{t\in\mathcal T(q)} \ln\!\left(1+\frac{N-n_t+0.5}{n_t+0.5}\right) \frac{f(t,D)(k_1+1)}{f(t,D)+k_1(1-b+b\lvert D\rvert/\mathop{\mathrm{avgdl}}\nolimits)}.

Here T(q)\mathcal T(q) is the set of distinct analyzed query terms; repeated-query weighting is omitted. Require N≥1N\ge1, 0≤nt≤N0\le n_t\le N, avgdl>0\mathop{\mathrm{avgdl}}\nolimits\gt 0, k1>0k_1\gt 0 and 0≤b≤10\le b\le1. This shifted natural-log IDF is positive even for a term in every document; it is not the unshifted Robertson IDF. The source defaults are:

k1=1.2,b=0.75k_1=1.2, \qquad b=0.75

Define the dimensionless length ratio and adjusted denominator term as:

ℓ=∣D∣avgdl,K=k1(1−b+bℓ)\ell=\frac{|D|}{\mathop{\text{avgdl}}}, \qquad K=k_1(1-b+b\ell)

At b=0b=0, document length is ignored. At b=1b=1, the length ratio is charged in full.

Plain-language mechanics

IDF raises rare terms. TF saturation gives the first few occurrences most of the benefit. Length normalization changes the saturation denominator instead of applying a hard score penalty. The two knobs are independent. k1k_1 controls saturation speed. bb controls length sensitivity.

Worked saturation grid

At average document length, ℓ=1\ell=1, and k1=1.2k_1=1.2, the TF factor becomes:

TFfactor(f)=2.2ff+1.2\mathop{\text{TFfactor}}(f)=\frac{2.2f}{f+1.2}
ff 11 22 55 1010 2020 Limit
TF factor (rounded) 1.0001.000 1.3751.375 1.7741.774 1.9641.964 2.0752.075 2.2002.200

The second occurrence adds 0.3750.375. Ten additional occurrences, from f=10f=10 to f=20f=20, add approximately 0.1111860.111186, about 29.65%29.65\% of that second-occurrence increment. The final column is the limit, not a finite-frequency score.

Worked length normalization

For a document twice the mean length with one term occurrence:

f=1,k1=1.2,b=0.75,ℓ=2f=1, \qquad k_1=1.2, \qquad b=0.75, \qquad \ell=2
K=1.2(1−0.75+0.75×2)=1.2×1.75=2.1K=1.2(1-0.75+0.75\times2)=1.2\times1.75=2.1
TFfactor=2.21+2.1≈0.709677.\mathop{\mathrm{TFfactor}}\nolimits=\frac{2.2}{1+2.1}\approx0.709677.

The TF factor is approximately 29.0323%29.0323\% below its average-length, one-occurrence value of 11. The length adjustment acts inside the denominator; the percentage is the resulting score-factor decrease, not a denominator discount.

Conditions, failures, and rules

  • Treat k1=1.2k_1=1.2 and b=0.75b=0.75 as example starting values, not universal implementation defaults or optima.
  • A lower bb, such as 0.30.3, can be tested when length reflects additional useful content. Document genre alone does not determine the best value.
  • The unshifted IDF ln⁡((N−nt+0.5)/(nt+0.5))\ln((N-n_t+0.5)/(n_t+0.5)) is negative above half the collection. The displayed shifted form is positive and must not be confused with flooring the unshifted form.
  • BM25 and hybrid retrieval remain baselines to evaluate on the actual relevance task, including exact entities and rare terms.

A.2 Reciprocal Rank Fusion

Formula and symbols

Section 21.621.6 derives RRF, which assigns one reciprocal contribution for every list that contains document dd.

RRF(d)=∑ℓ=1L1k+rℓ(d)\mathop{\text{RRF}}(d)=\sum_{\ell=1}^{L}\frac{1}{k+r_\ell(d)}

A missing document contributes nothing. This is equivalent to sending its rank to infinity. The conventional default is:

k=60k=60

Within one list, rank rr has weight relative to that list’s first result:

w(r)w(1)=k+1k+r\frac{w(r)}{w(1)}=\frac{k+1}{k+r}

That ratio is exactly one-half at:

r=k+2r=k+2

For LL equal-weight lists and k≥0k\ge0, assume a document is present at the same rank rr in every list. Compare it with a competitor present only at rank 11 in one list:

Lk+r>1k+1⟺r<L(k+1)−k\frac{L}{k+r}\gt \frac{1}{k+1} \quad\Longleftrightarrow\quad r \lt L(k+1)-k

Plain-language mechanics

RRF combines ranks rather than claiming comparable raw scores. Require k+r>0k+r\gt 0 and consistent document identity. Raising kk flattens within-list weights; it does not establish that agreement is independent or correct. Correlated lists can repeat the same error. Unequal list weights or different ranks need their actual sums, not the equal-rank shortcut.

Worked crossover cases

With two lists and k=60k=60:

r∗=2(61)−60=62r^{*}=2(61)-60=62

Under that equal-rank comparison, a common document at rank 6161 or better in both lists beats the competitor present only at one list’s first position. At rank 6262 the scores tie. List depth must be sufficient to observe those ranks. With two lists and k=0k=0:

r∗=2r^{*}=2

Against a competitor present only at one list’s first position, strict victory requires a common rank of 11. A common rank-22 item ties it. This inequality does not imply that all k=0k=0 RRF rankings reduce to interleaving the list heads. With three lists and k=60k=60:

r∗=3(61)−60=123r^{*}=3(61)-60=123

Conditions, failures, and rules

  • Treat k=60k=60 as a common evaluated convention, not a derived optimum.
  • Use RRF when rank aggregation suits the task; normalized score fusion is an alternative to validate, not something justified by normalization alone.
  • Fusion depth 100100 followed by a final depth 1010 is an example. Tune candidate coverage, latency and judged quality together.
  • Shallow lists may hide useful consensus. An added weak or correlated list may also promote errors; extra agreement is not an automatic quality gain.

A.3 Mean Reciprocal Rank

Formula and symbols

Section 32.232.2 derives Reciprocal Rank, which depends only on the first relevant result for query qq.

RRq@K={1/rq,rq≤K,0,no relevant hit in the evaluated prefix,\mathop{\mathrm{RR}}\nolimits_q@K=\begin{cases} 1/r_q,&r_q\le K,\\ 0,&\text{no relevant hit in the evaluated prefix}, \end{cases}

Here rqr_q is the first relevant rank, K≥1K\ge1 is the evaluation cutoff, and the query set is nonempty. MRR averages those per-query values; multiple relevant items are permitted but only the first contributes:

MRR@K=1∣Q∣∑q∈QRRq@K.\mathop{\mathrm{MRR}}\nolimits @K=\frac{1}{\lvert\mathcal Q\rvert}\sum_{q\in\mathcal Q}\mathop{\mathrm{RR}}\nolimits_q@K.

A missing relevant result in the evaluated prefix receives zero. Unbounded MRR uses a declared complete ranking or another explicit missing-hit convention.

Plain-language mechanics

MRR asks one question: how far down is the first relevant document? It ignores every relevant result after the first.

Worked examples

A ten-document list with relevant results at ranks one and ten has:

RR=1/1=1.0\mathop{\text{RR}}=1/1=1.0

A list with only one relevant result at rank one receives the same score. The following calculation is not MRR:

1/1+1/1010=0.11\frac{1/1+1/10}{10}=0.11

It sums every relevant hit and divides by list length. A metric that changes when a second relevant document appears cannot be RR for that query.

First relevant rank 11 22 33 55 1010 Absent
RR 1.0001.000 0.5000.500 0.3330.333 0.2000.200 0.1000.100 00

Rank 22 earns half the rank-11 reciprocal credit. Rank 55 still earns 0.20.2 and rank 1010 earns 0.10.1; calling these “failure” is a task judgment, not a property of the formula.

Conditions, failures, and rules

  • MRR suits first-success objectives even when several relevant items exist. It is not a complete multi-evidence retrieval metric.
  • Report cutoff, relevance criterion, query denominator and tie handling.
  • Pair rank metrics with recall and, for multi-hop RAG, coverage of the full sufficient evidence set. “At least one gold hit” and “all required evidence retrieved” are different events.
  • The value of a rank improvement versus a recall improvement depends on the downstream task and costs.

A.4 nDCG

Formula and symbols

Section 32.232.2 derives the ranking metrics, beginning with Cumulative Gain, which ignores order.

CG@k=∑i=1kreli\mathop{\text{CG}}@k=\sum_{i=1}^{k}\mathop{\text{rel}}_i

Discounted Cumulative Gain divides each grade by a log-rank term.

DCG@k=∑i=1krelilog⁡2(i+1)\mathop{\text{DCG}}@k= \sum_{i=1}^{k} \frac{\mathop{\text{rel}}_i}{\log_2(i+1)}

Normalize by IDCG computed from the same nonnegative gain function, cutoff and judgment universe. For positive IDCG:

nDCG@k=DCG@kIDCG@k,IDCG@k>0.\mathop{\mathrm{nDCG}}\nolimits @k=\frac{\mathop{\mathrm{DCG}}\nolimits @k}{\mathop{\mathrm{IDCG}}\nolimits @k},\qquad \mathop{\mathrm{IDCG}}\nolimits @k\gt 0.

Under those conditions, and with the ideal ordering formed from the same candidate/judgment universe:

0≤nDCG@k≤10\leq\mathop{\text{nDCG}}@k\leq1

Plain-language mechanics

CG ignores position and DCG discounts later gains. The +1+1 makes rank 11 undiscounted under log⁡2\log_2. IDCG uses a declared judgment universe, ideally all available relevant judgments rather than just the returned items. A score of 11 means an ideal ranking relative to that universe; it does not prove exhaustive labeling of the corpus. For zero IDCG, explicitly exclude the query or assign a stated convention such as zero.

Worked discount grid

Rank ii 11 22 33 55 1010
log⁡2(i+1)\log_2(i+1) 1.0001.000 1.5851.585 2.0002.000 2.5852.585 3.4593.459
DCG weight 1.0001.000 0.6310.631 0.5000.500 0.3870.387 0.2890.289
RR weight 1.0001.000 0.5000.500 0.3330.333 0.2000.200 0.1000.100

At rank 10, DCG still assigns 0.2890.289 while RR assigns 0.1000.100. A useful document at rank four or five retains material credit.

Gain choice and judgment conditions

The displayed formula uses direct relevance grades. An alternative uses exponential gain:

gaini=2reli−1\mathop{\text{gain}}_i=2^{\mathop{\text{rel}}_i}-1

Exponential gain emphasizes higher grades more strongly, but does not make ordinal labels cardinal ground truth. State gain, cutoff and averaging. Treating unjudged items as zero gain is a common evaluation policy, not evidence of non-relevance; shallow pools can bias comparisons.

Conditions, failures, and rules

  • Report cutoff, gain function, relevance judgments, zero-IDCG policy and macro/micro averaging.
  • Binary nDCG and graded nDCG are different metrics. Choose exponential gain only when that weighting matches the objective.
  • Pair reranker nDCG with retrieval recall at a declared candidate cutoff, and evaluate end-to-end evidence sufficiency.
  • nDCG can penalize missing judged relevant documents as well as poor ordering. Recomputing IDCG only from returned hits can conceal retrieval failure.

A.5 Modularity

Formula and symbols

For an undirected unweighted graph with m>0m\gt 0, the following is standard modularity at resolution 11. Louvain and Leiden are optimization heuristics; neither name alone guarantees a global maximum.

Q=12m∑i,j[Aij−kikj2m]δ(ci,cj)Q=\frac{1}{2m} \sum_{i,j} \left[A_{ij}-\frac{k_i k_j}{2m}\right] \delta(c_i,c_j)

Here mm counts undirected edges once, the sum over i,ji,j is ordered and includes the diagonal, AijA_{ij} is binary adjacency, and kik_i is node degree. The delta selects pairs assigned to the same community. The configuration-model expectation is:

kikj2m\frac{k_i k_j}{2m}

Modularity therefore measures connectivity beyond chance at fixed degree. It does not measure absolute connectivity.

Worked four-node partition

Nodes one, two, and three form a triangle. Node four has one edge to node three.

m=4,2m=8m=4, \qquad 2m=8

For partition A, the triangle and singleton contributions are:

6−498=−0.1256-\frac{49}{8}=-0.125
0−18=−0.1250-\frac{1}{8}=-0.125

Thus:

QA=−0.258=−0.03125Q_A=\frac{-0.25}{8}=-0.03125

For partition B, all four nodes are together.

QB=8−64/88=0Q_B=\frac{8-64/8}{8}=0

The modularity gain is:

QB−QA=0.03125Q_B-Q_A=0.03125

For these two partitions, adding the dangling edge changes a tie into a 0.031250.03125 preference for merging. This does not claim that the selected partition is uniquely optimal over all partitions.

Conditions, failures, and rules

  • Under the standard assumptions in the Leiden analysis, completed iterations provide connected-community guarantees that Louvain lacks. They do not guarantee semantic coherence or a globally optimal partition.[1]
  • The modularity null model uses whole-graph degrees and edge count. Updates can change optimal partitions outside the edited neighborhood, but do not force every community to change or every implementation to rebuild globally.
  • Compare GraphRAG and LightRAG maintenance policies and measured workloads; global modularity alone proves no universal cost ordering.
  • Generic relations can distort communities, while capping them can remove useful evidence. Audit the effect rather than assuming semantic value always collapses.
  • Modularity has a resolution limit, but no universal internal-edge cutoff guarantees absorption at every hierarchy level. A more precise pairwise merge condition is:
ΔQA,B=eABm−KAKB2m2;ΔQA,B>0 ⟺ 2meAB>KAKB.\Delta Q_{A,B}=\frac{e_{AB}}m-\frac{K_AK_B}{2m^2};\qquad \Delta Q_{A,B}\gt 0\ \Longleftrightarrow\ 2me_{AB}\gt K_AK_B.

Here eABe_{AB} counts edges between two communities and KA,KBK_A,K_B are their degree sums. For a single bridge and equal degree sums, merging is favorable when KA=KB<2mK_A=K_B\lt \sqrt{2m}. Translating that into internal-edge counts depends on external degrees; the classic symmetric examples have a m/2\sqrt{m/2} scale. Resolution and hierarchy choices can change the outcome.[2]

A.6 Product Quantization sizing

Formula and symbols

Section 16.116.1 derives Product Quantization. Split a dd-dimensional vector into mm subvectors, each with width:

dm\frac{d}{m}

For equal subspaces, require positive integer mm dividing dd. With k=2bsubk=2^{b_{\mathrm{sub}}} centroids, each sub-code uses bsubb_{\mathrm{sub}} bits and total packed code length is:

bcode=mlog⁡2k=mbsub bits,bpacked=⌈mbsub8⌉ B.b_{\mathrm{code}}=m\log_2k=m b_{\mathrm{sub}}\ \text{bits},\qquad b_{\mathrm{packed}}=\left\lceil\frac{m b_{\mathrm{sub}}}{8}\right\rceil\,\mathrm B.

The number of representable vectors is:

kmk^m

The number of stored centroids is:

k×mk\times m

Each centroid has dimension dm\frac{d}{m}, so fp32 codebook memory is:

k×m×dm×4=k×d×4 bytesk\times m\times\frac{d}{m}\times4 =k\times d\times4\text{ bytes}

For fixed kk, dd and centroid precision, this shared codebook payload is independent of mm. That is not true if changing mm changes kk, adds transforms or adds per-subquantizer metadata. In a deliberately simplified operation count, building the query lookup table costs 2kd2kd and each candidate lookup costs mm, versus 2d2d for a direct distance. The equality break-even is:

N∗=2kd2d−mN^{*}=\frac{2kd}{2d-m}

candidate distances, provided 2d>m2d\gt m. Strict savings require more candidates than N∗N^*. Cache behavior, SIMD, residual/coarse-distance tables and actual kernels can change the measured break-even.

Why the mechanism compresses

Representable combinations grow as kmk^m. Stored centroids grow only as k×mk\times m. This asymmetry is the compression mechanism.

Worked 768-dimensional design

Start with:

d=768,m=96,d/m=8,k=256=28d=768, \qquad m=96, \qquad d/m=8, \qquad k=256=2^8

One fp32 vector uses:

768×4=3072 bytes768\times4=3072\text{ bytes}

The PQ code uses:

96×8=768 bits=96 bytes96\times8=768\text{ bits}=96\text{ bytes}

Compression is:

3072/96=323072/96=32

Representable combinations are:

25696=2768≈1.55251809×10231.256^{96}=2^{768}\approx1.55251809\times10^{231}.

Stored centroids are:

256×96=24576256\times96=24576

The codebook contains 196,608196{,}608 fp32 values and occupies:

256×768×4=786432 bytes=768 KiB256\times768\times4=786432\text{ bytes}=768\text{ KiB}

This is 786.432 kB=768 KiB786.432\,\mathrm{kB}=768\,\mathrm{KiB}. The source’s “768 kB768\,\mathrm{kB}” label must not be treated as a decimal-unit equality. The break-even candidate count is:

N∗=2×256×7681,536−96=393,2161,440≈273.066667.N^*=\frac{2\times256\times768}{1{,}536-96}=\frac{393{,}216}{1{,}440}\approx273.066667.

Equality occurs at a noninteger count, so the first whole candidate count with strict savings is 274274 in this proxy. A list shorter than that may not amortize the table on its own; aggregating probes and reusing tables depends on the implementation. The rounded 273273 is not the strict threshold.

Why one codebook loses

A single bb-bit codebook needs:

k=2bk=2^b

For b=32b=32 in 768 dimensions:

232×3,072 B=13,194,139,533,312 B≈13.19414 TB.2^{32}\times3{,}072\,\mathrm B=13{,}194{,}139{,}533{,}312\,\mathrm B\approx13.19414\,\mathrm{TB}.

This is the full-centroid payload for a hypothetical single 3232-bit codebook in 768768 dimensions, not 3232 bytes per vector. A claim of “400 times the corpus” needs a specified corpus size and representation; it does not follow from codebook size alone.

Conditions, failures, and rules

  • Default to k=256k=256, which gives one byte per subvector.
  • Choose mm to divide dd evenly and meet the byte budget.
  • A common starting point is:
m=d/8m=d/8
  • Keep kk and centroid precision fixed when claiming codebook independence from mm.
  • At k=256k=256, code storage is m Bm\,\mathrm B per vector, before identifiers and other structures. A Faiss IVF-PQ posting normally adds an eight-byte identifier.[3]
  • The Faiss warning default is 3939 training points per centroid; at 256256 centroids this is 9,9849{,}984 original training vectors, projected into each subspace. It is a warning heuristic, not a statistical guarantee or 9,984m9{,}984m distinct required source vectors.[4]

A.7 FLOPs and latency

Compute formulas

For a dense Transformer, count a multiply-add as two FLOPs and use NN as an approximate active parameter count. The usual parameter-matmul proxies are:

Wforward/token≈2N,Wbackward/token≈4N,Wtrain/token≈6N,Ctrain≈6NDtokens.\begin{aligned} W_{\mathrm{forward/token}}&\approx2N,&W_{\mathrm{backward/token}}&\approx4N,\\ W_{\mathrm{train/token}}&\approx6N,&C_{\mathrm{train}}&\approx6ND_{\mathrm{tokens}}. \end{aligned}

Generation has no backward pass, but its 2N2N parameter-matmul proxy omits context-dependent attention, memory bandwidth, batching effects and other overhead. MoE active parameters, tied embeddings and architecture details need their own ledger. For an idealized causal prefill over ss tokens, counting both attention matrix products over all causal pairs, a compatible proxy is:

Wprefill≈2Ns+2Llayerss(s+1)dhidden.W_{\mathrm{prefill}}\approx2Ns+2L_{\mathrm{layers}}s(s+1)d_{\mathrm{hidden}}.

The second term is quadratic and approaches 2Llayerss2dhidden2L_{\mathrm{layers}}s^2d_{\mathrm{hidden}} for large ss. Full bidirectional attention instead uses approximately 4Llayerss2dhidden4L_{\mathrm{layers}}s^2d_{\mathrm{hidden}}. Real kernels may exploit masking and attention variants differently. Doubling context adds a superlinear attention component but does not double every serving cost.

Memory formulas

Weight memory is:

Mweights=N×bbytesM_{weights}=N\times b_{bytes}

Nominal payload bytes per scalar are 44 for fp32, 22 for bf16, 11 for int8 and 0.50.5 for packed int4. Quantization scales, zero points, alignment, unquantized layers and runtime state are additional. KV cache per token is:

MKV,token=2LlayersnkvdheadbbytesM_{KV,token}=2L_{layers}n_{kv}d_{head}b_{bytes}

Multiply by cached tokens and independent request sequences when no prefix sharing applies. Count allocated pages, variable lengths, sliding windows, tensor-parallel placement and cache precision separately. LoRA trainable parameters for one adapted matrix are:

PLoRA=r(din+dout)P_{LoRA}=r(d_{in}+d_{out})

Worked weight and cache examples

Treating the nominal “27B” parameter count as exactly 27×10927\times10^9 for illustration gives this fp32 weight payload:

27×109×4=108 GB at fp3227\times10^9\times4=108\text{ GB at fp32}

An 80 GB80\,\mathrm{GB} usable device budget cannot hold that fp32 payload. The same rounded-count payload is 54 GB54\,\mathrm{GB} at bf16 and 27 GB27\,\mathrm{GB} at int8 before quantization metadata, KV cache and runtime overhead; it is not an all-in fit guarantee for a named checkpoint. For Llama 3.13.1 8B with 32 layers, eight key-value heads, head dimension 128, and bf16:

2×32×8×128×2=131072 bytes=128 KiB per token2\times32\times8\times128\times2 =131072\text{ bytes} =128\text{ KiB per token}

A 2,048-token context uses:

2048×128 KiB=256 MiB2048\times128\text{ KiB}=256\text{ MiB}

per concurrent request. The source labels this 256 MB256\,\mathrm{MB} even though its KiB-based arithmetic yields 256 MiB256\,\mathrm{MiB}.

Worked latency examples

For an 8B model with 32 layers, hidden size 4,0964{,}096, and context 2,0482{,}048:

(2×8×109×2,048)+(2×32×2,048×2,049×4,096)=33,868,048,498,688 FLOP.(2\times8\times10^9\times2{,}048) +(2\times32\times2{,}048\times2{,}049\times4{,}096) =33{,}868{,}048{,}498{,}688\ \mathrm{FLOP}.

At the stipulated achieved throughput 3.4×1014 FLOP s−13.4\times10^{14}\,\mathrm{FLOP\,s^{-1}}, the compute proxy is:

33,868,048,498,6883.4×1014 s≈99.611907 ms.\frac{33{,}868{,}048{,}498{,}688}{3.4\times10^{14}}\,\mathrm s\approx99.611907\,\mathrm{ms}.

For a nominal 110110-million-parameter cross-encoder over 5050 total query-document pairs of 256256 tokens each, parameter-matmul work alone is:

2×110×106×256×50=2.816×1012 FLOP.2\times110\times10^6\times256\times50=2.816\times10^{12}\ \mathrm{FLOP}.

At the same stipulated throughput, before attention and all serving overhead:

tlinear≈2.816×10123.4×1014 s≈8.282353 ms,Wwith attention≈2.816×1012+4(12)(2562)(768)(50)=2.9367959552×1012 FLOP,twith attention≈8.637635 ms.\begin{aligned} t_{\mathrm{linear}}&\approx\frac{2.816\times10^{12}}{3.4\times10^{14}}\,\mathrm s\approx8.282353\,\mathrm{ms},\\ W_{\mathrm{with\ attention}}&\approx2.816\times10^{12}+4(12)(256^2)(768)(50)\\ &=2.9367959552\times10^{12}\ \mathrm{FLOP},\\ t_{\mathrm{with\ attention}}&\approx8.637635\,\mathrm{ms}. \end{aligned}

Worked LoRA example

Use rank 16 adapters on query and output projections of size 4,0964{,}096 by 4,0964{,}096 across 32 layers:

16(4,096+4,096)×2×32=8,388,608.16(4{,}096+4{,}096)\times2\times32=8{,}388{,}608.

The corresponding two full square projections per layer contain 4,0962×2×32=1,073,741,8244{,}096^2\times2\times32=1{,}073{,}741{,}824 parameters. Comparing only those adapted matrices:

8,388,6081,073,741,824=0.0078125=0.78125%,4,0962×16=128.\frac{8{,}388{,}608}{1{,}073{,}741{,}824}=0.0078125=0.78125\%,\qquad \frac{4{,}096}{2\times16}=128.

Conditions, failures, and rules

  • Prefill is often compute-limited at useful batch sizes; low-batch decode is often memory-bandwidth-limited. These are regimes to measure, not universal identities.
  • Extra context affects prefill, KV capacity and decode attention/traffic. It need not leave decode tokens/s unchanged.
  • The illustrative 99.611907 ms99.611907\,\mathrm{ms} prefill and 8.282353 ms8.282353\,\mathrm{ms} linear-only rerank use one stipulated rate. They are not observed wall times.
  • LoRA reduces trainable adapted-matrix parameters by 128128 here, not total-model training FLOPs or total GPU memory by that factor.
  • Size weights, cache and runtime for target concurrency and utilization. There is no universal two-to-three-times conversion from peak to achieved throughput.

A.8 Index memory, end to end

Per-vector and total formulas

Sections 16.516.5 and 15.215.2 derive total index memory and the HNSW link term. Per-vector data bytes are:

bvec={4dfor fp32mfor PQ with k=256b_{vec}= \begin{cases} 4d & \text{for fp32}\\ m & \text{for PQ with }k=256 \end{cases}

Posting identifiers use:

bid=4 to 8 bytesb_{id}=4\text{ to }8\text{ bytes}

Under independent geometric HNSW layer allocation Pr⁡(ℓ≥j)=M−j\Pr(\ell\ge j)=M^{-j}, four-byte neighbor slots, 2M2M base slots and MM slots per allocated upper layer, the expected slot payload is:

E[blink]=4(2M+MM−1) B,M>1.\mathbb E[b_{\mathrm{link}}]=4\left(2M+\frac{M}{M-1}\right)\,\mathrm B,\qquad M\gt 1.

This graph term is zero for a plain IVF index, but not necessarily for an IVF coarse quantizer that itself uses HNSW. Layer counters, offsets, actual containers and unused slot capacity are not covered by the expression. Include only the structures present in the chosen implementation; a separate posting ID can be absent when positions supply identity. For IVF/PQ indicators and a remainder covering transforms, precomputed tables, maps and metadata:

E[Mindex]=N(bvec+bid+E[blink])+1IVF 4nlistd B+1PQ 4kd B+Mother.\begin{aligned} \mathbb E[M_{\mathrm{index}}]={}&N\bigl(b_{\mathrm{vec}}+b_{\mathrm{id}}+\mathbb E[b_{\mathrm{link}}]\bigr)\\ &+\mathbf1_{\mathrm{IVF}}\,4n_{\mathrm{list}}d\,\mathrm B +\mathbf1_{\mathrm{PQ}}\,4kd\,\mathrm B+M_{\mathrm{other}}. \end{aligned}

For RR live index copies and index-only rebuild overlap fraction hIh_I, payload replication RPR_P and payload rebuild fraction hPh_P, one explicit fleet ledger is:

Mfleet=R(1+hI)Mindex+RP(1+hP)Mpayload+Mruntime.M_{\mathrm{fleet}}=R(1+h_I)M_{\mathrm{index}}+R_P(1+h_P)M_{\mathrm{payload}}+M_{\mathrm{runtime}}.

Layer zero stores up to:

M0=2MM_0=2M

The expected number of allocated upper layers is a geometric tail sum, not an exact layer count for every node:

E[blink]=4(2M+M∑j≥1M−j) B=4(2M+MM−1) B.\mathbb E[b_{\mathrm{link}}]=4\left(2M+M\sum_{j\ge1}M^{-j}\right)\,\mathrm B=4\left(2M+\frac{M}{M-1}\right)\,\mathrm B.

At M=32M=32:

E[blink]=4(64+3231) B≈260.129032 B.\mathbb E[b_{\mathrm{link}}]=4\left(64+\frac{32}{31}\right)\,\mathrm B\approx260.129032\,\mathrm B.

The base-layer-only slot payload is 256 B256\,\mathrm B at M=32M=32. The expected upper-layer addition is approximately 4.129032 B4.129032\,\mathrm B, or 1.612903%1.612903\% of that base payload. This is not a complete all-in Faiss memory rule. The next table deliberately compares only vector/code and base-layer slots; IVF adds its stated posting IDs.[3]

Ten-million-vector comparison

Use 10 million chunks and d=768d=768.

Configuration Scoped bytes/vector Corpus subtotal Ratio to raw subtotal
HNSW-Flat, M=16M=16 3,072+128=3,200 B3{,}072+128=3{,}200\,\mathrm B 32.0 GB32.0\,\mathrm{GB} 11
HNSW over 6464-byte PQ 64+128=192 B64+128=192\,\mathrm B 1.92 GB1.92\,\mathrm{GB} 16.66666716.666667 times smaller
Faiss-style IVF-PQ, 9696-byte code 96+8=104 B96+8=104\,\mathrm B 1.04 GB1.04\,\mathrm{GB} 30.76923130.769231 times smaller

The compressed-HNSW subtotal has 128/192=2/3128/192=2/3 of its bytes in base-layer links. With this link allocation fixed, sending vector payload to zero can reduce that subtotal by at most 192/128=1.5192/128=1.5 further. Link widths and topology can be redesigned, so “incompressible” is not an information-theoretic claim. A four-byte-ID toy IVF-PQ posting would be 100 B100\,\mathrm B and 1.00 GB1.00\,\mathrm{GB}, unlike the eight-byte Faiss posting.

Rebuild, replication, and payload

If a full old and new index coexist in the declared capacity domain, index-only overlap can require:

hI=1.h_I=1.

A separate build host moves that memory elsewhere in the fleet. A target reserve such as the following is a planning assumption, not a consequence of hot swapping:

hI≈0.2(example reserve, not a bound).h_I\approx0.2\quad\text{(example reserve, not a bound).}

At 400400 tokens/chunk, stipulate four UTF-8 bytes/token, not merely four Unicode characters/token. Uncompressed text then uses 1,600 B=1.6 kB1{,}600\,\mathrm B=1.6\,\mathrm{kB} per chunk. At 10710^7 chunks:

107×1,600 B=16 GB.10^7\times1{,}600\,\mathrm B=16\,\mathrm{GB}.

Metadata at 200 B200\,\mathrm B per chunk adds 2 GB2\,\mathrm{GB}, giving an 18 GB18\,\mathrm{GB} payload before compression, object overhead and additional copies. Using only the 1.04 GB1.04\,\mathrm{GB} Faiss posting subtotal, two live copies, full index-only rebuild overlap, two payload copies and no payload rebuild gives:

2×2×1.04+2×18=40.16 GB.2\times2\times1.04+2\times18=40.16\,\mathrm{GB}.

If the 18 GB18\,\mathrm{GB} payload is instead one shared resident copy, the corresponding subtotal is 2×2×1.04+18=22.16 GB2\times2\times1.04+18=22.16\,\mathrm{GB}. The old 22 GB22\,\mathrm{GB} figure additionally used the four-byte-ID toy 1 GB1\,\mathrm{GB} index. All versions omit remaining index/runtime memory; neither proves fit or availability.

Conditions, failures, and rules

  • Separate capacity, per-query service demand, traffic, replication and failover. Chapter 41’s ceiling estimates are lower bounds rather than a claim that a fixed two-node cluster suffices.
  • Aggregate-memory ceiling division gives only:
nnodes≥⌈Mresident,totalMusable/node⌉.n_{\mathrm{nodes}}\ge\left\lceil\frac{M_{\mathrm{resident,total}}}{M_{\mathrm{usable/node}}}\right\rceil.
  • Shards are logical partitions; replicas are copies. Aggregate bytes alone do not assign partitions, traffic or failure domains.
  • Text can dominate after compression, but the crossover depends on chunk size, representation, compression and replication; “30 times” is not universal.
  • State identifiers, graph slots, codebooks, coarse centroids, rebuild overlap, payload copies and runtime. A 3232-fold vector-code reduction is not a 3232-fold whole-fleet reduction.

Diagrams

Source visual accounting is 0 figures and 0 tables in the manifest. The source contains display equations and unnumbered numeric grids, not captioned source visuals. This appendix preserves those items as equations and Markdown grids without inventing figure or table numbers.

Whiteboard pack

What to draw

  1. Draw a ranking lane with BM25, RRF, MRR, and nDCG in source order.
  2. Under BM25, split IDF from saturating and length-normalized TF.
  3. Under RRF, draw two ranked lists meeting at the crossover inequality.
  4. Under MRR and nDCG, contrast first-hit credit with graded log-discounted credit.
  5. Draw modularity as observed adjacency minus degree-based expected adjacency.
  6. Draw one vector split into mm PQ subspaces and label kmk^m versus k×mk\times m.
  7. Draw compute, weight, KV cache, and LoRA formulas as a model-serving block.
  8. Finish with the memory stack: vector, id, links, centroids, replicas, rebuild, payload.
  9. Add units to every intermediate value and circle each independent sanity check.

Spoken script

Start with lexical scoring and rank aggregation, then first-hit and graded ranking metrics. State gain, cutoff and missing-judgment policy. Draw modularity as observed connectivity minus a degree-based expectation, with no semantic or global-optimum guarantee. Next show PQ code bits, shared codebooks and scoped memory. Convert model FLOPs into an idealized compute time only under a declared achieved rate. Add attention, weight precision, KV cache and adapter parameters. Finish with a ledger for index structures, payload replication, rebuild copies and runtime; byte ceilings are capacity lower bounds, not deployment plans.

Interview traps

1. Why is a numerically correct answer still wrong?

A value without units, scope, or achieved hardware rate is not defensible. Track bytes versus bits, decimal GB versus KiB, per-token versus per-request cache, per-vector versus fleet memory, and FLOPs versus FLOPs per second. State which local meaning of NN, kk, mm, bb, or QQ applies before substituting.

2. Which ranking formula is being misused?

BM25 length normalization belongs inside the saturation denominator, while RRF uses ranks because source scores are incomparable. MRR reads only the first relevant result, whereas nDCG needs a cutoff, gain scale, and judgment-pool caveat. Diagnose the objective before tuning a constant.

3. Which sanity ablation exposes a false metric or graph claim?

Add a second relevant hit after rank 11: RR remains 11. Permute unequal grades: CG stays fixed while DCG can change. Remove the dangling edge from the four-node graph: both displayed partitions then have modularity 00, a tie rather than a forced reversal. Generic relations may still yield communities, but semantic quality requires its own audit.

4. Why did compression or latency miss the estimate?

For PQ, check whether codebook memory was confused with per-vector codes and whether mm divides dd. For latency, use achieved rather than peak FLOPs per second and include quadratic attention. For index memory, add identifiers, HNSW links, rebuild overlap, replicas, payload, and metadata because a 32 times vector compression does not imply 32 times fleet compression.

5. What claim limits must be said aloud?

The RRF constant is a convention, not an optimum. nDCG needs positive IDCG or an explicit zero-IDCG rule. Modularity has graph- and resolution-dependent limits. The toy PQ operation model gives N∗≈273.066667N^*\approx273.066667 and first strict integer saving at 274274. The compute times use unrounded arithmetic and one assumed rate; metadata, payload copies, model architecture and batching can change the answer.

Key numbers

Topic Key values Use and limit
Formula-sheet reliance Two weeks If the sheet is still needed, re-derive each formula instead of re-reading it
BM25 defaults and limits k1=1.2k_1=1.2, b=0.75b=0.75; b∈[0,1]b\in[0,1] Illustrative parameters, not universal defaults
BM25 TF limit 1.0001.000, 1.3751.375, 1.7741.774, 1.9641.964, 2.0752.075, 2.2002.200 Frequencies 1, 2, 5, 10, 20, and infinity
BM25 length case K=2.1K=2.1, factor ≈0.709677\approx0.709677 About 29.0323%29.0323\% factor decrease versus average length
BM25 lower length setting Example b=0.3b=0.3; unshifted IDF negative above half Tune by evaluation; the displayed shifted IDF stays positive
RRF default k=60k=60 Conventional original evaluation value
RRF crossovers Equal-rank tie points 6262, 123123, and 22 at k=0k=0 Strict victories are below the tie point; no general interleaving conclusion
RRF deep fusion Example depth 100100, final depth 1010 Tune jointly with candidate coverage and costs
RR grid and false formula 1, 0.5, 0.333, 0.2, 0.1, 01,\ 0.5,\ 0.333,\ 0.2,\ 0.1,\ 0, and non-MRR 0.110.11 First hit at 1, 2, 3, 5, 10, absent, plus the rejected two-hit calculation
nDCG discount grid Log values 1.0001.000, 1.5851.585, 2.0002.000, 2.5852.585, 3.4593.459 and weights 1.0001.000, 0.6310.631, 0.5000.500, 0.3870.387, 0.2890.289 Ranks 1, 2, 3, 5, and 10
nDCG range and grades [0,1][0,1] for nonnegative gains and positive IDCG State gain, judgment universe, cutoff and zero-IDCG policy
Modularity toy m=4m=4, 2m=82m=8, contributions −0.125-0.125 and −0.125-0.125, QA=−0.03125Q_A=-0.03125, QB=0Q_B=0 Merge gain is 0.031250.03125
Modularity resolution 2meAB>KAKB2me_{AB}\gt K_AK_B favors merging No universal internal-edge cutoff or every-level absorption guarantee
PQ design d=768d=768, m=96m=96, k=256k=256 Eight dimensions and one byte per subvector
PQ compression 3,0723{,}072 bytes to 96 bytes, 32 times Vector-only compression
PQ combinations 2768≈1.55251809×102312^{768}\approx1.55251809\times10^{231} 24,57624{,}576 stored centroids; not materialized combinations
PQ codebook 196,608196{,}608 fp32 scalars; 786,432 B=768 KiB786{,}432\,\mathrm B=768\,\mathrm{KiB} Also 786.432 kB786.432\,\mathrm{kB}; fixed k,dk,d and precision
PQ break-even N∗≈273.066667N^*\approx273.066667; strict whole count 274274 Simplified operation model, not measured latency
PQ single codebook 2322^{32} centroids; ≈13.19414 TB\approx13.19414\,\mathrm{TB} A corpus multiplier needs an explicit corpus size
PQ training rule 39×256=9,98439\times256=9{,}984 source training vectors Faiss warning heuristic; same vectors project into each subspace
Compute and precision rules Forward 2N2N, backward 4N4N, training 6N6N, fp32 4 bytes, bf16 2, int8 1, int4 0.50.5 Per-token FLOPs and per-scalar bytes
Gemma 2 27B weights 108 GB108\,\mathrm{GB} fp32, 54 GB54\,\mathrm{GB} bf16, 27 GB27\,\mathrm{GB} int8, 80 GB80\,\mathrm{GB} card Excludes context cache and fp32 does not fit
Llama 3.13.1 8B KV 128 KiB per token, 256 MiB256\,\mathrm{MiB} at 2,0482{,}048 tokens The source labels the binary result 256 MB256\,\mathrm{MB} per concurrent request
Prefill 33,868,048,498,688 FLOP33{,}868{,}048{,}498{,}688\,\mathrm{FLOP}; ≈99.611907 ms\approx99.611907\,\mathrm{ms} Causal-pair attention proxy at the stipulated achieved rate
Reranking 2.816×1012 FLOP2.816\times10^{12}\,\mathrm{FLOP}, 8.282353 ms8.282353\,\mathrm{ms} linear only With stated bidirectional attention: 2.9367959552×1012 FLOP2.9367959552\times10^{12}\,\mathrm{FLOP}, 8.637635 ms8.637635\,\mathrm{ms}
LoRA 8,388,6088{,}388{,}608 versus 1,073,741,8241{,}073{,}741{,}824; 0.78125%0.78125\% A 128128-fold reduction only in the adapted-matrix trainable parameters
HNSW links Expected 260.129032 B260.129032\,\mathrm B versus base-only 256 B256\,\mathrm B M=32M=32; 1.612903%1.612903\% extra slot payload, not exact node memory
HNSW-Flat 3,200 B3{,}200\,\mathrm B/vector; 32.0 GB32.0\,\mathrm{GB} Vector/base-slot subtotal only
HNSW-PQ 192 B192\,\mathrm B/vector; 1.92 GB1.92\,\mathrm{GB} 16.66666716.666667 times smaller subtotal; 2/32/3 base links
IVF-PQ Faiss 104 B104\,\mathrm B/posting, 1.04 GB1.04\,\mathrm{GB} 96+896+8 bytes; toy 96+4=10096+4=100 is a different ID assumption
Rebuild headroom hI=1h_I=1 for a full overlapping copy; 0.20.2 is an example reserve Separate build hosts still consume fleet resources
Payload 16 GB16\,\mathrm{GB} text plus 2 GB2\,\mathrm{GB} metadata Assumes four bytes/token and one declared payload copy
Fleet example 40.16 GB40.16\,\mathrm{GB} with two payload copies; 22.16 GB22.16\,\mathrm{GB} shared Scoped posting subtotal, two live copies, full index rebuild overlap; runtime omitted
Payload crossover Workload-dependent, not a universal 3030-fold threshold Count text compression, code size, links and copy policies

00-START-HERE · 01-READING-ROUTES · 41_end_to_end_design_drills · A2_question_bank

Contents

Search the book

Search all 60 pages. Try “chunking”, “latency”, or “evaluation”.