Retrieval-Augmented Code Completion via Hybrid Vector Indexing

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Large machine learning models for code completion require significant computing resources, making them impractical for deployment in systems with limited resources despite achieving high accuracy through large-scale training.

Innovation Solution

A retrieval-augmented code completion system uses a hybrid retrieval technique to find semantically similar source code segments from a database, combining embedding and sparse vector indices to predict the next tokens in a source code snippet, reducing the need for extensive training data and model size.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Measurement precision

If large-scale machine learning models are trained on large datasets to achieve high code completion accuracy, then prediction accuracy is improved, but model size and computing resource requirements increase

Engineering Contradiction:
Improvecode completion accuracyVSAvoidmodel size
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The patent segments the code completion task into two parts: (1) a retrieval component that fetches relevant code snippets from a database using embedding vectors, and (2) a smaller decoder model that generates completions based on retrieved snippets. This segmentation allows the system to achieve high accuracy without requiring a single large model to handle all aspects of the task

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The patent introduces a retrieval database as an intermediary between the input code snippet and the completion generator. The database stores pre-processed code embeddings that serve as intermediate representations, allowing the decoder model to focus on generation rather than both retrieval and generation, thereby reducing model size while maintaining accuracy

Inventive Principle:
Principle #24Intermediary (Mediator)

2Measurement precision

If large machine learning models with billions of parameters are deployed for accurate code completion, then prediction quality is improved, but computing resources required for deployment increase

Engineering Contradiction:
Improveprediction accuracyVSAvoidcomputing resource consumption
Core Design Contradiction:
Measurement precisionVSUse of energy by moving object

Solution Approach 1:

The system segments the computational workload between offline retrieval database construction and online code completion. The computationally intensive embedding training is performed offline, while the online decoder model remains small and resource-efficient, reducing deployment computing requirements while maintaining prediction quality

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The patent performs preliminary processing by pre-training embedding models and constructing the retrieval database offline before deployment. This preliminary action transfers computational burden from the deployment phase to the preparation phase, allowing the deployed system to use smaller, more resource-efficient models

Inventive Principle:
Principle #10Preliminary action

3Reliability

If extensive training data is used to train large models for code completion, then model performance is improved, but training time and computational cost increase

Engineering Contradiction:
Improvemodel performanceVSAvoidtraining time
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The training process is segmented into two stages: (1) training embedding models on large code corpora to create the retrieval database, and (2) training a smaller decoder model on retrieved examples. This segmentation allows the system to leverage extensive training data for the embedding stage while keeping the decoder training faster and more efficient

Inventive Principle:
Principle #1Segmentation

Data Source

PatentUS12073195B2Retrieval-augmented code completion
Publication Date: 2024.08.27 MICROSOFT TECHNOLOGY LICENSING LLC
  • US12073195B2 patent drawing
  • US12073195B2 patent drawing
  • US12073195B2 patent drawing

AI summary

A retrieval-augmented code completion system uses the context of a partially-formed source code snippet of a source code program and a hint to predict the source code tokens needed to complete the partially-formed source code snippet. The hint is a source code segment that completes a semantically-similar source code segment of the partially-formed source code snippet. The hint is found in a retrieval source code database using a hybrid retrieval technique. A deep learning decoder model uses the context of the partially-formed source code snippet and the hint to predict the most likely candidate sequence of source code tokens to complete the partially-formed source code snippet.