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 🙏

© 2025 – Pkg Stats / Ryan Hefner

leumas-embeddings-api

v1.0.0

Published

API for generating and managing text and file embeddings.

Readme

@leumas/embeddings-api

API for generating and managing text and file embeddings. This package provides helper functions and Express.js routes to convert text and file content into embedding vectors.

Installation

To install the package, use npm:

npm install @leumas/embeddings-api

Usage

As an npm package (programmatic usage)

You can use the helper functions directly in your Node.js application:

const { textToEmbedding, fileToEmbedding } = require('@leumas/embeddings-api');

// Example: Convert text to embedding
const text = "Hello, world!";
const textEmbedding = textToEmbedding(text);
console.log("Text Embedding:", textEmbedding);

// Example: Convert file content to embedding
// Make sure 'path/to/your/file.txt' exists
const filePath = 'path/to/your/file.txt';
const fileEmbedding = fileToEmbedding(filePath);
if (fileEmbedding) {
    console.log("File Embedding:", fileEmbedding);
} else {
    console.log("Could not generate embedding for file.");
}

Integrating with an existing Express.js server

You can mount the provided Express.js router to your application:

  1. Install dependencies:

    npm install express @leumas/embeddings-api
  2. In your main application file (e.g., app.js or server.js):

    const express = require('express');
    const embeddingsRouter = require('@leumas/embeddings-api/routes'); // Note: points to the routes.js file
    
    const app = express();
    app.use(express.json()); // Middleware to parse JSON request bodies
    
    // Mount the embeddings router under a specific path, e.g., '/api'
    app.use('/api', embeddingsRouter);
    
    const PORT = process.env.PORT || 3000;
    app.listen(PORT, () => {
        console.log(`Server running on port ${PORT}`);
    });

API Endpoints

The following endpoints are available when you integrate the router into your Express.js application:

POST /embedding/code

Convert a text string into an embedding vector.

  • Request Body:
    {
        "text": "Your text string here."
    }
  • Response:
    {
        "embedding": [0.1, 0.2, 0.3, ...]
    }
  • Errors:
    • 400 Bad Request: If text is not provided in the request body.
    • 500 Internal Server Error: If an error occurs during embedding generation.

POST /embedding/path

Convert file content into an embedding vector.

  • Request Body:
    {
        "filePath": "/path/to/your/file.txt"
    }
  • Response:
    {
        "embedding": [0.1, 0.2, 0.3, ...]
    }
  • Errors:
    • 400 Bad Request: If filePath is not provided in the request body.
    • 404 Not Found: If the specified file does not exist or cannot be read.
    • 500 Internal Server Error: If an error occurs during embedding generation.

Helper Functions

textToEmbedding(text)

Generates an embedding vector from a given text string.

  • Parameters:
    • text (String): The input text string.
  • Returns:
    • Array: An array of numbers representing the embedding vector.

fileToEmbedding(filePath)

Generates an embedding vector from the content of a specified file.

  • Parameters:
    • filePath (String): The absolute path to the file.
  • Returns:
    • Array or null: An array of numbers representing the embedding vector, or null if the file is not found or cannot be processed.

Development

Project Structure

.
├── index.js              # Main entry point for the npm package (exports helper functions)
├── README.md             # This documentation file
├── routes.js             # Express.js router for API endpoints
└── functions/
    ├── embed-file.js     # Helper function to embed file content
    └── embed-text.js     # Helper function to embed text content

Running Tests

(Add your test command here if you have one, e.g., npm test)

License

This project is licensed under the MIT License.