Knowledge Graph Construction: Process, Ontology Design, and Practical Applications

    This article walks through how to build a knowledge graph end to end: why triples are the standard representation, how to design an ontology with clear constraints, how top-down and bottom-up construction paths differ and combine, and which processing stages matter most, including entity recognition, relation extraction, entity alignment, quality evaluation, and storage and query design. It also covers typical use cases and common pitfalls, so you can decide what to model first and how to keep the graph accurate over time.

    1. Rethinking Knowledge Graphs: From Data Tables to a Semantic Network

    Relational databases excel at exact matching over structured fields. But questions such as “Which diseases interact with a given drug?” or “Which manufacturers do a component’s upstream suppliers also supply?” require multi-hop joins. Answering them usually means writing deeply nested queries, which are expensive to maintain.

    A knowledge graph takes a different approach. It models the world as a semantic network of nodes and edges: nodes represent distinguishable, independently referenceable things, and edges represent specific relationships between them. The basic unit of representation is the triple: entity–relation–entity.

    Triples became the de facto standard for three reasons:

    • General enough in expressiveness: Whether it is “Zhang San–works at–a company” or “Model X–applies to–scenario Y”, the same structure carries both, with no need to design a separate table for each knowledge type.
    • Natural support for multi-hop reasoning: A path from A to B to C is simply a reachability problem on the graph, so query semantics match the storage structure.
    • Easy incremental evolution: Adding knowledge means appending triples, not making large-scale schema changes.

    The value of a graph is not in how the diagram looks. It is in turning implicit knowledge scattered across documents, spreadsheets, and logs into explicit structures that machines can compute over, validate, and reason about.

    2. Ontology Design: The Foundation of the Graph

    An ontology defines which entity types and relation types are allowed in the graph, along with their constraints. This step sets the ceiling for everything downstream, so think it through before writing code.

    Design recommendations:

    1. Start small, then expand: Cover the types and relations needed for one business loop first, rather than aiming for something all-encompassing from day one.
    2. State constraints explicitly: Declare the domain and range of each relation (for example, the subject of “works at” must be a person and the object must be an organization), and note the cardinality (one-to-many or many-to-many).
    3. Leave room for extension: Keep expressive capacity for type hierarchies, attributes, and time intervals, since most real-world relationships are time-bound.

    A simplified ontology example:

    1. {
    2. "entity_types": ["Person", "Organization", "Equipment", "Symptom", "Remediation"],
    3. "relations": [
    4. {"name": "works_at", "domain": "Person", "range": "Organization", "cardinality": "N:1"},
    5. {"name": "manifests_on", "domain": "Symptom", "range": "Equipment", "cardinality": "N:1"},
    6. {"name": "recommends_remediation", "domain": "Remediation", "range": "Symptom", "cardinality": "N:M"}
    7. ],
    8. "temporal": {"enabled": true, "fields": ["valid_from", "valid_to"]}
    9. }

    3. Two Construction Paths: Top-Down and Bottom-Up

    3.1 Top-Down: Starting from High-Quality Structured Data

    When the domain already has a relatively mature body of material (industry encyclopedias, terminology databases, product catalogs, internal master data systems), you can extract the type system and relation patterns directly from it and quickly form the skeleton of the graph. This approach offers high accuracy and stable structure. Its limitation is that coverage is bounded by the data sources, and the update cadence depends on the source systems.

    Practical tip: build a schema mapping table that maps each source field to a type or relation in the ontology, and explicitly mark fields that cannot be mapped as pending, so information is not silently lost.

    3.2 Bottom-Up: Mining Patterns from Large Volumes of Text

    For unstructured documents, tickets, and customer service records, you need natural language processing and machine learning to first extract candidate entities and candidate relations. Higher-confidence new patterns then go through manual review, and only confirmed ones are allowed into the production graph.

    Practical tip: manage candidate patterns and published patterns in separate stores. All automatically produced results land in the candidate area first, gated by both a threshold and sampling checks, to keep noise out of the ontology.

    3.3 Combining Both: The More Common Shape in Engineering

    Real projects usually use a hybrid strategy: top-down to establish the backbone and constraints, bottom-up to fill in long-tail knowledge and newly emerging concepts, and periodic reviews to promote patterns that have stabilized into published ones.

    4. Breaking Down the Key Processing Stages

    4.1 Entity Recognition and Relation Extraction

    Entity recognition answers “which spans in the text are entities”, and relation extraction answers “what relation holds between entities”. A common approach models the two as a combination of sequence labeling and classification tasks; joint modeling is also an option, reducing error accumulation. An illustrative flow:

    1. Raw text
    2. → Sentence splitting and cleaning
    3. → Entity candidate recognition (type + boundary)
    4. → Relation candidate generation (entity pairs + trigger words)
    5. → Confidence scoring and threshold filtering
    6. → Manual sampling review → ingest

    One engineering concern is negative sample construction: irrelevant entity pairs vastly outnumber valid relations, so the sampling strategy directly affects real model performance.

    4.2 Entity Alignment and Disambiguation

    The same thing often has multiple surface forms, and different things may share a name. Alignment usually proceeds in two steps: coarse filtering with literal similarity, edit distance, and vector semantic similarity, then fine-grained judgment using attribute consistency and context features. For conflicting attributes (such as two different founding years for the same entity), retain the source and confidence rather than simply overwriting.

    4.3 Quality Evaluation

    Monitor at least four categories of metrics: coverage (whether every type and relation in the ontology has instances), accuracy (the proportion of correct triples in sampling), consistency (whether domain, range, or cardinality constraints are violated), and timeliness (whether relations have passed their validity period). Write validation rules as executable assertions and run them on a schedule in the pipeline.

    4.4 Storage and Query

    At small scale, a relational store can hold the triple table. As scale grows, graph databases have an advantage for variable-length path queries. A common engineering compromise is a graph database for relations, object storage for raw documents and attachments, a message queue for incremental updates, and logging and monitoring services for observability. On the query side, materialized views or precomputation for frequent multi-hop patterns help avoid a full graph traversal every time.

    5. Typical Application Scenarios

    • Intelligent question answering: Parse a natural language question into a graph query, return a structured answer along with an evidence path. Explainability is clearly better than pure vector retrieval.
    • Recommendation and association discovery: Use path features on the graph to supplement collaborative filtering and mitigate cold start.
    • Risk and anomaly detection: Surface groups or systemic risks through cycles, dense subgraphs, and anomalous propagation paths.
    • Operations and knowledge assistants: Connect symptoms, equipment, and remediations into a network that supports similar case retrieval and ranked remediation suggestions.

    6. Implementation Advice and Common Pitfalls

    1. Define the questions before the graph: List the questions you need to answer, work backward to the required types and relations, and avoid building a graph nobody queries.
    2. Treat updates as a first-class concern: Design an incremental pipeline and a versioning mechanism; a graph is not a one-time deliverable.
    3. Human-machine collaboration is not optional: Automated extraction provides scale, manual review provides the baseline, and the ratio between them shifts dynamically with maturity.
    4. Put permissions and compliance first: When sensitive fields are involved, handle masking and access control at the ingestion stage.

    To lower the cost of building your own stack, you can compose general cloud capabilities: a container platform to host extraction and inference services, object storage to archive the raw corpus, a message queue to decouple the incremental pipeline, and monitoring and alerting to safeguard task success rates. General cloud product categories from providers such as Baidu AI Cloud can serve as a reference for selection, but the core ontology design and quality system still need to be built up against your own business.