← 18 Session 20 - An explicit index of the training data - Mon 23 Nov 22 →
All decks
  1. 1 Why retrieval nowMon 31 Aug
  2. 2 The inverted indexWed 02 Sep
  3. 3 Index construction and ranking foundationsMon 07 Sep
  4. 4 BM25: finish probabilistic rankingWed 09 Sep
  5. 5 Evaluation and the changing goals of retrieval benchmarksMon 14 Sep
  6. 6 Coarse retrieval and rerankingWed 16 Sep
  7. 7 LLM embeddings and rerankingMon 28 Sep
  8. 9 Hard queries: reasoning and ambiguityWed 07 Oct
  9. 10 Approximate nearest neighbour search and search systemsMon 12 Oct
  10. 12 Agentic memory - introduction, desiderata, and evaluationMon 26 Oct
  11. 14 Agentic memory - approaches and handcrafted methodsMon 02 Nov
  12. 16 Agentic memory - RL methods and wrap-upMon 09 Nov
  13. 18 Retrieval from the parametersMon 16 Nov
  14. 20 An explicit index of the training dataMon 23 Nov
  15. 22 Architectural lookupMon 30 Nov
  16. 24 Retrieval from the context - attention and the KV cacheMon 07 Dec
  17. 25 Retrieval from the context - which tokens are readWed 09 Dec
  18. 26 Course wrap-upMon 14 Dec
Contents
  1. 1Non-parametric learning, kernels, and retrieval
  2. 2Upcoming sessions
  3. 3Today
  4. 4Kernel machines predict by retrieving from the training data
  5. 5kNN predicts from the nearest training examples
  6. 6Nadaraya-Watson softens the vote
  7. 7Can any model be considered a kernel machine?
  8. 8The representer theorem
  9. 9A linear layer is attention over its training inputs
  10. 10Quiz: two training pairs in one step
  11. 11The last layer is a weighted sum over training points
  12. 12Inhibitory training points explain a mistake
  13. 13The whole network is a kernel machine in a limit
  14. 14Domingos integrates the kernel along the training path
  15. 15Where the kernel view holds for language models
  16. 16Influence functions approximate any model as a kernel machine
  17. 17Why view learning as retrieval?
  18. 18Influence functions score training points with a kernel
  19. 19Attribution methods differ in the kernel
  20. 20Influence is retrieval with gradient keys
  21. 21Stored gradient keys for a pretraining corpus
  22. 22The metric decides which relevance you get
  23. 23What is retrieved changes with scale
  24. 24Influence is expensive to read
  25. 25An explicit datastore of the training data
  26. 26kNN-LM stores one entry per training token
  27. 27Neighbours vote with a kernel
  28. 28Interpolate the datastore and the model
  29. 29Does the datastore help reasoning?
  30. 30SILO splits low-risk weights from a high-risk datastore
  31. 31Wrap-up
  32. 32Next time

The recording

1

Non-parametric learning, kernels, and retrieval

Information retrieval for AI

23 November 2026

Seong Joon Oh - KAIST AI

2

Upcoming sessions

25 November - Interpolation or extrapolation

The anchor paper is Reasoning or Reciting? (Wu et al., NAACL 2024). Preparation is due 24 November, 18:00 KST.

2 December - Weights or an explicit store

Preparation is due 1 December, 18:00 KST.

Roles and readings are in the course schedule.

3

Today

Session 18 postulated a connection between learning and search. Learning retrieves from past experience, that is, the training data. Today we go deeper into this view.

  1. Kernel machines predict by retrieving from the training data
  2. Can any model be considered a kernel machine?
  3. Influence functions approximate any model as a kernel machine
  4. An explicit datastore of the training data
4

Kernel machines predict by retrieving from the training data

5
Constructed diagram. With k = 3, the nearest training points are two of class A and one of class B, so the vote predicts A.
Constructed diagram. With k = 3, the nearest training points are two of class A and one of class B, so the vote predicts A.

kNN predicts from the nearest training examples

Store every training pair .

For a new input , find the training inputs closest to .

Predict by a vote over their labels.

The training set is the model. Prediction is a retrieval step.

Cover and Hart, IEEE Trans. Inf. Theory 1967.

6

Nadaraya-Watson softens the vote

Every training example votes. Its weight is its similarity to , and the weights sum to one.

