hermes.systems.training_free

Training-free

The training-free system writes one SPARQL query from the schema vocabulary in a single model call, plus one repair call if the draft does not parse.

Command

hermes generate \
  --ontology GeoOutage.ttl \
  --question "Which counties have the highest number of outages?" \
  --context notes.txt \
  --examples pairs.jsonl
FlagMeaning
--ontology, --graph, or --endpointOne is required: an RDF file, a graph name from data/graphs.yaml, or a SPARQL endpoint URL.
--questionRequired.
--contextA text file of extra context.
--examplesJSONL, one object per line with nl and sparql (nl_text and sparql_query are accepted).
--systemAny registered system; the default is training-free.

Source: cli.py.

From Python

from hermes import Context, Example, TrainingFree

system = TrainingFree()          # or TrainingFree(llm=...)
result = system(
    "Which counties have the highest number of outages?",
    "GeoOutage.ttl",
    Context(text="Counties are administrative regions.",
            examples=[Example(nl="List outage records.",
                              sparql="SELECT ?rec WHERE { ?rec a geooutageonto:OutageRecord }")]),
)
print(result["sparql"])

The result has sparql, model, and provider. Source: training_free.py.

Prompt

build_prompt joins these sections with a blank line:

  1. Instructions: one query, only the prefixes and terms below, match labels in quotes, triples inside WHERE, ORDER BY and LIMIT after it, no SELECT inside FILTER, do not copy the shape example, return only the query.
  2. A shape example with ex: terms that are not from the ontology.
  3. Prefixes, classes, and properties from the vocabulary.
  4. Context text and example pairs, when given.
  5. The question, last.

Errors

A reply without a query raises ValueError. A query that still fails to parse after one repair raises ValueError with the parser message. Model failures are LookupError; see Models.