Devcavi19/hf-all-minilm-l6-v2-wp-api
0
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 -> ResponseFeatures
- 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:
{
"text": "Your input text here"
}Response:
{
"embedding": [0.123, -0.456, 0.789, ...]
}POST /embed/batch
Generate embeddings for multiple texts
Request:
{
"texts": ["Text 1", "Text 2", "Text 3"]
}Response:
{
"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
# Build the image
docker build -t ollama-embedder .
# Run the container
docker run -p 8000:8000 ollama-embedderDeploying to Hugging Face Spaces
- Create a new Hugging Face Space with Docker runtime
- Push your code to the repository
- 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 textPOST /embed/batch- Generate embeddings for multiple textsGET /health- Health check endpointGET /model-status- Check if the model is available
Example Usage
You can test the API using curl:
curl -X POST https://<your-username>-<space-name>.hf.space/embed \
-H "Content-Type: application/json" \
-d '{"text": "Hello world"}'Or using Python requests:
import requests
response = requests.post("https://<your-username>-<space-name>.hf.space/embed",
json={"text": "Hello world"})
embedding = response.json()["embedding"]Usage Example
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+
