HN user

Jashwanth01

14 karma

AI/ML Engineer & Researcher. Building practical, production ready ML systems and exploring real-world applications of AI. Always experimenting, learning, and sharing.

Posts2
Comments9
View on HN
[dead] 5 months ago

A few days ago I shared SmartKNN. I’ve now added full benchmark results.

I ran regression and classification benchmarks on multiple OpenML datasets. Everything was run on Kaggle CPU (no GPU).

What I measured: 1. 3-fold CV metrics 2. Test metrics 3. Single inference P95 latency

All models were run with default settings. No hyperparameter tuning...

1. Preprocessing was consistent across models- Median imputation for missing values 2. Target encoding for categorical features (done fold-wise to avoid leakage) 3. Scaling applied only to KNN and Linear models No dataset-specific tricks...

The goal here was to understand the practical tradeoffs of a weighted KNN under real CPU constraints, especially when you measure single

Full benchmark tables and implementation details are in the repo.. https://github.com/thatipamula-jashwanth/smart-knn If anyone has suggestions for- More datasets to test, Additional baselines to compare, Improvements to the benchmark setup, Better ways to measure latency, I’d appreciate the feedback.

Good Point.. Right Now the benchmarks are mostly tables, So I agree graphs would be much better to understand.. I'll work on adding Visuals( accuracy vs latency, maybe memory too ) similar to ann-benchmarks style. If you've got any datasets or libraries you think i should compare it against, let me know. So far i have mostly tested it against GBMS and Linear models.. but open to trying more.

That’s a fair question... I wrote the implementation and experiments myself. I did use an LLM to refine and structure the README for clarity, but the design, benchmarking, and validation are my own... By (production ready), I mean the system has been validated beyond just accuracy metrics. It has been benchmarked against GBMs and linear models under the same settings for both regression and classification, with competitive results. I’ve also measured batch and single-query latency, including p95 inference time, and tested memory usage under CPU only constraints. It’s been scale-tested into the low millions of samples on limited RAM, with stable behavior across multiple runs and consistent accuracy. And it’s not yet deployed in a live environment this post is partly to gather feedback.. but the claim is based on reproducibility, API stability, deterministic inference, and performance validation. If you think there are additional criteria I should meet before calling it production-ready, I’d genuinely appreciate the feedback..

When I first learned about KNN, I assumed the implementation in scikit-learn was essentially the model. It felt “solved.” You pick k, choose a distance metric, maybe normalize the data, and you’re done.

Then I started asking a simple question: why can’t nearest neighbor methods be both fast and competitive with stronger tabular models in real production settings?

That question led me down a much deeper path than I expected.

First, I realized there isn’t just “KNN.” There are many variations: weighted distances, metric learning, approximate search structures, indexing strategies, pruning heuristics, and hybrid pipelines. I also discovered that most fast approaches trade accuracy for speed, and many accurate ones assume large training time, heavy indexing, or GPU-based vector engines.

I wanted something CPU-focused, predictable, and deployable.

Some of the key things I learned along the way:

Feature importance matters a lot more than I initially thought. Treating all features equally is one of the biggest weaknesses of classical KNN. Noise and irrelevant dimensions directly hurt distance quality.

The curse of dimensionality is not theoretical — it’s painfully practical. In high dimensions, naive distance metrics degrade quickly.

Scaling and normalization are not optional details. They fundamentally shape the geometry of the space.

Inference time often matters more than raw accuracy. In many real-world systems, predictable latency is more valuable than squeezing out 0.5% extra accuracy.

Memory footprint is a first-class concern. Nearest neighbor methods store the dataset; this forces you to think carefully about representation and pruning.

GBMs are not “just models.” They’re systems. After studying gradient boosting more closely, I started seeing it less as a single model and more as a structured system with layered feature selection, residual fitting, and region partitioning. That perspective changed how I thought about improving KNN.

I began experimenting with:

Learned feature weighting to reduce noise.

Feature pruning to reduce dimensional effects.

Vectorized distance computation on CPU.

Integrating approximate neighbor search while preserving final exact scoring.

Structuring the algorithm more like a deployable system rather than a classroom algorithm.

One big realization: no model dominates under every dataset and constraint. There is no universal winner. Performance depends heavily on feature quality, data size, dimensionality, and latency requirements.

Building this forced me to think less about “which algorithm is best” and more about:

What constraints does production impose?

Where is the real bottleneck: compute, memory, or data geometry?

How do we balance accuracy, latency, and simplicity?

I’m still exploring this space and would really appreciate feedback from people who’ve worked on large-scale similarity search or production ML systems.

If anyone has suggestions on:

Better CPU vectorization strategies,

Lessons from deploying nearest-neighbor systems at scale,

Or papers I should study on metric learning / scalable distance methods,

I’d love to learn more.

I’ve put the current implementation on GitHub for anyone curious, but I’m mainly interested in discussion and technical feedback.

Thanks for clarifying... I appreciate you taking the time to explain.

I understand the sensitivity around spam lately. I’m new here and still learning the culture, so the context helps a lot.

I’ll take the feedback on presentation and positioning, polish it properly, and resubmit in a better form. Thanks again for pointing me in the right direction.

Hi HN,

I’ve been working on SmartKNN, a nearest-neighbor system designed specifically for production deployment rather than academic experimentation.

The goal was not to slightly tweak classical KNN, but to restructure it into a deployable, latency-aware system while preserving interpretability.

What it does differently

Traditional KNN is simple and interpretable, but in practice it struggles with:

Inference latency as datasets grow

Equal treatment of all features

Fixed distance metrics

Unpredictable performance under load

SmartKNN addresses these issues through:

1. Learned Feature Weighting

Feature importance is learned automatically and incorporated into the distance computation. This reduces noise and improves neighbor quality without manual tuning.

2. Adaptive Distance Behavior

Distance computation adapts to learned feature relevance instead of relying on a fixed metric like plain Euclidean.

3. Backend Selection

SmartKNN supports both brute-force and approximate nearest-neighbor strategies.

Small datasets → brute-force

Larger datasets → approximate candidate retrieval

Approximate search is used only to retrieve candidates. Final prediction always uses the learned distance function.

4. CPU-Focused Design

The system is optimized for predictable CPU inference performance rather than GPU-heavy workflows. The focus is stable latency characteristics suitable for production workloads.

5. Unified API

Supports both classification and regression through a scikit-learn compatible interface.

Performance

On structured/tabular datasets with strong local structure, SmartKNN achieves competitive accuracy against tree-based models.

It does not aim to replace tree models or neural networks universally. It performs best where neighborhood structure is meaningful and interpretability is desired.

Limitations

- Requires dataset to remain in memory - High-dimensional dense data can still challenge nearest-neighbor methods - No online/incremental updates yet - Backend preparation adds setup time for large datasets

Project Status

- Public release: 0.2.2 - Stable API - Open source - CPU-optimized core Repository: https://github.com/thatipamula-jashwanth/smart-knn I’d appreciate feedback, especially from people who have deployed nearest-neighbor systems in production.

Thanks.

- Jashwanth

[dead] 5 months ago

Thanks for the feedback.. that makes sense.

I’ve updated the post to include a direct link to the repository. I appreciate the note about keeping the HN submission lighter and letting the linked page speak for itself.

This project is engineering-focused rather than academic research, so there isn’t a peer-reviewed paper at this stage. The goal was to explore practical deployment tradeoffs in nearest-neighbor systems.

I’ll consider writing a blog post focused on lessons learned and design decisions that’s a good suggestion.