Problem
Teams that classify objects with k-nearest neighbors (kNN) find that training is easy but serving is hard. In production, new classes appear and need predictions quickly. A usual model must be retrained for each new set of classes, which is often slow and expensive. A kNN solution predicts a new class as soon as enough examples of it exist, but only if the vector space can be updated while the service is running.
Example from the article: Kontur ran different algorithms in production, met these problems and built its own vector-space service.
Solution in brief
The system has four parts: a vectorization model service, a daemon that fills the space, a main service that answers queries, and one abstraction over the vector space that searches and updates it. Build that abstraction first on a library such as faiss, annoy or nmslib behind an HTTP API, then add versioning, sharding and filters as the load grows.
Questions this case answers
- How to serve nearest-neighbor classification over a vector space that must be updated online, without retraining a model for every new class
- How to scale and version a vector search service so that algorithm changes can be rolled back and A/B tested
- How to serve a kNN classifier in production so that new classes start working without retraining?
- How to keep a vector space updatable (add and remove vectors) while serving nearest-neighbor queries?
Tools and methods
- k-nearest neighbors — classify an object by the classes of its closest vectors
- Vector search — find the k closest vectors to a query vector
- FAISS, Annoy — libraries for nearest-neighbor search (nmslib is also named)
- Vektonn — the service Kontur shared with the community (the author gives no internals)
Google or a one-time email code. No password.
