---
title: Two-Level Queries Model
url: https://www.emergentmind.com/topics/two-level-queries-model
type: topic
---

# Two-Level Queries Model

A two-level queries model organizes query or explanation tasks into two hierarchically related layers, typically reflecting structure in the data, the tasks, or the semantics of the application domain. Such models appear throughout data management and machine learning, supporting increased expressiveness, clarity, and efficiency. They formalize the relationship and mutual constraints between different abstraction levels—such as high-level groups and low-level items, or structured sets and sequences—enabling consistent, interpretable, and optimizable computation and analytics.

## 1. Theoretical Foundations of Two-Level Queries

At its core, a two-level queries model distinguishes between two orthogonal or hierarchically related types of query or explanation:

- The **first (higher) level** targets groups, classes, sets, or abstractions (e.g., data subsets, high-level features, intents).
- The **second (lower) level** targets elements, members, or internal structure within those groups (e.g., individual records, sub-features, item sequences).

This framework arises in several paradigms:

- **Relational and Concept-Oriented Models**: In the Concept-Oriented Model (CoM) [0801.0131], nested ordered sets model both inclusion (hierarchies) and ordering (multi-dimensional relationships), enabling queries both at the group (concept) level and the instance level, with explicit operations for moving "up" (projection) and "down" (de-projection) the abstraction hierarchy.
- **Logic and Deductive Databases**: Query-subquery networks (QSQN) [1201.2564] directly instantiate a two-level model via explicit representation of queries (top-level goals) and subqueries (generated by rule bodies); all evaluation flows between these levels.
- **Machine Learning Explainability**: In hierarchical feature attribution models, such as C2FA [2405.14522], attributions are assigned simultaneously to high-level features (e.g., groups) and their low-level constituents, with mathematical constraints enforcing consistency between levels.

This dual-level structure sharply contrasts with "flat" models, where all items are treated uniformly, or "monolithic" approaches, where query/explanation mixes levels without structural awareness.

## 2. Formal Definitions and Algebraic Characterizations

Two-level models are usually accompanied by rigorous formalism:

### Nested Ordered Sets (CoM)

An element in a nested labelled ordered set is represented as:
\[
e = \{c_1, c_2, \ldots\}(x_1 = e_1, x_2 = e_2, \ldots)
\]
where the $c_i$ are child elements (hierarchical structure/inclusion) and $x_j = e_j$ are references to super-elements along labelled dimensions (multi-dimensional/ordering).

**Projection/De-projection (for moving across levels):**
\[
e \rightarrow d = s \quad \text{where } e = (\ldots, d : s, \ldots)
\]
\[
e \leftarrow f \leftarrow F = \{ s \mid s \rightarrow f = e \}
\]

### Surrogate Models and Consistency in ML Attribution

For nested inputs (groups with sub-features), feature attribution explanations are modeled as:
\[
\text{HiFA surrogate:}\qquad e^{H}(z^{H}) = \sum_{j=1}^J \alpha_j z^{H}_j
\]
\[
\text{LoFA surrogate:}\qquad e^{L}(z^{L}) = \sum_{j=1}^J \sum_{d=1}^{D_j} \beta_{jd} z^{L}_{jd}
\]
with the **consistency property**:
\[
\alpha_j = \sum_{d=1}^{D_j} \beta_{jd}
\]
ensuring explanations at two levels align [2405.14522].

### Query-Subquery Nets

Each "subquery" is explicitly represented as a pair
\[
(t, \theta) \quad \text{where } t \text{ is a tuple, } \theta \text{ is a substitution}
\]
and query evaluation propagates data and substitutions from queries to subqueries and back [1201.2564].

## 3. Architectural Realizations and Algorithms

### Data Management Systems

