Skip to main content

Single-Shot Questions Tutorial

This tutorial demonstrates how to submit single-shot questions to Knowledge Discovery agents and retrieve answers.

Prerequisites

  • Valid access token (see Authentication)
  • At least one configured agent with data sources
  • Discovery User role or higher

Tutorial Overview

In this tutorial, you'll learn to:

  1. Submit a question to an agent
  2. Submit a question with dynamic filters to narrow search results
  3. Retrieve answers with source references
  4. Provide feedback on answers
  5. Retrieve question history

Part 1: Submit a Simple Question

Basic Question Submission

Let's start by submitting a simple question to an agent.

POST {{baseUrl}}/agent/agents/{{agentId}}/questions
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: {{appKey}}
Content-Type: application/json

{
"question": "What is the company's vacation policy for new employees?",
"dynamicFilter": null
}

Understanding Question Parameters

ParameterRequiredDescription
questionYesThe natural language question text
dynamicFilterNoRuntime filter expression to apply to the search
Asynchronous Processing

The POST /agents/{agentId}/questions endpoint returns 202 Accepted immediately. The question is processed asynchronously. Poll the GET endpoint to retrieve the answer once ready.

Part 2: Submit a Question with Dynamic Filter

When to Use Dynamic Filters

Use dynamicFilter when you need to narrow search results at query time based on metadata or document properties. Dynamic filters are applied at runtime, allowing different filter criteria for each question without modifying the agent configuration.

Use dynamic filters for:

  • Filtering by date ranges (e.g., documents from the last quarter)
  • Restricting to specific categories or document types
  • Applying user-specific context (e.g., department, project)
  • Combining multiple metadata criteria

Dynamic vs. Static Filters:

  • Static filters are configured in the agent and apply to all queries automatically
  • Dynamic filters are provided with each question and allow per-query customization
  • Both can be used together - static filters for permanent restrictions, dynamic filters for runtime flexibility

Dynamic Filter Example

Here's a practical example filtering documents by date and category:

POST {{baseUrl}}/agent/agents/{{agentId}}/questions
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: {{appKey}}
Content-Type: application/json

{
"question": "What are the latest product updates?",
"dynamicFilter": {
"logicalOperator": "And",
"conditions": [
{
"field": "Category",
"type": "Text",
"operator": "Equals",
"value": "Product Updates"
},
{
"field": "PublishedDate",
"type": "Date",
"operator": "GreaterThan",
"value": "2025-01-01"
}
]
}
}
Filter Structure

The filter uses:

  • logicalOperator: "And", "Or", or "Not" to combine conditions
  • field: The metadata field name to filter on
  • type: Field data type - "Text", "Number", "Date", or "Boolean"
  • operator: Comparison operator (e.g., "Equals", "GreaterThan", "Contains", "Any")
  • value or values: The value(s) to compare against

For more filter operators and complex examples, see the Managing Agents Tutorial.

Part 3: Retrieve the Answer

After submitting a question, retrieve the answer using the question ID.

GET {{baseUrl}}/qna/questions/{{questionId}}/answer
Authorization: Bearer {{accessToken}}

Answer Response Structure

{
"answer": "New employees are eligible for 15 days of paid vacation per year...",
"agentId": "hr-agent-id",
"agentVersion": 1,
"responseCompleteness": "Complete",
"objectReferences": [
{
"objectId": "doc-123",
"references": [
{
"referenceId": "chunk-456",
"rankScore": 0.95,
"rank": 1
}
]
}
],
"question": "What is the company's vacation policy for new employees?",
"feedback": null,
"staticFilter": null,
"dynamicFilter": null
}

Response Completeness Values

ValueMeaning
SubmittedQuestion has been submitted and is being processed
CompleteAnswer has been generated and is ready
ErrorAn error occurred during processing

Part 4: Provide Feedback

Users can provide feedback on answers to help improve the system.

POST {{baseUrl}}/qna/questions/{{questionId}}/answer/feedback
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: {{appKey}}
Content-Type: application/json

{
"feedback": "Good"
}

Feedback Values

Supported feedback types:

  • "Good" - Answer was helpful and accurate
  • "Bad" - Answer was not helpful or contained errors
  • "Retry" - Request to regenerate the answer

Part 5: Retrieve Question History

Retrieve the history of questions asked to a specific agent.

GET {{baseUrl}}/qna/agents/{{agentId}}/questions/history?pageNumber=1&pageSize=50
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: {{appKey}}

Query Parameters

ParameterRequiredDefaultDescription
pageNumberNo1Page number for pagination
pageSizeNo100Number of items per page (max: 100)
maxContentLengthNonullMaximum length of question/answer content (10-1000)

Response Structure

{
"data": [
{
"id": "c9d6f822-e88c-48a7-bfb9-1f91e7214b40",
"question": "What is the company's vacation policy for new employees?",
"answer": "New employees are eligible for 15 days of paid vacation per year...",
"dateCreated": "2025-11-12T10:30:00Z",
"dateAnswered": "2025-11-12T10:30:15Z",
"agentVersion": 1,
"responseCompleteness": "Complete",
"feedback": "Good",
"staticFilter": null,
"dynamicFilter": null
},
{
"id": "a1b2c3d4-e5f6-4789-a012-3456789abcde",
"question": "What are the office hours?",
"answer": "Office hours are Monday to Friday, 9 AM to 5 PM.",
"dateCreated": "2025-11-12T09:15:00Z",
"dateAnswered": "2025-11-12T09:15:10Z",
"agentVersion": 1,
"responseCompleteness": "Complete",
"feedback": null,
"staticFilter": null,
"dynamicFilter": null
}
],
"pagination": {
"pageSize": 50,
"pageNumber": 1,
"totalItems": 125,
"totalPages": 3
}
}

Understanding the Response

FieldTypeDescription
dataarrayArray of question history items
data[].idUUIDQuestion identifier
data[].questionstringThe question text
data[].answerstring (nullable)The answer text (null if error or still processing)
data[].dateCreateddatetimeWhen the question was submitted
data[].dateAnswereddatetime (nullable)When the answer was generated
data[].agentVersionintegerVersion of the agent used
data[].responseCompletenessenumStatus: Submitted, Complete, Error
data[].feedbackenum (nullable)User feedback: Good, Bad, Retry
data[].staticFilterobject (nullable)Static filters applied
data[].dynamicFilterobject (nullable)Dynamic filters applied
pagination.pageSizeintegerItems per page
pagination.pageNumberintegerCurrent page number
pagination.totalItemsintegerTotal number of questions
pagination.totalPagesintegerTotal number of pages

Summary

In this tutorial, you learned how to:

✅ Submit questions to agents
✅ Retrieve answers with source references
✅ Provide feedback on answer quality
✅ Retrieve question history for an agent