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

vector-embedb

v1.1.0

Published

Vector based image and text database

Downloads

1

Readme

EmbeDB

Vector based image and text database

How it works

EmbeDB uses a vector based approach to store data. This means that the data is stored as a vector of numbers, called an embedding. This allows for fast retrieval of similar data.

What can you do with it?

  • Similar image search
  • Long term memory
  • Web searching
  • Much more!

Installation

EmbeDB requires Node.js and Python 3 to be installed.

Install the package using npm:

npm install embedb

Then, create a .env file in the root directory of your project and add the API keys for the models you want to use.

HUGGINGFACE_API_KEY=<your api key>
OPENAI_API_KEY=<your api key>

Usage

First, require the module and create a new instance of the database.

Memory(model<string, default='huggingface'>)
const Memory = require('embedb');

const memory = new Memory();

Inserting data

To memorize text, use the memorize method.

async Memory.memorize({
    key<string>,
    value<string>,
    model<string, default='huggingface'>
})
await memory.memorize({
	key: 'What is my name?',
	value: 'EmbeDB',
});

To memorize an image, you must pass in the image path and use an image model such as resnet50.

await memory.memorize({
	key: 'Matrix meme',
	value: './matrixMeme.png',
	model: 'resnet50',
});

To memorize multiple items, use the memorizeAll method.

async Memory.memorizeAll([
    {
        key<string>,
        value<string>,
    },
    {
        key<string>,
        value<string>,
    },
], model<string, default='huggingface'>)
await memory.memorizeAll([
  {
    key: "What is my name?",
    value: "EmbeDB",
  },
  {
    key: "Who is the president of the United States in 2023?"
    value: "Joe Biden",
  },
]);

Retrieving data

To retrieve the first most similar memory item, use the recall method.

async Memory.recall(key<string>, n<number> model<string, default='huggingface'>) -> MemoryItem{
    key<string>,
    value<string>,
    similarity<number>,
    prune<function>
}
const data = await memory.recall("What's my name?");

To retrieve the first n most similar memory items, use the recall method with the second parameter as n

const name = await memory.recall("What's my name?", 2);
/*
{
    key: "What is my name?",
    value: "EmbeDB",
    similarity: 0.9999999999999999,
    prune: [Function: prune]
},
{
    key: "What is your name?",
    value: "User",
    similarity: 0.3664122137402344,
    prune: [Function: prune]
}
*/

Deleting data

To delete a memory item, use the prune method on a returned memory item from recall.

MemoryItem.prune()
const name = await memory.recall("What's my name?");

await name.prune();

Loading saved data

Memory.load(memoryData<object>)

To load saved data, use the load method.

const fs = require('fs');
await memory.load(JSON.parse(await fs.promises.readFile('./memory.json')));

Embedding Models

Image Models

  • resnet50

Text Models

  • huggingface
  • openai