graphrag icon indicating copy to clipboard operation
graphrag copied to clipboard

[Issue]: Entity Extraction Error & Error Invoking LLM & ERROR error extracting graph when indexing.

Open luneice opened this issue 1 year ago • 9 comments

Do you need to file an issue?

  • [x] I have searched the existing issues and this bug is not already filed.
  • [ ] My model is hosted on OpenAI or Azure. If not, please look at the "model providers" issue and don't file a new one here.
  • [x] I believe this is a legitimate bug, not just a question. If this is a question, please use the Discussions area.

Describe the issue

当文档数量比较大时,indexing阶段总会报错。文档数量比较少时,偶尔能一次执行成功。 不知道是不是ds-v3导致的,不论是ds官方的ds-v3还是豆包的ds-v3模型,都会出现这个问题。 也尝试过单步调试,主要对以下地方进行了断点,没有定位出来是什么原因导致:

When the number of documents is relatively large, the indexing stage always reports an error. When the number of documents is relatively small, it can be successfully executed once in a while. I don't know if it is caused by deepseek-v3. Whether it is the official deepseek-v3 of ds or the deepseek-v3 model of Doubao, this problem will occur. I have also tried single-step debugging and mainly set breakpoints in the following places, but I haven't located what causes this problem:

graphrag/language_model/providers/fnllm/models.py

...
        if history is None:
            response = await self.model(prompt, **kwargs)
        else:
            response = await self.model(prompt, history=history, **kwargs)
[->]     return BaseModelResponse(
            output=BaseModelOutput(content=response.output.content),
            parsed_response=response.parsed_json,
            history=response.history,
            cache_hit=response.cache_hit,
            tool_calls=response.tool_calls,
            metrics=response.metrics,
        )
...

graphrag/index/operations/summarize_descriptions/description_summary_extractor.py

...
    async def _summarize_descriptions_with_llm(
        self, id: str | tuple[str, str] | list[str], descriptions: list[str]
    ):
        """Summarize descriptions using the LLM."""
        response = await self._model.achat(
            self._summarization_prompt.format(**{
                self._entity_name_key: json.dumps(id, ensure_ascii=False),
                self._input_descriptions_key: json.dumps(
                    sorted(descriptions), ensure_ascii=False
                ),
            }),
            name="summarize",
            model_parameters={"max_tokens": self._max_summary_length},
        )
        # Calculate result
        return str(response.output.content)

Steps to reproduce

No response

GraphRAG Config Used

# Paste your config here
### This config file contains required core defaults that must be set, along with a handful of common optional settings.
### For a full list of available settings, see https://microsoft.github.io/graphrag/config/yaml/

### LLM settings ###
## There are a number of settings to tune the threading and token limits for LLM calls - check the docs.

models:
  default_chat_model:
    type: openai_chat # or azure_openai_chat
    api_base: ${DEEPSEEK_BASE_URL}
    # api_version: 2024-05-01-preview
    auth_type: api_key # or azure_managed_identity
    api_key: ${DEEPSEEK_API_KEY} # set this in the generated .env file
    # audience: "https://cognitiveservices.azure.com/.default"
    # organization: <organization_id>
    model: ${DEEPSEEK_LLM_MODEL}
    # deployment_name: <azure_model_deployment_name>
    # encoding_model: cl100k_base # automatically set by tiktoken if left undefined
    model_supports_json: true # recommended if this is available for your model.
    concurrent_requests: 25 # max number of simultaneous LLM requests allowed
    async_mode: threaded # or asyncio
    retry_strategy: native
    max_retries: -1 # set to -1 for dynamic retry logic (most optimal setting based on server response)
    tokens_per_minute: 0 # set to 0 to disable rate limiting
    requests_per_minute: 0 # set to 0 to disable rate limiting
    temperature: 1
    max_tokens: 8192
  default_embedding_model:
    type: openai_embedding # or azure_openai_embedding
    api_base: ${DASHSCOPE_BASE_URL}
    # api_version: 2024-05-01-preview
    auth_type: api_key # or azure_managed_identity
    api_key: ${DASHSCOPE_API_KEY}
    # audience: "https://cognitiveservices.azure.com/.default"
    # organization: <organization_id>
    model: ${DASHSCOPE_EMBEDDING_MODEL}
    # deployment_name: <azure_model_deployment_name>
    # encoding_model: cl100k_base # automatically set by tiktoken if left undefined
    model_supports_json: true # recommended if this is available for your model.
    concurrent_requests: 10 # max number of simultaneous LLM requests allowed
    async_mode: threaded # or asyncio
    retry_strategy: native
    max_retries: -1 # set to -1 for dynamic retry logic (most optimal setting based on server response)
    tokens_per_minute: 0 # set to 0 to disable rate limiting
    requests_per_minute: 0 # set to 0 to disable rate limiting

