textrawl
byJeff Green

relate_entities

Create directed relationships between entities

Create directed relationships between entities to build a knowledge graph.

Parameters

ParameterTypeRequiredDefaultDescription
fromEntitystringREQUIRED-Source entity name (1-200 chars)
relationstringREQUIRED-Relation type (1-100 chars)
toEntitystringREQUIRED-Target entity name (1-200 chars)
fromEntityTypeenumOPTIONALinferredType of source entity
toEntityTypeenumOPTIONALinferredType of target entity

Common Relation Types

RelationExample
works_atJeff works_at Acme Corp
knowsAlice knows Bob
prefersUser prefers TypeScript
createdTeam created Project Alpha
part_ofModule part_of System
related_toConcept A related_to Concept B
usesProject uses PostgreSQL
managesManager manages Team

Example Request

{
  "fromEntity": "Jeff",
  "relation": "works_at",
  "toEntity": "Acme Corp"
}

Response

Compact Mode (Default)

When COMPACT_RESPONSES=true (default), responses use short keys to reduce token usage by 40-60%:

{"ok":true,"rel":"550e8400","from":{"id":"550e8401","n":"Jeff","t":"person"},"to":{"id":"550e8402","n":"Acme Corp","t":"organization"}}

Key mapping: ok=success, rel=relationId, n=name, t=type

Verbose Mode

When COMPACT_RESPONSES=false:

{
  "success": true,
  "message": "Created relation: Jeff works_at Acme Corp",
  "relationId": "550e8400-e29b-41d4-a716-446655440000",
  "fromEntity": {
    "id": "550e8400-e29b-41d4-a716-446655440001",
    "name": "Jeff",
    "type": "person"
  },
  "toEntity": {
    "id": "550e8400-e29b-41d4-a716-446655440002",
    "name": "Acme Corp",
    "type": "organization"
  }
}

Auto-Creation

If entities don't exist, they are automatically created:

  • Entity types are inferred from context if not provided
  • Default type is concept if type cannot be inferred
  • Existing entities keep their original type

Use Cases

Organization Structure

{
  "fromEntity": "Jeff",
  "relation": "works_at",
  "toEntity": "Engineering Team",
  "fromEntityType": "person",
  "toEntityType": "organization"
}

Project Dependencies

{
  "fromEntity": "Project Alpha",
  "relation": "uses",
  "toEntity": "PostgreSQL",
  "fromEntityType": "project",
  "toEntityType": "concept"
}

Knowledge Connections

{
  "fromEntity": "React",
  "relation": "related_to",
  "toEntity": "JavaScript"
}

Relation Directionality

Relations are directed (from → to):

  • Jeff works_at Acme means Jeff is the employee
  • Acme employs Jeff would be the inverse

Use get_entity_context to see both outgoing and incoming relations.

Duplicate Relations

If the same relation already exists, the existing relation is returned:

{
  "success": true,
  "message": "Created relation: Jeff works_at Acme Corp",
  "relationId": "existing-relation-id"
}

Errors

ErrorCauseFix
Self-referential relationfromEntity and toEntity are the sameUse different entity names
Invalid entity nameName exceeds 200 chars or is emptyProvide names between 1-200 chars
Invalid relation typeRelation exceeds 100 chars or is emptyProvide relation between 1-100 chars
Memory not enabledENABLE_MEMORY feature flag is falseSet ENABLE_MEMORY=true
Database errorConnection or query failureCheck DB connectivity and logs

On this page