Module de.seggebaeing.sqlanalyzer
Class LLMComparator
java.lang.Object
de.seggebaeing.sqlanalyzer.logic.util.eval.impl.LLMComparator
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionLLMComparator
(LLM llm, double temperature) Creates an LLM-backed statement comparator with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptiondouble
compare
(SQLQueryWrapper query1, SQLQueryWrapper query2) Compares two SQL statements by delegating to the configured LLM.void
setRateLimitReporter
(Consumer<Instant> rateLimitReporter) Sets a callback to receive retry instants when a rate limit is encountered.
-
Constructor Details
-
LLMComparator
Creates an LLM-backed statement comparator with the given configuration.- Parameters:
llm
- the LLM used to perform the comparisontemperature
- the sampling temperature passed to the LLM
-
-
Method Details
-
compare
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, returnsDouble.NaN
.- Specified by:
compare
in interfaceStatementComparator
- Parameters:
query1
- first SQL statement wrapperquery2
- second SQL statement wrapper- Returns:
- normalized similarity score in
0.0–1.0
, orNaN
on failure
-
setRateLimitReporter
Sets a callback to receive retry instants when a rate limit is encountered.- Parameters:
rateLimitReporter
- consumer invoked with theInstant
after which a retry is allowed; may benull
to disable reporting
-