vector_store:
  default_vector_store:
    type: lancedb
    db_uri: output\lancedb
    container_name: default
    overwrite: True

embed_text:
  model_id: default_embedding_model
  vector_store_id: default_vector_store

### Input settings ###

input:
  type: file # or blob
  file_type: text # or csv
  base_dir: "input"
  file_encoding: utf-8
  file_pattern: ".*\\.txt$$"

chunks:
  size: 1200
  overlap: 100
  group_by_columns: [id]

### Output settings ###
## If blob storage is specified in the following four sections,
## connection_string and container_name must be provided

cache:
  type: file # [file, blob, cosmosdb]
  base_dir: "cache"

reporting:
  type: file # [file, blob, cosmosdb]
  base_dir: "logs"

output:
  type: file # [file, blob, cosmosdb]
  base_dir: "output"

### Workflow settings ###

extract_graph:
  model_id: default_chat_model
  prompt: "prompts/extract_graph.txt"
  entity_types:
    [
      xxxx,
    ]
  max_gleanings: 1

summarize_descriptions:
  model_id: default_chat_model
  prompt: "prompts/summarize_descriptions.txt"
  max_length: 500

extract_graph_nlp:
  text_analyzer:
    extractor_type: regex_english # [regex_english, syntactic_parser, cfg]

extract_claims:
  enabled: true
  model_id: default_chat_model
  prompt: "prompts/extract_claims.txt"
  description: "Any claims or facts that could be relevant to information discovery."
  max_gleanings: 1

community_reports:
  model_id: default_chat_model
  graph_prompt: "prompts/community_report_graph.txt"
  text_prompt: "prompts/community_report_text.txt"
  max_length: 2000
  max_input_length: 8000

cluster_graph:
  max_cluster_size: 10

embed_graph:
  enabled: true # if true, will generate node2vec embeddings for nodes

umap:
  enabled: true # if true, will generate UMAP embeddings for nodes (embed_graph must also be enabled)

snapshots:
  graphml: true
  embeddings: true

### Query settings ###
## The prompt locations are required here, but each search method has a number of optional knobs that can be tuned.
## See the config docs: https://microsoft.github.io/graphrag/config/yaml/#query

local_search:
  chat_model_id: default_chat_model
  embedding_model_id: default_embedding_model
  prompt: "prompts/local_search_system_prompt.txt"

global_search:
  chat_model_id: default_chat_model
  map_prompt: "prompts/global_search_map_system_prompt.txt"
  reduce_prompt: "prompts/global_search_reduce_system_prompt.txt"
  knowledge_prompt: "prompts/global_search_knowledge_system_prompt.txt"

drift_search:
  chat_model_id: default_chat_model
  embedding_model_id: default_embedding_model
  prompt: "prompts/drift_search_system_prompt.txt"
  reduce_prompt: "prompts/drift_search_reduce_prompt.txt"

basic_search:
  chat_model_id: default_chat_model
  embedding_model_id: default_embedding_model
  prompt: "prompts/basic_search_system_prompt.txt"

Logs and screenshots

Engine log as below:

