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

relate-text

v1.0.0

Published

`relate-text` is a versatile library for creating, storing, updating, and querying text embeddings using neural embeddings. It supports operations via a REST API, a CLI, or programmatic interfaces, making it a powerful tool for text similarity, semantic s

Downloads

67

Readme

relate-text

relate-text is a versatile library for creating, storing, updating, and querying text embeddings using neural embeddings. It supports operations via a REST API, a CLI, or programmatic interfaces, making it a powerful tool for text similarity, semantic search, and other embedding-based applications.

Features

  • Create and manage text embeddings.
  • Query for similar text based on embeddings.
  • REST API server with predefined endpoints.
  • Command-line interface (CLI) for embedding management.

Installation

Install the library using npm:

npm install relate-text

For global CLI usage:

npm install -g relate-text

Usage

Programmatic Usage

You can directly use relate-text in your Node.js applications.

Example:

import { TextToEmbeddingController } from 'relate-text';

(async () => {
  const controller = new TextToEmbeddingController();
  await controller.ready();

  // Create a new embedding
  await controller.create('example-id', 'This is a sample text', { tag: 'example' });

  // Query for similar text
  const results = await controller.retrieveSimilar('sample text', 5);
  console.log('Similar results:', results);

  // Update the embedding
  await controller.update('example-id', 'Updated text content', { tag: 'updated' });

  // Delete the embedding
  await controller.destroy('example-id');

  // Delete all embeddings
  await controller.destroyAll();
})();

REST API

You can start the REST API server to interact with embeddings.

Starting the Server

Run the server with:

relate-text start-server --port 3000

Available Endpoints

  • Create an Embedding
    POST /embeddings
    Body:

    {
      "id": "example-id",
      "text": "This is a sample text",
      "metadata": { "tag": "example" }
    }
  • Update an Embedding
    PUT /embeddings
    Body:

    {
      "id": "example-id",
      "text": "Updated text content",
      "metadata": { "tag": "updated" }
    }
  • Delete an Embedding
    DELETE /embeddings/:id

  • Delete All Embeddings
    DELETE /embeddings/all

  • Query Similar Text
    POST /similar
    Body:

    {
      "text": "sample text",
      "limit": 5
    }

Command-Line Interface (CLI)

The CLI provides easy access to all major operations.

Commands

  1. Create an Embedding

    relate-text create -i "example-id" -t "This is a sample text" -m '{"tag":"example"}'
  2. Update an Embedding

    relate-text update -i "example-id" -t "Updated text content" -m '{"tag":"updated"}'
  3. Delete an Embedding

    relate-text delete -i "example-id"
  4. Delete All Embeddings

    relate-text delete-all
  5. Find Similar Text

    relate-text similar -t "sample text" -l 5
  6. Start the Server

    relate-text start-server --port 3000

Configuration

Metadata

Metadata can be provided as a JSON object during create or update operations. It is optional and useful for tagging or storing additional information about embeddings.

Development

Clone the repository:

git clone https://github.com/yourusername/relate-text.git

Install dependencies:

npm install

Build the library:

npm run build

Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your changes. Ensure all tests pass and your code follows the existing style.

Acknowledgments

  • Built with Node.js, Express, and Commander.js.
  • Uses @xenova/transformers for generating embeddings.