graphiti icon indicating copy to clipboard operation
graphiti copied to clipboard

[BUG] v0.30.0pre5: NameError when AsyncOpenSearch import fails

Open CodeByMAB opened this issue 2 months ago • 4 comments

Bug Description When opensearchpy package is not installed (optional dependency), Graphiti v0.30.0pre5 raises NameError: name 'AsyncOpenSearch' is not defined at import time, preventing the driver from being instantiated.

Steps to Reproduce

  1. Install graphiti-core v0.30.0pre5 without the opensearch optional dependency: pip install graphiti-core==0.30.0pre5

Do NOT install: pip install opensearchpy

  1. Try to import and use any graph driver: from graphiti_core import Graphiti

This will fail at class definition time

client = Graphiti( uri="bolt://localhost:7687", user="neo4j", password="password" )

Expected Behavior

The code should handle the missing opensearchpy dependency gracefully, setting AsyncOpenSearch = None and allowing the driver to work without OpenSearch functionality.

Actual Behavior

Python raises NameError: name 'AsyncOpenSearch' is not defined when trying to define the GraphDriver class, because the import error handler sets the wrong variable name.

Environment

  • Graphiti Version: 0.30.0pre5
  • Python Version: 3.12
  • Operating System: Linux (Docker container, Debian)
  • Database Backend: Neo4j 5.26.13
  • LLM Provider & Model: OpenAI-compatible API (Ollama) with gpt-oss:20b

Installation Method

  • pip install
  • uv add
  • Development installation (git clone)

Error Messages/Traceback

NameError: name 'AsyncOpenSearch' is not defined File "/app/.venv/lib/python3.12/site-packages/graphiti_core/driver/driver.py", line 174 aoss_client: AsyncOpenSearch | None # type: ignore ^^^^^^^^^^^^^^^^

Configuration

.env configuration

OPENAI_API_KEY= OPENAI_BASE_URL=http://host.docker.internal:5050/v1 MODEL_NAME=gpt-oss:20b EMBEDDING_MODEL_NAME=nomic-embed-text NEO4J_URI=bolt://neo4j:7687 NEO4J_USER=neo4j NEO4J_PASSWORD=

Additional Context

  • Happens consistently: Yes, 100% reproducible when opensearchpy is not installed
  • Component: Core library (graphiti_core)
  • Root cause location: graphiti_core/driver/driver.py lines 33-37

try: from opensearchpy import AsyncOpenSearch, helpers _HAS_OPENSEARCH = True except ImportError: OpenSearch = None # ← BUG: Wrong variable name! helpers = None

Later in the file (line 174):

class GraphDriver: aoss_client: AsyncOpenSearch | None # ← NameError because AsyncOpenSearch is not defined!

  • Regression: This worked correctly in v0.22.0, which used aoss_client: Any instead of type annotation
  • Workaround: Install opensearchpy even if not using OpenSearch, or downgrade to v0.22.0

Possible Solution

The error handler should set AsyncOpenSearch = None instead of OpenSearch = None:

Option 1 - Fix the variable name: try: from opensearchpy import AsyncOpenSearch, helpers _HAS_OPENSEARCH = True except ImportError: AsyncOpenSearch = None # ← Correct variable name helpers = None

Option 2 - Use type annotation from typing (as v0.22.0 did): from typing import Any

Later:

aoss_client: Any = None

Option 3 - Use string literal type annotation: aoss_client: "AsyncOpenSearch | None" = None # type: ignore

I recommend Option 1 as it's the simplest fix that aligns with the existing error handling pattern for other optional dependencies in the codebase.

CodeByMAB avatar Oct 21 '25 02:10 CodeByMAB

@CodeByMAB Is this still an issue? Please confirm within 14 days or this issue will be closed.

claude[bot] avatar Nov 17 '25 00:11 claude[bot]

Yes, @claude, yes it is.

CodeByMAB avatar Nov 17 '25 01:11 CodeByMAB

Have you upgraded to the latest graphiti release? Pre-releases aren't considered stable releases and so they will often have bugs or only work for specific setups while we test them and iterate on them. We recommend using only stable releases for a more consistent experience

prasmussen15 avatar Nov 22 '25 17:11 prasmussen15

Looks like I'm currently on graphiti-core version 0.22.0 which could definitely be the reason why.

CodeByMAB avatar Nov 24 '25 21:11 CodeByMAB