Hermes
Overview
Hermes is named for the Greek messenger and interpreter. A question, a Turtle ontology, and optional context go in. One SPARQL query comes out. Each approach is a system behind one interface, so systems can be swapped and compared.
The public entry is hermes.ask(question, ontology, system=...). A system is any callable registered by name, and Systems shows how to add one. The one that ships today is training-free. It loads a compact vocabulary, asks a model for a draft, walks a fixed list of stages, and checks that the result parses. The stages are the place later techniques plug in. Today each of them returns the draft unchanged.
The pieces
ask, and how to register a new system.
Training-freeThe command, generate, and the prompt that lists prefixes, classes, and properties.
VocabularyClasses, properties, and prefixes read from a Turtle file, capped for the prompt.
StagesGuardrails, query guided, context guided, and chase and backchase. Hooks only, for now.
ValidationExtract the query, lift modifiers out of WHERE, parse, and repair once.
ModelsA local Ollama model by default, or an OpenAI-compatible API.
One call
load_vocabularyreads the Turtle file.build_promptlists prefixes, classes, properties, context, and examples.completeasks the model for one query.prepare_draftextracts the query and lifts solution modifiers.apply_stageswalks guardrails, query guided, context guided, then chase and backchase.parse_errorchecks the query. On failure, one repair call runs, then the same stages and the same check.
The return value is a dict with sparql, model, and provider.
Install
git clone https://github.com/lamng3/hermes.git
cd hermes
pip install -e .
The install name is hermes-sparql and the import name is hermes. Python 3.11 or newer. Dependencies are rdflib and httpx. Tests use the dev extra: pip install -e ".[dev]", then pytest.