OpenAI provides industry-leading language models that power Cognee’s entity extraction, relationship discovery, and intelligent querying capabilities.
OpenAI is the default LLM provider for Cognee, offering the best balance of performance, reliability, and ease of use.

Supported Models

GPT-4o-mini

Recommended Default
  • Best balance of performance and cost
  • Excellent entity extraction
  • Fast response times
  • Recommended for most use cases

GPT-4o

Premium Performance
  • Highest accuracy for complex reasoning
  • Superior relationship discovery
  • Best for critical applications
  • 128k context window

GPT-3.5-turbo

Budget Option
  • Most cost-effective
  • Good for simple tasks
  • Fastest response times
  • 16k context window

Embeddings

Semantic Understanding
  • text-embedding-3-large
  • text-embedding-3-small
  • text-embedding-ada-002

Quick Setup

1

Get API Key

  1. Visit OpenAI Platform
  2. Sign up or log in to your account
  3. Navigate to API Keys section
  4. Create a new API key
Store your API key securely and never commit it to version control.
2

Configure Cognee

import os
import cognee

# Set your OpenAI API key
os.environ["LLM_API_KEY"] = "your-openai-api-key"

# Optional: Specify model (defaults to gpt-4o-mini)
os.environ["LLM_MODEL"] = "gpt-4o-mini"
3

Test Configuration

import asyncio

async def test_openai():
    # Test with simple data
    await cognee.add("OpenAI powers Cognee's intelligence.")
    await cognee.cognify()
    
    result = await cognee.search("What powers Cognee?")
    print(result[0])

asyncio.run(test_openai())

Configuration Options

import os

# Minimal configuration
os.environ["LLM_API_KEY"] = "your-openai-api-key"
os.environ["LLM_PROVIDER"] = "openai"  # Optional (default)
os.environ["LLM_MODEL"] = "gpt-4o-mini"  # Optional (default)

Model Comparison

Performance Comparison

Code Examples

import cognee
import os
import asyncio

async def main():
    # Configure OpenAI
    os.environ["LLM_API_KEY"] = "your-openai-api-key"
    
    # Add and process data
    text = """
    OpenAI's GPT-4 is a large multimodal model that can process 
    text and images. It demonstrates human-level performance on 
    various professional and academic benchmarks.
    """
    
    await cognee.add(text)
    await cognee.cognify()
    
    # Query with natural language
    result = await cognee.search("What can GPT-4 process?")
    print(result[0])

asyncio.run(main())
import cognee
import os
import asyncio

async def main():
    # Advanced OpenAI setup
    os.environ["LLM_API_KEY"] = "your-openai-api-key"
    os.environ["LLM_MODEL"] = "gpt-4"
    os.environ["LLM_TEMPERATURE"] = "0.1"  # More deterministic
    os.environ["LLM_MAX_TOKENS"] = "2000"
    
    # Configure embeddings
    os.environ["EMBEDDING_PROVIDER"] = "openai"
    os.environ["EMBEDDING_MODEL"] = "text-embedding-3-large"
    
    # Process technical documentation
    with open("technical_docs.txt", "r") as f:
        content = f.read()
    
    await cognee.add(content)
    await cognee.cognify()
    
    # Get structured insights
    insights = await cognee.search(
        "technical concepts and their relationships",
        query_type=SearchType.INSIGHTS
    )
    
    for insight in insights[:5]:
        print(f"{insight['entity']} -> {insight['relationship']} -> {insight['target']}")

asyncio.run(main())

Next Steps