KNN Router

A minimal server for generating a ranked list of targets, for a query, based on its k-nearest semantic neighbors. Written in Go.

KNN-router can be used within a larger system to route natural language queries to the right system, with minimal latency. Given a user query, KNN-router:

  1. Looks up the most semantically similar neighbors from a curated corpus of example utterances
  2. Computes a weighted average score (based on the distances between query and top-K example utterances) for each target associated with the respective utterances. Targets can be information retrieval systems, agents, LORA adapters, Small/Large Language Models, or others. The sky is the limit!
  3. Returns a ranked list of targets that are most suitable for satisfying the query

At Pulze.ai, we use KNN-router to select the best LLM for user requests. Try it out locally here. Pulze Smart Router

Works with:

Usage

Quickstart

See this example for getting started locally.

Generating deployment artifacts

Dependencies:

The following artifacts are required for deployment:

Use this script to generate these artifacts:

scripts/gen-artifacts.sh --points-data-path points.jsonl --scores-data-path targets.jsonl --output-dir ./dist

TODOs