Relation Extraction
Experimental5 creditsExtract 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
https://api.latence.ai/api/v1/ontology/build_graphRequest Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
text | string | — | Input text | |
entities | array | — | List of entities with positions | |
config.resolve_entities | boolean | — | Merge duplicate entities | |
config.optimize_relations | boolean | — | Refine relations with LLM | |
config.kg_output_format | string | — | Output: custom, rdf_turtle, property_graph |
Response Fields
| Field | Type | Description |
|---|
Response Example
{
"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
Looking for production-grade processing?
The Data Intelligence Pipeline chains services automatically and returns structured Data Packages.