LLM Codebase Summarization Using Docstrings for Context Reduction

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Large codebases exceed the token limit of Large Language Models (LLMs), leading to context length issues and potential inaccuracies when using iterative processing methods fail to capture dependencies.

Innovation Solution

The method involves identifying and utilizing docstrings within code files to generate summaries, organizing these summaries based on the codebase structure, and determining whether to transmit summaries or code to downstream tasks, reducing context length by using suitable docstrings and LLM-generated summaries.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Loss of information

If the entire codebase is input to the LLM, then complete code context is provided, but no tokens are left for generation due to context length limits

Engineering Contradiction:
Improvecode context informationVSAvoidtoken availability for generation
Core Design Contradiction:
Loss of informationVSProductivity

Solution Approach 1:

The codebase is divided into multiple files, and each file is further segmented into functional components represented by docstrings. The LLM processes one file at a time, extracting docstrings that capture essential functionality without requiring the entire codebase in context. This segmentation allows the system to handle large codebases within token limits while preserving necessary information.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The system extracts docstrings from code files as representative summaries of file functionality. These docstrings are taken out from the full code context and used as the primary input to the LLM, eliminating the need to process entire source files. This extraction approach retains key information while dramatically reducing token consumption.

Inventive Principle:
Principle #2Taking out (Extraction)

2Productivity

If iterative processing with different parts of the codebase is used, then context length is managed, but dependencies and general context are missed leading to inaccurate results

Engineering Contradiction:
Improvetoken management efficiencyVSAvoidaccuracy of processing results
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

The system merges multiple docstrings from different files into a unified context for the LLM. By combining these extracted summaries, the LLM receives a comprehensive view of the codebase structure and dependencies without exceeding token limits. This merging approach preserves inter-file relationships that iterative processing alone would miss.

Inventive Principle:
Principle #5Merging (Combining)

Solution Approach 2:

Docstrings are extracted and organized in advance before LLM processing. This preliminary action prepares a structured summary of the codebase that includes dependency information and contextual relationships, allowing the LLM to process files in a meaningful sequence rather than isolated iterations.

Inventive Principle:
Principle #10Preliminary action

3Productivity

If docstrings are used as summaries, then context length is reduced, but docstring quality and suitability vary across files

Engineering Contradiction:
Improvecontext length reductionVSAvoidsummary quality
Core Design Contradiction:
ProductivityVSMeasurement precision

Solution Approach 1:

The system evaluates each docstring individually to determine its suitability for use as a summary. Different quality criteria are applied based on the specific characteristics of each docstring, such as completeness, accuracy, and relevance. This local quality assessment ensures that only appropriate docstrings are used, maintaining high summary quality across diverse code files.

Inventive Principle:
Principle #3Local quality

Solution Approach 2:

The system adjusts parameters such as docstring selection criteria, summary length, and organization structure based on the specific characteristics of each code file. By dynamically changing these parameters, the system optimizes summary quality for different types of code while maintaining consistent context length reduction benefits.

Inventive Principle:
Principle #35Parameter changes

Data Source

PatentUS12430124B2System and method for reducing context length in processing codebase using large language model
Publication Date: 2025.09.30 JPMORGAN CHASE BANK NA
  • US12430124B2 patent drawing
  • US12430124B2 patent drawing
  • US12430124B2 patent drawing

AI summary

A method and system for reducing context length in processing a codebase using large language model (LLM) are disclosed. The method includes receiving the codebase including multiple files for processing, generating, via the LLM, summaries based on the multiple files, and subsequently organizing the summaries based on a structure of the codebase. The method further includes determining a downstream task, determining whether the downstream task requires a summary of a code or the code itself, and transmitting the summary or the code to the downstream task for executing the downstream task.