Overview
Relationship extraction identifies semantic connections between entities in your knowledge graph. After extracting entities from text, relationships describe how those entities are connected. For example:- “Sam Altman” LEADS “OpenAI”
- “OpenAI” FOUNDED_BY “Sam Altman”
- “GPT-4” DEVELOPED_BY “OpenAI”
- LLM - Context-aware extraction using language models (default)
- Co-occurrence - Simple proximity-based relationships (no LLM required)
How Relationship Extraction Works
Relationships are extracted after entities are identified:lib/arcana/graph/graph_builder.ex:196
Relationship Extractors
LLM Extractor (Default)
Uses your configured LLM to identify semantic relationships with context awareness. Configuration:lib/arcana/graph/relationship_extractor/llm.ex:23
Advantages:
- 🎯 Context-aware - Understands semantic meaning
- 🔧 Flexible - Identifies diverse relationship types
- 📊 Strength scoring - Rates relationship importance
- 📝 Descriptive - Includes natural language descriptions
- 🐌 Slower - Requires LLM calls
- 💸 Costly - LLM API fees
- 🎲 Non-deterministic - Output may vary
Co-occurrence Extractor
Creates relationships based on entity proximity in text. Useful when LLM costs are prohibitive or for initial graph construction. Configuration:- Entities appearing within a text window are connected
- Relationship type is “CO_OCCURS_WITH”
- Strength based on proximity (closer = stronger)
- ⚡ Fast - No LLM calls
- 💰 Free - No API costs
- 🔒 Private - No external calls
- 📊 Generic - All relationships have same type
- ❌ No semantics - Doesn’t understand meaning
- 🎯 Less accurate - May connect unrelated entities
Disabling Relationships
Set tonil to skip relationship extraction:
Custom Extractors
Implement theArcana.Graph.RelationshipExtractor behaviour:
lib/arcana/graph/relationship_extractor.ex:63
Relationship Format
All extractors must return relationships as maps with: Required Fields::source(string) - Name of the source entity:target(string) - Name of the target entity:type(string) - Relationship type (e.g., “LEADS”, “FOUNDED”)
:description(string) - Natural language description:strength(integer 1-10) - Relationship importance/confidence
lib/arcana/graph/relationship_extractor.ex:51
Real Examples from Source
Example 1: LLM Prompt
Fromlib/arcana/graph/relationship_extractor/llm.ex:57:
Example 2: Validation
Fromlib/arcana/graph/relationship_extractor/llm.ex:160:
Example 3: Type Normalization
Fromlib/arcana/graph/relationship_extractor/llm.ex:137:
Example 4: Strength Scoring
Fromlib/arcana/graph/relationship_extractor/llm.ex:145:
Common Relationship Types
Based on typical knowledge graphs: People & Organizations:WORKS_AT- Employment relationshipLEADS- Leadership role (CEO, CTO, etc.)FOUNDED- Founder relationshipMEMBER_OF- Membership in organizationADVISES- Advisory role
LOCATED_IN- Physical locationHEADQUARTERED_IN- Main office locationOPERATES_IN- Areas of operation
DEVELOPED_BY- Creator relationshipOWNED_BY- OwnershipACQUIRED_BY- AcquisitionCOMPETES_WITH- Competition
USES- Technology dependencyBUILT_WITH- Implementation technologyINTEGRATES_WITH- IntegrationREPLACES- Replacement/successor
CITES- CitationAUTHORED_BY- AuthorshipPUBLISHED_IN- Publication venueBASED_ON- Theoretical foundation
Configuration Options
Inline Function
Module with Options
Per-Call Override
Performance Considerations
LLM Extractor:- ~500-2000ms per chunk
- Cost: ~$0.001-0.02 per chunk (varies by model and relationship count)
- Parallelizable: Yes (concurrent API calls)
- ~10-50ms per chunk
- Cost: Free
- Parallelizable: Yes
- Extract relationships only for chunks with multiple entities
- Use co-occurrence for initial graph, LLM for refinement
- Cache relationships by (chunk_hash, entity_set)
- Batch LLM calls when possible
- Use parallel processing (see
lib/arcana/graph.ex:361)
Validation
Relationships are automatically validated:- Entity existence: Both source and target must be in the entity list
- No self-loops: Source ≠ Target
- Valid types: Non-empty string types
- Strength range: 1-10 if provided
Next Steps
- Communities - Detect communities from relationships
- Search - Traverse relationships during search
- Entity Extraction - Configure entity extractors