NLP API for text validation, toxicity detection, and semantic search using embeddings. Powered by SentenceTransformer, language detection, and toxicity classification models.
docker run -d \
-p 9050:9050 \
-e POSTGRES_HOST=postgres.example.com \
-e POSTGRES_USER=student \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=mscstudents \
-e POSTGRES_PORT=5432 \
-e API_TOKEN=my_secure_token \
--name embedding-api \
sever3d/embedding-api:latest
| Variable | Required | Default | Description |
|---|---|---|---|
POSTGRES_HOST | Yes | — | PostgreSQL hostname |
POSTGRES_USER | Yes | — | PostgreSQL username |
POSTGRES_PASSWORD | Yes | — | PostgreSQL password |
POSTGRES_DB | Yes | — | Database name |
POSTGRES_PORT | No | 5432 | PostgreSQL port |
API_TOKEN | Yes | — | Bearer token for all endpoints |
API_PORT | No | 9050 | API port |
SEARCH_LIMITS_COUNT | No | 5 | Default search result limit |
LANG_CONFIDENCE_THRESHOLD | No | 0.5 | Language detection threshold (0-1) |
TOXICITY_SCORE_THRESHOLD | No | 0.8 | Toxicity threshold (0-1) |
CHECK_TOXICITY_DEFAULT | No | true | Enable toxicity check by default |
version: "3.9"
services:
postgres:
image: pgvector/pgvector:pg13
environment:
POSTGRES_USER: student
POSTGRES_PASSWORD: password
POSTGRES_DB: mscstudents
volumes:
- postgres_data:/var/lib/postgresql/data
- ./postgres/init:/docker-entrypoint-initdb.d:ro
ports:
- "5432:5432"
embedding-api:
image: sever3d/embedding-api:latest
ports:
- "9050:9050"
environment:
POSTGRES_HOST: postgres
POSTGRES_USER: student
POSTGRES_PASSWORD: password
POSTGRES_DB: mscstudents
POSTGRES_PORT: 5432
API_TOKEN: my_secure_token
API_PORT: 9050
volumes:
- hf_models:/models
depends_on:
- postgres
volumes:
postgres_data:
hf_models:
Required PostgreSQL extensions:
CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE IF NOT EXISTS question_embeddings (
question_id text PRIMARY KEY,
question text NOT NULL,
embedding vector(768) NOT NULL
);
CREATE INDEX IF NOT EXISTS question_embeddings_embedding_hnsw_idx
ON question_embeddings
USING hnsw (embedding vector_cosine_ops);
Include these SQL files in PostgreSQL initialization directory (mounted at /docker-entrypoint-initdb.d).
All endpoints require x-access-tokens header.
curl -H "x-access-tokens: my_secure_token" \
http://localhost:9050/healthcheck
Response:
{"status": "OK"}
POST /embedding
Generate 768-dimensional embedding for text.
curl -X POST \
-H "x-access-tokens: my_secure_token" \
-H "Content-Type: application/json" \
-d '{"text": "Hello world"}' \
http://localhost:9050/embedding
Response:
{
"embedding": [0.123, -0.456, 0.789, ...]
}
POST /validatetext
Check if text is English. Optionally detect toxicity.
curl -X POST \
-H "x-access-tokens: my_secure_token" \
-H "Content-Type: application/json" \
-d '{
"text": "This is good content",
"check_toxicity": true
}' \
http://localhost:9050/validatetext
Response:
{"valid": true}
Payload:
text (required) — Text to validatecheck_toxicity (optional) — Override default toxicity checkPOST /toxicity
Score text for toxicity (0-1, higher = more toxic).
curl -X POST \
-H "x-access-tokens: my_secure_token" \
-H "Content-Type: application/json" \
-d '{"text": "Some content"}' \
http://localhost:9050/toxicity
Response:
{"score": 0.05}
POST /embedding/mongostore
Generate embedding and store in PostgreSQL.
curl -X POST \
-H "x-access-tokens: my_secure_token" \
-H "Content-Type: application/json" \
-d '{
"questionId": "q1",
"question": "What is artificial intelligence?"
}' \
http://localhost:9050/embedding/mongostore
Response:
{
"questionId": "q1",
"question": "What is artificial intelligence?",
"question_embedding": [0.123, -0.456, ...]
}
POST /embedding/search
Find similar stored questions by semantic similarity.
curl -X POST \
-H "x-access-tokens: my_secure_token" \
-H "Content-Type: application/json" \
-d '{"question": "machine learning basics"}' \
"http://localhost:9050/embedding/search?limit=5"
Response:
[
{
"questionId": "q1",
"question": "What is artificial intelligence?"
},
{
"questionId": "q3",
"question": "How does deep learning work?"
}
]
Query Parameters:
limit (optional) — Number of results (default: SEARCH_LIMITS_COUNT)POST /validate/question
Validate both title and body (language + toxicity).
curl -X POST \
-H "x-access-tokens: my_secure_token" \
-H "Content-Type: application/json" \
-d '{
"title": "How to learn programming?",
"body": "I want to start learning Python and JavaScript."
}' \
http://localhost:9050/validate/question
Response:
{
"valid_english_title": true,
"valid_english_body": true,
"toxicity_score_title": 0.02,
"toxicity_score_body": 0.01
}
sentence-transformers/all-mpnet-base-v2 — Text embeddingspapluca/xlm-roberta-base-language-detection — Language detectionunitary/toxic-bert — Toxicity classificationUse it, but be kind to mention my repo name and maybe Github as well ?
Content type
Image
Digest
sha256:60aea4c30…
Size
4.1 GB
Last updated
7 months ago
docker pull sever3d/nlp-api