DEV Community

Cover image for Building a restaurant recommendation system using vector search
Gayatri Sachdeva
Gayatri Sachdeva

Posted on • Originally published at dronahq.com

Building a restaurant recommendation system using vector search

Recommendation systems are the engines behind personalized user experiences on platforms like Netflix, Amazon, and Spotify. In this post, we'll walk you through building your own restaurant recommendation system using MyScaleDB's vector search combined with DronaHQ's low-code platform.

In this guide, you’ll learn how to:

  • Understand the basics of vector search.
  • Prepare and manage data in MyScaleDB for effective searches.
  • Integrate MyScaleDB with DronaHQ to create a location-aware restaurant recommendation system.
  • Build and deploy a working app using these tools.

Let’s dive in!


What is Vector Search?

Vector search goes beyond keyword matching by transforming data into vectors within a multi-dimensional space. Each vector represents the key features of a data point (like user preferences, reviews, or restaurant attributes). Using cosine similarity, the system can then compare how similar two vectors are, even if they don't share exact keywords.

For example, in a restaurant recommendation system, vector search compares factors like ambiance, user reviews, and dining experiences. It can then recommend restaurants that offer similar overall experiences, rather than just matching by specific criteria like cuisine type or price range.

Preparing Data in MyScaleDB

For this project, we use MyScaleDB, an open-source SQL-based vector database built on top of ClickHouse. It supports both structured and vectorized data, making it ideal for large-scale applications that require efficient search.

Steps to Prepare Data:

Create a MyScaleDB Cluster: Head over to the MyScaleDB console, log in, and create a new cluster for your data.

  1. Install Dependencies: Install the necessary libraries:
pip install sentence-transformers clickhouse_connect
Enter fullscreen mode Exit fullscreen mode
  1. Prepare Data: Load synthetic data into MyScaleDB. We have three CSV files:
  • restaurants.csv: Details about restaurant attributes.
  • users.csv: User preferences like cuisine types and average spending.
  • reviews.csv: Reviews and ratings for each restaurant.

Example code for loading CSV data:

import pandas as pd

df_restaurants = pd.read_csv("restaurants.csv")
df_users = pd.read_csv("users.csv")
df_reviews = pd.read_csv("reviews.csv")
Enter fullscreen mode Exit fullscreen mode
  1. Generate Embeddings: Use a HuggingFace model to generate vector embeddings for the text data (cuisines, reviews). These embeddings allow us to perform similarity searches later:
from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
model = AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")

def get_embeddings(texts: list) -> list:
    inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="pt")
    outputs = model(**inputs)
    return outputs.last_hidden_state.mean(dim=1).numpy().tolist()
Enter fullscreen mode Exit fullscreen mode
  1. Apply the function to your data:
df_restaurants["cuisine_embeddings"] = get_embeddings(df_restaurants["cuisine"].tolist())
df_users["cuisine_preference_embeddings"] = get_embeddings(df_users["cuisine_preference"].tolist())
df_reviews["review_embeddings"] = get_embeddings(df_reviews["review"].tolist())
Enter fullscreen mode Exit fullscreen mode

Setting Up MyScaleDB

With your data ready, let’s set up the tables in MyScaleDB:

Create Tables for users, restaurants, and reviews:

CREATE TABLE default.restaurants (
    restaurantId Int64,
    name String,
    cuisine String,
    rating Float32,
    price_range Int64,
    cuisine_embeddings Array(Float32)
) ENGINE = MergeTree() ORDER BY restaurantId;
Enter fullscreen mode Exit fullscreen mode

Insert Data into these tables:

client.insert("default.restaurants", df_restaurants.to_records(index=False).tolist(), column_names=df_restaurants.columns.tolist())
Enter fullscreen mode Exit fullscreen mode

Add Vector Index to enable vector search:

ALTER TABLE default.restaurants ADD VECTOR INDEX restaurant_index cuisine_embeddings TYPE MSTG;
Enter fullscreen mode Exit fullscreen mode

Integrating MyScaleDB with DronaHQ

Next, let’s integrate MyScaleDB with DronaHQ, a low-code platform that lets you build custom web and mobile apps quickly using pre-built UI components, data connectors, and workflow automation tools.

Steps:
Configure the ClickHouse Connector in DronaHQ (since MyScaleDB operates on ClickHouse). Fill in your MyScaleDB credentials to set up the connection.

Write Queries to fetch restaurant recommendations. For example, fetch restaurants based on user preferences:

SELECT * FROM default.restaurants 
WHERE cuisine LIKE '%[[cuisine_pref]]%' 
AND price_range < [[price]] 
LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

Vector Search for Similar Restaurants:

SELECT *, distance(cuisine_embeddings, [[embedding]]) AS dist 
FROM default.restaurants 
ORDER BY dist 
LIMIT 5;

Enter fullscreen mode Exit fullscreen mode

Building the App on DronaHQ

With the backend ready, let’s build the app using DronaHQ’s drag-and-drop builder.

  • Design the UI: Use DronaHQ’s component library to build a clean, responsive interface with dropdowns for cuisine preferences, price sliders, and result cards to display restaurant recommendations.

  • Create Action Flows: Set up actions that trigger your queries based on user input, dynamically updating the UI as the user interacts with the app.

  • Deploy the App: Once everything is set, deploy your app and test it live!

Conclusion

By combining the power of MyScaleDB’s vector search and DronaHQ’s low-code environment, we’ve built a scalable, personalized restaurant recommendation system. Whether you're a seasoned developer or just starting out, this approach offers flexibility and speed in creating data-driven applications.

Beyond restaurant finders, the same techniques can be applied to many other use cases like chatbots, product recommendations, or even intelligent search systems.

If you're looking to dig deeper, you can explore more advanced features in vector search and how they can be integrated into your existing applications!

Top comments (0)