Documentation/Relation Extraction

Relation Extraction

Experimental5 credits

Extract relations and build structured knowledge graphs from unstructured text. Discover entity relationships, output in RDF/Turtle, Neo4j property graph, or custom formats.

Production Recommendation

This is a direct endpoint for development and testing. For production workloads, use the Data Intelligence Pipeline -- it provides structured Data Packages with quality metrics, is async by default, and is covered by Enterprise SLAs.

Overview

Build structured knowledge graphs from unstructured text. Extract entities and their relationships, output in RDF/Turtle, Neo4j property graph, or custom formats.

Key features:

  • Entity resolution (merge duplicates)
  • Relation extraction with LLM optimization
  • Multiple output formats (RDF/Turtle, Property Graph)
  • Missing relation prediction

API Reference

POSThttps://api.latence.ai/api/v1/ontology/build_graph
Build knowledge graph from text and entities

Request Parameters

ParameterTypeRequiredDefaultDescription
textstringInput text
entitiesarrayList of entities with positions
config.resolve_entitiesbooleanMerge duplicate entities
config.optimize_relationsbooleanRefine relations with LLM
config.kg_output_formatstringOutput: custom, rdf_turtle, property_graph

Response Fields

FieldTypeDescription

Response Example

200 OKJSON
{
  "entities": [...],
  "relations": [
    {"subject": "Microsoft", "predicate": "founded_by", "object": "Bill Gates", "confidence": 0.95},
    {"subject": "Microsoft", "predicate": "located_in", "object": "Redmond", "confidence": 0.92}
  ],
  "knowledge_graph": {...},
  "success": true,
  "usage": { "credits": 2.0 }
}

Code Examples

from latence import Latence

client = Latence(api_key="YOUR_API_KEY")

# First extract entities, then build knowledge graph
text = "Microsoft was founded by Bill Gates in 1975. It is headquartered in Redmond."

# Get entities first
entities_result = client.experimental.extraction.extract(
    text=text,
    config={"label_mode": "generated"}
)

# Build knowledge graph from entities
result = client.experimental.ontology.build_graph(
    text=text,
    entities=[e.model_dump() for e in entities_result.entities],
    config={
        "resolve_entities": True,      # Merge duplicates
        "optimize_relations": True,    # Refine with LLM
        "kg_output_format": "property_graph"  # or "rdf_turtle", "custom"
    }
)

print(f"Entities: {len(result.entities)}")
print(f"Relations: {len(result.relations)}")
for rel in result.relations:
    print(f"  {rel.subject} --[{rel.predicate}]--> {rel.object}")

Explore Tutorials & Notebooks

Deep-dive examples and interactive notebooks in our GitHub repository

View on GitHub

Looking for production-grade processing?

The Data Intelligence Pipeline chains services automatically and returns structured Data Packages.