How do memory access and cache behavior affect real-time KNN latency compared to logistic regression?

Quick Overview

Asks how memory access patterns and CPU cache behavior shape real-time k-nearest neighbors inference latency, compared with a parametric model like logistic regression. Tests reasoning about bytes read per query, index traversal, tail latency and practical ways to speed up KNN serving.

How do memory access and cache behavior affect real-time KNN latency compared to logistic regression?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

How do memory access patterns and cache behavior affect real-time k-nearest neighbors (KNN) inference latency, compared with a parametric model such as logistic regression? ```hint Count the bytes For one prediction, estimate how many bytes each model has to read and which level of the memory hierarchy (L1, L2/L3 or DRAM) those bytes come from. ``` ```hint Look at the access pattern Compare a sequential scan over all training points, a tree or graph traversal, and a single weight vector reused by every request. Think about prefetching and cache hits in each case. ``` ### What a Strong Answer Covers - How many bytes a KNN query reads compared with a logistic regression prediction, and where in the memory hierarchy those bytes live - Why brute-force KNN is limited by memory bandwidth and how its latency grows with the training set - How tree and graph indexes change the access pattern, and the effect on cache misses and p99 latency - Why logistic regression latency is small, fixed and independent of training set size - Concrete ways to cut KNN latency and what each one costs ### Follow-up Questions - How would you estimate brute-force query latency for 10 million vectors of 768 dimensions, and which change would you make first? - Batching queries turns distance computation into a matrix multiply. What does that do to throughput and to the latency of a single request? - How does product quantization reduce memory traffic, and what does it cost in recall? - When does moving KNN search to a GPU help, and when does it not?

Overview: Asks how memory access patterns and CPU cache behavior shape real-time k-nearest neighbors inference latency, compared with a parametric model like logistic regression. Tests reasoning about bytes read per query, index traversal, tail latency and practical ways to speed up KNN serving.

Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

How do memory access patterns and cache behavior affect real-time k-nearest neighbors (KNN) inference latency, compared with a parametric model such as logistic regression?

What a Strong Answer Covers Guidance

  • How many bytes a KNN query reads compared with a logistic regression prediction, and where in the memory hierarchy those bytes live
  • Why brute-force KNN is limited by memory bandwidth and how its latency grows with the training set
  • How tree and graph indexes change the access pattern, and the effect on cache misses and p99 latency
  • Why logistic regression latency is small, fixed and independent of training set size
  • Concrete ways to cut KNN latency and what each one costs

Follow-up Questions Guidance

  • How would you estimate brute-force query latency for 10 million vectors of 768 dimensions, and which change would you make first?
  • Batching queries turns distance computation into a matrix multiply. What does that do to throughput and to the latency of a single request?
  • How does product quantization reduce memory traffic, and what does it cost in recall?
  • When does moving KNN search to a GPU help, and when does it not?