| 22 | | This column stores the semantic meaning of each property.We created a database view:{{{vw_property_embedding_text}}} |
| 23 | | This view prepares one text description for every property.This text is then converted into an embedding. |
| | 22 | This column stores the semantic meaning of each property. Additionaly we created a new table for this phase. |
| | 23 | {{{ |
| | 24 | CREATE TABLE user_recommendation_profiles ( |
| | 25 | user_id BIGINT PRIMARY KEY |
| | 26 | REFERENCES users(user_id) |
| | 27 | ON DELETE CASCADE |
| | 28 | ON UPDATE CASCADE, |
| | 29 | |
| | 30 | preference_embedding vector(384), |
| | 31 | updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP |
| | 32 | ); |
| | 33 | }}} |
| | 34 | We created a database view:{{{vw_property_embedding_text}}} |
| | 35 | This view prepares one text description for every property. This text is then converted into an embedding. |
| | 36 | The view: |
| | 37 | {{{ |
| | 38 | |
| | 39 | CREATE OR REPLACE VIEW vw_property_embedding_text AS |
| | 40 | SELECT |
| | 41 | p.property_id, |
| | 42 | |
| | 43 | CONCAT( |
| | 44 | 'Title: ', p.title, '. ', |
| | 45 | 'Description: ', COALESCE(p.description, ''), '. ', |
| | 46 | 'Listing type: ', lt.type_name, '. ', |
| | 47 | 'City: ', a.city, '. ', |
| | 48 | 'Country: ', c.country_name, '. ', |
| | 49 | 'Base price: ', p.base_price, '. ', |
| | 50 | 'Max guests: ', p.max_guests, '. ', |
| | 51 | 'Property amenities: ', COALESCE(string_agg(DISTINCT pa_am.amenity_name, ', '), ''), '. ', |
| | 52 | 'Room types: ', COALESCE(string_agg(DISTINCT rt.type_name, ', '), ''), '. ', |
| | 53 | 'Room amenities: ', COALESCE(string_agg(DISTINCT ra_am.amenity_name, ', '), ''), '. ', |
| | 54 | 'Average rating: ', COALESCE(ROUND(AVG(rv.rating)::numeric, 2), 0), '.' |
| | 55 | ) AS embedding_text |
| | 56 | |
| | 57 | FROM properties p |
| | 58 | JOIN listing_types lt |
| | 59 | ON lt.listing_type_id = p.listing_type_id |
| | 60 | JOIN addresses a |
| | 61 | ON a.address_id = p.address_id |
| | 62 | JOIN countries c |
| | 63 | ON c.country_id = a.country_id |
| | 64 | |
| | 65 | LEFT JOIN property_amenities pa |
| | 66 | ON pa.property_id = p.property_id |
| | 67 | LEFT JOIN amenities pa_am |
| | 68 | ON pa_am.amenity_id = pa.amenity_id |
| | 69 | LEFT JOIN rooms r |
| | 70 | ON r.property_id = p.property_id |
| | 71 | LEFT JOIN room_types rt |
| | 72 | ON rt.room_type_id = r.room_type_id |
| | 73 | LEFT JOIN room_amenities ra |
| | 74 | ON ra.room_id = r.room_id |
| | 75 | LEFT JOIN amenities ra_am |
| | 76 | ON ra_am.amenity_id = ra.amenity_id |
| | 77 | |
| | 78 | LEFT JOIN reviews rv |
| | 79 | ON rv.property_id = p.property_id |
| | 80 | |
| | 81 | GROUP BY |
| | 82 | p.property_id, |
| | 83 | p.title, |
| | 84 | p.description, |
| | 85 | p.base_price, |
| | 86 | p.max_guests, |
| | 87 | lt.type_name, |
| | 88 | a.city, |
| | 89 | c.country_name; |
| | 90 | |
| | 91 | }}} |