Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
suyiqing
Participant
This tutorial aims to help you master custom enrichment for SAP Conversational AI and use it smartly to power your bot and improve how the memory is leveraged in the Bot Builder. It is intended for users who have already read our introductory tutorials, such as how to build your first chatbot with SAP Conversational AI.
If you haven’t already done so, we recommend that you check out this tutorial to learn the fundamentals of the bot platform. You can find more starter tutorials here. When you’re ready to dive into this tutorial, you can call up the dedicated bot here.

What is custom enrichment?


By default, when you create custom entities, they have only three keys:

  • Value

  • Raw

  • Confidence


In line with the subject of this tutorial, let’s assume someone is using a bot created for a department store that has a branch on the Champs Elysées. When the user enters “where is Champs.Elysees store?”, the bot detects an entity called #store. The “raw” value is precisely what the user has entered (here, “Champs.Elysees”), including uppercase and special characters; the “value” is the “raw” value without uppercase or special characters; and the “confidence” is how sure the bot is that it has detected an entity.


The goal of custom enrichment is to help you provide more information than these three default values can: With custom enrichment, whenever an entity is detected, the JSON returned by the NLP API is enhanced with additional information about that entity. Enrichments for gold entities are currently fixed by the SAP Conversational AI team and therefore cannot be configured.

Example use case


Let’s assume you’ve found the department store’s branch on the Champs Elysées mentioned above. You can ask your bot how many floors the store has. When you’re on a specific floor, you can ask the bot about the different categories of items on this floor and which items are currently available.

Here’s an example of the conversation:



Modelization


The following figure shows the design of the database model used in this tutorial. There are multiple categories on each floor, and each category contains multiple items.



Intents and entities


In this tutorial, we know what store we’re in, so we’ll only have two main intents: @choose-floor and @buy-items.

  • @choose-floor allows users to select a floor or find out the number of floors in the store.

  • @buy-items allows users to select the category of items they want to buy.


We have three floors: first floor, second floor, and third floor. There are two categories on each floor and up to four items in each category.

If we were to set up an entity for each floor and each category, we’d soon have lots of entities. Fortunately, we don’t need to do this. Instead, we can create just two entities, which list the floors and categories respectively. These are as follows:

  • #floor lists all possible ways to express a floor (1st floor, floor 2, and so on)

  • #items lists all available categories in the store (CDs, DVDs, and the like)


In the @choose-floor intent, you train the bot to understand sentences such as the following:

  • How many floors?

  • I am on the first floor.

  • Which floor am I on?


The #floor entity is linked to this intent. This entity contains a list of words denoting floors, which you want to use to find the categories.

In the @buy-items intent, you train the bot to understand what category the user has chosen:

  • I want to buy CDs

  • I want to buy DVDs


The #items entity is linked to this intent. This entity will contain a list of categories that are used to find the items.

Keys and values to add in the custom enrichments of our two entities


#floor:

  • Floor: a number (integer) representing the generic value for the floor (for example, 1 is the generic value of 1st, 1, and first)

  • Categories: an array of strings representing the categories of items available for the floor

  • Store: a string representing the store address

  • Max-floor: a number (integer) representing the number of floors in the current store


#items:

  • Floor: a number (integer) indicating the floor for the category

  • Type: a string representing the standard name of categories

  • Item-details: an array of JSON objects. Each object has four keys that show details of items in each category:

    • Title: a string containing the title of the item

    • Description: a string describing the item

    • Picture: a string providing a link to the picture of the item

    • Link: a string providing a link to the shopping website




How to create a store guide bot on the SAP Conversational AI platform


Create intents


You create a new bot in the same way as you created your first bot. You can fork the intents @choose-floor and @buy-items from the tutorial bot to your bot. In the following, we’ll focus on how to create our two entities and use custom enrichments.

Create entities



  • #floor entity


You create the #floor entity as a free entity. This allows the bot to detect other values in addition to the defined ones. For example, if the user asks for floor 5, the bot can’t give a list of available categories, but it can tell the user that the floor they’re asking about doesn’t exist. See below for the #floor enrichments:

1) Go to #floor > Enrichments tab, you see “Your default enrichment”.


2) Use the + ADD NEW PAIR button and create the four enrichments mentioned above: “floor”, “categories”, “store”, and “max-floor”. You should give two of them a default value.


3) Next you add groups of values in the Your specific enrichment A group is a list of synonyms that have the same enrichments. Create three groups (“1”, “2”, and “3”) for the three floors in our store:


