CoolFace
Apppublic

Devcavi19/hf-all-minilm-l6-v2-wp-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

Ollama All-MiniLM L6 v2 Embedding API

This is a FastAPI-based embedding service that uses Ollama with the all-minilm:l6-v2 model for generating text embeddings. It's designed to be used in a RAG (Retrieval-Augmented Generation) pipeline with Qdrant vector database.

Architecture

User Query -> API Embedder -> Qdrant -> Retrieved Context -> LLM -> Response

Features

  • —Single text embedding endpoint
  • —Batch text embedding endpoint
  • —Health check endpoint
  • —FastAPI with automatic API documentation
  • —Docker-ready for deployment to Hugging Face Spaces
  • —Autorun/Keepalive feature - Automatically prevents Hugging Face Spaces sleep mode by periodically pinging the health endpoint

Endpoints

POST /embed

Generate embedding for a single text

Request:

json
{
  "text": "Your input text here"
}

Response:

json
{
  "embedding": [0.123, -0.456, 0.789, ...]
}

POST /embed/batch

Generate embeddings for multiple texts

Request:

json
{
  "texts": ["Text 1", "Text 2", "Text 3"]
}

Response:

json
{
  "embeddings": [
    [0.123, -0.456, 0.789, ...],
    [0.234, -0.567, 0.890, ...],
    [0.345, -0.678, 0.901, ...]
  ]
}

GET /health

Health check endpoint

Deployment

Using Docker

bash
# Build the image
docker build -t ollama-embedder .

# Run the container
docker run -p 8000:8000 ollama-embedder

Deploying to Hugging Face Spaces

  1. 1.Create a new Hugging Face Space with Docker runtime
  2. 2.Push your code to the repository
  3. 3.Hugging Face will automatically build and deploy the Docker image

Accessing the API

Once deployed to Hugging Face Spaces, your API will be accessible at: https://<your-username>-<space-name>.hf.space

The API endpoints will be available at:

  • —POST /embed - Generate embedding for a single text
  • —POST /embed/batch - Generate embeddings for multiple texts
  • —GET /health - Health check endpoint
  • —GET /model-status - Check if the model is available

Example Usage

You can test the API using curl:

bash
curl -X POST https://<your-username>-<space-name>.hf.space/embed \
  -H "Content-Type: application/json" \
  -d '{"text": "Hello world"}'

Or using Python requests:

python
import requests

response = requests.post("https://<your-username>-<space-name>.hf.space/embed",
                        json={"text": "Hello world"})
embedding = response.json()["embedding"]

Usage Example

python
import requests

# Single embedding
response = requests.post("http://localhost:8000/embed",
                        json={"text": "Hello world"})
embedding = response.json()["embedding"]

# Batch embeddings
response = requests.post("http://localhost:8000/embed/batch",
                        json={"texts": ["Text 1", "Text 2", "Text 3"]})
embeddings = response.json()["embeddings"]

Model Information

  • —Model: all-minilm:l6-v2
  • —Description: A compact model for semantic search and embeddings
  • —Size: ~200MB
  • —Performance: Fast inference with good quality embeddings

Requirements

  • —Docker (for local development)
  • —Ollama service (automatically pulled in the Docker image)
  • —Python 3.8+