AI task wont talk to knowledge base
# 🤝help
s
I have a chatbot that is a hotel concierge. I can get it to greet the user, ask for the group size, best activity and it they want to travel or stay local. These are all store in variables. I then ask the user 'Is there anything else we need to know' and store that in a variable too. I then want the chatbot to suggest the best activity. In the knowledge base I have 2 websites for things to do in location X. I also have a separate knowledge base with some additional information. I have passed all this to the AI but I keep getting the answer 'I don't know'. How do I get my chatbot to talk the user variable as search the KB for the best answer to their inputs? Is using an AI task best? If so what have I done wrong. If the AI task is not the best card what should I do?
a
Hey @salmon-exabyte-57459, right now the only way to trigger a knowledge base search is with a user message. This isn't helpful for you because the user is not going to suddenly include all the needed context for a full knowledge base search in their last question. Depending on how comfortable you are with code, there are two ways to get around this: 1. Do everything in an AI task with in-context learning If your list of activities is small, you can add them into your AI prompt along with all the other user information and ask for a recommendation. 2. Use a hook to modify the user's message If you're comfortable with code, you can use an "After incoming message" hook to add more context to the user message that the bot sees. I've had good success with the code below, just change
addContext
to true to trigger it in your node with the capture card.
Copy code
js
  if (workflow.addContext> 0) {
    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
  }
This code will mash all of the user's past messages into one big message that can be used to search the knowledge base. You can customize this as needed for your use case. I'm really hoping to see a "Manually query knowledge base" card coming in the future. Until then, we have these workarounds and #1111026806254993459
f
This screenshot says knowledge disabled on that node. What I would do is go to the knowledge agent settings and set it to manually respond(this may change other parts of your bot so keep that in mind), and then enable the answer from knowledge in the node that you have this ai talk card in. You will then have to give the ai task the answer from the knowledge agent manually, which is a variable {{knowledge.response}} or something, it is on the window for the knowledge agent settings but I don’t remember exactly what it is. This should work
c
i changed the website URL to test if the bot is workign with another website URL but it doesnt seem to erase earlier memory.... How to solve this ?
s
Tried, it does not work. thanks
Thank yo @acceptable-kangaroo-64719 . I have watched all your videos on the YouTube channel at least twice! Can I make a suggestion as a viewer and someone who will be relying ALOT on the AI to generate code. Could you either but the prompt you used in the video to create the code of the code itself into the descriptions of the videos? I tried making your recipe bot but I can't get past this point

https://youtu.be/261qGO-0Ye0?t=316

as you create the code without showing how you use the execute code function. Just a suggestion from someone with a non-coding background. Thanks
c
Can I clarify that this is what you mean by changing addContext to true if (workflow.addContext === true) {
or if (workflow.true> 0) {
a
neither,
workflow.addContext = true
to turn it on or
workplace.addContext = false
to turn it off
53 Views