Depura un desbordamiento: presupuesto práctico para RAG
Divide la solicitud, reserva espacio para generar y localiza la mayor fuente de crecimiento.
Calcula el presupuesto completo
La solicitud no es solo el último mensaje. Incluye instrucciones del sistema, historial, documentos recuperados, texto del usuario y margen para mensajes o herramientas. Reserva también la salida.
El ejemplo asigna 8.096 de 8.192 tokens y deja 96. Un documento adicional de 500 tokens excedería el límite en 404. Son cifras didácticas, no especificaciones de un modelo.
Study guide & lesson outlineLEARNING CONTRACT
Understand → implement → investigate
Goal: explain the mechanism in this lesson, reproduce one example and test a failure case. Reading alone does not mark mastery.
Understand: state assumptions, shapes/units and a counterexample.
Implement: reproduce a numerical example and inspect boundaries.
Investigate: compare one alternative under a matched budget.
Localiza la mayor contribución
Introduce cada sección por separado en Presupuesto de contexto. La herramienta la codifica y muestra su contribución. Carga el ejemplo que supera el límite para observar el aviso y la sección RAG dominante.
La codificación separada permite atribuir el uso, pero no reconstruye exactamente la solicitud final. Separadores, plantillas, esquemas de herramientas y medios pueden cambiarlo. Reserva margen y compara con el uso de la API.
Si la recuperación es excesiva, elimina duplicados y reordena por relevancia; conserva los pasajes útiles y sus fuentes. Resume turnos antiguos sin perder decisiones y conserva el intercambio reciente.
Vuelve a contar y evalúa respuestas representativas tras cada cambio. No recortes silenciosamente instrucciones esenciales. Comprueba además el límite específico de salida: una ventana amplia no garantiza una respuesta de igual tamaño.
8096 of 8192 leaves 96 tokens. Adding 500 overflows by 404; to also preserve a 256-token reserve, remove 660. Provider template overhead must be measured separately.
Shared code, English mathematical explanation and key multilingual numeric passages reviewed. This is not a full translation proofread.
Mechanism map: follow the transformations from top to bottom.
Before running: predict a boundary case
8096 of 8192 leaves 96 tokens. Adding 500 overflows by 404; to also preserve a 256-token reserve, remove 660. Provider template overhead must be measured separately.
Hint: isolate the assumption
Keep the baseline input fixed, change one parameter or boundary, and compare both the numerical result and the claimed units. A passing example verifies this fixture only.
Minimal executable example
Save the example and linked modules in one folder. Use Node.js 22 or newer, then run node context-budget-rag.mjs. No third-party runtime dependencies.
8096 of 8192 leaves 96 tokens. Adding 500 overflows by 404; to also preserve a 256-token reserve, remove 660. Provider template overhead must be measured separately.
Record input, code version, expected result and observed result in the notebook below. Then construct a counterexample that violates the assumption above and explain why the original conclusion no longer follows.
Before revealing an answer, predict one result. After the exercise, record the discrepancy and a transfer test. Saved locally across language editions.
The mathematical review scope is recorded per lesson. It does not establish empirical paper reproduction; report suspected errors in your notes. Review scope