java.lang.Object
de.seggebaeing.sqlanalyzer.logic.util.eval.impl.LLMComparator
All Implemented Interfaces:
StatementComparator

public class LLMComparator extends Object implements StatementComparator
StatementComparator that delegates semantic comparison to an LLM.

Sends both SQL statements to the configured LLM using a fixed instruction prompt and expects a numeric score 0–100. The result is normalized to 0.0–1.0; if parsing fails or the call errors, Double.NaN is returned.

Rate limiting is handled via PromptAuthorizer; an optional setRateLimitReporter(java.util.function.Consumer) receives retry instants. Calls are blocking and may wait for rate limits—avoid invoking on UI threads.

Since:
1.0
Author:
Felix Seggebäing
  • Constructor Details

    • LLMComparator

      public LLMComparator(LLM llm, double temperature)
      Creates an LLM-backed statement comparator with the given configuration.
      Parameters:
      llm - the LLM used to perform the comparison
      temperature - the sampling temperature passed to the LLM
  • Method Details

    • compare

      public double compare(SQLQueryWrapper query1, SQLQueryWrapper query2)
      Compares two SQL statements by delegating to the configured LLM.

      Builds a fixed instruction prompt, requests an integer score (0–100), and returns the normalized value in 0.0–1.0. If the response is absent or unparsable, returns Double.NaN.

      Specified by:
      compare in interface StatementComparator
      Parameters:
      query1 - first SQL statement wrapper
      query2 - second SQL statement wrapper
      Returns:
      normalized similarity score in 0.0–1.0, or NaN on failure
    • setRateLimitReporter

      public void setRateLimitReporter(Consumer<Instant> rateLimitReporter)
      Sets a callback to receive retry instants when a rate limit is encountered.
      Parameters:
      rateLimitReporter - consumer invoked with the Instant after which a retry is allowed; may be null to disable reporting