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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bageldb-beta

v1.0.24

Published

A npm client for BagelDB.

Downloads

7

Readme

BagelDB JavaScript Client 🥯

Table of Contents

Installation

npm install bageldb-beta

Overview

The official BagelDB API endpoint is api.bageldb.ai.

The BagelDB JavaScript client provides easy access to the BagelDB API from Node.js applications.

The full source code with examples is available on GitHub: https://github.com/Bagel-DB/Client/tree/main/javascript

See example.js for complete usage examples.

Client

const { Client } = require('bageldb-beta');

const client = new Client(settings);

The Client class is the main interface to the BagelDB API. It requires a Settings object to configure connectivity:

// Settings config
const settings = new Settings({
  bagel_api_impl: "rest",
  bagel_server_host: "api.bageldb.ai",
  bagel_server_http_port: 80
});

Settings

The Settings class contains configuration options for the client:

  • bagel_api_impl - The BagelDB API implementation, usually "rest"
  • bagel_server_host - BagelDB server hostname
  • bagel_server_http_port - BagelDB HTTP port
  • See Settings source for additional options

Usage

Once you have created a Client instance, you can call API methods like:

API Methods

Ping API

const response = await client.ping(); 

Pings the API to check connectivity.

Get API Version

const version = await client.get_version();

Gets the API version string.

Get All Clusters

const clusters = await client.get_all_clusters();

Gets info on all existing clusters.

Create Cluster

const cluster = await client.create_cluster('mycluster');

Creates a new cluster.

Get Cluster

const cluster = await client.get_cluster('mycluster'); 

Gets an existing cluster by name.

Delete Cluster

await client.delete_cluster('mycluster');

Deletes a cluster by name.

Cluster Methods

The Cluster class represents a specific cluster and has methods like:

// Add documents
await cluster.add([
  { id: 1, text: 'Document 1' },  
  { id: 2, text: 'Document 2' }
]);

// Search by vector 
const results = await cluster.query([0.5, 0.5]); 

See the Cluster class documentation for full details on:

  • count() - Get total rows
  • add() - Insert new rows
  • delete() - Delete rows
  • update() - Update existing rows
  • query() - Search by vectors
  • peek() - Sample rows
  • And more

Full Example

const { Client } = require('bageldb-beta');

const settings = new Settings({
  bagel_api_impl:"rest",
  bagel_server_host:"api.bageldb.ai",
  bagel_server_http_port:80,
});

const client = new Client(settings); 

const cluster = await client.get_or_create_cluster('products');

await cluster.add([
  { id: 1, name: 'Baseball', vector: [0.1, 0.3] },
  { id: 2, name: 'Bat', vector: [0.7, 0.2] }
]);

const results = await cluster.query([0.5, 0.5]); 

Here is another example showing the usage flow:

You're right, I should show an example of searching by text as well. Here is an updated full example:

// Import and initialize client
const { Client } = require('bageldb-beta');

const settings = new Settings({
  bagel_api_impl: "rest",
  bagel_server_host: "api.bageldb.ai", 
  bagel_server_http_port: 80  
});

const client = new Client(settings);

// Get or create cluster
const cluster = await client.get_or_create_cluster('products');  

// Add documents
await cluster.add([
  { id: 1, text: 'Baseball' },
  { id: 2, text: 'Bat' }  
]); 

// Search by vector 
const results1 = await cluster.query([0.5, 0.5]);

// Search by text
const results2 = await cluster.query(null, {
  query_texts: ['Baseball'] 
});

// BagelDB will search using the embeddings
// it previously generated for the documents

The key addition is the query_texts parameter to search by text directly:

const results2 = await cluster.query(null, {
  query_texts: ['Baseball']  
});

This searches for the document with the text "Baseball" without needing to provide any embeddings.

The key points are:

  • You can insert documents by just providing a text field instead of an embedding vector.

  • Behind the scenes, BagelDB will run the text through its built-in neural network to generate an embedding vector.

  • When you search by vector later, it will use the embeddings it previously generated.

This allows you to easily index and search text without having to generate embeddings yourself. BagelDB handles it automatically.

Let me know if this helps explain the full end-to-end flow!

See the GitHub README and example.js for more complete examples. Let me know if any part needs more explanation!