Filtering Capabilities
The Retrieve API provides flexible filtering options to ensure that queries return only the most relevant content. Filters can be applied at request time to narrow down the search space based on metadata such as article type, topics, tags, and user profiles.
Supported Filters
1. Article Type (Certified Answers)
-
Ensures that only articles of the
articleType
FAQ are considered during the Certified Answers pipeline. - Learn more by reading the Certified Answers guide.
2. Topic IDs ($filter[topicIds]
)
- Restricts the scope of the content retrieved by the Retrieve API to only the provided topics.
- Accepts an array of IDs (1–20) for multi-topic filtering.
-
Example:
curl -X POST "https://<API_DOMAIN>/core/aiservices/v4/<YOUR_PORTAL_ID>/retrieve?q=<YOUR_QUERY>>&$filter[topicIds]=<YOUR_TOPIC_ID>" -H "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \ -H "Content-Type: application/json" \
3. Tags ($filter[tags]
)
- Restricts the scope of content retrieved by the Retrieve API using hierarchical category tags.
- Each key is a Category Tag ID, and each value is an array of Tag IDs for that category.
- Supports up to 15 categories, each with up to 200 tags.
-
Example:
curl -X POST "https://<API_DOMAIN>/core/aiservices/v4/<YOUR_PORTAL_ID>/retrieve?q=<YOUR_QUERY>" \ -H "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "filter[tags]": { "YOUR_CATEGORY_TAG_ID": ["YOUR_TAG_IDS"] } }'
4. User Profile ID (
$filter[userProfileID]
) - Restricts the scope of content retrieved by the Retrieve API based on a specific user profile ID.
- Useful for tailoring answers to a given persona (e.g., customer vs. agent).
-
Example:
curl -X POST "https://<API_DOMAIN>/core/aiservices/v4/<YOUR_PORTAL_ID>/retrieve?q=<YOUR_QUERY>" \ -H "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "$filter[userProfileID]": "YOUR_USER_PROFILE_ID" }'
Combining Filters
Filters can be combined to achieve fine-grained control. For example, restricting by topicIds, tags, and userProfileID in the same request:
curl -X POST "https://<API_DOMAIN>/core/aiservices/v4/<YOUR_PORTAL_ID>/retrieve?q=<YOUR_QUERY>&$filter[topicIds]=<YOUR_TOPIC_ID>" \ -H "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "$filter[userProfileID]": "YOUR_USER_PROFILE_ID", "filter[tags]": { "YOUR_CATEGORY_TAG_ID": ["YOUR_TAG_IDS"] } }'
Placeholders to Replace:
- <API_DOMAIN>: The domain of your API.
- <YOUR ACCESS TOKEN>: Your OAuth 2.0 access token.
- <YOUR_QUERY>: The query you send to the API.
- <YOUR TOPIC ID>: The eGain topic id(s) you want to filter by. It will limit the scope of results to use for answer generation to content belonging to those topic ids.
- YOUR USER PROFILE_ID: The eGain user profile id you want to filter by. This will reduce the scope of eGain articles by only using content available to that specific user profile.
- YOUR CATEGORY TAG_ID: The eGain category tag id you want to filter by.
- YOUR TAG IDS: The eGain tag ids belonging to the category tag id provided.