Cache the claude backend system prompt via Anthropic prompt caching
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- ai, performance
Línea de trabajo
Empieza en graphify/llm.py, en _call_claude(), y revisa cómo acepta el SDK de Anthropic bloques de contenido del sistema con cache_control. Aplica el almacenamiento en caché al prompt del sistema de extracción tal como se describe y, después, verifica que la llamada siga usando el mismo prompt y contenido del mensaje. El issue define como completado habilitar el almacenamiento en caché de prompts para el backend nativo de Claude sin cambiar la salida.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
extract --backend claude issues one messages.create call per file, and each call re-sends the fixed _extraction_system prompt at full input price. Marking the system block with Anthropic prompt caching (cache_control: ephemeral) bills that shared prefix at ~0.1× on reads after the first call. Output is unchanged — this is a billing/latency optimization only.
Where
graphify/llm.py, _call_claude() — system= is passed as a plain string, so the extraction system prompt is re-ingested on every per-file call.
Proposed change
diff
resp = client.messages.create(
model=model,
max_tokens=max_tokens,
-
system=_extraction_system(deep=deep_mode),
-
system=[{ -
"type": "text", -
"text": _extraction_system(deep=deep_mode), -
"cache_control": {"type": "ephemeral"}, -
)}], messages=[{"role": "user", "content": _anthropic_content(user_message, images or [])}],
The anthropic SDK already in use supports the content-block form of system with cache_control.
Why it helps
_extraction_system is identical across all per-file calls (only deep toggles). On a repo with N files the system prefix is paid N× at 1×; with caching it’s one write (1.25×) + (N−1) reads (0.1×) → ~90% off the system portion of input.
Caveats (for reviewers)
Only the system block is cacheable here; per-file user content isn’t reused.
Needs the system prompt ≥ the model’s min cacheable length (e.g. 512 tokens on recent Sonnet/Opus); below that it silently no-ops (cache_*_input_tokens = 0), no error.
With --max-concurrency > 1 the first wave of parallel calls misses (a cache entry is only available after the first response begins) — still a net win on multi-file runs.
5-min ephemeral TTL refreshes on each hit, so it stays warm through an active extraction.
Scoped to the native claude backend; the Bedrock path (system=[{"text": ...}]) uses a different caching mechanism and could be a follow-up.
Impact
Billing/latency only. No behavior change.
- Lenguaje dominante
- Python
- Estrellas
- 124k
- Forks
- 11.9k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Graphify-Labs/graphify
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Graphify-Labs/graphify#4860 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
extract --out <dir>: semantic cache never saved, docs missing from manifest (relative source_file resolved against --out)Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Graphify-Labs/graphify#4831 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 75/100
Graphify-Labs/graphify#4829 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
hooks: last-resort `python3` probe launches the Microsoft Store redirector on Windows (visible console flash, exit 9009)Posiblemente ocupada @Deepjyoti-Sarmah la tomó hace 10 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Graphify-Labs/graphify#4563 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
GRAPHIFY_DISABLE_THINKING is ignored by the claude backend, so thinking eats max_tokens and extraction truncatesPosiblemente ocupada @bercedev la tomó hace 10 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
Graphify-Labs/graphify#4546 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de Graphify-Labs/graphify
Issues similares
-
:bug: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
scikit-image/scikit-image#8377 ·
Los mantenedores suelen responder en 1 día
-
Ingredient import validation accepts negative nutrient values and NaNPosiblemente ocupada @LukeSekai la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
wger-project/wger#2564 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
apache/ponymail-foal#351 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
Los mantenedores suelen responder en 4 días
-
To Lower Case(온보딩 전용)Abiertoproblem
Dificultad 1/5 1-3 horas Aptitud para principiantes 72/100
DaleStudy/leetcode-study#2885 ·