Vector Clustering Recommendations: Django REST + Capstone Machine Learning
Integrating K-Means and Content-Based recommendation engines directly into REST API controllers. Explores itinerary schema designs on PostgreSQL and low-latency request-response serialization cycles.
Serving ML Predictions at Production Scale
Serving complex tourist itinerary recommendations in real-time requires tight coupling between Django APIs and machine learning model weights. Loading model weights on every request cycle causes latency degradation (exceeding 800ms). To resolve this, our system loads the model parameters in memory at application startup, maintaining them in a global context.
# Django REST View Controller using preloaded K-Means models
from rest_framework.views import APIView
from rest_framework.response import Response
from .ml_loaders import preloaded_kmeans, preloaded_vectors
class ItineraryRecommendationView(APIView):
def post(self, request):
user_preferences = request.data.get('preferences')
vector = parse_preferences(user_preferences)
cluster_id = preloaded_kmeans.predict([vector])[0]
# Query geographical listings matching cluster id on Postgres
listings = Attraction.objects.filter(cluster=cluster_id)[:5]
serializer = AttractionSerializer(listings, many=True)
return Response(serializer.data)
PostgreSQL Optimization for Geolocations
Recommended nodes are geographically clustered to avoid routing users back-and-forth across long distances. We integrated the PostGIS extension on PostgreSQL, indexing our database tables with GiST indexes. This allows the Django API to execute bounding-box distance queries in under 12ms.
Response Time Results
By pre-calculating K-Means vectors and executing fast geographic lookups on PostgreSQL, the total request-response cycle averages a clean 65ms on production environments, guaranteeing smooth interaction forNext.js mobile client applications.
Systems Telemetry Logs (Comments) [ 0 ]
Transmit New Comment Log