run-llama/llama_index · error · NotImplementedError

SimpleGraphStore does not support query

Error message

SimpleGraphStore does not support query

What it means

SimpleGraphStore.query() unconditionally raises NotImplementedError (and note its param_map default is a mutable `{}`). SimpleGraphStore stores raw triples in dicts and exposes only direct get/upsert accessors — it has no query language interpreter, so any query-string API call is rejected rather than silently returning wrong results.

Source

Thrown at llama-index-core/llama_index/core/graph_stores/simple.py:159

        persist_path: str = os.path.join(DEFAULT_PERSIST_DIR, DEFAULT_PERSIST_FNAME),
        fs: Optional[fsspec.AbstractFileSystem] = None,
    ) -> None:
        """Persist the SimpleGraphStore to a directory."""
        fs = fs or self._fs
        dirpath = os.path.dirname(persist_path)
        if not fs.exists(dirpath):
            fs.makedirs(dirpath)

        with fs.open(persist_path, "w", encoding="utf-8") as f:
            json.dump(self._data.to_dict(), f)

    def get_schema(self, refresh: bool = False) -> str:
        """Get the schema of the Simple Graph store."""
        raise NotImplementedError("SimpleGraphStore does not support get_schema")

    def query(self, query: str, param_map: Optional[Dict[str, Any]] = {}) -> Any:
        """Query the Simple Graph store."""
        raise NotImplementedError("SimpleGraphStore does not support query")

    @classmethod
    def from_persist_path(
        cls, persist_path: str, fs: Optional[fsspec.AbstractFileSystem] = None
    ) -> "SimpleGraphStore":
        """Create a SimpleGraphStore from a persist directory."""
        fs = fs or fsspec.filesystem("file")
        if not fs.exists(persist_path):
            logger.warning(
                f"No existing {__name__} found at {persist_path}. "
                "Initializing a new graph_store from scratch. "
            )
            return cls()

        logger.debug(f"Loading {__name__} from {persist_path}.")
        with fs.open(persist_path, "rb") as f:
            data_dict = json.load(f)
            data = SimpleGraphStoreData.from_dict(data_dict)

View on GitHub (pinned to afd0fef371)

Solutions

  1. Switch to a query-capable backend (Neo4j, Neptune, Kuzu, etc.) via the corresponding llama-index integration.
  2. For SimpleGraphStore, retrieve data with get_triplets()/get(subject, predicate) instead of a query string.
  3. Wrap store access in an adapter that checks capability before issuing structured queries.

Example fix

# before
rows = graph_store.query("MATCH (s)-[p]->(o) RETURN s, p, o")

# after
triplets = graph_store.get_triplets()  # SimpleGraphStore supported API
Defensive patterns

Strategy: fallback

Validate before calling

from llama_index.core.graph_stores.simple import SimpleGraphStore

if isinstance(graph_store, SimpleGraphStore):
    triplets = graph_store.get_triplets()  # supported access path
else:
    rows = graph_store.query(cypher, param_map={})

Type guard

def supports_query(store) -> bool:
    return not isinstance(store, SimpleGraphStore)

Try / catch

try:
    rows = graph_store.query(query_str, param_map=params)
except NotImplementedError:
    rows = graph_store.get_triplets()  # degrade to direct triple access

Prevention

When it happens

Trigger: Calling graph_store.query('MATCH (n) RETURN n') or any Cypher/SPARQL-style string on a SimpleGraphStore; generic query layers or LLM tool-calls that route a query string to whatever graph store is configured.

Common situations: Developing against Neo4j locally and deploying with the default simple store (or vice versa); KnowledgeGraphIndex flows that attempt structured queries; agent code that always calls query() regardless of backend.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/835fa9b9ba1684e6. Report an issue: GitHub.