Enhancing Retrieval Systems with Inference-Time Logical Reasoning

Felix Faltings, Wei Wei, Yujia Bao

Abstract

Traditional retrieval methods rely on transforming user queries into vector representations and retrieving documents based on cosine similarity within an embedding space. While efficient and scalable, this approach often fails to handle complex queries involving logical constructs such as negations, conjunctions, and disjunctions. In this paper, we propose a novel inference-time logical reasoning framework that explicitly incorporates logical reasoning into the retrieval process. Our method extracts logical reasoning structures from natural language queries and then composes the individual cosine similarity scores to formulate the final document scores. This approach enables the retrieval process to handle complex logical reasoning without compromising computational efficiency. Our results on both synthetic and real-world benchmarks demonstrate that the proposed method consistently outperforms traditional retrieval methods across different models and datasets, significantly improving retrieval performance for complex queries.

Introduction

Modern search and Retrieval-Augmented Generation (RAG) systems predominantly utilize dense retrieval, where queries and documents are mapped to a shared embedding space. While effective for semantic matching, these systems are often "logic-blind." They struggle to interpret explicit logical constraints such as "NOT" or "AND," frequently returning documents that contain excluded terms simply because they are semantically related to the query topic.

To address this, we introduce Inference-Time Logical Reasoning (ITLR). ITLR is a framework that leverages Large Language Models (LLMs) to parse natural language queries into formal logical expressions. Instead of embedding the entire query as a single vector, ITLR decomposes the query, retrieves scores for individual components, and mathematically recombines them to respect the user's logical intent.

The Challenge of Logic-Blind Retrieval

Standard vector embeddings focus on global semantic similarity. For instance, a search for "benefits of Vitamin D excluding bone health" often retrieves documents heavily focused on bone health because "Vitamin D" and "bone health" are strongly associated in the training data. The embedding space lacks a robust mechanism to represent the negation operator.

Visualizing logical operations in document retrieval. Standard vector search struggles with explicit exclusions (NOT) and specific combinations (AND).

As queries become more complex—incorporating multiple conditions or exclusions—the performance of traditional dense retrieval degrades significantly. This "logic gap" necessitates a shift from simple vector compression to structured composition.

The ITLR Framework

The ITLR approach moves logical reasoning from the embedding space to the scoring process through a three-step pipeline:

  1. Logical Query Transformation: An LLM (e.g., Llama 3) acts as a logic parser, converting a natural language query into a structured expression like ("Vitamin D") AND NOT ("Bone Health").
  2. Term-Level Embedding: The system generates embeddings for each atomic term in the logical expression separately and calculates cosine similarity scores against the document corpus.
  3. Score Composition: Individual scores are combined using operators derived from fuzzy logic and probability theory:
  4. AND ($x * y$): Ensures the final score is high only if both terms are present.
  5. OR ($x + y$): Allows a document to rank well if either term matches.
  6. NOT ($1 - x$): Penalizes documents that match the excluded term.

This method is "inference-time" because it requires no retraining of the underlying embedding models, making it highly adaptable to existing search infrastructures.

Experimental Evaluation

We evaluated ITLR using both synthetic and real-world benchmarks:

  • Synthetic Benchmarks: 32 templates (e.g., t1 AND t2 OR NOT t3) were used to generate 3,200 queries of varying logical complexity.
  • Real-World Benchmarks: We utilized datasets from the BEIR benchmark, including NFCorpus (medical), SciFact (scientific), ArguAna (argumentation), and LegalBench (legal). To test logical reasoning, we used an LLM to transform simple queries from these datasets into complex, compositional versions.

Results and Key Insights

ITLR consistently outperformed baseline retrieval across all tested models (including OpenAI, Nvidia, and Mistral) and datasets.

Retrieval performance (nDCG@10) for AND queries. ITLR significantly outperforms the baseline as the number of logical terms increases.

Key findings include:

  • Superior Negation Handling: On synthetic data with three negations, the baseline nDCG@10 was 0.52, while ITLR achieved 1.00.
  • Real-World Gains: On the NFCorpus dataset, ITLR improved retrieval scores from 0.56 to 0.74 when using the NV-Embed-V1 model.
  • Robustness: The performance gains were consistent regardless of the underlying embedding model, indicating that the improvement stems from the retrieval strategy rather than the vector quality itself.
  • Parsing Accuracy: LLMs proved highly effective as logic parsers, with human annotators verifying 85-87% accuracy in query transformation.

Discussion and Future Work

While ITLR offers a significant leap in retrieval accuracy for complex queries, it relies on the LLM's ability to correctly parse user intent. Future work will focus on improving score calibration across different embedding models and extending the framework to handle more complex operators, such as temporal constraints or quantifiers. For simple queries where baselines are already strong, ITLR provides parity, ensuring it remains a robust general-purpose retrieval strategy.

Summary updated

BibTeX
@inproceedings{faltings2025enhancing,
  author = {Felix Faltings and Wei Wei and Yujia Bao},
  title = {{Enhancing Retrieval Systems with Inference-Time Logical Reasoning}},
  booktitle = {VecDB @ ICML},
  year = {2025},
  url = {https://openreview.net/forum?id=fQUQPcTk8c},
}
Figure