Louis-François Bouchard Claude Opus 4.8 (1M context) commited on
Commit ·
4b82527
1
Parent(s): 824b2e8
graphrag: route Gemini 2.5 via OpenAI-compat endpoint; add index retry wrapper
Browse filesNative litellm gemini transport dropped connections (Server disconnected / 503) and aborted extract_graph even sequentially; the OpenAI-compatible endpoint (still gemini-2.5-flash) is stable and completed a full index first try at concurrency 6. Add run_graphrag_index.sh: loops graphrag index until entities.parquet exists (cache resumes), since one exhausted-retry call otherwise aborts the whole stage. Calibrated course-content cost ~= $88/1M corpus tokens.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
data/graphrag/settings.yaml
CHANGED
|
@@ -7,21 +7,31 @@
|
|
| 7 |
|
| 8 |
completion_models:
|
| 9 |
default_completion_model:
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
model: gemini-2.5-flash
|
|
|
|
| 12 |
auth_method: api_key
|
| 13 |
api_key: ${GEMINI_API_KEY}
|
| 14 |
# graphrag defaults to 25 concurrent requests; that burst triggers Gemini
|
| 15 |
# connection resets ([Errno 32] Broken pipe). Keep it low + let rate_limit
|
| 16 |
# pace throughput. graphrag caches each successful call, so a re-run resumes.
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
async_mode: threaded
|
| 19 |
call_args:
|
| 20 |
temperature: 0 # deterministic extraction
|
|
|
|
|
|
|
| 21 |
retry:
|
| 22 |
type: exponential_backoff
|
| 23 |
-
max_retries:
|
| 24 |
-
|
|
|
|
| 25 |
# Throttle to stay friendly to the Gemini free/low tier and avoid the
|
| 26 |
# TPM blowups noted in evals.md. On a paid tier-1 key these can be raised
|
| 27 |
# (e.g. requests_per_period: 200) to finish the full index faster.
|
|
|
|
| 7 |
|
| 8 |
completion_models:
|
| 9 |
default_completion_model:
|
| 10 |
+
# Still Gemini 2.5 Flash, but routed through Gemini's OpenAI-compatible
|
| 11 |
+
# endpoint instead of litellm's native gemini transport: the native path
|
| 12 |
+
# drops connections ("Server disconnected" / 503) under sustained
|
| 13 |
+
# extraction and aborts the stage; the OpenAI client path is far steadier.
|
| 14 |
+
model_provider: openai
|
| 15 |
model: gemini-2.5-flash
|
| 16 |
+
api_base: https://generativelanguage.googleapis.com/v1beta/openai
|
| 17 |
auth_method: api_key
|
| 18 |
api_key: ${GEMINI_API_KEY}
|
| 19 |
# graphrag defaults to 25 concurrent requests; that burst triggers Gemini
|
| 20 |
# connection resets ([Errno 32] Broken pipe). Keep it low + let rate_limit
|
| 21 |
# pace throughput. graphrag caches each successful call, so a re-run resumes.
|
| 22 |
+
# Moderate parallelism over the OpenAI-compatible endpoint. Caching + the
|
| 23 |
+
# index retry-loop absorb any transient drops.
|
| 24 |
+
concurrent_requests: 6
|
| 25 |
async_mode: threaded
|
| 26 |
call_args:
|
| 27 |
temperature: 0 # deterministic extraction
|
| 28 |
+
# Gemini throws transient 503 / broken-pipe under load; retry hard. graphrag
|
| 29 |
+
# caches each success, so a failed run is re-run to resume (see index loop).
|
| 30 |
retry:
|
| 31 |
type: exponential_backoff
|
| 32 |
+
max_retries: 20
|
| 33 |
+
base_delay: 2
|
| 34 |
+
max_delay: 120
|
| 35 |
# Throttle to stay friendly to the Gemini free/low tier and avoid the
|
| 36 |
# TPM blowups noted in evals.md. On a paid tier-1 key these can be raised
|
| 37 |
# (e.g. requests_per_period: 200) to finish the full index faster.
|
data/scraping_scripts/run_graphrag_index.sh
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Build the GraphRAG index (experiment: GraphRAG vs classical RAG).
|
| 3 |
+
#
|
| 4 |
+
# graphrag aborts the whole extract_graph stage if a single Gemini call fails
|
| 5 |
+
# after its retries (transient 503 / broken pipe happen under load), but it
|
| 6 |
+
# CACHES every successful call -- so re-running resumes and only retries what's
|
| 7 |
+
# missing, at no extra cost. This wrapper loops the index until entities.parquet
|
| 8 |
+
# exists (or MAX_ATTEMPTS is hit).
|
| 9 |
+
#
|
| 10 |
+
# Prereqs: a valid GEMINI_API_KEY (indexing LLM, 2.5 Flash) and OPENAI_API_KEY
|
| 11 |
+
# (embeddings) in .env. Cohere is NOT needed to index. The graph DB is
|
| 12 |
+
# local-only (data/graphrag/output) and never uploaded to the HF bundle.
|
| 13 |
+
#
|
| 14 |
+
# Usage:
|
| 15 |
+
# data/scraping_scripts/graphrag_prep_input.py --sources full_stack_ai_engineering
|
| 16 |
+
# bash data/scraping_scripts/run_graphrag_index.sh
|
| 17 |
+
set -u
|
| 18 |
+
|
| 19 |
+
ROOT="${GRAPHRAG_ROOT:-data/graphrag}"
|
| 20 |
+
MAX_ATTEMPTS="${MAX_ATTEMPTS:-8}"
|
| 21 |
+
OUT="$ROOT/output/entities.parquet"
|
| 22 |
+
|
| 23 |
+
for i in $(seq 1 "$MAX_ATTEMPTS"); do
|
| 24 |
+
echo "=== graphrag index attempt $i/$MAX_ATTEMPTS ==="
|
| 25 |
+
uv run --env-file .env graphrag index --root "$ROOT"
|
| 26 |
+
if [ -f "$OUT" ]; then
|
| 27 |
+
echo "SUCCESS: $OUT present after attempt $i"
|
| 28 |
+
exit 0
|
| 29 |
+
fi
|
| 30 |
+
echo "attempt $i did not produce entities.parquet; retrying (cache resumes)"
|
| 31 |
+
sleep 5
|
| 32 |
+
done
|
| 33 |
+
|
| 34 |
+
echo "FAILED: no entities.parquet after $MAX_ATTEMPTS attempts" >&2
|
| 35 |
+
exit 1
|