Shunya LabsShunya LabsPlayground

How to Build a Knowledge Graph With a Small Language Model

ByNavvya Jain|Research & Product Analyst|Build & Learn|18 Nov 2026

TL;DR , Key Takeaways:

  • Yes, a small model can extract a knowledge graph. Pulling entities and relationships from text is a narrow, repetitive task that suits small language models (SLMs) far better than open-ended reasoning.
  • Extraction is where knowledge-graph costs pile up, because every chunk of every document passes through a model. A small model in place of a large API model cuts the cost of each pass.
  • A working prototype is the easy part. A schema, a prompt and a small model can extract a few hundred documents in an afternoon.
  • Enterprise scale is where it breaks. Domain terminology, mixed-language documents, constant updates, access rules and audit requirements are what separate a demo from a system people can rely on.
  • Measure before you scale. Check extraction on a hand-labelled sample, and expect to fine-tune on your own data to close the gap.

Why use a small model to build a knowledge graph?

The most expensive part of a knowledge graph is usually building it, not querying it. Before a graph can answer anything, a model has to read every chunk of every document and pull out the entities and relationships it contains.

We compared the main approaches and their costs in GraphRAG vs Vector RAG vs LazyGraphRAG. One of the most direct ways to bring the bill down is to change which model does the reading.

A large general-purpose model can write poetry, debug code and summarise a legal brief. Entity extraction needs none of that. It needs a model that reads a passage, finds the products, policies and people in it, and reports how they connect, in the same format, thousands of times. That is the kind of narrow, repeatable job small language models are suited to.

If you are new to knowledge graphs, start with Knowledge Graphs and RAG for Enterprise AI.

Can a small language model build a knowledge graph?

Yes. A small model can build a reliable knowledge graph when the task is tightly defined: a fixed list of entity and relationship types, short text chunks and a strict output format. Quality drops when the model is asked to infer relationships the text does not state, or to handle long, tangled passages.

There is also evidence that a model trained specifically for extraction can compete with much larger ones. Triplex, a 3.8-billion-parameter model fine-tuned from Phi-3 for knowledge-graph construction, is reported by its developers to outperform GPT-4 on this task at 1/60th of the cost. That is the developers’ own benchmark, and the model’s licence restricts commercial use for larger organisations, so treat it as a sign of what is possible rather than a drop-in choice.

What the extraction task actually needs

  • Recognising named things: products, plans, policies, teams, customer segments.
  • Spotting stated relationships: “Plan X is covered by Policy Y”, “Team A owns Product B”.
  • Following a format exactly: the same JSON shape on every chunk, so the output can be loaded without hand-cleaning.
  • Not inventing facts: reporting only what the text says. This is where model choice matters most; see why enterprise LLMs hallucinate.

None of these require broad world knowledge, which is what most of a large model’s size pays for.

Small model vs GPT for knowledge-graph extraction

A small model wins on cost, control and data residency; a large API model wins on setup time and on messy, ambiguous text. For most enterprise collections, the practical answer is a small model for the bulk of chunks and a larger one for the exceptions.

Small model (1–4B parameters, run locally)Large API model (GPT-class)
Cost per chunkYour own compute; no per-token feePer-token fee on every chunk, every re-index
Where data goesStays on your serversSent to the provider
HardwareA single GPU or, for small models, a CPU (see SLMs on CPUs)None on your side
Following a fixed schemaGood with structured outputs and a tight schemaGood, with more tolerance for vague instructions
Ambiguous or long passagesMore missed or wrong relationshipsHandles them better
Improving accuracyFine-tune on your own labelled examplesMostly prompt changes
Setup effortHigher: model serving, testingLower: an API key

How small-model extraction works

At its core, small-model extraction is a loop: split documents into short chunks, ask the model to return the entities and relationships in each chunk in a fixed format, check the output, and write it to a graph database.

  1. Define a schema. Decide which entity types (product, plan, policy, team, customer segment) and relationship types (covered by, applies to, owned by, replaces) your questions depend on. A closed list keeps the model focused.
  2. Split documents into short chunks. Small models are more accurate on passages of a few hundred words. Keep an ID for each chunk so every fact can be traced to its source.
  3. Extract with a fixed output format. Structured outputs force the model’s reply into your schema, so the result can be loaded without hand-cleaning.
  4. Validate. Drop relationships that point to entities the model never extracted, and merge duplicate names.
  5. Load into a graph, linking each entity back to the chunk it came from.

