API Reference
Sync Integrations

Sync Integrations

Cortex can automatically sync memories from external sources like Gmail and Google Calendar. This turns your emails and events into searchable, AI-ready context.

How Sync Works

  1. Connect - Link your account (Gmail, Calendar, etc.)
  2. Initial Sync - Cortex pulls historical data
  3. Continuous Sync - New emails/events synced automatically
  4. Processing - Entities, relationships, and commitments extracted

Sync Connections

List Connections

const connections = await cortex.sync.listConnections();
 
for (const conn of connections) {
  console.log(conn.provider);      // "gmail"
  console.log(conn.isActive);      // true
  console.log(conn.lastSyncAt);    // "2024-01-22T08:00:00Z"
  console.log(conn.syncFrequency); // "hourly"
}

Response

{
  "connections": [
    {
      "id": "sync_abc123",
      "provider": "gmail",
      "accountId": "user@example.com",
      "isActive": true,
      "syncEnabled": true,
      "lastSyncAt": "2024-01-22T08:00:00Z",
      "nextSyncAt": "2024-01-22T09:00:00Z",
      "syncFrequency": "hourly",
      "stats": {
        "itemsSynced": 1250,
        "lastDurationMs": 4500
      },
      "createdAt": "2024-01-01T10:00:00Z"
    }
  ]
}

Supported Providers

ProviderWhat's SyncedStatus
gmailEmails, attachments (metadata)Available
google_calendarEvents, attendeesAvailable
slackMessages, threadsComing Soon
notionPages, databasesComing Soon

Connect Gmail

// Initiate OAuth flow
const authUrl = await cortex.sync.connectGmail();
// Redirect user to authUrl
 
// After OAuth callback
const connection = await cortex.sync.completeConnection({
  provider: "gmail",
  authCode: "oauth_code_from_callback"
});

Connect Google Calendar

const authUrl = await cortex.sync.connectCalendar();
// Same OAuth flow as Gmail

Trigger Manual Sync

Force an immediate sync instead of waiting for the scheduled time.

const result = await cortex.sync.trigger("sync_abc123");
 
console.log(result.status);          // "running"
console.log(result.itemsProcessed);  // 0 (still running)

Sync Logs

View the history of sync operations.

const logs = await cortex.sync.logs("sync_abc123");
 
for (const log of logs) {
  console.log(log.syncType);        // "delta"
  console.log(log.status);          // "completed"
  console.log(log.itemsProcessed);  // 25
  console.log(log.memoriesCreated); // 25
  console.log(log.durationMs);      // 3200
}

Response

{
  "logs": [
    {
      "id": "log_xyz",
      "connectionId": "sync_abc123",
      "syncType": "delta",
      "status": "completed",
      "itemsProcessed": 25,
      "memoriesCreated": 25,
      "errors": [],
      "startedAt": "2024-01-22T08:00:00Z",
      "completedAt": "2024-01-22T08:00:03Z",
      "durationMs": 3200
    }
  ],
  "total": 150
}

Sync Types

TypeDescription
fullComplete sync of all data
deltaOnly new/changed items since last sync
manualUser-triggered sync

Update Connection Settings

await cortex.sync.updateConnection("sync_abc123", {
  syncEnabled: true,
  syncFrequency: "daily"  // hourly, daily, realtime, manual
});

Sync Frequencies

FrequencyDescription
realtimeEvery 5 minutes (best for active use)
hourlyOnce per hour (balanced)
dailyOnce per day (minimal API usage)
manualOnly when manually triggered

Disconnect

Remove a sync connection. Historical memories are preserved.

await cortex.sync.disconnect("sync_abc123");

What Gets Extracted

From Gmail

  • Memories: One memory per email
  • Entities: Sender extracted as person entity
  • Relationships: Email frequency → relationship strength
  • Commitments: "I'll send you..." → tracked commitment

From Calendar

  • Memories: One memory per event
  • Entities: Attendees extracted as person entities
  • Relationships: Meeting frequency → relationship strength
  • Commitments: Action items in event description

Example: Email-Aware AI

// User asks about a project
const context = await cortex.recall({
  query: "What did Sarah say about the mobile launch?",
  includeProfile: true
});
 
// Cortex returns memories from emails, meetings, and manual notes
// All unified into a single searchable context
 
const response = await ai.chat({
  messages: [
    {
      role: "system",
      content: `You have access to the user's email and calendar context.
 
Recent relevant information:
${context.memories.map(m => `[${m.source}] ${m.content}`).join('\n\n')}`
    },
    { role: "user", content: "What did Sarah say about the mobile launch?" }
  ]
});