A lightweight Go microservice that generates 1536-dimensional text embeddings using either real OpenAI SmallEmbedding-3 or deterministic mock embeddings.
POST /embed-> returns an embedding vector- Real OpenAI mode (
USE_MOCK_EMBEDDINGS=false) - Deterministic mock mode (
USE_MOCK_EMBEDDINGS=true) - Go Fiber server
- Zerolog request logging
- Metrics middleware
- Clean Dockerfile with CA certificates
- Fly.io production-ready
.env.example(safe) +.env(local only)
{
"text": "My sample text to embed."
}
{
"embedding": [0.0123, -0.9932, ... 1536 floats ...]
}
{
"embedding": [0.3321, 0.9922, 0.1010, ... deterministic ...]
}
OPENAI_API_KEY=your_real_key_here
USE_MOCK_EMBEDDINGS=true
PORT=8080
OPENAI_API_KEY=your_openai_api_key_here
USE_MOCK_EMBEDDINGS=false
PORT=8080
Install dependencies:
go mod tidy
Start the server:
go run .
Test:
curl -X POST http://localhost:8080/embed -H "Content-Type: application/json" -d '{"text":"embedding test"}'
Set secrets:
flyctl secrets set OPENAI_API_KEY="your_real_key" -a ai-embedding-microservice
flyctl secrets set USE_MOCK_EMBEDDINGS=false -a ai-embedding-microservice
Deploy:
flyctl deploy -a ai-embedding-microservice
ai-embedding-microservice/
├── main.go
├── go.mod
├── .gitignore
├── .dockerignore
├── .env.example
├── Dockerfile
├── internal/
│ ├── ai/
│ │ ├── embeddings.go
│ │ └── select.go
│ ├── handlers/
│ │ └── embed_handler.go
│ └── middleware/
│ ├── logger.go
│ └── metrics.go