https://discord.gg/botpress logo
#🌎general
Title
# 🌎general
m

millions-xylophone-94406

07/06/2023, 5:26 PM
Hello! There is a problem with the processing of the Knowledge Base. I have a file that contains information about different T-shirts. For example, I have 10 T-shirts, each with a unique description. And on top of that, each t-shirt has a description of how to care for it. I have two types of care. When I ask the bot to describe a t-shirt to me, it seems to handle everything correctly, but when I say "it" instead of the name of the t-shirt in the next question, the bot doesn't understand and outputs everything. 1) I set up the chat history correctly, but for some reason it can not remember which t-shirt in question. 2) What is the best way to structure the file, I tried two ways. 1. Write the name of the t-shirt, description and care. 2. the name of the T-shirt and a description to it, and down the file added blocks of care and in parentheses wrote which T-shirts are each of them.
e

early-train-33247

07/07/2023, 1:23 AM
Hey @millions-xylophone-94406, that's not an actual problem on the Botpress side. What is happening is that the knowledge base has no contextual info to figure out what is the it you are talking about. You could achieve that by using manual answering on the Knowledge Agents and AI Tasks
But I can see we adding a feature for that soon! - knowledge questions should consider the last X messages
By the way, please make a post on #1111026806254993459 so we can follow up with this!!! 🚀 __________
Now, @acceptable-kangaroo-64719 could you give us an detailed outline of how we can achieve this? I see this coming up a lot, so I might as well learn it too!
a

acceptable-kangaroo-64719

07/07/2023, 11:18 AM
There's a couple ways we could go about this, some easier than others. The easiest way I can think of would be to use an AI Task instead of a knowledge search for T-shirt specific questions. After the user clicks a button or otherwise indicates which T shirt they want, you pass all the information you have on that T shirt, plus the user's question, plus the last few chat messages, to an AI task and let GPT sort it out. If we want to stick with knowledge bases, we can actually change the user input that the KB agent uses as a search term before the search is performed. If you have which T shirt they're looking at saved in a variable, you could prepend the T-shirt name so that "Can it be machine washed?" becomes "(Cotton Polo size S) Can it be machine washed?" You could also prepend the last few chat messages, too. This would all need to be done in an 'After incoming message' hook, which means you'll need to write code. The last (and hardest) way is usign scoped knowledge bases. If a flow & a KB are in a separate folder, and KB search is limited to whatever is in the folder. You could make separate flows and knowledge bases for each T shirt, and that way any knoweldge that comes back would definitely be about that specific t shirt. It would require a lot of re-organizing for your existing KB, but if you have too much info to cram into a single AI task prompt, this would be the next best thing.
e

early-train-33247

07/08/2023, 1:40 AM
Thanks for the detailed reply @acceptable-kangaroo-64719, I will try out these options!
@salmon-art-82621, this could help you!
s

salmon-art-82621

07/08/2023, 6:39 AM
Thank you, @early-train-33247 and thank you @acceptable-kangaroo-64719 , that is certainly a very good solution. However, with my current knowledge of programming, I am not able to implement it on my own. An example would greatly assist me in understanding it better and being able to program something similar. Since this problem has been raised by multiple users in our community, these examples would not only benefit me but also others. Would it be possible for you to provide such examples as assistance?
e

early-train-33247

07/11/2023, 1:09 AM
Hey @salmon-art-82621, I will try to come up with a example for you!
s

salmon-art-82621

07/11/2023, 9:18 AM
I greatly appreciate your help @early-train-33247 !
a

acceptable-kangaroo-64719

07/11/2023, 12:24 PM
@early-train-33247 I got one from a bot I'm working on. @salmon-art-82621 to get this hook to trigger, use an execute code card and put
workflow.changeContext = true
before taking the user's input, and
workflow.changeContext = false
when you're done, otherwist this will run on every user message and cause problems.
Copy code
js
  if (workflow.changeContext) {
    console.log('\n\n\n Context hook triggered! \n\n\n')
    let usr_msgs = []
    event.state.session.history.map((turn) => {
      if (turn.sender == 'user') {
        usr_msgs.push(turn.preview)
      }
    })
    let full_context = usr_msgs.join(' ')
    event.preview = full_context //Oh I absolutely should not be allowed to do this
  }
The above code will augment the user's most recent message with the last 3 - 6 messages they have previously sent the bot and join them all together into one message. For example, in this conversation: Bot: Would you like to buy a car or a truck? User: I want a truck please? Bot: We have trucks in blue, green, and red User: How much is the red one? The hook would turn "How much is the red one?" into "I want a truck please? How much is the red one?"
s

salmon-art-82621

07/11/2023, 12:31 PM
Thank you so much @acceptable-kangaroo-64719 and @early-train-33247 ! I will give it a try and hope that it works for me. Surely, the other members will also benefit from the code. Once again, thank you very much! ❤️