Wine Sommeliers at upmarket restaurants provide in-depth knowledge on flavour, notes and the perfect food pairing. Online wine merchants could provide a similar service to their customers with new AI technology. Imagine an online AI Wine Sommelier to help you pick out the perfect bottle…
Searching for a great bottle of wine online should be fairly straightforward, but it can be disappointing when the ones you love are out of stock, or simply out of your budget. In these situations, the ‘next best’ wines are recommended, but flavours can range widely, even within a region or grape variety. This can leave the customer disappointed if the alternative recommendations don’t quite meet their expectations.
As a result, buying wine often feels like a gamble. The 1–5 star rating system doesn’t tell us anything about the properties of the wine, and reviews are subjective.
This article will show how wine recommendations can be based on flavours, notes, food pairings and cost using RDFox, a high-performance knowledge graph and semantic reasoning engine. It will also show how this approach enables customers to select new wines without compromising on flavour, or having to hire an in-house sommelier.
RDFox is a high-performance knowledge graph and semantic reasoning engine, optimised for speed and reasoning. It is an in-memory solution, which allows flexible incremental addition and retraction of data, and incremental reasoning. Knowledge graphs are graph databases with a reasoning layer to interpret and manipulate the data. (For more information on reasoning read the article).
Knowledge graphs overcome the flexibility and speed limitations of relational databases, by allowing data points to be encoded as richly connected entities. Data is stored in triples, which contain nodes (data points) and edges (relationships).
This image is a graph representation of the wine Lupi e Sirene Riserva 2013. The representation demonstrates the various characteristics of the wine, including: flavour votes, pairings, ratings and region.
Vivino is an online wine merchant which has built a community of wine critics, who are encouraged to leave reviews and score the notes and flavours of the bottles they have purchased. Unfortunately, Vivino doesn’t allow users to search by reviewed flavours. To demonstrate how Vivino could enhance their website navigation with an AI Wine Sommelier of their own, we used RDFox to express the reviews and wine descriptions given by their entourage of wine critics.
As Vivino’s website allows any wine critic to cast their vote, there is not a uniform number of votes for each wine. To be able to find a wine similar in flavour, notes or pairings, to your favourite bottle, we can calculate the ‘normalised’ flavour votes and rankings using the data from Vivino’s website. This will allow direct comparisons of the wine’s characteristics based on user ratings and can be done in RDFox thanks to its reasoning capabilities.
Reasoning is the ability to calculate the logical consequences of applying a set of rules to a set of facts. Rules offer a convenient and expressive way to process, manipulate and create new data and bring the logical layer closer to the data.
In RDFox rules are expressed in Datalog, a declarative and formal logic-based programming language. Rules represent ‘if, then’ statements, where the formula to the left of the :- operator is the rule head (the ‘then’ part) and the formula to the right is the rule body (the ‘if’ part).
First, we can use rules to calculate the total number of flavour votes for a San Domino 2018 bottle and store this new information within the knowledge graph. In the following graph representation, all the numbers in yellow boxes on the left represent the flavour votes. These are added up to calculate the total number of votes cast for that wine’s flavour, which is 44. RDFox then stores this information as a new node, ‘FlavourCount’ 44.
The next step is to use rules to normalise the flavour votes. If we have 44 flavour votes by wine critics for the San Domino 2018 bottle of wine, then we must divide the number of votes for each flavour by 44 (i.e. the total number of votes for that wine). Using RDFox this calculation is not only quick, but scalable, and it can be used to determine the normalised flavour votes for all Vivino wines, in real time, even as votes change.
For example, the normalised flavour vote for ‘Oaky’ flavour is 0.386, for ‘blackFruit’ is 0.159 and for ‘earthy’ is 0.136.
Once we have calculated the flavour scores for each bottle of wine, we can cluster the wines by their flavour ranking. This allows us to discover which wines have been voted as similar in flavour by the wine critics.
To do this we use a rule which will create a new relationship (edge) between the bottles of wine which share similar flavours. The following graph representation shows the result of the similarity rule. As you can see, the Sanct Valentin Pinot Grigio and the Toscana Batar 2016 have very similar ‘citrus’ and ‘treeFruit’ normalised flavour ratings. This similarity results in 4 edges between the wines, because of the symmetry.
Once the rules have been executed for all wines within the knowledge graph, finding wines based on their similarities would be simple and quick for the user.
The following image provides an example of a graph of similarities between the wines:
To search for alternative wines with similar flavours, one can then look for wines that are similar in some way. This requires us to request information from the database using a query.
RDFox uses SPARQL, the standard query language for RDF triplestores. SPARQL provides a similar function to SQL for relational databases, but for graph databases, by enabling information within the RDF triplestore to be queried. Queries retrieve and model data stored within RDFox.
This can be done through the RDFox console, a code editor e.g. visual studio code, or alternatively through web applications. Web applications can be built and attached to the RDFox console, allowing users to interact with the knowledge graph without having to write SPARQL queries. This has significant benefits for businesses, like online wine merchants, whose customers would want to easily access information on the website. For this example however, we will show the SPARQL queries in the RDFox console.
The following console image demonstrates a query search for wines which share similar notes to a bottle of Podere 2013. RDFox provides 4 answers, with varying levels of similarity.
For example, the Avvoltore 2013 is similar to the Podere 2013 due to its oakiness, but the Saint Émilion is similar due to the ageing.
In a similar way we can ask for wines that are similar to the Podere 2013 in one particular way. For example, if a wine enthusiast loves ‘black fruit’ flavour, then we can request wines with a similar ‘black fruits’ score.
We can venture deeper into the dataset by finding similar wines, categorised by flavour and also by pairings. For example, if we wanted an alternative to the Ceretto Barolo 2013, which shares some similar flavours and goes with pasta, we could be recommended the Toscana Batar 2016 or the Salice Salentino 2012.
Additionally, as wine merchants often include cost within their search parameters, customers could use their AI Wine Sommelier to find wines which have similar flavours, notes and food pairings, but at a lower cost. This would allow customers to save money on wine whilst not compromising on the flavours they love.
Online wine merchants could extend their use of RDFox further than just providing their own AI Wine Sommelier, but also for managing their wine database. Wine merchants will regularly have wines added and removed from the database and wines discounted.
A significant benefit to using RDFox, is its ability to add or remove data incrementally. If a new wine bottle is added or stock is discontinued, unlike other graph databases, RDFox can incrementally add or remove recommendation data, allowing for real-time updates. Thus, the maintenance of the search interface and the data is simple. New triples, such as votes for flavours, notes and pairings — can be added directly into the database. Rules will then automatically derive conclusions on top of this data, such as which wine is similar to which other wine. See a further article on rules here.
The ability of RDFox to provide flexibility without compromising on performance, is significant in comparison to alternative database or knowledge graph solutions. This feature is great for the wine merchants as RDFox allows their website to respond in real-time to both stock counts and consumer’s needs and can be used within an AI Assistant or Faceted Search.
Additionally, wine merchants may hold discounts on certain wines. RDFox can be used to calculate these discounts. For example, if there is a discount of 29% on the Chassagne-Montrachet, we can use rules to calculate the discounted price. The discounted price is then stored in the knowledge graph as a new node, ‘discountedPrice’, 38.979.
RDFox’s ability to carry out incremental reasoning also means that if the discount changes, or the full price changes, then so does the sale price. Updates are processed incrementally within RDFox, so there is no need for batch updates or the creation of whole streaming infrastructure.
In RDFox, rules are written in Datalog. The rule for calculating the discounted price is simple example of a datalog rule used in this article:
For more in-depth examples of rules and how to write them you can find a selection of articles on ‘RDFox and Reasoning’ listed here.
By using data provided by Vivino’s wine critics, we can create clusters of similar wines, based on the flavours, pairings and cost. This approach is more akin to asking a sommelier for recommendations and can therefore reduce the risk of consumer disappointment.
Wine merchants could use RDFox to provide an AI wine Sommelier experience for their customers on their websites. This would improve the user-experience and have knock on effects for customer satisfaction and return rates, whilst empowering wine enthusiasts to find the perfect bottle.
If you would like to see a demonstration of how RDFox could be used to build your AI Wine Sommelier, get in touch at firstname.lastname@example.org
To try RDFox yourself, click here to request an evaluation license.