With , close examples dominate and distant ones fade. Hard kNN keeps the top and drops the rest.

1 0 x_i distance from x_i h = 2 h = 0.5

Plotted from for a single training point. Not a reported result. A smaller narrows the vote towards the nearest example.

7

Can any model be considered a kernel machine?

8

The representer theorem

Fix a kernel function . It is positive definite and measures the similarity of two inputs.

Fit a smooth to the training pairs by solving

The penalty keeps smooth.

Every minimiser has the form

This weighted sum of kernels over the training set is a kernel machine. A prediction compares the query with every training input.

Kimeldorf and Wahba, J. Math. Anal. Appl. 1971. Schölkopf, Herbrich, and Smola, COLT 2001.

9
Irie et al. (2022), Fig. 2. The dual form of a linear layer trained by gradient descent.
Irie et al. (2022), Fig. 2. The dual form of a linear layer trained by gradient descent.

A linear layer is attention over its training inputs

Gradient descent adds one outer product per step. is the layer input and is the error signal.

For a new input the layer outputs

The training inputs are the keys, the error signals are the values, and the new input is the query. The identity is exact and needs no limit.

Irie, Csordás, and Schmidhuber, ICML 2022, Eqs. 11 and 13.

10

Quiz: two training pairs in one step

Take with , one training pair , squared loss, and step .

The gradient is , so one step gives . At the prediction moves from to .

Read the same step as retrieval with . The key is the training input . The value is the error signal . The query is .

The change is similarity times value, .

Now add a second pair and take one step from on both pairs. Each pair adds its own term, .

(x₁, y₁) = (1, 2) (x₂, y₂) = (-1, 1) w = 1 after a step on (x₁, y₁) 0 → 3 query x = 2 x w₀ = 0 -1 1 3 2 3

How does each pair contribute to the new weight w, and what is the prediction at x = 2?

Sign in with your course account to choose. The lecturer will reveal responses and the answer.

Constructed arithmetic, not a reported result.

11
Yeh et al. (2018), Fig. 4. Positive (excitatory) and negative (inhibitory) training images, with influence functions on the right.
Yeh et al. (2018), Fig. 4. Positive (excitatory) and negative (inhibitory) training images, with influence functions on the right.

The last layer is a weighted sum over training points

This is a theorem, not an empirical finding. Write the pre-softmax output as , where holds the penultimate features and is the last layer. Let be the features of training input .

It holds under two conditions.

  • The training loss adds an L2 penalty on the last layer.
  • The weights sit at a stationary point, so the gradient with respect to is zero.

Then, for any test input ,

Each training point contributes its feature similarity to , scaled by . is the loss gradient at , one entry per class. A positive contribution raises that class’s logit at and is called excitatory. A negative one lowers it and is called inhibitory.

A network trained with SGD rarely reaches an exact stationary point. The authors therefore fine-tune only the last layer, with the L2 penalty, until it does.

Yeh, Kim, Yen, and Ravikumar, NeurIPS 2018, Theorem 3.1 and §3.1.

12
Yeh et al. (2018), Fig. 5. A misclassified antelope (left) and four training images with the most inhibitory representer values.
Yeh et al. (2018), Fig. 5. A misclassified antelope (left) and four training images with the most inhibitory representer values.

Inhibitory training points explain a mistake

A training point is inhibitory for a class when its term for that class is negative. The test image resembles it in feature space, and that similarity lowers the class score. An excitatory point raises it.

The model is a ResNet-50 on Animals with Attributes. Of 181 test antelopes, 15 are misclassified and 12 of those as deer.

All 12 have the same four training images among their top inhibitory points. Those images show small antelopes beside larger animals and carry the larger animal’s label, such as zebra or elephant.

The model learns to suppress the antelope class for an image with small antelopes and other large objects.

Yeh et al., NeurIPS 2018, §3, §4.3, and Fig. 5.

13

The whole network is a kernel machine in a limit

This is a theorem about an idealised network, not an empirical finding. The neural tangent kernel (NTK) is

It measures how far a small gradient step on moves the output at .

The result holds under four conditions.

  • The network is fully connected, and every hidden layer is infinitely wide.
  • The weights start as independent Gaussians, scaled by .
  • Training is gradient descent with infinitesimal steps.
  • The nonlinearity is smooth and Lipschitz.

Then is fixed at initialisation and does not change during training. With squared loss, and positive definite on the training inputs, training ends at