4) Add some synonyms for the three groups in the box on the left. For example, “1”, “first”, and “1st” are synonyms for the first floor:


5) Add corresponding “floor” enrichment values in each of the groups:


6) Add corresponding “categories” enrichment values in each of the groups. You can simply copy and paste the following values:

The 1st floor:

[“CD”, “DVD”]

The 2nd floor:

[“guide”, “book”]

 The 3rd floor:

[“smartphone”, “camera”]


As you can see, instead of adding a single value, you can add a list of values in the enrichment. This will later allow you to propose different options for your users in the Bot Builder. Once you complete this step, you have added all the information for #floor.

7) Tag the #floor entity manually in the expressions in the @choose-floor intent.


Click here to see the completed #floor entity. The entity is free. As a result, List of values is empty. If you have tagged the entity in the @choose-floor intent, then you can see a list of sentences under the heading Tagged value.

  • #items entity


You create the #items entity as a restricted entity. A restricted entity should have a strictly defined list of values to detect. If the user doesn’t ask about a category in the list, the bot asks them to try other categories.
Click here to download the category list, and see below for the #items enrichments:

1) In the List of values tab, choose the Import a csv file button to use the downloaded file to add values for the #items entity. These values are the names of categories.


2) Create three enrichments: “floor”, “type”, and “item-details”. None of them has a default value.


3) Create six groups of categories: “camera”, “smartphone”, “cd”, “dvd”, “guide”, and “book”.


4) Add synonyms for the six groups. Because the entity is restricted, when you click to add a synonym, you choose from values in the previously defined list of values.


5) Add corresponding enrichment values in groups. The “item-details” enrichment is enriched with an array of JSON objects, as mentioned above in Keys and values to add in the custom enrichments of our two entities. And the great thing is: You can define all the different information related to the item in one JSON object. Of course, our brick-and-mortar store is unlikely to link to an online competitor like Amazon. We’ve included these URLs simply as an example.

You can copy the following enrichments for the corresponding group to your bot:

cd group

floor: 1

type: “CD”

Item-details:

