AI Wine Sommelier

  • R.P. Consulting (freelance)
  • 2024 – 2025
  • role: backend developer

Flask API for an Italian company: GPT-4o and embedding search over its wine database turn a request in plain Italian into recommendations, food pairings and themed 'wine playlists'.

results

  • In production with the client: 11 endpoints for search, pairings and 'wine playlists' with DALL·E 3 covers
  • Semantic search over OpenAI embeddings of each wine’s Italian description, kept in their own table next to the catalogue and blended with a rule-based score
  • A first model call checks whether a request is specific enough before any search runs
  • Answers stream back as server-sent events; the enriched catalogue is cached in memory for a day

architecture

The client's app calls a Flask API (11 endpoints, streamed over SSE, catalogue cached for a day), which combines MySQL with 30,000+ wines, OpenAI embedding search blended with a rule-based score, GPT-4o for recommendations and pairings, and DALL·E 3 for playlist covers.

External. To Flask API.Client's appin productionBuilt by me. From Client's app. To MySQL, Embedding search, GPT-4o, DALL·E 3.Flask API11 endpoints · SSEcatalogue cached 24 hStorage. From Flask API.MySQL30,000+ winesAI / ML. From Flask API.Embedding searchOpenAI embeddings+ rule-based scoreAI / ML. From Flask API.GPT-4orecommendationsfood pairingsAI / ML. From Flask API.DALL·E 3'wine playlist' coversExternal. To Flask API.Client's appin productionBuilt by me. From Client's app. To MySQL, Embedding search, GPT-4o, DALL·E 3.Flask API11 endpoints · SSEcatalogue cached 24 hStorage. From Flask API.MySQL30,000+ winesAI / ML. From Flask API.Embedding searchOpenAI embeddings+ rule-based scoreAI / ML. From Flask API.GPT-4orecommendationsfood pairingsAI / ML. From Flask API.DALL·E 3'wine playlist' covers

the story

A freelance project for R.P. Consulting, an Italian company, in production: a Flask API behind the client's own app, over a MySQL database of more than 30k wines. You ask for something in plain Italian and get recommendations, food pairings, or a themed wine playlist with a description, a menu and a cover image.

A request goes through a few steps. First a model call checks whether it's specific enough to search on. Then the search: every wine's long Italian description, stripped of stopwords, is embedded with OpenAI's text-embedding-ada-002, and the vectors sit in their own table next to the catalogue in MySQL. The query is matched against them by cosine similarity to pick the best candidates first: the threshold starts strict (0.82) and relaxes in steps until there are ten, and the similarity is blended with a rule-based score. GPT-4o then writes the recommendation or the pairing, and DALL·E 3 draws the playlist covers.

Keeping it quick

One request means several model calls and a search over the whole catalogue. The catalogue, joined with producers and prices, is built once into an in-memory table and cached for a day, lookups for an hour, and the answers stream back as server-sent events, so the first words arrive while the rest is still being written. On the database side, a connection pool with retries and exponential backoff keeps a slow MySQL from failing a request.

built with