is the kernel matrix over the training inputs. The first term is kernel regression on the training labels, the form the representer theorem gives. comes from the random initial network and is zero on every training input.

Jacot, Gabriel, and Hongler, NeurIPS 2018, Theorems 1 and 2 and §5.

14
Domingos (2020), Fig. 2. The query is compared with every training example through the kernel, and the weighted sum gives the answer.
Domingos (2020), Fig. 2. The query is compared with every training example through the kernel, and the weighted sum gives the answer.

Domingos integrates the kernel along the training path

This is a theorem, not an empirical finding. It holds under two conditions.

  • The model and the loss are differentiable in the weights .
  • Training is gradient descent on the loss summed over the training set, with infinitesimal steps.

Unlike the infinite-width result, it needs no width or initialisation condition. The trained model is

is the path of the weights during training, and adds up the tangent kernel along it. is the initial model. is the negative loss derivative at , averaged along the path and weighted by its tangent-kernel similarity to .

Remark 1 states that “the ‘s and depend on ”. So the form is not a fixed kernel machine. The theorem rewrites the trained function. It does not give a store of training examples you can query after training.

Domingos, arXiv 2020, Theorem 1 and Remark 1.

15
Malladi et al. (2023), Fig. 1. Performance gap between SGD fine-tuning and kernel regression, for standard and prompt-based fine-tuning.
Malladi et al. (2023), Fig. 1. Performance gap between SGD fine-tuning and kernel regression, for standard and prompt-based fine-tuning.

Where the kernel view holds for language models

The study fine-tunes RoBERTa-base with prompts on 14 few-shot tasks. The kernel is the empirical NTK at the pre-trained weights,

  • On 12 tasks, kernel regression with comes close to fine-tuning, with no gradient training.
  • On 8 of them, fine-tuning itself behaves as a kernel method. The model stays close to linear in its weights, and barely changes.

Malladi et al., ICML 2023, Table 1 and §6.1.

16

Influence functions approximate any model as a kernel machine

17

Why view learning as retrieval?

The previous section gave a theoretical understanding of learning as retrieval. A trained model can be written as a sum over its training points.

The rest of today asks what this view buys in practice. A model that retrieves from its training data supports two operations.

  • Knowledge tracing. Name the training examples behind an output.
  • Knowledge update. Change what the model knows by adding or removing training examples.

Influence functions trace knowledge in any trained model, approximately. An explicit datastore makes both operations lookups. Distilling the datastore back into weights loses them.

18

Influence functions score training points with a kernel

Influence functions apply the kernel-machine form to any trained model. They ask which training points moved a given prediction, and score each point for the test input as

is a global weight that does not depend on , and is a kernel. Tsai et al. prove that an explanation meeting five axioms has exactly this form. The methods differ in the kernel, and the score reads as retrieval with gradient keys.

Tsai, Yeh, and Ravikumar, NeurIPS 2023, Theorem 7.

19

Attribution methods differ in the kernel

MethodKernel
Representer points over penultimate features
TracIn over checkpoints
Influence functions

In each case the global weight is a loss derivative at .

Tsai et al., NeurIPS 2023, Eqs. 12, 14, and 16.

20

Influence is retrieval with gradient keys

The key is the training gradient and the query is the test gradient . The score is , and the top- scores are returned.

Method
TracIn
Koh and Liang
Grosse et al. (EK-FAC)

The methods share the form and differ in quality. Plain dot products of gradients reach an MRR of 0.003 on fact tracing at 8B.

Koh and Liang, ICML 2017. Grosse et al., 2023, Eq. 25. Chang et al., ICLR 2025, Table 2.

21
Chang et al. (2025), Fig. 1. Top C4 proponents retrieved by TrackStar for a factual query.
Chang et al. (2025), Fig. 1. Top C4 proponents retrieved by TrackStar for a factual query.

Stored gradient keys for a pretraining corpus

  • TrackStar scores a training passage by the cosine between its gradient and the query’s gradient, both corrected and randomly projected.
  • Each training key is computed once and reused for every query.
  • For an 8B model over 365M C4 passages, the keys take 87 TB. A query costs one gradient and one scan of the keys.

Chang et al., ICLR 2025, Fig. 1, Eq. 1, §3, and §6.

22

The metric decides which relevance you get