Here is a simplified illustration of steps 1 and 3, using a small model served locally with Ollama’s structured outputs. It shows the idea, not a production pipeline:

from typing import Literal
from pydantic import BaseModel
from ollama import chat

class Entity(BaseModel):
    name: str
    type: Literal["Product", "Plan", "Policy", "Team"]

class Relation(BaseModel):
    source: str
    target: str
    type: Literal["COVERED_BY", "APPLIES_TO", "OWNED_BY"]

class Graph(BaseModel):
    entities: list[Entity]
    relations: list[Relation]

def extract(chunk: str) -> Graph:
    response = chat(
        model="qwen2.5:3b",  # any small instruction-tuned model
        messages=[
            {"role": "system", "content": "Extract only facts stated in the text. Return JSON."},
            {"role": "user", "content": chunk},
        ],
        format=Graph.model_json_schema(),
        options={"temperature": 0},
    )
    return Graph.model_validate_json(response.message.content)

Run on a few hundred clean, English documents, a setup like this can produce a useful graph in an afternoon. The harder questions start when you point it at a real enterprise document estate.

How to check extraction quality before scaling

Check a small model’s extraction against a hand-labelled sample before you trust it with the full collection. Model size alone does not predict accuracy: on Vectara’s hallucination leaderboard (October 2026), models of similar size ranged from 5.7% (Qwen3-4B) to 23.5% (Phi-4-mini) on a summarisation test. Extraction errors are worse than summary errors, because every wrong relationship ends up in every answer built on the graph.

A simple evaluation routine:

  1. Label 50–100 chunks by hand. Pick a mix of easy and difficult passages, and record the entities and relationships a domain expert would expect.
  2. Measure precision. Of the relationships the model extracted, how many are correct? Low precision means the model is inventing facts.
  3. Measure recall. Of the relationships in your labels, how many did the model find? Low recall means the graph will have gaps.
  4. Read the failures. Errors usually cluster: one confusing entity type, long tables, abbreviations. Fix the schema or prompt for those cases first.
  5. Re-run after every change to the model, prompt or schema, using the same labelled set.

If precision is high but recall is low, the graph is trustworthy but incomplete, and you can add a vector search layer to fill gaps (see the hybrid knowledge graph and RAG architecture). If precision is low, fix it before going further.

Where most projects stall. Teams often get a promising prototype, then find accuracy drops on their own documents: internal product codes, abbreviations and mixed-language text the model has never seen. Closing that gap usually means training a model on the organisation’s own data. That is the work Shunya Labs’ custom SLMs are built for.

What changes at enterprise scale

A prototype proves the idea; an enterprise knowledge graph has to be accurate, current, secure and explainable every day. These are the six problems that tutorials skip.

1. Your terminology is not the model’s terminology

General models know common words, not your plan codes, product variants or internal shorthand. “Gold Plus”, “GP” and “Plan 7” may be the same thing; a model that does not know this creates three nodes and breaks every answer that depends on them. Fixing it means training on your own vocabulary, as covered in when a domain-specific model makes sense.

2. Documents are rarely in one language

In India and across Asia, policies, call transcripts and customer messages often mix English with Hindi or other regional languages in the same sentence. Most small models are trained mainly on English and lose accuracy on mixed-language text. We explain the problem in how code-switching affects voice AI accuracy.

3. The graph has to stay current

Policies change, products launch and plans are retired. Rebuilding the whole graph each time is slow and costly, so production systems need to re-extract only what changed and retire facts that are no longer true. Without that, the graph quietly drifts out of date.

4. Not everyone should see everything

A knowledge graph built from HR files, contracts and customer records holds information with different access rules. The graph has to carry those permissions through, so an answer never reveals a fact the person asking is not allowed to see.

5. Every answer needs a source

In banking, insurance and healthcare, “the AI said so” is not enough. Each fact in the graph needs a link back to the document and passage it came from, so answers can be checked and audited. Read more on knowledge-grounded AI.

