- The paper introduces an LLM-driven pipeline that dynamically selects between Classifier and Cluster Join strategies to optimize semantic join execution.
- It details a methodology combining embedding selection, unsupervised clustering, and deterministic fallbacks to efficiently process unstructured data joins.
- Experimental results show consistent F1 improvements of 20–33 points and substantial token cost reductions over traditional techniques.
SemJoin: LLM-Driven Semantic Join Optimization
Context and Motivation
With the proliferation of unstructured and semi-structured data sources, there is increasing demand for integrating natural language semantics into relational database joins. Standard join operators—designed for structured data and logical predicates—are ill-suited to natural language conditions where similarity or membership may not be representable as attribute equality. Existing AI-enabled DBMSs attempt to address this by incorporating LLM-powered semantic operators, but face significant efficiency challenges because naive evaluation incurs O(M×N) LLM invocations. Previous approaches such as embedding-based similarity, block join batching, and featurization provide partial efficiency gains but lack flexible adaptivity across diverse data and predicates.
SemJoin Pipeline Architecture
SemJoin introduces a novel LLM-driven advisory pipeline that optimizes the semantic join workflow by dynamically selecting the optimal execution strategy conditioned on the characteristics of the input tables and predicate. The pipeline is structured as follows:
- The advisor LLM inspects the join predicate, table schemas, and sampled data from both sides.
- Based on this analysis, the advisor routes the workload to either a Classifier strategy (if the predicate reduces to equi-join over a discrete label set), or a Cluster Join strategy (for general semantic predicates).
- The pipeline guarantees valid routing via a set of deterministic fallbacks, and all advisory decisions can be user-overridden.

Figure 1: High-level depiction of SemJoin’s strategy selection and cluster join sub-pipelines.
Execution Strategies
Classifier Strategy
For predicates equating to same-label or discrete taxonomy matches, SemJoin applies an LLM-powered classifier to independently assign a canonical label to each tuple in both tables. An equi-join over these predicted labels replaces expensive cross-table comparisons. Tuples assigned as “unknown” by the LLM are filtered out. This generalizes the approach in Cortex AISQL and is highly efficient when the label set is small and explicit.
Cluster Join Strategy
For all other cases, the pipeline executes a multi-step Cluster Join:
- Embedding Model Selection: The advisor selects the best sentence transformer for the workload (e.g., all-mpnet-base-v2).
- Optional Projection: Where clusters from each table are not directly comparable, the LLM projects tuples from one table into the semantic domain of the other, aligning cross-table representations (e.g., mapping verbose Stack Overflow questions to predicted tags).
- Embedding + Clustering: Each tuple is embedded, and unsupervised clustering (e.g., k-means or HDBSCAN) generates candidate blocks likely to contain relevant join matches.
- Cluster-Pair Filtering: For each cluster pair, a small sample is evaluated via LLM-driven matching. Cluster pairs below a learned match-rate threshold are pruned.
- Final Matching: For retained cluster pairs, block join batching maximizes context window utilization for cost-effective LLM invocation.
This design is robust—falling back to the Cluster Join in all ambiguous scenarios—and supports parameterization for further tuning.
Experimental Evaluation
Datasets
Three diverse datasets were selected to evidence the generality of SemJoin:
- IMDb Movie Reviews: Join based on shared sentiment (binary classification).
- Email Contradictions: Logical contradiction detection between paired emails and statements (complex reasoning).
- Stack Overflow Questions and Tags: Join between natural language question texts and technical tags (highly asymmetric, poor semantic similarity).
Baselines
SemJoin is compared with (i) Adaptive Block Join (ABJ), a context-aware block nested-loop scheme that adaptively sizes batches (Trummer, 9 Oct 2025), and (ii) Featurized-Decomposition Join (FDJ), which uses LLM-extracted feature filters with statistical guarantees (Zeighami et al., 5 Dec 2025).
Core Results
SemJoin’s LLM advisor consistently routes workloads to the empirically optimal strategy. Across all three datasets, SemJoin outperforms ABJ by 20–33 F1 points while reducing token cost on two datasets, and exceeds FDJ’s F1 at one to two orders of magnitude lower token expenditure.
- On IMDb (sentiment join), the Classifier achieves 78.08% F1 at 22,362 tokens, with a substantial gain in both accuracy (+28 points) and cost efficiency (-68%) over ABJ.
- On Emails (contradiction join), Cluster Join attains 75.11% F1 at 26,963 tokens, absolute improvements in both F1 and cost over ABJ (42.00% F1, 43,340 tokens).
- On Stack Overflow (question–tag join), although the Classifier is also optimal (74.95% F1, 30,216 tokens), Cluster Join’s utility diminishes on small asymmetric tables, incurring higher cost than ABJ.
Importantly, FDJ fails to provide reliable filtering on these concrete datasets due to non-discriminative feature extraction, reverting to quadratic LLM calls and poor cost-performance.
Parameter and Ablation Studies
Extensive grid searches over cluster ratio and sample thresholds reveal a robust cost–quality tradeoff for Cluster Join. The batch size analysis confirms optimal batching at 10–15, balancing token cost and F1 for moderate table sizes. Optional projection increases F1 on all datasets (by ~0.4–4.5 points) at predictable token overhead—useful if accuracy is prioritized.
Theoretical and Practical Implications
SemJoin demonstrates that LLM-driven dynamic strategy selection outperforms fixed or static pipelines in semantic join optimization, especially as predicate complexity and table topology diversify. The low overhead of the routing LLM (∼13k tokens across all tests) affirms that the advisor can be invoked without concern for dominant cost. The pipeline’s modular construction supports practical deployment in adaptive AI-augmented DBMSs (e.g., Palimpzest [liu2025palimpzest], Cortex AISQL [liskowski2025cortexaisql]) and motivates additional avenues: advisor retraining, new execution strategies, richer embedding selection, and extended evaluations over real-scale workloads.
Conclusion
SemJoin provides an LLM-agent-based semantic join pipeline where strategy selection, not mere join execution, is the core optimization challenge. By delegating workload analysis and routing to an LLM, it robustly identifies the optimal strategy—Classifier or Cluster Join—outperforming established baselines in both effectiveness and token cost in benchmarked settings. As data ecosystems increasingly require seamless integration of structured and unstructured sources, adaptive LLM-driven pipelines like SemJoin represent a foundational shift in semantic database operator design and optimization. Scaling such architectures, refining dynamic advisors, and incorporating emerging foundation models remain key directions for future work.