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 🙏

© 2025 – Pkg Stats / Ryan Hefner

topk-js

v0.7.1

Published

![TopK](https://qdmy0nqdjsamgtso.public.blob.vercel-storage.com/topk-logo-light.svg)

Readme

TopK

TopK Javacript SDK

Full documentation is available at docs.topk.io.

The TopK SDK is a fully TypeScript-compatible JavaScript client that brings together keyword and vector search, semantic search with automatic or user-defined embeddings, advanced metadata filtering, and built-in reranking.

Features

  • Keyword and vector search
  • Semantic search out of the box
  • Filtering
  • Reranking
  • Collection and document management

1. Install the SDK

Install the TopK SDK:

npm install topk-js

# or

yarn add topk-js

2. Create an API Key

To authenticate with TopK, you'll need an API key:

  1. Go to the TopK Console.
  2. Create an account and generate your API key.

Keep your API key secure—you'll need it for authentication.

3. Create a Collection

Collections are the primary data structure in TopK. They store documents and enable queries.

Initialize the Client

import { Client } from "topk-js"

const client = new Client({
  apiKey: "YOUR_TOPK_API_KEY",
  region: "aws-us-east-1-elastica"
});

Define and Create a Collection

import { text, semanticIndex } from "topk-js/schema"

await client.collections().create("books", {
  title: text().required().index(semanticIndex()), // Semantic search enabled on `title`
});

Note: Other fields can still be upserted even if they are not defined in the schema.

4. Add Documents

Now, add documents to the collection. Each document must have an _id field.

await client.collection("books").upsert([
  { _id: "gatsby", title: "The Great Gatsby" },
  { _id: "1984", title: "1984" },
  { _id: "catcher", title: "The Catcher in the Rye" },
]);

5. Run a Search Query

Now, retrieve books using semantic search:

import { select, fn, match, field } from "topk-js/query"

const results = await client.collection("books").query(
  select({
    title: field("title"),
    // Perform semantic search on the `title` field
    title_similarity: fn.semanticSimilarity(
      "title",
      "classic American novel"
    ),
  })
    // Sort results by the `title_similarity` field, selecting the top 10 results
    .topk(field("title_similarity"), 10)
);

6. (Optional) Delete a Collection

To remove the entire collection:

await client.collections().delete("books")