| | 282 | = Worker Recommendation for Task Requests = |
| | 283 | |
| | 284 | Besides recommending task requests to workers, the system also supports recommending suitable workers for a specific task request. |
| | 285 | |
| | 286 | The function compares the embedding of the selected task request with the stored worker profile embeddings and ranks the workers according to their vector similarity. Workers who have already submitted an offer for the given task request are excluded from the results. |
| | 287 | |
| | 288 | {{{#!sql |
| | 289 | CREATE OR REPLACE FUNCTION |
| | 290 | recommend_workers_for_task_request |
| | 291 | ( |
| | 292 | p_task_request_id BIGINT, |
| | 293 | p_limit INT DEFAULT 20 |
| | 294 | ) |
| | 295 | RETURNS TABLE |
| | 296 | ( |
| | 297 | worker_id BIGINT, |
| | 298 | distance DOUBLE PRECISION, |
| | 299 | recommendation_type TEXT |
| | 300 | ) |
| | 301 | LANGUAGE plpgsql |
| | 302 | AS |
| | 303 | $$ |
| | 304 | BEGIN |
| | 305 | RETURN QUERY |
| | 306 | SELECT |
| | 307 | wrp.worker_id::BIGINT, |
| | 308 | tre.embedding |
| | 309 | <=> |
| | 310 | wrp.preference_embedding |
| | 311 | AS distance, |
| | 312 | 'PERSONALIZED'::TEXT |
| | 313 | FROM task_request_embeddings tre |
| | 314 | JOIN worker_recommendation_profiles wrp |
| | 315 | ON wrp.preference_embedding IS NOT NULL |
| | 316 | WHERE |
| | 317 | tre.task_request_id = p_task_request_id |
| | 318 | AND wrp.worker_id NOT IN |
| | 319 | ( |
| | 320 | SELECT |
| | 321 | o.worker_id |
| | 322 | FROM Offer o |
| | 323 | WHERE |
| | 324 | o.task_request_id = p_task_request_id |
| | 325 | ) |
| | 326 | ORDER BY |
| | 327 | distance ASC |
| | 328 | LIMIT |
| | 329 | p_limit; |
| | 330 | END; |
| | 331 | $$; |
| | 332 | }}} |
| | 333 | |
| | 334 | {{{#!sql |
| | 335 | SELECT * |
| | 336 | FROM recommend_workers_for_task_request(150, 20); |
| | 337 | }}} |
| | 338 | |
| | 339 | The query returns the 20 workers whose previous completed tasks are the most semantically similar to the selected task request. |