Yoseph Naoom

Back to timeline

Project · Mar 2025

YAMZ - Ontology-Grounded Medical Diagnostic Assistant

A medical Q&A system that answers from an OWL knowledge graph, comparing RAG retrieval against generated SPARQL.

YAMZ was in autumn 2025, around a question that comes up whenever a knowledge graph meets a language model: if the structured knowledge already exists, does it help to embed it as text and retrieve chunks from it, or is it better to query it directly?

The ontology came first, hand-built in Protégé, 32 classes and 60 individuals covering diseases, symptoms, treatments, body parts and risk groups. Three reasoning modes then sit behind the same question box, so they can be compared on identical inputs.

RAG flattens the RDF into readable sentences, embeds them with all-mpnet-base-v2, and pulls the closest chunks in as context.

SPARQL gives the model the ontology schema instead, lets it write a query, runs that query with rdflib, and summarises whatever rows come back.

Comparing the three is where it gets interesting. SPARQL only ever reports what is actually in the graph, but it is brittle: a slightly malformed query returns nothing at all. RAG copes better with vague phrasing, though it will quietly fill in medical knowledge the ontology never asserted. The ungrounded answers sound the most convincing of the three, which is rather the point.

The interface shows the working, meaning the generated query, the raw result rows and the retrieved chunks, so any answer can be checked against the graph instead of trusted.

Built with Django, rdflib, ChromaDB and the OpenAI API.

  • Knowledge Graphs
  • Generative AI