Common Causes and Solutions:
LLM Failure to Generate Valid JSON/Reports:
The most common reason for create_community_reports to fail is that the LLM is unable to produce the expected JSON format for the reports. GraphRAG provides prompts to the LLM to generate these summaries in a specific structure. If the LLM's response is malformed, empty, or not in JSON, GraphRAG will consider it a failure.
Solution:
Check LLM Response Quality: If your LLM (DeepSeek in this case) is not well-tuned for instruction following or JSON output, it might struggle. You can try testing your FastAPI endpoint with a prompt designed to elicit JSON to see if DeepSeek is reliably returning it.
Adjust LLM Parameters:
temperature: A very low temperature (e.g., 0.0) can sometimes make models "stick" to undesired patterns or get stuck. Try a slightly higher value like 0.1 or 0.2 in your settings.yaml for default_chat_model to allow for a little more creativity while still being deterministic.
max_tokens: Ensure max_tokens is sufficient for a meaningful report. If reports are being cut off, they might be incomplete and unparseable. GraphRAG's default is often 4000, which should be plenty.
LLM Model Choice: While deepseek-chat is generally good, some models are better at strict JSON generation than others. If you have access to a model specifically fine-tuned for structured output or function calling, that might perform better.
LLM Context Window/Token Limits:
If the input chunks for community reports are very large, your LLM might be exceeding its context window, leading to truncated or failed responses.
Solution:
Adjust chunk_size in settings.yaml: In the indexing section of your settings.yaml, try reducing the chunk_size. This will create smaller chunks of text, which in turn lead to smaller inputs for the LLM when generating community reports.
# ...
indexing:
chunk_size: 512 # Try reducing this from default (e.g., 1024 or 2048)
# ... other indexing settings
# ...
Verify max_tokens on your FastAPI server: Ensure the max_tokens you pass to DeepSeek is appropriate for the model and allows for a full response.
Authentication/Connection Issues to DeepSeek:
While your FastAPI server starts up, there could still be intermittent connection or authentication issues when the actual LLM calls are made for create_community_reports. The None output could imply the call itself failed or timed out.
Solution:
FastAPI Server Logs: While GraphRAG is running, keep an eye on your FastAPI server's console. Look for any ERROR or WARNING messages, especially around the time GraphRAG tries to create community reports. You might see OpenAIError or HTTPException logs there.
DeepSeek API Key: Double-check your DEEPSEEK_API_KEY environment variable on the machine running the FastAPI server. Ensure it's correct and has access to the deepseek-chat model.
Network Connectivity: Verify that the machine running your FastAPI server has stable internet connectivity to https://api.deepseek.com.
GraphRAG Prompts:
GraphRAG uses internal prompts for these steps. Sometimes, if the prompts are too complex or the LLM is sensitive to prompt wording, it can fail.
Solution:
Update GraphRAG: Ensure you're using the latest version of GraphRAG. Newer versions often include prompt improvements and bug fixes.
Custom Prompts (Advanced): GraphRAG allows you to customize the prompts used for various steps. This is an advanced step, but if all else fails, you could try inspecting the default community_reports_extractor.py (or similar) in the GraphRAG source code to understand the expected prompt format and potentially provide your own in settings.yaml. This is generally only needed if you have highly specialized needs or are using a very unusual LLM.
Recommended Steps to Fix:
Start your FastAPI server. Keep its terminal open and visible.
Verify DEEPSEEK_API_KEY is correctly set as an environment variable in the terminal where you launch your FastAPI server.
Modify your GraphRAG settings.yaml:
Add encoding_model: cl100k_base at the top level (if you haven't already).
For default_chat_model, try setting temperature: 0.1 or 0.2.
Consider adding an indexing section if it's not there, and setting chunk_size: 512.
encoding_model: cl100k_base
models:
default_chat_model:
type: openai_chat
api_base: http://localhost:8000/v1
api_key: "sk-graphrag-llm"
model: "deepseek-chat"
temperature: 0.1 # <--- Try this
max_tokens: 4000
request_timeout: 600.0
concurrent_requests: 5
max_retries: 5
default_embedding_model:
type: openai_embedding
api_base: http://localhost:8000/v1
api_key: "sk-graphrag-embedding"
model: "all-MiniLM-L6-v2"
batch_size: 16
batch_max_tokens: 8191
concurrent_requests: 5
max_retries: 5
indexing: # <--- Add this section if not present
chunk_size: 512 # <--- Try this
# Other indexing parameters...
# ... rest of your settings
Run the GraphRAG indexer again.
Observe the output in both the GraphRAG terminal and your FastAPI server's terminal for any new errors or clues. The FastAPI logs will tell you if the request to DeepSeek was successful or failed at the API level.
By systematically adjusting these parameters and monitoring logs, you should be able to pinpoint why create_community_reports is failing. Most often, it's the LLM not returning the expected JSON or hitting token limits.
No comments:
Post a Comment