graphrag: [Bug] "ValueError: Columns must be same length as key" - Entity extraction fails due to invalid format returned by API

Model used: GPT-4o, openai api, JSON mode. Default settings, default prompts, OAI Rate limits configured according to tier.

The pipeline fails with the error message “ValueError: Columns must be same length as key”. It seems the cluster_graph() function receives an empty create_base_extracted_entities.parquet file with zero nodes (indicated at 16:40:36,22 in logs below).

Taking a closer look the entity extraction seems to fail due to invalid formatting. When the run fails the cache folder still holds the entity_extraction responses. After closer inspection the problem is in the prefix of the “result” object returned by the API.

Expected format: {"result": "(\"entity\"<|>\" ....}

Failing formats sampled from different runs: {"result": "**Entities:**\n\n(\"entity\"<|>\" ....} {"result": "##(\"entity\"<|>\" ....}

After removing the unnecessary prefix in all cached files the run can successfully index the document.

Constraining the response using logit bias / pydantic would help and validating response samples would catch this earlier. The pipeline (and cluster_graph()) should fail gracefully when there are no nodes extracted. This is a frustrating error during an expensive run on a large corpus. Looking forward to dig deeper.

Logs:

16:40:36,13 graphrag.index.run INFO Running workflow: create_base_entity_graph… 16:40:36,14 graphrag.index.run INFO dependencies for create_base_entity_graph: [‘create_summarized_entities’] 16:40:36,14 graphrag.index.run INFO read table from storage: create_summarized_entities.parquet 16:40:36,22 datashaper.workflow.workflow INFO executing verb cluster_graph 16:40:36,22 graphrag.index.verbs.graph.clustering.cluster_graph WARNING Graph has no nodes 16:40:36,25 datashaper.workflow.workflow ERROR Error executing verb “cluster_graph” in create_base_entity_graph: Columns must be same length as key Traceback (most recent call last): File “/Library/Caches/pypoetry/virtualenvs/graphrag-C7j4Bq5Y-py3.11/lib/python3.11/site-packages/datashaper/workflow/workflow.py”, line 410, in _execute_verb result = node.verb.func(**verb_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/workspace/graphrag/graphrag/index/verbs/graph/clustering/cluster_graph.py”, line 105, in cluster_graph output_df[[level_to, to]] = pd.DataFrame( ~~~~~~~~~^^^^^^^^^^^^^^^^ File “/Library/Caches/pypoetry/virtualenvs/graphrag-C7j4Bq5Y-py3.11/lib/python3.11/site-packages/pandas/core/frame.py”, line 4299, in setitem self._setitem_array(key, value) File “/Library/Caches/pypoetry/virtualenvs/graphrag-C7j4Bq5Y-py3.11/lib/python3.11/site-packages/pandas/core/frame.py”, line 4341, in _setitem_array check_key_length(self.columns, key, value) File “/Library/Caches/pypoetry/virtualenvs/graphrag-C7j4Bq5Y-py3.11/lib/python3.11/site-packages/pandas/core/indexers/utils.py”, line 390, in check_key_length raise ValueError(“Columns must be same length as key”) ValueError: Columns must be same length as key 16:40:36,27 graphrag.index.reporting.file_workflow_callbacks INFO Error executing verb “cluster_graph” in create_base_entity_graph: Columns must be same length as key details=None 16:40:36,27 graphrag.index.run ERROR error running workflow create_base_entity_graph Traceback (most recent call last): File “/workspace//graphrag/graphrag/index/run.py”, line 323, in run_pipeline result = await workflow.run(context, callbacks) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/Library/Caches/pypoetry/virtualenvs/graphrag-C7j4Bq5Y-py3.11/lib/python3.11/site-packages/datashaper/workflow/workflow.py”, line 369, in run timing = await self._execute_verb(node, context, callbacks) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/Library/Caches/pypoetry/virtualenvs/graphrag-C7j4Bq5Y-py3.11/lib/python3.11/site-packages/datashaper/workflow/workflow.py”, line 410, in _execute_verb result = node.verb.func(**verb_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/workspace/graphrag/graphrag/index/verbs/graph/clustering/cluster_graph.py”, line 105, in cluster_graph output_df[[level_to, to]] = pd.DataFrame( ~~~~~~~~~^^^^^^^^^^^^^^^^ File “/Library/Caches/pypoetry/virtualenvs/graphrag-C7j4Bq5Y-py3.11/lib/python3.11/site-packages/pandas/core/frame.py”, line 4299, in setitem self._setitem_array(key, value) File “/Library/Caches/pypoetry/virtualenvs/graphrag-C7j4Bq5Y-py3.11/lib/python3.11/site-packages/pandas/core/frame.py”, line 4341, in _setitem_array check_key_length(self.columns, key, value) File “/Library/Caches/pypoetry/virtualenvs/graphrag-C7j4Bq5Y-py3.11/lib/python3.11/site-packages/pandas/core/indexers/utils.py”, line 390, in check_key_length raise ValueError(“Columns must be same length as key”) ValueError: Columns must be same length as key 16:40:36,27 graphrag.index.reporting.file_workflow_callbacks INFO Error running pipeline! details=None

Possibly related issues: https://github.com/microsoft/graphrag/issues/437 https://github.com/microsoft/graphrag/issues/414 https://github.com/microsoft/graphrag/issues/426 https://github.com/microsoft/graphrag/issues/441

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (1 by maintainers)

Most upvoted comments

For those who are stuck after the create_base_text_units step with different error messages.

  • Open your project’s cache/entity_extraction folder.
  • Take a look at any chat_XXXX file.
  • Your files should start with {"result": "(\"entity\" but might have formatting like {"result": "**Entities**\n\n(\"entity\".
  • Remove the bogus prefix with a string replace on all cached files.
  • Re-run in the same project folder and it might succeed.

This is the most helpful comment I saw so far.

I used GraphRAG with Ollama and my cache files looked more like {"result": "1. Entities: so I guessed that my LLM might not be following the prompts closely enough to match the required format.

By changing my LLM to “mistral-nemo:latest” this error was gone 🎉 and the cache files now start with the expected format {"result": "(\"entity\"<|>

However, another one occured at create_final_entities which I am currently investigating …

Hi @ShivamGupta42 Glad this worked!

My general rule of thumb when facing this issues is:

  • Check the outputs of the entity extraction, this will show if the graph is empty
  • If the graph is empty, then it can be either faulty llm responses (unparseable) or, LLM calling failures

For rate limiting, you can try adjusting the requests_per_minute and tokens_per_minute settings

i found that if the input file is input.txt, it always throws this Columns must be same length as key error. changing the filename to anything else would resolve the issue. not sure why is it, but i finally got out of being stuck on this for 4 hours!!!

Hey folks, after spending time going through the code. I realised that the I was getting rate limiting errors in the logs and I was wrong in assuming that this is handled in the code. And due to those errors, workflows before the clustering execution were producing empty files and hence eventual error during execution of clustering.

TLDR; Please increase your rate limits on openAI. This worked for me. 😄

For those who are stuck after the create_base_text_units step with different error messages.

  • Open your project’s cache/entity_extraction folder.
  • Take a look at any chat_XXXX file.
  • Your files should start with {"result": "(\"entity\" but might have formatting like {"result": "**Entities**\n\n(\"entity\".
  • Remove the bogus prefix with a string replace on all cached files.
  • Re-run in the same project folder and it might succeed.