6. Quality has to be measured continuously

Accuracy measured once at launch does not stay true as documents and models change. Production graphs need a standing evaluation set and checks on every update, as described in the section above.

When to use a larger model instead

Use a larger model for the chunks a small one cannot handle, not for the whole collection. Routing only the hard cases keeps most of the cost saving while protecting quality. We explain this pattern in more depth in how AI model routing reduces cost and latency.

Send a chunk to a larger model when:

  • The small model’s output fails validation.
  • The text needs inference, not just reading. For example, a contract clause that only implies who is responsible.
  • The passage is long or dense, such as a large table or a multi-page section that cannot be split without losing meaning.
  • The stakes are high. Regulatory or clinical content may justify a second check even when the small model’s output looks clean.

If the same kinds of chunks keep failing, that is a signal to fine-tune. A model trained on a few hundred of your own labelled examples learns your entity names, abbreviations and document layouts. Our guide to choosing between prompt engineering, RAG and fine-tuning covers when that investment pays off.

How Shunya Labs builds enterprise knowledge graphs

Shunya Labs builds knowledge graphs for organisations that need the cost of a small model with the reliability of a production system. Each of the six problems above maps to part of how we work:

  • Models that know your language. Custom SLMs are trained on an organisation’s own workflows, terminology and enterprise knowledge, so product names, plan codes and internal abbreviations are recognised from the start.
  • Built for Indian and Asian languages. Shunya’s speech and language models are designed for multilingual and code-switched content, including mixed-language conversations, which matters when the source material is call recordings and customer messages as well as documents.
  • Inside your perimeter. Models are trained within the customer’s environment and delivered as a signed artefact rather than a shared inference endpoint. The platform runs in the cloud, in a private cloud, on premises or air-gapped, so source documents and access rules stay under your control.
  • Grounded, traceable answers. The knowledge layer organises products, regulations, SOPs and workflows into a graph that grounds every answer, including those given by Shunya’s voice agents.

The result is a knowledge graph your teams can trust, without paying large-model prices to build or maintain it.

Planning an enterprise knowledge graph? Talk to the Shunya Labs team about what it would take for your data.

Frequently asked questions

Can I build a knowledge graph with a small model instead of GPT?

Yes. Entity and relationship extraction is a narrow, repetitive task that small language models handle well when given a fixed schema, short text chunks and structured outputs. Test the results on a hand-labelled sample before processing a full document collection.

Which small model is best for knowledge-graph extraction?

There is no single best model; it depends on your documents and languages. Start with a 1–4 billion parameter instruction-tuned model, measure precision and recall on your own labelled sample, and consider fine-tuning on your data if accuracy falls short.

How do I build a knowledge graph from PDFs using an LLM?

Convert the PDFs to text, split the text into short chunks, ask the model to extract entities and relationships from each chunk in a fixed JSON format, validate the output, and load it into a graph database such as Neo4j using MERGE to avoid duplicates.

What is the hardest part of building an enterprise knowledge graph?

Extraction itself is the easier part. The harder parts are recognising company-specific terminology, handling mixed-language documents, keeping the graph current as documents change, enforcing access permissions and linking every fact to its source for audit.

Is a knowledge graph built by a small model accurate enough?

It can be, for well-defined extraction tasks. Accuracy varies widely between small models, so measure it on your own documents. Route chunks that fail validation, or that need inference rather than reading, to a larger model.

Why not just use GPT for knowledge-graph extraction?

You can, but every chunk is billed per token, every re-index is billed again, and documents leave your environment. A small local model avoids per-token fees and keeps data in-house, which matters for large or sensitive collections.

Can a small model for knowledge-graph extraction run without a GPU?

Smaller models can run on CPUs, though more slowly. For a one-off build of a modest collection, CPU inference may be enough; for large or frequently updated collections, a single GPU is usually more practical.

Sources

Navvya Jain
|

Navvya Jain

Research & Product Analyst

Bio: Navvya works at the intersection of product strategy and applied AI research at Shunya Labs. With a background in human behaviour and communication, she writes about the people, markets, and technology behind voice AI, with a particular focus on how speech interfaces are reshaping access across emerging markets.

The fastest way to add voice AI to your products

One platform for speech in and speech out.