Use Context in the Ask Action

You can apply a context to a question that you send with the Ask action. The context is an entity that specifies additional information to limit the scope of the question. For example, you might set a context to specify that a user is asking questions about Cambridge UK, rather than Cambridge Massachusetts or Ontario.

Create a Context

You create a question context by using the ManageResources action.

NOTE:

Each question context that you create uses a licensed conversation slot (in the same way as conversation sessions). ManageResources returns an error if you do not have enough capacity. In this case, you must wait until a conversation session or question context expires, or delete one before you can create another. See Configure Context Expiration.

You define a context by using an entity code from a Fact Bank instance. You do not set a system name in the ManageResources action, which means that the context applies to questions that you ask of all systems.

action=ManageResources
Data={ "type": "context", "operation": "add", "context": [{ "system_name": "factbank1", "data": [{ "code_type": "entity", "name": "Cambridge", "codes": ["Q350"] }] }] }

In this example, the code Q350 corresponds to Cambridge UK.

You can retrieve the full schema for the JSON object to use by using the GetResources action. See Find the JSON Schema for Your Update.

NOTE:

The ManageResources action fails if you attempt to use request JSON that contains properties that are not contained in the appropriate schema.

The action returns an ID, which you can use in the Ask action to set the context for a question.

TIP:

You can also retrieve the question context ID by sending a GetResources action with the Type parameter set to context.

Use a Question Context

When you have a question context ID, you can send it in the Ask action Context parameter. For example:

action=Ask&Text=What is its population?&Context=860028728520387723

If this is the ID for the context created in the previous section, this action returns the population of Cambridge UK.

Configure Context Expiration

Question contexts use conversation session license slots. To ensure that you do not run out of conversation sessions or question contexts, you can:

To configure context expiration, you can set the ExpirationIdleTime and ExpirationInterval configuration parameters in the [AskContext] section of your configuration file. For example:

[AskContext]
ExpirationIdleTime=600
ExpirationInterval=30

For more information about these parameters, refer to the Answer Server Reference.


_FT_HTML5_bannerTitle.htm