Abstract
While significant progress has been made with dual- and bi-encoder dense retrievers, they often struggle on queries with logical connectives, a use case that is often overlooked yet important in downstream applications. Current dense retrievers struggle with such queries, such that the retrieved results do not respect the logical constraints implied in the queries. To address this challenge, we introduce LogiCoL, a logically-informed contrastive learning objective for dense retrievers. LogiCoL builds upon in-batch supervised contrastive learning, and learns dense retrievers to respect the subset and mutually-exclusive set relation between query results via two sets of soft constraints expressed via t-norm in the learning objective. We evaluate the effectiveness of LogiCoL on the task of entity retrieval, where the model is expected to retrieve a set of entities in Wikipedia that satisfy the implicit logical constraints in the query. We show that models trained with LogiCoL yield improvement both in terms of retrieval performance and logical consistency in the results. We provide detailed analysis and insights to uncover why queries with logical connectives are challenging for dense retrievers and why LogiCoL is most effective.
Introduction: The Challenge of Logical Connectives
Dense retrievers have revolutionized information retrieval by mapping queries and documents into a shared embedding space. While they are excellent at capturing semantic similarity—for instance, recognizing the relationship between "puppy" and "dog"—they are notoriously deficient at handling logical connectives like AND, OR, and NOT.
When a user searches for "Films set in Libya and Tunisia" versus "Films set in Libya but not Tunisia," current models often produce nearly identical embeddings because the underlying atomic keywords are the same. This leads to "logical collapse," where the retriever returns overlapping results for queries that should be mathematically disjoint. Standard training objectives, such as InfoNCE, typically ignore the set-theoretic relationships inherent in human language, treating logical constraints as mere semantic keywords.
Methodology: Logically-Informed Contrastive Learning
To address these shortcomings, we introduce LogiCoL, a framework that integrates logical structure directly into the contrastive learning process through three primary innovations:
- Logically-Grouped Batching: Instead of random sampling, LogiCoL ensures that a single training mini-batch contains "companion" queries that share the same atomic parts (e.g., $A$, $B$, $A \land B$, and $A \setminus B$).
- Exclusion Consistency Loss: For queries that should have disjoint results (like $A \land B$ and $A \setminus B$), the model uses a symmetric KL-divergence loss. This forces the retriever’s similarity distributions over the documents to diverge, ensuring the model learns that these queries seek different result sets.
- Subset Consistency Loss: Logic dictates that if a document satisfies $A \land B$, it must also satisfy $A$. LogiCoL enforces this using a regularization term based on t-norms (a mathematical framework for fuzzy logic), penalizing the model if a document's similarity score for a specific query is higher than for its logical "parent."
Experimental Setup and Datasets
The study utilizes two primary datasets to evaluate entity retrieval performance:
- QUEST: An existing benchmark for entity retrieval involving logical operations across domains like films, books, and plants.
- QUEST+VARIANTS: A new, augmented version of the dataset created by the authors. By using Wikipedia category names to derive missing atomic queries and employing an LLM to paraphrase templated logical queries into natural language, the authors provided a much richer set of logically related query pairs for training.
Results and Analysis
The researchers tested LogiCoL across four popular backbone models: GTR, GTE, Contriever, and E5. The results demonstrate that LogiCoL consistently outperforms standard supervised contrastive learning (SupCon). On the augmented dataset, it improved Recall@1000 by approximately 5% across all backbones. Furthermore, the "logical consistency violation rate"—how often a model ranks an excluded document higher than a relevant one—dropped by over 20% compared to zero-shot and standard fine-tuned baselines.
One of the most significant insights is the mitigation of "Union Bias." Baseline retrievers tend to treat almost all logical operators as a "Union" (OR), retrieving everything related to any keyword. By visualizing document similarity correlations, we show that LogiCoL successfully "uncouples" embeddings. For example, the Pearson correlation between mutually exclusive queries dropped from a high of 0.88 in the baseline to as low as -0.29 with LogiCoL, proving the model learned to distinguish logical opposites.
Conclusion and Future Directions
LogiCoL marks a significant step forward in teaching dense retrievers to respect the laws of logic. Improving logical consistency directly correlates with better retrieval performance, especially for complex, multi-constraint queries involving negation.
Future work will focus on scaling these constraints to multi-billion parameter models and expanding the language scope beyond English to test cross-lingual generalizability. Additionally, the complexity of logically grouped batches presents an engineering challenge for massive-scale, "in-the-wild" web datasets that remains to be addressed.
Summary updated