| 11 | | This is the recommendation system that recommends open task requests to workers that have the most similar completed tasks. For this purpose we first embedded the open task requests and then as a starting point for our system we embedded three task requests that resulted in a completed task for each worker. We found this number of tasks enough as a starting point for our app. We built these embeddings with the script [attachment:embed_taskrequests.py] and we used a table to store these vectors: |
| 12 | | |
| | 11 | This is the recommendation system that recommends open task requests to workers that have the most similar completed tasks. For this purpose we first embedded the open task requests and then as a starting point for our system we embedded three task requests that resulted in a completed task for each worker. We found this number of tasks enough as a starting point for our app. We built these embeddings and we used a table to store these vectors: |
| | 12 | {{{ |
| | 13 | #!sql |
| | 14 | INSERT INTO worker_recommendation_profiles |
| | 15 | ( |
| | 16 | worker_id, |
| | 17 | preference_embedding, |
| | 18 | updated_at |
| | 19 | ) |
| | 20 | WITH ranked_tasks AS |
| | 21 | ( |
| | 22 | SELECT |
| | 23 | o.worker_id, |
| | 24 | o.task_request_id, |
| | 25 | ROW_NUMBER() OVER |
| | 26 | ( |
| | 27 | PARTITION BY o.worker_id |
| | 28 | ORDER BY |
| | 29 | COALESCE(t.updated_at, t.created_at) DESC |
| | 30 | ) AS rn |
| | 31 | FROM Task t |
| | 32 | JOIN Offer o |
| | 33 | ON o.id = t.offer_id |
| | 34 | WHERE t.status = 'COMPLETED' |
| | 35 | ) |
| | 36 | SELECT |
| | 37 | rt.worker_id, |
| | 38 | AVG(tre.embedding), |
| | 39 | CURRENT_TIMESTAMP |
| | 40 | FROM ranked_tasks rt |
| | 41 | JOIN task_request_embeddings tre |
| | 42 | ON tre.task_request_id = rt.task_request_id |
| | 43 | WHERE rt.rn <= 3 |
| | 44 | GROUP BY rt.worker_id |
| | 45 | ON CONFLICT (worker_id) |
| | 46 | DO UPDATE SET |
| | 47 | preference_embedding = EXCLUDED.preference_embedding, |
| | 48 | updated_at = CURRENT_TIMESTAMP; |
| | 49 | }}} |