projects / knn-content-addressable-network

⚡ Personal project

Distributed kNN over a Content Addressable Network (CAN)

Personal project: computing the k nearest neighbours efficiently over a structured peer-to-peer network, from the baseline implementation to the optimised algorithm, measured on a computing grid. The same principles as the vector search used in AI today.

  • Java
  • JUnit
  • DHT
  • CAN
  • P2P

$ cat architecture.md

kNN over CAN, in three steps

Spread the points across a space split into zones between peers, then find neighbours without scanning everything.

  1. 01

    Distributing the data

    Set Sdata points
    HashingCAN coordinates
    CAN zonesd-dimensional space
    Peersone zone each

    Each point of S is placed, by hashing, in the zone of the peer in charge of it: data gets an address.

  2. 02

    Finding the k neighbours

    Point of Rquery
    CAN routingneighbour to neighbour
    Neighbour zonestargeted search
    k nearestresult

    The query is routed to the point’s zone, then expands to neighbouring zones while better candidates are possible.

  3. 03

    The approach

    Basic kNNbaseline
    Optimised kNNCAN structure
    Benchmarkcomputing grid

    A baseline, an optimised version, then proof through measurements in a distributed setting.

The stakes The k-nearest-neighbours (kNN) join is costly: for every point of a set R, all the points of S must be compared. At large volumes, the computation must be distributed, and how data is organised across machines is what drives performance. kNN is at the heart of recommendation, similarity search and, today, the vector search used in AI. The solution (October 2015 – February 2016) • Step 1: a baseline kNN over a Content Addressable Network (CAN), a distributed hash table that splits the space into zones assigned to peers. • Step 2: an optimised algorithm that uses the CAN zone structure to visit only the relevant zones. • Step 3: a benchmark in a distributed setting, on a computing grid. • Java 7 development, testing with JUnit. What it demonstrates Solid foundations in algorithms and distributed systems: data distribution, routing, trade-offs between accuracy and cost. The same principles as the MongoDB sharding or DynamoDB partitions I use today.

October 2015