Geospatial Recommendation
Geospatial Recommendation System

In this tutorial, we'll enhance our restaurant recommendation system using Full Text Search (FTS) Indexes and Geospatial APIs.
- Extract User Preferences: Identify key details from user input such as preferred cuisines and location.
- Construct Query String: Synthesize these details into a structured query string for searching.
- Perform FTS Index Search: Use the query string to find relevant restaurant recommendations.
- Apply Geospatial Filtering: Use a Geospatial API to locate the user and refine recommendations based on proximity.
We can enhance later on by adding a filter to sort the recommendations based on distance
Importing the relevant libraires
--2025-01-05 10:34:14-- https://drive.google.com/uc?export=download&id=17Div0ml4Nelr1C4QaGVJzC7lnMx--BkM Resolving drive.google.com (drive.google.com)... 74.125.126.139, 74.125.126.138, 74.125.126.102, ... Connecting to drive.google.com (drive.google.com)|74.125.126.139|:443... connected. HTTP request sent, awaiting response... 303 See Other Location: https://drive.usercontent.google.com/download?id=17Div0ml4Nelr1C4QaGVJzC7lnMx--BkM&export=download [following] --2025-01-05 10:34:14-- https://drive.usercontent.google.com/download?id=17Div0ml4Nelr1C4QaGVJzC7lnMx--BkM&export=download Resolving drive.usercontent.google.com (drive.usercontent.google.com)... 74.125.202.132, 2607:f8b0:4001:c06::84 Connecting to drive.usercontent.google.com (drive.usercontent.google.com)|74.125.202.132|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 883287 (863K) [application/octet-stream] Saving to: ‘data.csv’ data.csv 100%[===================>] 862.58K --.-KB/s in 0.007s 2025-01-05 10:34:17 (121 MB/s) - ‘data.csv’ saved [883287/883287]
Embedding the relevant parts of the data.
We will extract key information from the restaurant dataset columns and create a query string. This string will be encoded using our embedding model and then combined with additional data for storage in the Vector Database.
/usr/local/lib/python3.10/dist-packages/sentence_transformers/SentenceTransformer.py:195: FutureWarning: The `use_auth_token` argument is deprecated and will be removed in v4 of SentenceTransformers. warnings.warn(
Using the LanceDB database
Query Transformation
'Food type/Biryani,Chinese,North Indian,South Indian#Avg ratings/4.4#Address/5Th Block'
Extracting the specifics from the query
Just like we pulled out the key details from our CSV to craft query strings, we’ll do the same with user queries. This step is important because it makes searching for the right recommendations much smoother. I mean doing so we can easily run the FTS Index Search.
{
"Food type": "Indian or Italian",
"Avg ratings": None,
"Address": "HSR Bangalore"
}
Food type/Indian or Italian#Address/HSR Bangalore
Using LanceDB FTS for searching
GeoSpatial Recommendation
Ok now we will use the Google Geospatial API to pinpoint the exact locations of restaurants and find their coordinates. The next step is to calculate the distance between these restaurants and the user's location. For this, I am going to use the Haversine formula, which uses the coordinates of two points to draw an imaginary straight line between them, measuring the distance across the Earth's surface. There's some math behind how this formula works, but we'll keep things simple and focus on its application for now.
Restaurant Name: Cafe Azzure Distance: 8.06 km Area: Ashok Nagar Price: 1000.0 Coordinates: (12.975012, 77.6076558) Cuisines Type: American,Italian ---------------------------------------- Restaurant Name: Hyderabad Biryaani House Distance: 8.55 km Area: Victoria Layout Price: 499.0 Coordinates: (12.9715987, 77.5945627) Cuisines Type: Indian ---------------------------------------- Restaurant Name: Aaliyar Ambur Dum Biryani Distance: 7.53 km Area: Ashok Nagar Price: 200.0 Coordinates: (12.9694702, 77.60761529999999) Cuisines Type: Indian ---------------------------------------- Restaurant Name: Jw Kitchen - Jw Marriott Distance: 8.58 km Area: Ashok Nagar Price: 1000.0 Coordinates: (12.972231, 77.59495299999999) Cuisines Type: Indian,Continental ---------------------------------------- Restaurant Name: The Ritz-Carlton - Ganache Distance: 8.55 km Area: Ashok Nagar Price: 1000.0 Coordinates: (12.9715987, 77.5945627) Cuisines Type: Indian,Bakery ----------------------------------------