Segments in the Query Generation semantic layer
Segments are predefined filter conditions that map business terminology to specific query filters, helping the semantic layer translate natural language questions into accurate database queries.
Segments provide non-obvious context to assist the semantic layer in selecting the correct entity, dimension, and values. For example, in the utterance "How many open emergency change requests are there?", a segment identifies that "open" means "active=true" and "emergency" is a Type, not a Priority.
How segments work
The system uses AI search to find segments that are semantically similar to the user's query. AI search indexes the Name, Description, Entity, and Filter fields in the Segments table, comparing them to the user's query to produce a subset of relevant segments.
In the LLM call, the system passes the Name, Description, Entity, and Filters. The LLM uses the segments as building blocks for generating a new query. For example, if a user asks "Unassigned Incidents located in San Diego" and the segment "Unassigned Incidents" is passed to the LLM, the LLM uses the segment's filter as the starting point and attaches the location filter "San Diego" on top of the segment.
| Step | Purpose | Output |
|---|---|---|
| 1: Input | Capture user's natural language query | Raw query text |
| 2: Search | Find semantically similar prebuilt segments | Subset of relevant segments |
| 3: Context | Provide segment metadata to LLM | Structured segment data |
| 4: Generate | Combine segment logic with new conditions | Complete executable query |
Automatic segment sources
The system auto-generates segments from existing ServiceNow data sources on a schedule. The Query Generation Sync Segments job creates segments automatically, running at installation and then weekly by default.
| Source | What it pulls |
|---|---|
| Saved Reports (sys_report) | Report filters from recently viewed reports |
| Report Sources (sys_report_source) | Analytics data source filters |
| PA Indicators (pa_cubes) | Performance Analytics indicator conditions |
| Saved Filters (sys_filter) | Global saved filters only (excludes user-specific and group-specific filters) |
| App Modules (sys_app_module) | Module-level list view filters |
Automated segment rules
To reduce noise from outdated and irrelevant segments, the job follows specific rules. Segments based on reports, report sources, or indicator sources are active only if the records meet certain criteria:
- Reports must be shared, created by a user with an analytics manager role (admin, dashboard_admin, report_admin, pa_admin, or viz_admin), and have run recently (within 180 days by default).
- Report sources must be included in a data visualization or used in a report that has run recently.
- Indicator sources must be linked to indicators with scores that have recently changed.
For reports, "run recently" is defined by the sn_query_gen.segments.reports.last_viewed_threshold_days system property. The default value is 180 days.
For indicator sources, the time span for "recently changed" depends on the indicator frequency:
- Daily: last 7 days
- Weekly: last 30 days
- Bi-weekly: last 30 days
- Monthly: last 90 days
- Four weeks: last 90 days
- Bi-monthly: last 90 days
- Quarterly: last 180 days
- Fiscal quarterly: last 180 days
- Six months: last 12 months
- Yearly: last 24 months
- Fiscal yearly: last 24 months
You can change the time spans for indicator sources by applying a multiplier using the sn_query_gen.segments.indicator.inactivity_threshold_multiplier system property. The value must be an integer, meaning you can only lengthen the periods, not shorten them.
Disabling segment sources
You can disable segment creation altogether, or for individual source types. You might disable segment generation to troubleshoot, or if segments from a source are "noisy." Each source type has a corresponding sn_query_gen.segments.disable.* system property. Disable segments for that source by setting the corresponding system property to true. All existing segments created from sources of that type are excluded from AI Data Explorer search results. No new segments of that type are created. During the next Sync Segments job, all segments of that type are deactivated. For more information, see Query Generation properties.
Create a manual segment
Manual segments are admin-created filter conditions that map business terminology to specific query filters.
Before you begin
Role required: sn_query_gen.admin or higher
About this task
- Your organization has standard terminology that maps to specific filters (for example, "Sev1", "VIP", "overdue")
- Users repeatedly ask the same filtered question and the system does not automatically pick up the right filter
- You want to encode business logic that cannot be inferred from field values alone (for example, "at-risk accounts" = combination of multiple conditions)
- The special terminology of your organization is not translated accurately to filter conditions
Procedure
General guidelines
Follow these suggestions to help you use segments in the semantic layer effectively.
- Test segments by asking the question and verifying the segment appears in .
- Disable noisy auto-generated segments rather than trying to overfit with multiple manual ones.
- Use natural phrasing that matches how your users actually speak.
- Keep one segment per concept to avoid confusion.
- Monitor segment usage through the logs to identify which segments are most valuable.