Git Product home page Git Product logo

embedb's Introduction

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

embedb's People

Contributors

cadenmarinozzi avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.