The 8B model retrieves from all 365M C4 passages for T-REx facts.

RetrieverEvidence (MRR)Influence (one-step gain)
BM250.687+0.83%
TrackStar0.338+2.11%

Evidence counts passages that state the fact. Influence is the target gain after one training step on the retrieved passages.

BM25 finds the evidence a reader accepts. Gradients find what changed the model.

“a misalignment between factual attribution and causal influence”

Chang et al., ICLR 2025, Table 2 and abstract.

23
Grosse et al. (2023), Fig. 13. Influential sequences for the math_clips query on the 810M and 52B models.
Grosse et al. (2023), Fig. 13. Influential sequences for the math_clips query on the 810M and 52B models.

What is retrieved changes with scale

The query is a GSM8k problem. “Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May…”

For the 810M model, an influential sequence describes clips that secure an elevator. It shares the word, not the task.

For the 52B model, an influential sequence works through arithmetic on the friendship paradox.

“Larger models consistently generalize at a more abstract level than smaller models”

Grosse et al., 2023, Fig. 13 and p. 8.

24

Influence is expensive to read

Each read needs a gradient for the query, a curvature approximation, and a scan over stored training gradients.

The result is an estimate of influence, not a record of the source.

The next step stores the training data directly and looks it up.

25

An explicit datastore of the training data

26
Khandelwal et al. (2020), Fig. 1. Datastore construction and the interpolated kNN-LM prediction.
Khandelwal et al. (2020), Fig. 1. Datastore construction and the interpolated kNN-LM prediction.

kNN-LM stores one entry per training token

The key is the input to the final feed-forward layer for context . The value is the next token.

WikiText-103 gives 103M entries. The model is not retrained.

Khandelwal et al., ICLR 2020, §2 and Eq. 1.

27

Neighbours vote with a kernel

𝟙

holds the nearest keys to , and is the squared L2 distance.

This is Nadaraya-Watson over training tokens, in the model’s own representation space. The paper calls it an RBF kernel.

Khandelwal et al., ICLR 2020, Eq. 2.

28

Interpolate the datastore and the model

A 247M model on WikiText-103 retrieves neighbours from its own training set. Test perplexity falls from 18.65 to 16.12.

The authors conclude that “learning similarity between sequences of text is easier than predicting the next word”.

Khandelwal et al., ICLR 2020, Eq. 3, Table 1, and abstract.

29
Geng et al. (2025), Fig. 1. A relevant neighbour fails to raise the correct answer in a multi-hop question.
Geng et al. (2025), Fig. 1. A relevant neighbour fails to raise the correct answer in a multi-hop question.

Does the datastore help reasoning?

The table gives Llama-3-8B accuracy when the answer is placed among the retrieved neighbours.

TaskLMkNN-LM with the answer
NQ23.6446.40
HotpotQA25.1449.85

Perplexity on NQ falls from 112.56 to 8.91. About half of the questions still fail.

“even with perfect retrieval, kNN-LMs still fail to determine the correct answers”

Geng, Zhao, and Rush, NAACL 2025, Table 6 and abstract.

30
Min et al. (2024), Fig. 1. Low-risk data in the parameters, high-risk data in a test-time datastore.
Min et al. (2024), Fig. 1. Low-risk data in the parameters, high-risk data in a test-time datastore.

SILO splits low-risk weights from a high-risk datastore

  • The weights train on 228B tokens of public-domain and permissively licensed text. Copyrighted text sits in a datastore, read only at inference through kNN-LM.
  • The datastore closes 91% of the out-of-domain perplexity gap to Pythia-1.4B (19.0 to 12.0, against 11.3).
  • Deleting an entry needs no retraining, and attribution reads the retrieved entries. Neither covers what the weights learned.

Min et al., ICLR 2024, Fig. 1, Table 4, and §6.

31

Wrap-up

  • Kernel machines predict by a similarity-weighted vote over training examples.
  • Trained networks behave as kernel machines. The result is exact for one linear layer and for the last layer, and holds for the whole network in a limit or with query-dependent weights.
  • Influence functions read this form from any trained model. Each read needs gradients, a curvature approximation, and terabytes of stored keys.
  • An explicit datastore makes the retrieval literal. kNN-LM lowers perplexity with no extra training, and SILO turns deletion and attribution into lookups for the data it stores.
32

Next time

Can the store live inside the network and stay addressable?