Search code examples
watson-conversation

Context size limit inside a node in Watson Conversation


My Watson Conversation bots typically have a node where I load some data into context. This usually contains all possible answers, strings, various other data.

So one of my first nodes in any bot looks like this:

{
  "type": "standard",
  "title": "Load Messages",
  "output": {
    "text": {
      "values": [
        ""
      ],
      "selection_policy": "sequential"
    }
  },
  "context": {
    // A whole bunch of data here
  }
  ...

Is there a limit on how much data I can put there? Currently I have around 70 kilobytes, but potentially I can put a few megabytes there just for the convenience of running the logic inside Conversation. (Yes I am aware that this entire data will be sent back to the client, which is not very efficient)


Solution

  • There is no documented limit. You are more likely to hit network issues before Watson Assistant has any issues.

    But storing your whole applications logic in the context object is considered an anti-pattern.

    Your context object should only store what is required in Watson Assistant, and then if possible only for the related portion of the conversation.

    For one time context values you can store them in the output object.

    {
        "context": {
        },
        "output": {
          ...
          "one_time_var": "abc"
        }
    }
    

    This will be discarded on your next call.

    If you have a large volume of data that could be used at different times, then one pattern to use is a context request object.

    For example:

    "context": {
        "request": "name,address,id"
    }
    

    Your next response from the application layer would send this:

       "context": {
            "name" : "Bob",
            "address": "123 street",
            "id": "1234"
       }
    

    You have your returning response update those variables, then clear the context variables again. If you have other context variables that need to stay, then store those in an object and erase just that object.