DirectionGuard

class DirectionGuard(cues: Set<String> = Vocabulary.DIRECTIONAL_CUES, stopwords: Set<String> = Vocabulary.STOPWORDS) : MatchGuard

Rejects matches where the same words appear in an order that reverses the question.

"Is Postgres better than MySQL?" and "Is MySQL better than Postgres?" contain an identical bag of words. Every set-based check — word overlap, entity comparison, embedding similarity — sees two copies of the same question, because in the bag-of-words view that is exactly what they are.

Word order alone cannot be the signal, though: "In Python, how do I sort a dictionary by value?" and "How do I sort a dictionary by value in Python?" are also a reordering, and they must stay a hit. Two conditions narrow the guard to real swaps.

A cue must be present — a comparison or a conversion, the constructions where argument order carries meaning. And the words must be the same; different words are somebody else's problem, which keeps "how many miles is 50 km" matching "convert 50 km to miles".

The reordering must not be a rotation. Moving a phrase from the end of a sentence to the front rotates the token list, and it never changes the question: "How do I migrate a file in Linux?" and "In Linux, how do I migrate a file?" are one prompt. Swapping two arguments around a cue is a different permutation entirely — no rotation turns [postgres, better, mysql] into [mysql, better, postgres]. Without this test the guard rejects every fronted prepositional phrase whose sentence happens to contain a cue word, which is a paid API call for nothing.

Constructors

Link copied to clipboard
constructor(cues: Set<String> = Vocabulary.DIRECTIONAL_CUES, stopwords: Set<String> = Vocabulary.STOPWORDS)

Properties

Link copied to clipboard
open override val name: String

Short stable identifier, surfaced in dev.kmemo.CacheLookup.Miss.detail.

Functions

Link copied to clipboard
open override fun evaluate(query: String, candidate: String): GuardVerdict

Judges serving the response cached for candidate in answer to query.