TypeGraphTypeGraphTypeGraphDocs
Back to Dashboard
IntroductionGuidesDatabase AdaptersEmbeddersExtraction LLMs
SetupBucketsDocumentsEventsThreadsSearchMemoryGraphJobsPolicyTypes

Extraction LLMs

TypeGraph uses LLMs for query rewriting, summarization, and - when graph extraction is enabled - automatic entity and relationship extraction during document, event, and thread ingestion. Any model supported by the Vercel AI SDK works. Pass an llmto use the default extractor, or pass a custom extractorwhen you want full control over extraction behavior.

@ai-sdk/openai

@ai-sdk/openai
llm.ts
import { openai } from '@ai-sdk/openai'

// Pass AI SDK models directly - TypeGraph auto-wraps them
const llm = openai('gpt-5.4-mini')

@ai-sdk/xai

@ai-sdk/xai
llm.ts
import { xai } from '@ai-sdk/xai'

// Pass AI SDK models directly - TypeGraph auto-wraps them
const llm = xai('grok-4.1-fast-reasoning')

@ai-sdk/google

@ai-sdk/google
llm.ts
import { google } from '@ai-sdk/google'

// Pass AI SDK models directly - TypeGraph auto-wraps them
const llm = google('gemini-3-flash')

AI Gateway (OpenAI)

@ai-sdk/gateway
llm.ts
import { gateway } from '@ai-sdk/gateway'

// Pass AI SDK models directly - TypeGraph auto-wraps them
const llm = gateway('openai/gpt-5.4-mini')

// Alternatives:
// gateway('xai/grok-4.1-fast-reasoning')
// gateway('google/gemini-3-flash')

AI Gateway (xAI)

@ai-sdk/gateway
llm.ts
import { gateway } from '@ai-sdk/gateway'

// Pass AI SDK models directly - TypeGraph auto-wraps them
const llm = gateway('xai/grok-4.1-fast-reasoning')

// Alternatives:
// gateway('openai/gpt-5.4-mini')
// gateway('google/gemini-3-flash')

Default Extractor

Pass an AI SDK language model as llm. TypeGraph builds its default extractor internally and uses the configured ontology when one is supplied:

config.ts
import { openai } from '@ai-sdk/openai'
import { typegraphInit } from '@typegraph-ai/sdk'

const typegraph = await typegraphInit({
  apiKey: process.env.TYPEGRAPH_API_KEY!,
  tenantId: process.env.TYPEGRAPH_TENANT_ID!,
  llm: openai('gpt-5.4-mini'),
  ontology: {
    entities: [{ type: 'organization' }, { type: 'product_issue' }],
    relations: [{ type: 'EXPERIENCES', from: 'organization', to: 'product_issue' }],
  },
})

Custom Extractor

TypeGraph does not expose single-pass or two-pass extraction knobs. Those staging choices are private to the default extractor. For self-hosted deployments, provide your own extractor when you need a different prompt, model stack, constrained-decoding pipeline, or deterministic parser:

config.ts
import type { Extractor } from '@typegraph-ai/sdk'

const extractor: Extractor = {
  name: 'acme-extractor',
  capabilities: {
    supportsBatch: true,
    supportsStreaming: false,
    requiresStructuredOutput: false,
    multimodal: ['text'],
    preservesOntology: true,
  },
  async extract(input, ctx) {
    // Run any extraction pipeline you want here.
    // Return normalized entities and relations matching TypeGraph's ExtractionResult.
    return { entities: [], relations: [], warnings: [] }
  },
}

const typegraph = await typegraphInit({
  tenantId: process.env.TYPEGRAPH_TENANT_ID!,
  vectorStore,
  embedding,
  searchEmbedding,
  extractor,
  ontology,
})
Self-Hosted Initialization GuideEntity Extraction GuideGraph RAG Guide