- **Partitioned Indexes:** Two-level spatial indexing schemes [2005.08600] split space into top-level partitions (tiles), then classify objects within each tile into secondary classes. This supports efficient, parallel, and duplicate-free spatial range queries. 
- **Multi-Model Data Query Engines:** In Multi-SQL [2011.08724], query execution is partitioned into a Multi-SQL layer (logical/global optimization) and sub-queries delegated to native storage engines, which execute physical/local optimization; this two-level implementation maximizes the reuse of underlying engine capabilities.

### Machine Learning and Explainability

- **Hierarchical Feature Attribution:** C2FA [2405.14522] fits surrogate models at both group and sub-feature level, with optimization enforcing the consistency property.
- **Structured Sequence Generation:** In RoomFormer [2211.15658], a transformer decoder outputs a set of sequences (polygon queries for rooms, each a sequence of corner positions), leveraging two-level queries for variable-size, variable-length prediction in structured output.

### Information Retrieval

- **Dynamic Rankings:** Two-level dynamic ranking models [1108.2754] first display a diversified set of head results, then, as the user interacts with a result, dynamically expand with a sub-ranking tailored to the inferred intent—formally modeled via utility functions parameterized by both diversity and depth metrics.

## 4. Consistency and Rewriting Between Levels

A distinguishing property of two-level models is the **formal consistency constraint** that links the outputs or semantics at both levels:

- In feature attribution, the sum of low-level attributions within a group equals the group’s high-level attribution [2405.14522].
- In data models, projection and de-projection operations are compositional, enabling constraints, filters, or aggregations at one level to propagate or be summarized at the other [0801.0131][0901.2224].
- For analytic (group-by) queries, a two-level model (e.g., in the context model [2305.13895]—data unavailable for details) would require that aggregation at the group level is defined by systematic summarization of measurements at the member level and that queries can be reformulated at either layer.

Such consistency enables query and explanation rewriting at both levels, often enabling optimization (e.g., propagating constraints down for filtering before aggregation, or merging surrogate fits for attribution).

## 5. Practical Applications and Empirical Results

| Domain/Task                               | Two-Level Approach                                        | Quantitative Gains         |
|-------------------------------------------|-----------------------------------------------------------|---------------------------|
| Image & Text Feature Attribution [2405.14522] | Joint HiFA/LoFA with consistency property                    | ↑ NDCG/AUROC, ↓ error     |
| Floorplan Reconstruction [2211.15658]        | Polygon-level (room) queries + corner-level vertex queries   | Room F1: 95.3% vs 73.4%   |
| Dynamic Retrieval [1108.2754]                | Diversified heads + personalized subrankings                | Outperforms all static IR |
| SQL Synthesis [2003.07438]                   | NLQ + table sketch dual input, guided PQE                   | 62.5%↑ over NLQ baseline  |
| Multi-model DB [2011.08724]                  | Multi-SQL logic + native engine optimization                | Query speed gains         |

Practical effects include human-intuitive explanations (at multiple granularities), scaling to large/complex data with parallel query processors [2005.08600], and enablement of more expressive, sound, and efficient information retrieval systems.

## 6. Future Directions and Open Problems

Many research avenues remain in the optimization, expressivity, and generalization of two-level queries models:

- Extending consistency constraints to more complex or unbounded hierarchies.
- Designing query languages and data models with first-class two-level (or multi-level) operators, supporting compositional navigation and aggregation.
- Developing efficient, general algorithms for constrained multi-level attribution with strong theoretical guarantees.
- Exploring query rewriting and determinacy in richer logic/data systems (e.g., implicit-to-explicit synthesis for nested data [2212.03085]).
- Investigating how user specification at multiple levels (e.g., dual NLQ/PBE in Duoquest [2003.07438]) can improve system performance and usability.

A plausible implication is that, as data and tasks become more semantically structured and applications demand more transparent explanation and optimization, two-level and, more generally, multi-level query models will become central constructs in database, AI, and information retrieval systems.

Source: https://www.emergentmind.com/topics/two-level-queries-model