# Install dependencies
npm install
# Set up environment
cp .env.example .env
# Configure database
npm run migrate
# Initialize feature store
npm run init-feature-store
# Train initial models (offline)
npm run train-modelsnpm run start:inference
# Expected output:
# [Inference Service] Started on port 3000
# [Feature Store] Connected to PostgreSQL
# [Redis Cache] Connected
# [Models] Loaded 4 models (CF, CB, LPO, LTR)curl -X POST http://localhost:3000/api/recommendations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"userId": "user_001",
"context": {
"currentTimestamp": "'$(date -u +'%Y-%m-%dT%H:%M:%SZ')'",
"sessionDepth": 1,
"deviceType": "desktop"
},
"candidateContentIds": ["course_0001", "course_0002", "course_0003"],
"k": 3
}'Components: PostgreSQL, Redis, Feature ETL
# 1. Create PostgreSQL schema
npm run create-schema
# 2. Start Redis
docker run -d -p 6379:6379 redis:7
# 3. Initialize feature tables
npm run init-features
# 4. Load test data
npm run load-test-data
# Validate
npm run validate-feature-storeVerification:
- 100 users in user_features
- 500 content items in content_features
- 5000 interactions in user_content_interactions
- Redis cache responding
- Latency <50ms for feature retrieval
Components: Model Training Pipeline
# 1. Prepare interaction matrix
npm run prepare-interactions
# 2. Train collaborative filtering (ALS)
npm run train:cf --iterations=10 --factors=100
# 3. Train content embeddings
npm run train:nlp --model="all-MiniLM-L6-v2"
# 4. Train learning path optimizer
npm run train:lpo --strategy="heuristic"
# 5. Train LTR ranker
npm run train:ltr --model="xgboost"
# 6. Validate models
npm run validate:models
# Output:
# Collaborative Filtering NDCG@10: 0.78 ✓
# Content-based NDCG@10: 0.76 ✓
# LTR Ranker NDCG@10: 0.82 ✓Success Criteria:
- CF NDCG@10 > 0.75
- CB NDCG@10 > 0.73
- LTR NDCG@10 > 0.80
- MAP@10 > 0.65
- Recall@20 > 0.78
Components: API, Caching, Rate Limiting
# 1. Build Docker image
docker build -t teachlink-recommendation:v1.0 .
# 2. Deploy to Kubernetes
kubectl apply -f k8s/deployment.yaml
# 3. Set up monitoring
npm run setup:monitoring
# 4. Configure alerts
npm run setup:alerts
# Verify deployment
kubectl get pods -l app=teachlink-recommendationDeployment Checklist:
- 3 replicas running
- Load balancer configured
- Health checks passing
- Prometheus metrics exposed
- Latency <100ms P95
Components: Privacy Layer, GDPR Compliance
# 1. Enable differential privacy
npm run setup:privacy --epsilon=0.5 --delta=1e-5
# 2. Configure data retention
npm run setup:retention --max-days=90
# 3. Set up anonymization
npm run setup:anonymization --salt=YOUR_SALT
# 4. Test data deletion
npm run test:gdpr-deletion
# 5. Verify compliance
npm run audit:privacyCompliance Verification:
- User anonymization working
- Differential privacy applied to analytics
- Data deletion working end-to-end
- PII filtering active
- Audit logs captured
Components: Experiment Manager, Metrics Collection
# 1. Create baseline experiment
npm run create-experiment --name="control_vs_variant_a" \
--duration=14 \
--sample-size=10000
# 2. Launch experiments
npm run launch-experiments
# 3. Monitor metrics
npm run monitor:experiments
# 4. Analyze results
npm run analyze:experiments --experiment-id=exp_001
# Output: Statistical analysis with p-valuesExperiment Configuration:
- Control group defined
- Variant weights specified
- Metrics to track defined
- Minimum sample size met
- Statistical power calculated
# 1. Canary deployment (1% traffic)
npm run deploy:canary --percentage=1
# 2. Monitor canary metrics
npm run monitor:canary --duration=48h
# 3. Gradual rollout
npm run deploy:gradual --step=10 --interval=3h
# 4. Full production deployment
npm run deploy:production
# 5. Verify in production
npm run verify:productionimport { RecommendationInferenceService } from './src/inference/inference-service';
const response = await inferenceService.getRecommendations({
userId: 'new_user_001',
context: {
currentTimestamp: new Date(),
sessionDepth: 0,
deviceType: 'desktop',
isFirstSession: true,
},
requestId: 'req_001'
}, ['course_0001', 'course_0002', 'course_0003'], 5);
console.log(response.recommendations[0].explanation.primaryReason);
// Output: "Popular and highly-rated content for new learners"// User with >90% completion rate and high learning velocity
const advancedResponse = await inferenceService.getRecommendations({
userId: 'user_advanced_001',
context: {
currentTimestamp: new Date(),
sessionDepth: 3,
currentLearningGoal: 'learn-advanced-ml',
deviceType: 'desktop',
},
requestId: 'req_002'
}, allCourseIds, 5);
// Result: Advanced, challenging content recommended
console.log(response.recommendations[0].metadata.difficulty); // 4 (Expert)// User with low completion rate and high dropout risk
const strugglingResponse = await inferenceService.getRecommendations({
userId: 'user_struggling_001',
context: {
currentTimestamp: new Date(),
sessionDepth: 1,
deviceType: 'mobile', // Struggling users often use mobile
},
requestId: 'req_003'
}, allCourseIds, 5);
// Result: Easier, encouraging content recommended
console.log(response.recommendations[0].explanation.primaryReason);
// Output: "We're recommending engaging content to keep you motivated"# Run all unit tests
npm test
# Run specific module tests
npm test -- --testPathPattern=collaborative-filtering
# Coverage report
npm test -- --coverage# Test against real feature store
npm run test:integration
# Test recommendation pipeline end-to-end
npm run test:e2e# Load testing (simulate 1000 QPS)
npm run test:load --qps=1000 --duration=60s
# Latency profiling
npm run profile:latency
# Expected result: P95 latency <150ms# Evaluate models on held-out test set
npm run evaluate:offline
# Output:
# NDCG@10: 0.78 ✓
# MAP@10: 0.65 ✓
# Recall@20: 0.81 ✓
# Serendipity: 0.62 ✓Inference Service:
├── Latency: P50=28ms, P95=87ms, P99=142ms
├── Throughput: 1,250 QPS
├── Cache Hit Rate: 72%
└── Error Rate: 0.02%
Model Performance:
├── Collaborative Filtering: NDCG@10=0.78
├── Content-Based: NDCG@10=0.76
├── LTR Ranker: NDCG@10=0.82
└── Diversity: 0.75
Online Metrics:
├── CTR: 0.071
├── Completion Rate: 0.467
├── Retention (7-day): 0.72
└── Learning Gain: 7.5
alerts:
- name: high_latency
condition: latency_p95 > 150
severity: warning
- name: model_degradation
condition: ndcg10 < 0.70
severity: critical
- name: cache_miss_rate
condition: cache_miss_rate > 0.30
severity: warning
- name: error_rate
condition: error_rate > 0.01
severity: critical# Database
DATABASE_URL=postgresql://user:pass@localhost:5432/teachlink
REDIS_URL=redis://localhost:6379
# Models
CF_ITERATIONS=10
CF_FACTORS=100
NLP_MODEL_NAME=all-MiniLM-L6-v2
NLP_EMBEDDING_DIM=384
# Privacy
DIFFERENTIAL_PRIVACY_EPSILON=0.5
DIFFERENTIAL_PRIVACY_DELTA=1e-5
DATA_RETENTION_DAYS=90
# Inference
INFERENCE_CACHE_TTL=300000
MAX_BATCH_SIZE=100
LATENCY_TARGET_MS=150
# A/B Testing
EXPERIMENT_MIN_SAMPLE_SIZE=1000
EXPERIMENT_CONFIDENCE_LEVEL=0.95
# Feature Store
FEATURE_STORE_TYPE=postgresql
FEATURE_BATCH_SIZE=1000
FEATURE_CACHE_SIZE=50000Diagnostics:
npm run diagnose:latency
# Check:
# 1. Feature store query time
# 2. Model inference time
# 3. Network latency
# 4. Cache hit rateSolutions:
- Increase Redis cache size
- Use model quantization
- Add more inference replicas
- Verify database indexes
Diagnostics:
npm run diagnose:quality
# Check:
# 1. Feature freshness
# 2. Model versions
# 3. Training data quality
# 4. User cold-start ratioSolutions:
- Retrain models with fresh data
- Increase feature update frequency
- Improve cold-start strategy
- Validate interaction data quality
Solutions:
- Verify randomization logic
- Check for data pipeline issues
- Increase sample size
- Check for external factors (marketing campaign, etc.)
# Update user embeddings
npm run update:embeddings --interval=weekly
# Update content embeddings
npm run update:nlp-embeddings --interval=weekly
# Cleanup cache
npm run cleanup:cache
# Generate reports
npm run report:weekly# Retrain collaborative filtering
npm run retrain:cf --schedule=monthly
# Retrain LTR ranker
npm run retrain:ltr --schedule=monthly
# Audit privacy compliance
npm run audit:privacy
# Archive old experiments
npm run archive:experiments# Full model retraining
npm run retrain:all
# Feature store optimization
npm run optimize:feature-store
# Cost optimization analysis
npm run analyze:costs✓ Collaborative filtering working
npm run test:cf
✓ NLP content embeddings generated
npm run test:nlp
✓ Hybrid ranking functional
npm run test:hybrid
✓ Learning paths adapt to performance
npm run test:learning-paths
✓ Recommendations include explanations
npm run test:explanations
✓ A/B testing framework active
npm run test:ab-testing
✓ Privacy safeguards implemented
npm run test:privacy
✓ Test datasets validate multiple personas
npm run test:synthetic-data-
Caching Strategy
- Cache user embeddings (5m TTL)
- Cache content features (1h TTL)
- Cache similarity matrices (6h TTL)
-
Model Optimization
- Use model quantization (FP16)
- Batch inference requests
- Use GPU inference for neural models
-
Database
- Add indexes on user_id, content_id
- Partition interaction table by user
- Archive old events regularly
-
Infrastructure
- Use CDN for static embeddings
- Deploy inference service close to users
- Use load balancing for horizontal scaling
- API Reference: See
docs/API_REFERENCE.md - Architecture: See
ARCHITECTURE.md - Issues: GitHub Issues tracker
- Slack: #teachlink-recommendations
TeachLink Recommendation System - Proprietary © 2026