02:11:52,692 graphrag.callbacks.file_workflow_callbacks INFO Entity Extraction Error details={'doc_index': 0, 'text': '........'}
02:11:52,770 graphrag.callbacks.file_workflow_callbacks INFO Error Invoking LLM details={'prompt': '---目标---\n基于给定的文本文档和实体类型列表,识别文本中所有指定类型的实体及其相互关系..............', 'kwargs': {}}
02:11:52,770 graphrag.index.operations.extract_graph.graph_extractor ERROR error extracting graph
Traceback (most recent call last):
  File "/Users/luneice/Projects/python/graphrag/graphrag/index/operations/extract_graph/graph_extractor.py", line 127, in __call__
    result = await self._process_document(text, prompt_variables)
  File "/Users/luneice/Projects/python/graphrag/graphrag/index/operations/extract_graph/graph_extractor.py", line 155, in _process_document
    response = await self._model.achat(
  File "/Users/luneice/Projects/python/graphrag/graphrag/language_model/providers/fnllm/models.py", line 74, in achat
    response = await self.model(prompt, **kwargs)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/fnllm/openai/llm/openai_chat_llm.py", line 87, in __call__
    return await self._text_chat_llm(prompt, **kwargs)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/fnllm/openai/services/openai_tools_parsing.py", line 126, in __call__
    return await self._delegate(prompt, **kwargs)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/fnllm/base/base_llm.py", line 139, in __call__
    return await self._decorated_target(prompt, **kwargs)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/fnllm/base/services/json.py", line 78, in invoke
    return await delegate(prompt, **kwargs)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/fnllm/base/services/retryer.py", line 81, in invoke
    result = await delegate(prompt, **kwargs)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/fnllm/base/services/rate_limiter.py", line 75, in invoke
    result = await delegate(prompt, **args)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/fnllm/base/base_llm.py", line 120, in _decorator_target
    output = await self._execute_llm(prompt, kwargs)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/fnllm/openai/llm/openai_text_chat_llm.py", line 148, in _execute_llm
    completion = await self._client.chat.completions.create(
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/resources/chat/completions.py", line 1727, in create
    return await self._post(
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_base_client.py", line 1856, in post
    return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_base_client.py", line 1550, in request
    return await self._request(
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_base_client.py", line 1613, in _request
    return await self._retry_request(
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_base_client.py", line 1683, in _retry_request
    return await self._request(
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_base_client.py", line 1613, in _request
    return await self._retry_request(
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_base_client.py", line 1683, in _retry_request
    return await self._request(
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_base_client.py", line 1613, in _request
    return await self._retry_request(
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_base_client.py", line 1683, in _retry_request
    return await self._request(
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_base_client.py", line 1653, in _request
    return await self._process_response(
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_base_client.py", line 1750, in _process_response
    return await api_response.parse()
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_response.py", line 430, in parse
    parsed = self._parse(to=to)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/openai/_response.py", line 265, in _parse
    data = response.json()
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/site-packages/httpx/_models.py", line 832, in json
    return jsonlib.loads(self.content, **kwargs)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/homebrew/anaconda3/envs/rag/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 10 column 1 (char 9)

Additional Information

  • GraphRAG Version: 2.0.0
  • Operating System: macos Sequoia 15.3.1
  • Python Version: 3.10
  • Related Issues: N.A.

luneice avatar Mar 08 '25 04:03 luneice

相同问题,同样是用的deepseek-v3,目前还在找解决办法。(不知道跟2.0.0版本有没有关系)

ren-sheng avatar Mar 09 '25 11:03 ren-sheng

相同问题,同样是用的deepseek-v3,目前还在找解决办法。(不知道跟2.0.0版本有没有关系)

感觉跟版本有关,1.2.0没怎么失败过。 It feels related to the version. Version 1.2.0 has rarely failed.

luneice avatar Mar 09 '25 13:03 luneice

1.2.0 和 2.0.0, 在使用 DeepSeek-R1-Distill-Llama-70B 时都遇到了相同的问题, 不知道具体什么原因 更初期的 0.3.0 和 0.4.0 没有遇到这个问题 通过在 settings.yaml 里调低 chunk->size 到某个点, 问题消失, 且2.0.0需要设置的更低 但是修改 chunk-size 会影响索引构建, 进而影响效果 ε=(´ο`*)))唉

humid1ch avatar Mar 11 '25 02:03 humid1ch

1.2.0 和 2.0.0, 在使用 DeepSeek-R1-Distill-Llama-70B 时都遇到了相同的问题, 不知道具体什么原因 更初期的 0.3.0 和 0.4.0 没有遇到这个问题 通过在 settings.yaml 里调低 chunk->size 到某个点, 问题消失, 且2.0.0需要设置的更低 但是修改 chunk-size 会影响索引构建, 进而影响效果 ε=(´ο`*)))唉

不会是因为token的大小导致的?

luneice avatar Mar 11 '25 13:03 luneice

所以有找到什么解决办法吗,1.2.0、2.0.0和2.1.0我现在都遇到这个问题。

ren-sheng avatar Mar 15 '25 05:03 ren-sheng

所以有找到什么解决办法吗,1.2.0、2.0.0和2.1.0我现在都遇到这个问题。

2.1.0还没有对那部分代码进行优化,1.2.0应该没问题的

luneice avatar Mar 16 '25 03:03 luneice

我发现一个奇怪的现象,我在运行1.2.0的时候出现了实体提取错误,但是当我再次运行(此时存在有上次运行后获取的LLM的回答的缓存),就不会出现提取错误的报错,而且运行速度有很大的提升。

ren-sheng avatar Mar 25 '25 04:03 ren-sheng

我发现一个奇怪的现象,我在运行1.2.0的时候出现了实体提取错误,但是当我再次运行(此时存在有上次运行后获取的LLM的回答的缓存),就不会出现提取错误的报错,而且运行速度有很大的提升。

2.1.0 新的版本问题似乎修复了,ds耗费1500万token没有错误日志,均成功

但是如果运行index成功了,如果手欠再次运行被强制结束后会导致很多entity丢失

luneice avatar Mar 25 '25 05:03 luneice

I have the same issue (LLM errors when indexing using a high number of documents (I am using the version 2.1.0)

hjerbii avatar Mar 27 '25 10:03 hjerbii