Skip to content

Token Efficiency

Fresh

How MD-LD compares to JSON-LD and Turtle in LLM token consumption — measured across two tokenizers, seven graph structures, and scaling tests up to 500 entities.

Summary

ComparisonAverage token savings
MD-LD vs JSON-LD55.4%
MD-LD vs TTL29.5%
TTL vs JSON-LD40.3%

Results confirmed across two tokenizers: cl100k_base (GPT-4) and o200k_base (GPT-4o). Savings differ by less than 1% between tokenizers.

MD-LD carries 2.5x more RDF triples per token than JSON-LD and 1.4x more than TTL.

In a 128K context window with 120K tokens reserved for data: MD-LD fits ~2,884 person records, TTL fits ~2,675, JSON-LD fits ~2,055.

Per-Example Results (cl100k_base)

ExampleTriplesJSON-LDTTLMD-LDvs JSON-LDvs TTL
Simple Person51146646-59.6%-30.3%
Org + Members1122113388-60.2%-33.8%
Task Management20339286224-33.9%-21.7%
Academic Research10271194118-56.5%-39.2%
API Documentation10215147102-52.6%-30.6%
Complex Nested Graph20472266220-53.4%-17.3%
Diff / Retraction42199362-71.7%-33.3%
Average-55.4%-29.5%

Side-by-Side Example

The same person record in all three formats:

JSON-LD (114 tokens, 335 chars):

json
{
  "@context": {
    "ex": "tag:alice@example.org,2026:",
    "prov": "http://www.w3.org/ns/prov#",
    "name": "ex:name",
    "fullName": "ex:fullName",
    "email": "ex:email"
  },
  "@id": "tag:alice@example.org,2026:alice",
  "@type": "prov:Person",
  "name": "Alice",
  "fullName": "Alice Smith",
  "email": "alice@example.com"
}

TTL (66 tokens, 198 chars):

turtle
@prefix ex: <tag:alice@example.org,2026:> .
@prefix prov: <http://www.w3.org/ns/prov#> .

ex:alice a prov:Person ;
  ex:name "Alice" ;
  ex:fullName "Alice Smith" ;
  ex:email "alice@example.com" .

MD-LD (46 tokens, 133 chars):

markdown
[ex] <tag:alice@example.org,2026:>

# Alice {=ex:alice .prov:Person label}
[Alice Smith] {ex:fullName}
[alice@example.com] {ex:email}

Same 5 RDF triples. MD-LD is 59.6% fewer tokens than JSON-LD and 30.3% fewer than TTL.

Semantic Density

Raw token counts can be misleading — a format that uses fewer tokens but encodes less information is not truly more efficient. Semantic density (triples per token) normalizes for information content:

ExampleJSON-LDTTLMD-LDMD-LD / JSON-LDMD-LD / TTL
Simple Person0.0440.0760.1092.48x1.43x
Org + Members0.0500.0830.1252.50x1.51x
Diff / Retraction0.0180.0430.0653.61x1.51x
Average0.0420.0670.1092.50x1.43x

Scaling Behavior

Token cost grows linearly with entity count. MD-LD's advantage persists at scale:

Records (N)JSON-LDTTLMD-LDvs JSON-LDvs TTL
10677495440-35.0%-11.1%
502,9702,2682,093-29.5%-7.7%
1005,8374,4854,160-28.7%-7.2%
50028,77022,21820,693-28.1%-6.9%

Per-record token cost (constant at any scale):

FormatPer-record tokens
JSON-LD58.4
TTL44.9
MD-LD41.6

MD-LD saves 16.8 tokens per record vs JSON-LD and 3.3 tokens vs TTL — consistently, at any scale.

Context Window Utilization

In a 128K context window with 8K reserved for instructions (120K available for data):

FormatPer-record costRecords in 120K tokens
JSON-LD58.42,055
TTL44.92,675
MD-LD41.62,884

MD-LD fits 829 more records than JSON-LD and 209 more than TTL in the same context window.

Cost Implication

At GPT-4-class pricing (~$3/million input tokens), a full 128K context of knowledge graph data costs:

FormatCost per request
JSON-LD$0.36
TTL$0.28
MD-LD$0.26

MD-LD saves $0.10 per request vs JSON-LD. For 1,000 requests/day, that is approximately $36,500/year.

Why MD-LD Is More Token-Efficient

Four structural advantages explain the savings:

1. No structural scaffolding

JSON-LD spends tokens on {, }, ", :, ,, and key names ("@id", "@type", "@context") that carry zero RDF semantics. TTL reduces this but still requires ;, ., and string delimiters. MD-LD uses Markdown's natural structure as semantic carriers.

2. Prefix folding with positional context

MD-LD declares a prefix once and sets the subject via headings. TTL must re-state the subject for each new node. This eliminates per-node subject re-declaration.

3. Inline compaction

A single MD-LD annotation can encode multiple triples:

markdown
[Alice Chen] {+ex:alice ?org:member .prov:Person label}

This one line produces three triples: the ?org:member object property, the .prov:Person type declaration, and the implicit rdfs:label "Alice Chen". In TTL, three separate predicate-object pairs. In JSON-LD, a full nested object.

4. Diff-native semantics

MD-LD's polarity system is built into the syntax. Expressing corrections requires no out-of-band metadata — just -predicate inline. This is why the Diff/Retraction example shows the largest savings (71.7% vs JSON-LD).

Where MD-LD Wins Most vs JSON-LD

ExampleSavingsWhy
Diff / Retraction-71.7%JSON-LD has no retraction mechanism; MD-LD's - prefix handles it inline
Org + Members-60.2%MD-LD collapses member type + label + relationship into one annotation
Simple Person-59.6%JSON-LD @context is pure overhead, no triples produced