Issues using Google Gemini with graphiti-core==0.9.0
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 installwithin 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.pygraphiti_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 importGeminiClientorGeminiEmbedder. - 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-generativeailibrary (v0.8.4) likely uses a different initialization pattern (e.g.,genai.configure(api_key=...)followed bygenai.GenerativeModel(...)or specific embedding functions) than whatgraphiti-core==0.9.0expects. - Workaround: Temporarily patching the
__init__methods to usegenai.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
Graphiticlass constructor defaults to initializingOpenAIRerankerClient()if nocross_encoderis explicitly provided. This initialization requires an OpenAI API key. - Error: If only a
GEMINI_API_KEYis set in the environment, initializingGraphiti(even withGeminiClientandGeminiEmbedder) fails withopenai.OpenAIError: The api_key client option must be set.... - Workaround: Provide both
GEMINI_API_KEYandOPENAI_API_KEYenvironment variables, or pass a custom (potentially dummy)cross_encoderinstance duringGraphitiinitialization.
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.
Thanks for reporting. The import issue is resolved here: https://github.com/getzep/graphiti/pull/336/
Duplicate of https://github.com/getzep/graphiti/issues/333