Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@themaximalist/embedding.js

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@themaximalist/embedding.js

Easy embeddings for LLMs like gpt-3.5-turbo and gpt-4 using OpenAI's text-embedding-ada-002

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

embedding.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

Keywords

embedding

FAQs

Package last updated on 05 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts