Standalone AI/ML module for Nekazari platform - Independent repository for analysis and prediction services.
This module follows the Nekazari Module Template structure for consistency with the platform's module ecosystem.
Licensed under the Apache License 2.0.
Why Apache 2.0? This module uses Apache 2.0 to provide maximum flexibility for integration. Modules that connect via REST API are not affected by this license, allowing for easier commercial and open-source integration.
- Python 3.11+
- Redis (for job queue)
- Access to Orion-LD Context Broker
# Install dependencies
cd backend
pip install -r requirements.txt
# Copy environment template
cp ../env.example .env
# Edit .env with your configuration
# Run the service
uvicorn app.main:app --reload --port 8000# Build image
docker build -f backend/Dockerfile -t intelligence-backend:dev ./backend
# Run container
docker run -p 8000:8000 \
-e REDIS_HOST=host.docker.internal \
-e ORION_URL=http://host.docker.internal:1026 \
intelligence-backend:devThis is a completely independent module with:
- Zero dependencies on Core services code
- Standalone Docker image optimized for Data Science workloads
- REST API for triggering analysis and predictions (V1 job-based + V2 model/features canonical API)
- Redis with strict DB segmentation: DB 0 Celery broker, DB 1 Celery backend, DB 2 fast-result cache, DB 3 legacy job queue
- Celery workers (separate deployment) for heavy inference; API pod only enqueues and reads cache
- Orion-LD integration for writing Prediction entities (NGSI-LD standard)
- API.md — Canonical API contract (V2 predict, models, evaluate_status, execution modes, integration checklist). Use this for integrating from any platform module.
- OpenAPI (live):
GET /api/intelligence/docs,GET /api/intelligence/redocwhen the service is running.
Communication Channels:
-
Core → Module:
- REST API:
POST /api/intelligence/analyze - REST API:
POST /api/intelligence/predict - Webhooks:
POST /api/intelligence/webhook/n8n
- REST API:
-
Module → Core:
- ONLY through Orion-LD: Module writes
Predictionentities - Core reads these entities from Orion-LD (no direct API calls)
- ONLY through Orion-LD: Module writes
Strict Separation:
- No shared code libraries
- No imports from Core
- Pure REST API + Orion-LD contract
- Multi-tenant via
X-Tenant-IDheader
- Python 3.11+
- Redis (for job queue)
- Access to Orion-LD Context Broker
pip install -r requirements.txt# Redis Configuration
REDIS_HOST=redis-service
REDIS_PORT=6379
REDIS_PASSWORD= # set in env or K8s secret; leave empty only for no-auth Redis
# Orion-LD Configuration
ORION_URL=http://orion-ld-service:1026
CONTEXT_URL=https://YOUR_PLATFORM_DOMAIN/ngsi-ld-context.json
# Service Configuration
LOG_LEVEL=INFOcd backend
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reloadFor Celery worker (V2 inference): celery -A app.celery_app worker --loglevel=info --include app.tasks.
docker build -t nekazari-module-intelligence:latest .Full request/response details and V2 contract: see API.md.
GET /health
GET /api/intelligence/models— List registered models and feature schemasPOST /api/intelligence/v2/predict— Inference with model_id + features + execution_mode (validates before enqueue; 422 on invalid)GET /api/intelligence/v2/jobs/{task_id}— Poll async taskPOST /api/intelligence/evaluate_status— Cache-only adapter (e.g. agrivoltaic)
POST /api/intelligence/analyze
Content-Type: application/json
X-Tenant-ID: <tenant_id>
{
"entity_id": "urn:ngsi-ld:AgriSensor:sensor-123",
"attribute": "temperature",
"historical_data": [
{"timestamp": "2024-01-15T10:00:00Z", "value": 20.5},
{"timestamp": "2024-01-15T11:00:00Z", "value": 22.1}
],
"prediction_horizon": 24,
"plugin": "simple_predictor"
}
POST /api/intelligence/predict
Content-Type: application/json
X-Tenant-ID: <tenant_id>
{
"entity_id": "urn:ngsi-ld:AgriSensor:sensor-123",
"attribute": "temperature",
"historical_data": [...],
"prediction_horizon": 24
}
GET /api/intelligence/jobs/{job_id}
POST /api/intelligence/webhook/n8n
Content-Type: application/json
X-Tenant-ID: <tenant_id>
{
"entity_id": "urn:ngsi-ld:AgriSensor:sensor-123",
"attribute": "temperature",
"analysis_type": "predict",
"data": {...}
}
Plugins implement the IntelligencePlugin interface. Current plugins:
- simple_predictor: Basic linear extrapolation (placeholder for ML)
To add ML plugins, uncomment data science libraries in requirements.txt and implement new plugins in intelligence_service/plugins/.
- API:
k8s/backend-deployment.yaml— FastAPI (uvicorn); labelcomponent: backend; Service selects this only. - Worker:
k8s/worker-deployment.yaml— Celery worker (same image, different command); no HTTP, no Service. Apply both when using V2 inference.
This module was extracted from services/intelligence-service/ to maintain strict separation from Core services. All dependencies on common/ have been removed and replaced with standalone implementations.