Giter Club home page Giter Club logo

embedding.js's Introduction

embedding.js

NOTE: This repo has been archived and split into two: embeddings.js and vectordb.js

A simple in-memory embedding database that works with OpenAI's text-embedding-ada-002 text embeddings, built on top of hnswlib-node. Useful for finding relevant documents to include in gpt-3.5-turbo and gpt-4 context windows.

Features

  • Fast approximate nearest neighbor search using hierarchical navigable small world graphs.
  • Utilizes OpenAI's text-embedding-ada-002 model for text embeddings.
  • Easy-to-use API for adding and searching data in the database.

Installation

npm install --save @themaximalist/embedding.js

Configuration

To use this module, you will need an API key from OpenAI. Set the OPENAI_API_KEY environment variable with your API key:

export OPENAI_API_KEY=<your-openai-api-key>

Usage

const embedding = require("@themaximalist/embedding.js");

(async function () {
    const embeddings = new embedding.EmbeddingDatabase();
    await embeddings.add({
        name: "Cat",
        attributes: "It's a cat",
        sound: "meow",
    });

    await embeddings.add({
        name: "Dog",
        attributes: "It's a dog",
        sound: "woof",
    });

    await embeddings.add({
        name: "Cow",
        attributes: "It's a cow",
        sound: "moo",
    });

    let result;

    result = await embeddings.search("moo");
    console.log(result[0]); // cow

    result = await embeddings.search("woof");
    console.log(result[0]); // dog

    result = await embeddings.search("bark");
    console.log(result[0]); // dog

    result = await embeddings.search("roar");
    console.log(result[0]); // cat
})();

About

https://themaximalist.com

https://twitter.com/themaximal1st

License

MIT

embedding.js's People

Contributors

themaximalist avatar

Stargazers

Niranjan Anandkumar avatar Maxime Golfier avatar ZEN♡ avatar Guilherme avatar Sandalots avatar

Watchers

Kostas Georgiou avatar  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.