This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Rust-based embeddings service that provides sentence embeddings via a REST API. The service uses fastembed-rs with the all-MiniLM-L6-v2 model to generate 384-dimensional embeddings. It's built with Axum for the web framework and designed for high-performance NLP workloads.
cargo build- Build in debug modecargo build --release- Build optimized release versioncargo run- Run the service locally (listens on port 9000)cargo test- Run unit testscargo check- Quick syntax and type checking
docker build -t embeddings-service .- Build Docker imagedocker run -p 9000:9000 embeddings-service- Run containerdocker-compose up -d- Start with docker-composedocker-compose logs -f embeddings-service- View logsdocker-compose down- Stop services
docker-compose --profile production up -d- Deploy with nginx reverse proxydocker build -f Dockerfile.cuda -t embeddings-service-gpu .- Build with GPU support
- Main Application (
src/main.rs): Axum-based REST API server with CORS support - Model Management: Uses
fastembed-rsTextEmbedding with async mutex protection - Request/Response Types: Structured with serde for JSON serialization
- State Management: Arc-wrapped AppState containing model instances
GET /health- Health check with available models listPOST /embeddings- Batch embedding generation (JSON body with texts array)GET /embeddings?text=<text>- Single text embedding via query parameter
- Default model: all-MiniLM-L6-v2 (384-dimensional embeddings)
- Models cached in
~/.cache/fastembedor/app/.cache/fastembedin Docker - Additional models can be added in
AppState::new()method
- ONNX Runtime backend with automatic model download during first run
- Thread-safe model access with async mutex
- Fast inference with optimized ONNX models
- Memory-efficient with Docker multi-stage builds
- Multi-stage build: builder stage (Rust compilation) + runtime stage (Debian slim)
- Non-root user execution for security
- Health checks and resource limits configured
- Model cache persistence via Docker volumes
- Optional nginx reverse proxy for production
PORT- Server port (default: 9000)RUST_LOG- Logging level (default: info)
- Unit tests in
src/main.rsusingaxum-test - Test endpoints: health check and embeddings generation
- Models must be loaded for tests (may take time on first run)
- First run downloads ONNX models (1-2 minutes depending on connection)
- Model loading happens at startup (check logs for "Models loaded successfully!")
- Batch processing recommended for multiple texts
- GPU acceleration available with CUDA builds
- Memory requirements: 256MB minimum, 1GB recommended for production