Answer Server 23.4

# Use Context in the Ask Action

You can apply a context to a question that you send with the Ask action. The context specifies additional information to limit the scope of the question. In Fact Bank the context is a specific entity used in disambiguation, for example, you might set a context to specify that a user is asking questions about Cambridge UK, rather than Cambridge Massachusetts or Ontario. For Answer Bank or Passage Extractor, the context is a string that might, for example, come from a previous question.

When you include a valid Context ID with a question using the Ask action, the system caches the answer-system context associated with each answer. The response includes answers with a context tag which has a `token` attribute. A token can be used to update the context using the ManageResources action.

Tokens remain valid until the next time the user asks a question using that Context ID.

You can create an empty context to save tokens for use in a future context update, by using the ManageResources action to return a Context ID for an empty context. Then you can ask a question using the Ask action and the new Context ID. Returned answers from all answer systems then have a context tag with token attribute. To use the context for subsequent questions, select the appropriate answer, and update the Context in ManageResources with the context token for that answer. Specifying a token loads the associated system context from the cache into the current context.

## Create a Context

You create a question context by using the ManageResources action. You do not set a system name in the ManageResources action. You can create an empty context to save a token for use with future context updates.

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 can define a context in a Fact Bank instance by using an entity code.

    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 define a context in an Answer Bank instance by using a context string.

    action=ManageResources
    Data={
        "type": "context",
        "operation": "add",
        "context": [{
            "system_name": "answerbank1",
            "data": {
                "subject": ["MyCompany"]
            }
        }]
    }

In this example, `"MyCompany"` could be a context returned from a previous question.

You can define a context in a Passage Extractor instance by using a context string.

    action=ManageResources
    Data={
        "type": "context",
        "operation": "add",
        "context": [{
            "system_name": "passageextractor1",
            "data": {
                "context": ["france"]
            }
        }]
    }

In this example, `"france"` could be a context returned from a previous question.

You can define an empty context without the context entity code or context string that would be required if creating a context in a specific answer system.

    action=ManageResources
    Data={
        "type": "context",
        "operation": "add"
    }

This can be use to save a token for use with future context updates.

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 Fact Bank example above, 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:

- manually delete the contexts by using the ManageResources action.
- configure context expiration so that Answer Server automatically deletes unused contexts.

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

Copyright 2016-2023 Open Text
Version 23.4 | Last updated September 2023

Send documentation feedback

Close

Send documentation feedback

To send feedback using your default email client, open an email window.

Otherwise, send your feedback and the information below to swpdl.idoldocsfeedback@microfocus.com.

We appreciate your feedback!

Product: IDOL Answer Server 23.4

Topic Title: Use Context in the Ask Action