AST-Based Code Chunk Summarization for Accurate Source Code Retrieval
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing source code retrieval and generation techniques face challenges due to inadequate documentation, complex syntactic rules, and the lack of generalized training datasets, leading to inefficient and resource-intensive code adaptation.
Innovation Solution
The method involves generating an abstract syntax tree from source code, aggregating nodes into code chunks, and using a large language model (LLM) with prompts to summarize features, improving the extraction and summarization of code features.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of manufacture
If keyword-based approaches are used for source code retrieval, then the retrieval process is simple to implement, but the retrieval accuracy is low due to complex syntactic rules and inadequate documentation
Solution Approach 1:
The patent introduces an abstract syntax tree (AST) as an intermediary structure between the source code and the retrieval system. The AST captures the syntactic and semantic structure of the code, serving as a mediator that transforms complex code into a structured representation that can be effectively queried and matched, thereby improving retrieval accuracy without sacrificing implementation simplicity
Solution Approach 2:
The patent transforms the retrieval approach by changing the parameters from simple keyword matching to structured AST-based matching. This parameter change enables the system to consider syntactic relationships, code hierarchy, and semantic meaning, significantly improving retrieval accuracy while maintaining computational efficiency
2Measurement precision
If domain-specific models are trained on code comments and documentation, then the model can understand code semantics, but the model does not generalize well to different codebases and programming languages
Solution Approach 1:
The patent employs ASTs as a universal representation that can capture the structure of different programming languages and codebases. The AST approach provides a language-agnostic framework that maintains semantic understanding capabilities while enabling broad generalization across diverse code repositories, making the retrieval system universally applicable
Solution Approach 2:
The patent segments the code into hierarchical structures within the AST, breaking down complex code into manageable nodes representing different linguistic constructs. This segmentation enables the system to understand code semantics at multiple levels while maintaining adaptability to different languages through the standardized AST representation
3Reliability
If LLMs are used for code generation, then the generated code can be syntactically and semantically correct in various languages, but the generation process requires large training datasets that are not widely available
Solution Approach 1:
The patent performs preliminary action by generating AST representations and code summaries before the actual code generation task. This pre-processing creates structured training data that captures syntactic and semantic information, enabling LLMs to learn from organized representations rather than requiring vast amounts of raw code examples
Solution Approach 2:
The patent uses ASTs and code summaries as intermediary representations that bridge the gap between raw code and LLM training data. These intermediaries distill essential structural and semantic information into compact forms, reducing the quantity of training data needed while maintaining code generation reliability
4Ease of operation
If conventional RAG-based models are used for code retrieval, then the models can process source code, but the models struggle with large documents due to limited context windows and produce inconsistent results
Solution Approach 1:
The patent segments large code documents into smaller, manageable chunks represented as AST subtrees. This segmentation allows the retrieval system to process code within context window limits while maintaining structural relationships, thereby improving result consistency without sacrificing code processing capability
Solution Approach 2:
The patent employs a nested structure where AST nodes are hierarchically organized, with smaller code units nested within larger structures. This nesting enables the system to maintain context across different levels of code organization, improving consistency in retrieval results while working within context window constraints
Data Source
AI summary
Techniques for extracting source code features to support source code retrieval and generation include receiving source code; generating an abstract syntax tree (AST) based upon the source code; aggregating a plurality of nodes of the AST into a code chunk; presenting the code chunk to a large language model (LLM) with at least one prompt based on a type of feature of a language in which the source code is represented; and receiving a summary of the code chunk from the LLM based upon the at least one prompt, wherein the summary summarizes one or more features of the code chunk.


