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

in-browser-vector-db

v0.0.1

Published

https://github.com/nis12ram/in-browser-vector-db.git

Downloads

5

Readme

in-browser-vector-db

Features

  • Supports Binary vector.
  • Promise based implementation.
  • Supports Web Worker.

Installation

  npm i in-browser-vector-db

Quick Start

For float32(fp32) vectors.

import { Connection, getUniqueInteger } from "in-browser-vector-db";
const connection = new Connection();
const dbConnection = await connection.openDb(dbName);
const vectorBlockConnection = await dbConnection.openVectorBlock(vectorBlockName);
await vectorBlockConnection.configureVectorBlock({ vectorDimension: 384, vectorDType: 'float32' });
const insertmanyResult = await vectorBlockConnection.operations.insertMany({ indices: [getUniqueInteger(),getUniqueInteger(),getUniqueInteger()], texts: ["what is earth?","what is web?","what is vector db"], vectors: [[0.01...],[0.01...],[0.01...]], metadataArray: [{name:"test0",age:30,hobby:["dancing"]},{name:"test1",age:40,hobby:["running"]},{name:"test2",age:50,hobby:["cooking"]}] });
const searchResult = await vectorBlockConnection.operations.search({ queryVector: [0.001...], topK: 6, vectorDistance: 'cosine', where:{ name: { $eq: "test1" }, age: { $lte: 50 }, hobby: { $nin: "dancing" } }});

For bool(uint8) vectors.

import { Connection, convertFloatToBinary, getUniqueInteger } from "in-browser-vector-db";
const connection = new Connection();
const dbConnection = await connection.openDb(dbName);
const vectorBlockConnection = await dbConnection.openVectorBlock(vectorBlockName);
await vectorBlockConnection.configureVectorBlock({ vectorDimension: 384, vectorDType: 'bool' });
const binaryVectors = convertFloatToBinary([[0.001....],[0.001....],[0.001....]]);
const insertmanyResult = await vectorBlockConnection.operations.insertMany({ indices: [getUniqueInteger(),getUniqueInteger(),getUniqueInteger()], texts: ["what is earth?","what is web?","what is vector db"], vectors: binaryVectors, metadataArray: [{name:"test0",age:30,hobby:["dancing"]},{name:"test1",age:40,hobby:["running"]},{name:"test2",age:50,hobby:["cooking"]}] });
const searchResult = await vectorBlockConnection.operations.search({ queryVector: [0.001...], topK: 6, vectorDistance: 'normHamming', where:{ name: { $eq: "test1" }, age: { $lte: 50 }, hobby: { $nin: "dancing" } }});

Details

  • The configuration process of vectorblock is a one time process and the applied configurtaion cannot be modified.
  • The inserted vector should be same of same data type and dimension as specified in the vectorblock configuration(configureVectorBlock()).
  • Available dTypes ('float32' -> fp32 ,'bool' -> uint8).
  • Available vector distance ('cosine','l2','hamming','normHamming').
  • Available filter ('$eq','$ne','$gt','$lt','$gte','$lte','$in','$nin').

Documentation

Starting the connection

import { Connection } from "in-browser-vector-db";
const connection = new Connection();

Opening the database.

const dbConnection = await connection.openDb("dbTest");

Opening the vectorblock.

// case-1(when no vectorBlock is opened)
const vectorBlockConnection = await dbConnection.openVectorBlock("vbTest1");

// case-2(when already a vectorBlock is opened)

// first close the opened vectorBlock.
dbConnection.closeVectorBlock();

// then open the vectorBlock.
const vectorBlockConnection = await dbConnection.openVectorBlock("vbTest1");

Configure the vectorblock.

await vectorBlockConnection.configureVectorBlock({ vectorDimension: 768, vectorDType: 'float32' });

Insert the entry.

const insertResult = await vectorBlockConnection.operations.insert({ index: 0, text: "hello test.", vector: [0.000001 ,....], metadata: {name: "test",age: 30,hobby:["dancing","running"]} });

Insert many entries.

const insertManyResult = await vectorBlockConnection.operations.insertMany({ indices:[0], texts: ["hello test."], vectors: [[0.000001 ,....]], metadataArray: [{name: "test"}] });

Update the entry.

const updateResult = await vectorBlockConnection.operations.update(index, { text: "what about you?", vector: [0.001...],metadata:{name:"test00"} });

Update many entries.

const updateManyResult = await vectorBlockConnection.operations.updateMany(indices, { texts: ["what about you?","How are you?"], vectors: [[0.001...],[0.001...]],metadataArray:[{name:"test00"},{name:"test11"}] });

Get the entry by id.

const entryAtIndexZero = await vectorBlockConnection.operations.getByIndex(0);

Get the entries by ids.

const entries = await vectorBlockConnection.operations.getByIndices([0,1,2]);

Delete the entry by id.

const deleteResult = await vectorBlockConnection.operations.deleteByIndex(0);

Delete the entries by ids.

const deleteResults = await vectorBlockConnection.operations.deleteByIndices([0,1,2]);

Delete all entries.

const deleteAllResult = await vectorBlockConnection.operations.deleteAll();

Search the similar entries.

const serachResult = await search({queryVector: [0.001...], vectorDistance: 'cosine',topK: 5,where:{ name: { $eq: "test" }, age: { $lte: 50 }, hobby: { $in: "dancing" } }});

Close the opened vectorblock.

const closeResult =  dbConnection.closeVectorBlock();

Delete the vectorblock.

const deleteResult =  await dbConnection.deleteVectorBlock("vbTest1")

Delete the database .

 // case-1(when vectorBlock is opened)

 const connection = new Connection();
 const dbConnection = await connection.openDb('test');
 const vectorBlockConnection = await dbConnection.openVectorBlock('vbTest1');
 // first close the open vectorBlock.
 console.log(dbConnection.closeVectorBlock());
 // then delete the db.
 console.log(await connection.deleteDb('test'));

 // case-2(when no vectorBlock is opened)

 const connection = new Connection();
 const dbConnection = await connection.openDb('test');
 console.log(await connection.deleteDb('test'));