Hermes

hermes.generate

Training-free

The training-free system writes one SPARQL query for a question and an ontology. The command prints that result as JSON.

Command

hermes generate \
  --ontology GeoOutage.ttl \
  --question "Which counties have the highest number of outages?" \
  --context notes.txt \
  --examples pairs.jsonl
FlagRequiredMeaning
--ontologyyesTurtle file.
--questionyesThe competency question.
--contextnoA text file. The whole file is extra context.
--examplesnoJSONL. Each line is one object with nl and sparql. nl_text and sparql_query are accepted aliases.

Blank lines in the JSONL file are skipped. Source: cli.py.

Add --system NAME to run another registered system. The default is training-free.

From Python

from hermes import Context, Example, ask

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

hermes.generate is the same system called directly. context is optional. Pass None or a Context. Anything else raises TypeError. A blank question raises ValueError.

Context.text defaults to an empty string. Context.examples defaults to an empty list. Example has two strings, nl and sparql.

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 that block, no SELECT inside FILTER, do not copy the shape example terms, return only the query.
  2. A shape example that shows the clause order, using ex: terms that are not from the ontology.
  3. Declared prefixes as PREFIX name: <namespace>.
  4. Classes, one per line.
  5. Properties, one per line.
  6. Context text, when it is non-empty.
  7. Example question and query pairs, when any example has text.
  8. The question, always last.

Empty class or property lists render as (none found). No prefixes renders as (none).

Errors

If the model text has no query, prepare_draft raises ValueError. If the query still fails to parse after one repair call, generate raises ValueError with the parser message. Model failures are LookupError, described on the Models page.