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
| Flag | Required | Meaning |
|---|---|---|
--ontology | yes | Turtle file. |
--question | yes | The competency question. |
--context | no | A text file. The whole file is extra context. |
--examples | no | JSONL. 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:
- Instructions: one query, only the prefixes and terms below, match labels in quotes, triples inside
WHERE,ORDER BYandLIMITafter that block, noSELECTinsideFILTER, do not copy the shape example terms, return only the query. - A shape example that shows the clause order, using
ex:terms that are not from the ontology. - Declared prefixes as
PREFIX name: <namespace>. - Classes, one per line.
- Properties, one per line.
- Context text, when it is non-empty.
- Example question and query pairs, when any example has text.
- 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.