npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@reaatech/confidence-router-classifiers

v0.1.0

Published

Pluggable classifiers for confidence-router (keyword, embedding, LLM)

Readme

@reaatech/confidence-router-classifiers

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Pluggable classifier system for confidence-router, with built-in implementations for keyword matching, embedding similarity, and LLM-based classification. All classifiers conform to the Classifier interface and can be registered for fallback chain execution.

Installation

npm install @reaatech/confidence-router-classifiers
# or
pnpm add @reaatech/confidence-router-classifiers

Feature Overview

  • KeywordClassifier — deterministic pattern matching with exact / substring / regex modes
  • EmbeddingSimilarityClassifier — cosine similarity between input and reference vectors
  • LLMClassifier — OpenAI and Anthropic chat completion classifiers
  • ClassifierRegistry — named registration with default selection and automatic fallback chains
  • Pluggable architecture — implement Classifier to add custom classifiers
  • Zero runtime dependencies beyond core — uses native fetch (Node 18+) for LLM calls

Quick Start

import { KeywordClassifier, ClassifierRegistry } from "@reaatech/confidence-router-classifiers";

const classifier = new KeywordClassifier([
  { label: "book_flight", keywords: ["flight", "fly", "ticket", "plane"] },
  { label: "check_status", keywords: ["status", "check", "where", "track"] },
  { label: "cancel_booking", keywords: ["cancel", "refund", "delete"] },
]);

const result = await classifier.classify("I want to book a flight to Paris");
// result.predictions[0] → { label: "book_flight", confidence: 0.5 }

Built-in Classifiers

KeywordClassifier

Fast, deterministic pattern matching. Zero external dependencies.

import { KeywordClassifier } from "@reaatech/confidence-router-classifiers";

const classifier = new KeywordClassifier(
  [
    { label: "book_flight", keywords: ["flight", "fly", "ticket"], weight: 1.0 },
    { label: "cancel_booking", keywords: ["cancel", "refund"], mode: "substring" },
  ],
  { name: "intent-keywords", caseSensitive: false }
);

| Option | Type | Default | Description | |--------|------|---------|-------------| | name | string | "keyword" | Classifier name for registration | | priority | number | 1 | Priority in fallback chain | | enabled | boolean | true | Whether this classifier is active | | caseSensitive | boolean | false | Match keywords case-sensitively |

Pattern modes (MatchMode):

| Mode | Behavior | |------|----------| | "substring" (default) | Matches if keyword appears anywhere in the input | | "exact" | Matches on word boundaries only (\bkeyword\b) | | "regex" | Keywords are treated as regular expressions |

EmbeddingSimilarityClassifier

Compares input embedding vectors against labeled reference vectors using cosine similarity.

import { EmbeddingSimilarityClassifier } from "@reaatech/confidence-router-classifiers";

const classifier = new EmbeddingSimilarityClassifier(
  [
    { label: "positive", vector: [0.9, 0.1, 0.2] },
    { label: "negative", vector: [-0.8, 0.3, 0.1] },
  ],
  {
    embeddingProvider: async (text) => {
      // Call your embedding API
      return [0.8, 0.2, 0.1];
    },
  }
);

| Option | Type | Default | Description | |--------|------|---------|-------------| | name | string | "embedding" | Classifier name | | priority | number | 1 | Priority in fallback chain | | enabled | boolean | true | Whether active | | embeddingProvider | (text: string) => Promise<number[]> \| number[] | — | Function to generate embedding vectors |

The embeddingProvider can also be passed at classify time via context.embeddingProvider.

LLMClassifier

Uses OpenAI or Anthropic chat completions to classify input text into predefined labels.

import { LLMClassifier } from "@reaatech/confidence-router-classifiers";

const classifier = new LLMClassifier({
  provider: "openai",
  apiKey: process.env.OPENAI_API_KEY,
  model: "gpt-4o-mini",
  labels: ["book_flight", "check_status", "cancel_booking"],
  timeout: 15000,
  retries: 2,
});

| Option | Type | Default | Description | |--------|------|---------|-------------| | provider | "openai" \| "anthropic" | (required) | LLM provider | | apiKey | string | process.env.OPENAI_API_KEY / ANTHROPIC_API_KEY | API key | | model | string | "gpt-4o-mini" / "claude-3-haiku-20240307" | Model to use | | baseUrl | string | Provider default | Custom API endpoint | | labels | string[] | (required) | Legal classification labels | | timeout | number | 30000 | Request timeout in ms | | retries | number | 2 | Retry attempts with exponential backoff | | systemPrompt | string | Auto-generated | Custom system prompt |

The LLMClassifier automatically:

  • Normalizes confidence to [0, 1]
  • Fills missing labels with zero confidence
  • Strips markdown fences from responses
  • Validates that returned labels are in the allowed set

ClassifierRegistry

Manages named classifiers with default selection and fallback chain execution.

import { ClassifierRegistry } from "@reaatech/confidence-router-classifiers";
import { KeywordClassifier } from "@reaatech/confidence-router-classifiers";

const registry = new ClassifierRegistry();
registry.register(new KeywordClassifier([...], { name: "intents", priority: 1 }));
registry.register(new LLMClassifier({ name: "llm-backup", priority: 2, ... }));

// Classify with a specific classifier
const result = await registry.classify("book a flight", "intents");

// Run fallback chain (tries each enabled classifier in priority order)
const fallback = await registry.getFallbackChain("I want to fly");

| Method | Description | |--------|-------------| | register(classifier) | Adds a classifier; first enabled one becomes default | | get(name) | Retrieves by name; returns undefined if not found | | classify(input, name?, context?) | Classifies with the named or default classifier | | getFallbackChain(input) | Tries each enabled classifier in priority order; returns first success |

Custom Classifier

Implement the Classifier interface from @reaatech/confidence-router-core:

import type { Classifier, ClassificationResult } from "@reaatech/confidence-router-core";

class CustomClassifier implements Classifier {
  name = "custom";
  type = "custom";
  enabled = true;
  priority = 1;

  async classify(input: string, context?: Record<string, unknown>): Promise<ClassificationResult> {
    return {
      predictions: [{ label: "detected_intent", confidence: 0.95 }],
    };
  }

  async validate(): Promise<boolean> {
    return true;
  }
}

Related Packages

License

MIT