[{“title”:”The 20/20 Experience”, “description”: “Justin Timberlake”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/81C3LbZQstL._SY355_.jpg”, “link”: “https://www.amazon.com/20-Experience-Justin-Timberlake/dp/B00BCZU8WM”},  {“title”:”Femme Fatale Deluxe”, “description”: “Britney Spears”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/81VVfwRiklL._SL1500_.jpg”, “link”: “https://www.amazon.com/Femme-Fatale-Deluxe-Britney-Spears/dp/B004KSQN7C”}, {“title”:”La La Land Soundtrack”, “description”: “Emma Stone and Ryan Gosling”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/51AbW8DKNDL._SY355_.jpg”, “link”: “https://www.amazon.com/Land-Original-Motion-Picture-Soundtrack/dp/B01MPXX9GE”}, {“title”:”Bohemian Rhapsody”, “description”: “Queen”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/91sLchfSmpL._SX522_.jpg”, “link”: “https://www.amazon.com/Bohemian-Rhapsody-Queen/dp/B07GRVBTTT/ref=pd_sim_15_1/141-6047500-7233044?_en...}]

dvd group

floor: 1

type: “DVD”

item-details:

[{“title”:”Iron Man”, “description”: “Robert Downey Jr. stars as Tony Stark/Iron Man in the story of a billionaire industrialist and genius inventor who is kidnapped and forced to build a devastating weapon”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/41W6U03Kr4L.jpg”, “link”: “https://www.amazon.com/Iron-Man-Single-Disc-Robert-Downey/dp/B001C08RHA”}, {“title”:”Spiderman”, “description”: “Average teenager Peter Parker is transformed into an extraordinary super hero after he is accidentally bitten by a radioactive spider”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/51BZHCbJ-QL.jpg”, “link”: “https://www.amazon.com/Spider-Man-Screen-Special-Cliff-Robertson/dp/B00006F2TV”}]

guide group

floor: 2

type: “guide”

item-details:

[{“title”:”Guide du Routard Paris 2019″, “description”: “Le Routard, le meilleur compagnon de voyage depuis 45 ans.”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/51ekZ5QUpvL._SX297_BO1,204,203,200_.jpg”, “link”: “https://www.amazon.fr/Guide-Routard-Paris-2019-suprenantes/dp/2016267046”}, {“title”:”Lonely Planet Portugal”, “description”: “The most relevant, up-to-date advice.”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/513UbBGb2yL._SX322_BO1,204,203,200_.jpg”, “link”: “https://www.amazon.co.uk/Lonely-Planet-Portugal-Travel-Guide/dp/1786573229”}]

book group

floor: 2

type: “book”

item-details:

[{“title”:”Les Misérables”, “description”: “Victor Hugo”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/51JEItnoKFL.jpg”, “link”: “https://www.amazon.com/Mis%C3%A9rables-Victor-Hugo-ebook/dp/B0771X5YZL”}, {“title”:”Da Vinci Code (Édition anniversaire)”, “description”: “Dan Brown”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/91Q5dCjc2KL.jpg”, “link”: “https://www.amazon.com/Vinci-Code-Robert-Langdon/dp/0307474275”}]

camera group

floor: 3

type: “camera”

item-details:

[{“title”:”GoPro HERO 7 Black”, “description”: “Base Package”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/71LyTRGqB4L._SL1500_.jpg”, “link”: “https://www.amazon.com/GoPro-HERO7-Black-Waterproof-Streaming-Stabilization/dp/B07GDGZCCH”}, {“title”:”Sony FDR-X3000 4K Action Cam”, “description”: “64GB microSD Card”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/81nY87y2nHL._SY355_.jpg”, “link”: “https://www.amazon.com/Sony-FDR-X3000-Action-microSD-Accessory/dp/B01N060XY9“}]

smartphone group

floor: 3

type: “phone”

item-details:

[{“title”:”Apple iPhone X”, “description”: “64 GB – Space Grey”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/514YMVAc6NL._AC_SL1024_.jpg”, “link”: “https://www.amazon.co.uk/Apple-iPhone-64-GB-Space/dp/B076GQZRR9”}, {“title”:”Huawei P30 Pro”, “description”: “128 Go Noir, Double Nano SIM”, “picture”: “https://images-na.ssl-images-amazon.com/images/I/51zDfRUUhHL._SL1000_.jpg”, “link”: “https://www.amazon.com/Stunning-Display-Android-TM-Sim-Free-Smartphone/dp/B07PL5PD7V”}]

At the end of this step, you have now added all the information for #items, as shown below.


The entity is restricted. That’s why you don’t have to manually tag the #items entity in the @buy-items intent. You can find the completed #items entity here.

Create Skills


You’re almost there. We’ve prepared all our entities. Now let’s see how to use these entities and their custom enrichments in the Bot Builder. As mentioned in the Intents and entities step above, we need to create two skills: “choose-floor” and “buy-items”. You create these two skills as business skills.

  • choose-floor skill


1) Triggers


The “choose-floor” skill is triggered by the @choose-floor intent.



2) Requirements


This skill requires the user to tell the bot which #floor they want. If the #floor entity is missing, then the bot asks the user to choose the floor.




3) Actions


If the floor exists, the “buy-items” skill is triggered.


You can find the completed “choose-floor” skill here.

  • buy-items skill


Now let’s focus on the “buy-items” skill. Since the “buy-items” skill is triggered by the “choose-floor” skill, you don’t need to add a trigger.


1) Requirements

Before executing actions, the bot requires the #items entity to be detected. If #items is missing, we use information stored in the memory and ask the user to choose an available category. The interesting thing is that we can list all the options without calling a webhook. This is possible because categories are stored as an array, and we can list them with indexation. See below:



2) Actions


After the user has chosen the category, we want to show them all the items they can choose. This is very straightforward. Simply create a carousel and use the JSON data stored in memory to access the necessary information.

You use the CREATE NEW CARD button within the carousel and add a button as a link.


For example, to get information for the first item, you use:

{{memory.items.item-details[0].title}}

{{memory.items.item-details[0].description}}

{{memory.items.item-details[0].picture}}

{{memory.items.item-details[0].link}}

Here’s what this looks like after you’ve filled out one card of the carousel:


I’ve created four cards in the carousel because I know a category can contain up to four items.


Next you update the conversation using unset memory fields. Once you’ve performed this action, you’ve completed your store-guide bot!



Click here to see the created @buy-items skill.

Conversation


Here’s an example of what your bot looks like when users chat with it:



A few closing words


This tutorial has shown you how to use lists and JSON to enrich your entities and create a bot with a simple but flexible structure. It’s worth remembering that if you don’t use this approach, you may need to create more entities and could run into trouble if you have new values to add. With the approach presented in this tutorial, you maintain all your custom enrichment values in a single list or JSON structure. This also allows you to create a local database that you can use once it has been instantiated. As a result, response time is reduced because we don’t need to call a webhook. Another value-add is that you don’t need any code, making your bot highly scalable.
1 Comment