Skip to content

ergodic-flow/tiny-knn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tiny KNN

A small yet mighty brute-force KNN service, tested up to 1M vectors. Good enough for prototypes and experimentation.

Just supply your vectors in a JSONL file, and this service will make them queryable under cosine distance.

Usage

Run the server:

uv run main.py --vectors data/sample_vecs.jsonl

Curl the endpoint:

curl -s -X POST "http://localhost:8000/neighbors?k=5" \
  -H 'Content-Type: application/json' \
  -d '{"v":[0.9,0.1,0.0]}' | jq

Responds with:

[
  {
    "id": "quux2",
    "score": 0.5623031854629517
  },
  {
    "id": "foo3",
    "score": 0.5607672333717346
  },
  {
    "id": "bar2",
    "score": 0.5517436861991882
  },
  {
    "id": "bar",
    "score": 0.49591827392578125
  },
  {
    "id": "bar3",
    "score": 0.4637247920036316
  }
]

Quirks

This project only supports cosine distance and dense vectors. Due to the minimal nature of this project, it is quite fast. The core logic is basically a single Matrix-vector product in numpy. Performance is surprisingly competetive.

About

A tiny brute-force K-NN service -- fast enough for prototyping, tested up to 1M vectors

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages