Giter VIP home page Giter VIP logo

vector-embedding-api's Introduction

vector-embedding-api

vector-embedding-apiprovides a Flask API server and client to generate text embeddings using either OpenAI's embedding model or the SentenceTransformers library. The API server now supports in-memory LRU caching for faster retrievals, batch processing for handling multiple texts at once, and a health status endpoint for monitoring the server status.

SentenceTransformers supports over 500 models via HuggingFace Hub.

Features ๐ŸŽฏ

  • POST endpoint to create text embeddings
    • sentence_transformers
    • OpenAI text-embedding-ada-002
  • In-memory LRU cache for quick retrieval of embeddings
  • Batch processing to handle multiple texts in a single request
  • Easy setup with configuration file
  • Health status endpoint
  • Python client utility for submitting text or files

Installation ๐Ÿ’ป

To run this server locally, follow the steps below:

Clone the repository: ๐Ÿ“ฆ

git clone https://github.com/deadbits/vector-embedding-api.git
cd vector-embedding-api

Set up a virtual environment (optional but recommended): ๐Ÿ

virtualenv -p /usr/bin/python3.10 venv
source venv/bin/activate

Install the required dependencies: ๐Ÿ› ๏ธ

pip install -r requirements.txt

Usage

Modify the server.conf configuration file: โš™๏ธ

[main]
openai_api_key = YOUR_OPENAI_API_KEY
sent_transformers_model = sentence-transformers/all-MiniLM-L6-v2
use_cache = true/false

Start the server: ๐Ÿš€

python server.py

The server should now be running on http://127.0.0.1:5000/.

API Endpoints ๐ŸŒ

Client Usage

A small Python client is provided to assist with submitting text strings or files.

Usage python3 client.py -t "Your text here" -m local

python3 client.py -f /path/to/yourfile.txt -m openai

POST /submit

Submits an individual text string or a list of text strings for embedding generation.

Request Parameters

  • text: The text string or list of text strings to generate the embedding for. (Required)
  • model: Type of model to be used, either local for SentenceTransformer models or openai for OpenAI's model. Default is local.

Response

  • embedding: The generated embedding array.
  • status: Status of the request, either success or error.
  • elapsed: The elapsed time taken for generating the embedding (in milliseconds).
  • model: The model used to generate the embedding.
  • cache: Boolean indicating if the result was retrieved from cache. (Optional)
  • message: Error message if the status is error. (Optional)

GET /health

Checks the server's health status.

Response

  • cache.enabled: Boolean indicating status of the cache
  • cache.max_size: Maximum cache size
  • cache.size: Current cache size
  • models.openai: Boolean indicating if OpenAI embeddings are enabled. (Optional)
  • models.sentence-transformers: Name of sentence-transformers model in use.
{
  "cache": {
    "enabled": true,
    "max_size": 500,
    "size": 0
  },
  "models": {
    "openai": true,
    "sentence-transformers": "sentence-transformers/all-MiniLM-L6-v2"
  }
}

Example Usage

Send a POST request to the /submit endpoint with JSON payload:

{
    "text": "Your text here",
    "model": "local"
}

// multi text submission
{
    "text": ["Text1 goes here", "Text2 goes here"], 
    "model": "openai"
}

You'll receive a response containing the embedding and additional information:

[
  {
    "embedding": [...],
    "status": "success",
    "elapsed": 123,
    "model": "sentence-transformers/all-MiniLM-L6-v2"
  }
]

[
  {
    "embedding": [...],
    "status": "success",
    "elapsed": 123,
    "model": "openai"
  }, 
  {
    "embedding": [...],
    "status": "success",
    "elapsed": 123,
    "model": "openai"
  }, 
]

vector-embedding-api's People

Contributors

deadbits avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mspublic

vector-embedding-api's Issues

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.