Key takeaway
- Build a semantic search engine with ontology, RDF, SPARQL and Solr, and see when vector or hybrid search fits and how to govern retrieval for AI agents.
A semantic search engine returns results based on the meaning of a query, not only on the words it contains. It does this by modelling the domain (an ontology), storing facts in a machine-readable form (RDF triples) and ranking candidates by how close their meaning is to the query. Modern engines add vector embeddings to the same pipeline.
This guide explains each layer using a worked example from our own build: a domain search engine for computer science faculty profiles, using an ontology, Spark, Apache Jena and Solr. It also shows where this older, explicit-knowledge approach sits next to vector search and Graph RAG, and when governed retrieval matters for AI agents.
How does semantic search differ from keyword search?
Keyword search matches the words in the query against the words in each document, after cleaning and preprocessing, and ranks by how many match. Semantic search tries to work out what the user wants, so "when was he born" and "birthday" can reach the same answer. The table compares the main approaches.
| Approach | How it finds results | Where it fits | Main limit |
|---|---|---|---|
| Keyword search | Matches query terms to document terms | Exact names, codes, short queries | Misses different wording for the same idea |
| Ontology and RDF search | Expands the query using domain relations, then queries triples with SPARQL | Closed domains with stable concepts and explainable answers | The ontology must be built and maintained |
| Vector (embedding) search | Compares vectors of the query and the content | Open text, paraphrase, many languages | Hard to explain why a result matched |
| Hybrid | Combines lexical, vector and graph signals | Enterprise knowledge with mixed content | More components to tune and govern |
What is an ontology and how is it built?
According to the W3C, an ontology is a formal vocabulary of terms, usually focused on one domain, where each term is defined by its relationships to other terms. OWL 2 is the W3C language for writing them, with classes, properties, individuals and data values (W3C Recommendation, 11 December 2012, OWL 2 overview).
To build one, choose the domain, list its concepts and the relations between them, then encode them as OWL classes, subclasses and properties. In our example the classes are departments and research areas, and each faculty profile becomes a named individual with data properties. The ontology acts like a schema, and the individuals are the instances created from it.
How is unstructured text turned into RDF triples?
RDF represents information as triples of subject, predicate and object. The W3C defines a triple as a subject (an IRI or blank node), a predicate (an IRI) and an object (an IRI, literal or blank node) (RDF 1.1 Concepts, 25 February 2014). "Apple is red" becomes: subject apple, predicate hasColour, object red.
Turning documents into triples takes linguistic analysis and machine learning. Rules and models annotate people, organisations, locations and bibliographic details, find the relations between them, and write each relation as a triple. The triples and the ontology are then stored together in a triple store, which is the searchable knowledge base.
What does the architecture of a semantic search engine look like?
The reference build for faculty profiles runs in these stages.
- Ingest. A web crawler collects DOC, PDF, XML and HTML files from university sites and publishes a Kafka event for each page scraped.
- Persist. Extracted text is preprocessed and written to HDFS, with replication to survive node failure.
- Process. Spark Streaming reads the Kafka events, cleans the pages and prepares text for extraction.
- Classify and extract. A supervised model, trained on manually collected CVs tagged by department, decides whether a page is a computer science faculty profile. A second model assigns the top three research areas, and extraction rules capture names, emails, institutions and publication titles.
- Store. Ontology and RDF triples go into an Apache Jena triple store.
- Query. The user searches by university, research area or a short description of their own project, and SPARQL runs over the triples.
Apache Jena provides the storage and serving parts. According to its documentation, TDB2 is a transactional RDF store for a single machine, and Fuseki is a SPARQL server supporting the SPARQL 1.1 query, update and Graph Store protocols (TDB2, Fuseki). SPARQL itself is the W3C query language for RDF (SPARQL 1.1 Query, 21 March 2013).
Video: semantic search with ontology and machine learning, from XenonStack.
How do query expansion and ranking work?
The system first analyses the query to find words that belong to the domain. It expands them using the ontology's relations, and each expanded term receives a score based on how close the relation is. This is how a search for a research area also reaches related areas.
For ranking, Apache Solr indexes the RDF data by department and research area. TF-IDF turns text into vectors, and cosine similarity between the expanded query and each document gives the score that orders the results. The same Solr now offers dense vector search: its reference guide (version 10.1) describes a DenseVectorField, a knn query parser, euclidean, cosine and dot-product similarity, and lexical seeding or re-ranking for hybrid-style retrieval (Solr dense vector search). Embeddings can therefore be added to an ontology-driven pipeline without replacing it.
Which approach should an enterprise choose?
| Situation | Better fit | Why |
|---|---|---|
| Small, stable domain; answers must be explainable | Ontology and RDF with SPARQL | Every result traces back to explicit relations |
| Large, changing document set; varied wording | Vector or hybrid search | No hand-built model to maintain |
| Questions that follow relationships across entities | Graph-based retrieval | Relations are first-class data |
| Sensitive content with role-based access | Any of the above with permission-aware retrieval | Results must respect who may see what |
What are the trade-offs and when should you not use an ontology?
A better ontology gives better results, but no ontology for a domain is ever complete and it needs continuing upkeep. Reasoning has limits too: Jena's OWL reasoner is rule-based, aims to be sound but not complete, and does not support every construct, and its documentation recommends an external DL reasoner for complete OWL DL reasoning (Jena inference). If your content is broad, changes weekly and has no stable vocabulary, start with vector or hybrid search and add a lightweight knowledge graph only where explainability is needed.
Where does governed retrieval fit for AI agents?
Agents are only as reliable as the knowledge they retrieve. Ontologies and knowledge graphs give retrieval meaning to work with, and the same metadata can feed a catalogue (see our guides to the OpenMetadata platform and enterprise data catalog tools). Where agents act on what they find, add governance: who can retrieve what, and which actions are allowed.
According to its site, AgentSearch provides context-aware, permission-aware search across unstructured knowledge, and ElixirData keeps governed context, versioned policy and decision traces in one decision layer above AI agents. ElixirClaw is an agentic OS platform to build, orchestrate and govern AI agents and automation workflows while keeping humans in control. See also our guide to agentic workflows and the natural language processing overview.
How should you adopt semantic search?
- Pick one domain and write down its concepts, relations and the questions users actually ask.
- Build a small ontology and load a sample of content as triples.
- Measure against keyword search on real queries before scaling.
- Add vector retrieval where wording varies, and keep the ontology for explainable cases.
- Apply access control and logging to retrieval before agents use it.
Take the Agentic AI Readiness Assessment to see where your organisation stands and which use cases to start with.
To map one retrieval decision your agents should make, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.
Frequently Asked Questions
How is semantic search different from keyword search?
Keyword search matches words. Semantic search interprets intent and the relationships between concepts, so it can return relevant results that use different wording.
What is an ontology?
According to the W3C, it is a formal vocabulary of terms for a domain, where each term is defined by its relationships to other terms. OWL 2 is the W3C language for writing ontologies.
What is RDF and what is SPARQL?
RDF stores facts as subject, predicate and object triples. SPARQL is the W3C query language for RDF data.
How does machine learning help a semantic search engine?
It classifies documents, extracts entities and relations to build the triples, and supports ranking. Query expansion uses the ontology's relations.
Can vector search be combined with an ontology?
Yes. Solr, for example, supports dense vector fields and knn queries alongside lexical search, so embeddings can sit beside ontology-based expansion.
Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.
Explore the XenonStack platform family: ElixirData · ElixirClaw · ElixirHub · NexaStack · MetaSecure · Neural AI · AgentGRC · AgentSRE · AgentAnalyst · AgentInstruct · AgentRAI · AgentScrum · AgentSearch · AgentForce · AI Aviator · SAIF Aviator · CohortIQ · XenonStack AI · XenonStack UAE