graphiti icon indicating copy to clipboard operation
graphiti copied to clipboard

Issues using Google Gemini with graphiti-core==0.9.0

Open CaliLuke opened this issue 8 months ago • 1 comments

Environment:

  • graphiti-core Version: 0.9.0 (latest release on PyPI as of 2025-04-08)
  • google-generativeai Version: 0.8.4 (installed via pip install "graphiti-core[google-genai]" and also explicitly)
  • Python Version: 3.13.2
  • Operating System: macOS Sequoia
  • Installation Method: uv sync / pip install within a virtual environment

Description: When attempting to initialize graphiti_core.Graphiti with GeminiClient and GeminiEmbedder according to the README instructions, several issues arise within the graphiti-core==0.9.0 library code itself.

Issue 1: Incorrect google.generativeai Import Statements

  • Files:
    • graphiti_core/llm_client/gemini_client.py
    • graphiti_core/embedder/gemini.py
  • Problem: Both files use incorrect import statements:
    from google import genai  # Incorrect
    from google.genai import types # Incorrect
    
  • Error: This leads to ImportError: cannot import name 'genai' from 'google' when trying to import GeminiClient or GeminiEmbedder.
  • Expected: The imports should likely be:
    import google.generativeai as genai
    from google.generativeai import types
    
  • Workaround: Temporarily patching these import lines in the installed library files resolves this specific error.

Issue 2: Incorrect google.generativeai Client Initialization

  • Files:
    • graphiti_core/llm_client/gemini_client.py (__init__ method)
    • graphiti_core/embedder/gemini.py (__init__ method)
  • Problem: After patching the imports, the code fails when trying to initialize the Google client using self.client = genai.Client(...).
  • Error: This leads to AttributeError: module 'google.generativeai' has no attribute 'Client'.
  • Likely Cause: The google-generativeai library (v0.8.4) likely uses a different initialization pattern (e.g., genai.configure(api_key=...) followed by genai.GenerativeModel(...) or specific embedding functions) than what graphiti-core==0.9.0 expects.
  • Workaround: Temporarily patching the __init__ methods to use genai.configure(api_key=...) allows initialization to proceed further, but subsequent calls within the methods might still fail.

Issue 3: Required OpenAI Key for Reranker

  • File: graphiti_core/graphiti.py (__init__ method)
  • Problem: The Graphiti class constructor defaults to initializing OpenAIRerankerClient() if no cross_encoder is explicitly provided. This initialization requires an OpenAI API key.
  • Error: If only a GEMINI_API_KEY is set in the environment, initializing Graphiti (even with GeminiClient and GeminiEmbedder) fails with openai.OpenAIError: The api_key client option must be set....
  • Workaround: Provide both GEMINI_API_KEY and OPENAI_API_KEY environment variables, or pass a custom (potentially dummy) cross_encoder instance during Graphiti initialization.

Summary: Using Gemini with graphiti-core==0.9.0 currently requires patching the library's internal code due to incorrect imports and client initialization calls, and also requires providing an OpenAI API key for the default reranker.

CaliLuke avatar Apr 08 '25 17:04 CaliLuke

Thanks for reporting. The import issue is resolved here: https://github.com/getzep/graphiti/pull/336/

danielchalef avatar Apr 08 '25 22:04 danielchalef

Duplicate of https://github.com/getzep/graphiti/issues/333

danielchalef avatar Apr 09 '25 16:04 danielchalef