Skip to main content
XenonStack

Data Science

XenonStack Blog Semantic Search Engine: Ontology, RDF and Vectors

and | Published | Updated

Semantic Search Engine: Ontology, RDF and Vectors
9:41

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.

Two-column diagram mapping keyword, ontology and RDF, vector and hybrid search to how each finds results and its main trade-off
ApproachHow it finds resultsWhere it fitsMain limit
Keyword searchMatches query terms to document termsExact names, codes, short queriesMisses different wording for the same idea
Ontology and RDF searchExpands the query using domain relations, then queries triples with SPARQLClosed domains with stable concepts and explainable answersThe ontology must be built and maintained
Vector (embedding) searchCompares vectors of the query and the contentOpen text, paraphrase, many languagesHard to explain why a result matched
HybridCombines lexical, vector and graph signalsEnterprise knowledge with mixed contentMore 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.

  1. Ingest. A web crawler collects DOC, PDF, XML and HTML files from university sites and publishes a Kafka event for each page scraped.
  2. Persist. Extracted text is preprocessed and written to HDFS, with replication to survive node failure.
  3. Process. Spark Streaming reads the Kafka events, cleans the pages and prepares text for extraction.
  4. 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.
  5. Store. Ontology and RDF triples go into an Apache Jena triple store.
  6. 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?

SituationBetter fitWhy
Small, stable domain; answers must be explainableOntology and RDF with SPARQLEvery result traces back to explicit relations
Large, changing document set; varied wordingVector or hybrid searchNo hand-built model to maintain
Questions that follow relationships across entitiesGraph-based retrievalRelations are first-class data
Sensitive content with role-based accessAny of the above with permission-aware retrievalResults 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?

  1. Pick one domain and write down its concepts, relations and the questions users actually ask.
  2. Build a small ontology and load a sample of content as triples.
  3. Measure against keyword search on real queries before scaling.
  4. Add vector retrieval where wording varies, and keep the ontology for explainable cases.
  5. 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.

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

LinkedIn profile

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Get the latest articles in your inbox

Subscribe Now

Interested in solving your challenges with the XenonStack team?
Get Started

Tell us about you and your priorities so we can prepare the right conversation. It takes about 2 minutes.

Please Select your Industry
Banking
Fintech
Payment Providers
Wealth Management
Discrete Manufacturing
Semiconductor
Machinery Manufacturing / Automation
Appliances / Electrical / Electronics
Elevator Manufacturing
Defense & Space Manufacturing
Computers & Electronics / Industrial Machinery
Motor Vehicle Manufacturing
Food and Beverages
Distillery & Wines
Beverages
Shipping
Logistics
Mobility (EV / Public Transport)
Energy & Utilities
Hospitality
Digital Gaming Platforms
SportsTech with AI
Public Safety - Explosives
Public Safety - Firefighting
Public Safety - Surveillance
Public Safety - Others
Media Platforms
City Operations
Airlines & Aviation
Defense Warfare & Drones
Robotics Engineering
Drones Manufacturing
AI Labs for Colleges
AI MSP / Quantum / AGI Institutes
Retail Apparel and Fashion

Continue