Code Search Using Abstract Syntax Tree Indexing

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing code search methods often fail to accurately identify desired code due to treating code as mere text, leading to inefficient and inaccurate searches in large code repositories, which hampers the performance of computer system applications relying on code searches.

Innovation Solution

Implementing a code discovery system that uses code structure representation and index generation to perform searches based on the structural similarity of code, employing techniques like abstract syntax trees (AST) to generate index values and match analysis for efficient retrieval of similar code segments.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Ease of manufacture

If code is treated as mere text for search purposes, then search implementation is simple, but search accuracy and ability to identify desired code deteriorates

Engineering Contradiction:
Improvesearch implementation simplicityVSAvoidcode search accuracy
Core Design Contradiction:
Ease of manufactureVSMeasurement precision

Solution Approach 1:

The code is segmented into its structural components through parsing into abstract syntax trees (ASTs). This segmentation allows the search system to analyze code structure rather than treating it as opaque text, enabling accurate identification of code segments based on their structural similarity while maintaining manageable search complexity through hierarchical decomposition.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

An intermediary indexing system is introduced that generates index values from code structure representations. This intermediary layer translates complex code structure comparisons into efficient index-based lookups, resolving the contradiction by providing both structural accuracy (through AST-based indexing) and search efficiency (through index value comparison).

Inventive Principle:
Principle #24Intermediary (Mediator)

2Speed

If text-based search is used for code retrieval, then search speed is fast, but search accuracy deteriorates

Engineering Contradiction:
Improvesearch speedVSAvoidcode segment matching accuracy
Core Design Contradiction:
SpeedVSMeasurement precision

Solution Approach 1:

Code structure representations and index values are generated in advance during an indexing phase. This preliminary action prepares the code base for efficient searching by pre-computing structural features, allowing rapid retrieval during actual search operations without sacrificing structural matching accuracy.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

Instead of comparing entire code structures during search, simplified index values that capture essential structural characteristics are used as copies for comparison. This copying approach maintains structural matching accuracy while dramatically improving search speed by comparing compact representations rather than full code structures.

Inventive Principle:
Principle #26Copying

3Measurement precision

If structural analysis of code is performed for accurate searching, then code matching accuracy improves, but system complexity increases

Engineering Contradiction:
Improvecode segment matching accuracyVSAvoidsearch system complexity
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The essential structural features of code are extracted and isolated into separate index values, separating the complex structural analysis from the search operation. This extraction allows accurate structural matching while simplifying the search system by working with extracted features rather than full code structures.

Inventive Principle:
Principle #2Taking out (Extraction)

Solution Approach 2:

The search system transforms code from its original complex form into parameterized index values that capture structural characteristics. This parameter change simplifies the search operation by working with standardized structural parameters rather than raw code, reducing system complexity while maintaining matching accuracy.

Inventive Principle:
Principle #35Parameter changes

Data Source

PatentUS20230315405A1Discovering matching code segments according to index and comparative similarity
Publication Date: 2023.10.05 AMAZON TECH INC
  • US20230315405A1 patent drawing
  • US20230315405A1 patent drawing
  • US20230315405A1 patent drawing

AI summary

Code search is used to support various features. Code segments may be indexed using a code structure representation of the code segment. Code segments may be compared for similarity to identify a match with an input code segment using a comparison of logic trees generated for the input code segment and a stored code segment in an entry with a matching index value.