API Reference
Entities & Knowledge Graph

Entities & Knowledge Graph

Cortex automatically extracts entities (people, places, organizations, things) from your memories and builds a knowledge graph of relationships between them.

How Entity Extraction Works

When you add a memory like:

"Had coffee with Sarah yesterday. She mentioned she's moving to the London office."

Cortex extracts:

  1. Entity: Sarah (person) - with attribute "moving to London office"
  2. Entity: London office (place) - related to Sarah
  3. Relationship: Sarah → "relocating to" → London office

This happens automatically during memory processing.

List Entities

const entities = await cortex.entities.list();
 
for (const entity of entities) {
  console.log(entity.name);        // "Sarah"
  console.log(entity.type);        // "person"
  console.log(entity.attributes);  // { title: "Engineering Lead", office: "London" }
  console.log(entity.mentionCount); // 15
}

Response

{
  "entities": [
    {
      "id": "ent_abc123",
      "name": "Sarah",
      "type": "person",
      "attributes": {
        "title": "Engineering Lead",
        "office": "London",
        "email": "sarah@example.com"
      },
      "mentionCount": 15,
      "lastMentionedAt": "2024-01-22T10:00:00Z",
      "importanceScore": 0.85,
      "createdAt": "2024-01-01T09:00:00Z"
    }
  ],
  "total": 42
}

Entity Types

TypeDescriptionExamples
personIndividual peopleSarah, John Smith
organizationCompanies, teamsAcme Corp, Engineering Team
placeLocationsLondon office, Central Park
projectProjects, initiativesQ4 Roadmap, Mobile App
technologyTools, languagesReact, PostgreSQL
productProducts, servicesSlack, Notion
eventMeetings, conferencesQ4 Review, Annual Summit
conceptAbstract ideasAgile, User Research

Filter Entities

// Get only people
const people = await cortex.entities.list({
  type: "person"
});
 
// Get highly mentioned entities
const important = await cortex.entities.list({
  minMentions: 5,
  sortBy: "mentionCount"
});

Get Entity Details

const entity = await cortex.entities.get("ent_abc123");
 
console.log(entity.relationships);  // Related entities
console.log(entity.memories);       // Memories mentioning this entity
console.log(entity.timeline);       // How knowledge evolved over time

Response

{
  "id": "ent_abc123",
  "name": "Sarah",
  "type": "person",
  "attributes": {
    "title": "Engineering Lead",
    "office": "London"
  },
  "relationships": [
    {
      "targetEntityId": "ent_mike",
      "targetEntityName": "Mike",
      "relationshipType": "works_with",
      "confidence": 0.9
    },
    {
      "targetEntityId": "ent_mobile_team",
      "targetEntityName": "Mobile Team",
      "relationshipType": "leads",
      "confidence": 0.95
    }
  ],
  "recentMemories": [
    {
      "id": "mem_xyz",
      "content": "Sarah mentioned the London migration is ahead of schedule",
      "createdAt": "2024-01-22T10:00:00Z"
    }
  ]
}

Relationships

Relationships connect entities together, forming a knowledge graph.

Get Relationships

const relationships = await cortex.entities.relationships({
  entityId: "ent_abc123"  // Get relationships for Sarah
});
 
for (const rel of relationships) {
  console.log(`${rel.sourceEntity} ${rel.type} ${rel.targetEntity}`);
  // "Sarah leads Mobile Team"
}

Relationship Types

TypeDescriptionExample
works_withProfessional collaborationSarah works_with Mike
reports_toReporting structureSarah reports_to John
leadsLeadershipSarah leads Mobile Team
member_ofMembershipSarah member_of Engineering
located_atPhysical locationSarah located_at London
knowsGeneral connectionSarah knows David
related_toGeneric relationshipProject related_to Q4 Goals

Knowledge Graph

Get the full knowledge graph for visualization or analysis.

const graph = await cortex.entities.graph({
  depth: 2,           // How many hops from center
  minConfidence: 0.7  // Only strong relationships
});
 
// Returns nodes and edges for visualization
console.log(graph.nodes);  // Entities
console.log(graph.edges);  // Relationships

Response

{
  "nodes": [
    {
      "id": "ent_sarah",
      "name": "Sarah",
      "type": "person",
      "importance": 0.85
    },
    {
      "id": "ent_mike",
      "name": "Mike",
      "type": "person",
      "importance": 0.72
    }
  ],
  "edges": [
    {
      "source": "ent_sarah",
      "target": "ent_mike",
      "type": "works_with",
      "confidence": 0.9
    }
  ]
}

Entity Timeline

See how your knowledge about an entity evolved over time.

const timeline = await cortex.entities.timeline("ent_sarah");
 
for (const event of timeline) {
  console.log(event.date, event.type, event.description);
  // "2024-01-15" "attribute_added" "Added title: Engineering Lead"
  // "2024-01-20" "attribute_updated" "Office changed: SF → London"
}

Merge Entities

Sometimes the same entity is extracted with different names. Merge them:

// Merge "Sarah Smith" into "Sarah"
await cortex.entities.merge({
  sourceId: "ent_sarah_smith",
  targetId: "ent_sarah"
});

After merging:

  • All memories referencing the source entity now reference the target
  • Relationships are combined
  • Attributes are merged (target takes precedence on conflicts)
  • Source entity is archived for audit trail