Skip to content

Latest commit

 

History

History
226 lines (173 loc) · 5.58 KB

File metadata and controls

226 lines (173 loc) · 5.58 KB

Gemini + Tavily vs OpenAI Comparison

This project includes TWO versions of the Deep Research Agent. Here's how they compare:

Version 1: Gemini 2.5 + Tavily (RAG Architecture)

Files:

  • deep_research_agent.py
  • config.py
  • main.py
  • example_run.py

Architecture:

User Input
    ↓
Tavily Search API (4+ queries per section)
    ↓ (Returns 12+ web sources)
Format & Structure Context
    ↓
Gemini 2.5 LLM (Analyzes & Synthesizes)
    ↓
Research Report

How it works:

  1. Tavily searches the web with targeted queries
  2. Raw search results are formatted into context
  3. Gemini receives context and analyzes it
  4. Output includes citations from Tavily sources

Pros:Explicit control over search queries and sources ✅ Transparent - see exactly what sources were used ✅ Cost-effective - Gemini is cheaper, Tavily has free tier ✅ Modular - can swap search provider or LLM independently ✅ Better for compliance - control what sources are accessed

Cons:Two APIs required - More setup (Gemini + Tavily keys) ❌ More code - Manual orchestration of search + analysis ❌ Slower - Multiple sequential API calls per section

Best for:

  • Production systems needing audit trails
  • Cost-sensitive applications
  • When you need control over data sources
  • Compliance-heavy environments

Version 2: OpenAI (Integrated Architecture)

Files:

  • deep_research_agent_openai.py
  • config_openai.py
  • main_openai.py
  • example_run_openai.py

Architecture:

User Input
    ↓
OpenAI GPT-4o (handles search + analysis internally)
    ↓
Research Report

How it works:

  1. Single prompt to OpenAI GPT-4o
  2. OpenAI handles web search internally (built-in browsing)
  3. Analysis and synthesis done in same call
  4. Output includes citations from sources OpenAI found

Pros:Simpler setup - Only one API key needed ✅ Faster - Single API call per section ✅ Less code - OpenAI handles orchestration internally ✅ Potentially better quality - GPT-4o is very powerful ✅ More autonomous - Let OpenAI decide what to search

Cons:Less control - Can't see/control what OpenAI searches ❌ More expensive - GPT-4o costs more than Gemini 2.5 ❌ Black box - Don't know search strategy used ❌ Single vendor lock-in - Can't swap components

Best for:

  • Quick prototypes and demos
  • When you trust OpenAI's search capabilities
  • Simpler deployment scenarios
  • When development speed > cost

Side-by-Side Comparison

Feature Gemini + Tavily OpenAI
API Keys Required 2 (Gemini + Tavily) 1 (OpenAI)
Cost (per report) ~$0.10-0.30 ~$0.50-1.00
Speed Slower (multiple calls) Faster (single call)
Search Control Full control No control
Source Transparency High (see all sources) Medium (cites sources)
Code Complexity Higher (manual RAG) Lower (integrated)
Vendor Lock-in Low (modular) High (all OpenAI)
Quality Excellent Excellent
Free Tier Yes (Tavily 1000/mo) No

Which Should You Use?

Use Gemini + Tavily if:

  • 🏢 Building for production/enterprise
  • 💰 Budget-conscious or need free tier
  • 🔍 Need audit trail of sources
  • 🔒 Compliance requirements around data access
  • 🔧 Want to customize search strategy
  • 📊 Need to control what gets searched

Use OpenAI if:

  • 🚀 Building quick POC/demo
  • ⚡ Need fastest development time
  • 🤝 Already using OpenAI ecosystem
  • 🎯 Trust OpenAI's search judgment
  • 💡 Want simplest architecture
  • 📈 Quality > cost

Running Each Version

Gemini + Tavily Version

# Setup
export GOOGLE_API_KEY="your_gemini_key"
export TAVILY_API_KEY="your_tavily_key"

# Run
python example_run.py
# or
python main.py --company "Bizzi" --sector "SaaS" --region "Vietnam" --website "https://bizzi.vn/en/"

OpenAI Version

# Setup
export OPENAI_API_KEY="your_openai_key"

# Run
python example_run_openai.py
# or
python main_openai.py --company "Bizzi" --sector "SaaS" --region "Vietnam" --website "https://bizzi.vn/en/"

Technical Differences

Gemini + Tavily (RAG Pattern)

Retrieval-Augmented Generation (RAG):

  • Explicit separation of retrieval (Tavily) and generation (Gemini)
  • You control the retrieval logic
  • Context is assembled manually
  • Classic RAG architecture

Code Structure:

# 1. Search with Tavily
results = tavily_client.search(query)

# 2. Format results
context = format_search_results(results)

# 3. Analyze with Gemini
response = gemini.invoke([
    SystemMessage("You are an analyst..."),
    HumanMessage(f"Context: {context}\n\nAnalyze...")
])

OpenAI (Integrated Pattern)

Agent with Tools:

  • OpenAI acts as agent with built-in search tool
  • Internal orchestration of search
  • Single unified call
  • Agentic architecture

Code Structure:

# Single call - OpenAI handles search internally
response = openai.chat.completions.create(
    model="gpt-4o",
    messages=[{
        "role": "user",
        "content": "Research X and analyze Y..."
    }]
)

Recommendation

For this POC: Start with OpenAI version for fastest results, then migrate to Gemini + Tavily if:

  • You need cost optimization
  • Compliance requires audit trails
  • You want more control

For production: Use Gemini + Tavily for enterprise-grade solution with transparency and control.


Both Are Included!

Try both and see which fits your needs better. All files are included in this repo.