Microsoft · Filed Mar 14, 2025 · Published Sep 17, 2026 · verified — real USPTO data

Microsoft Patents a Method to Find Better Code References for AI Generation

Before an AI writes a single line of code, it has to know what it's working with. Microsoft's new patent describes a smarter way to gather that background knowledge, using two back-to-back searches instead of one.

An example of a user query and an AI assistant's response, showing code and a natural language summary. Drawing from patent filing US 2026/0277563 A1.
An example of a user query and an AI assistant's response, showing code and a natural language summary.
See all 11 drawings from this filing ↓
Publication number US 2026/0277563 A1
Applicant Microsoft Technology Licensing, LLC
Filing date Mar 14, 2025
Publication date Sep 17, 2026
Inventors Mukul SINGH, Sumit GULWANI, Avik DUTTA, Vu Minh LE, Gust Ben Anneloes VERBRUGGEN
CPC classification 717/106
Grant likelihood Medium
Examiner CENTRAL, DOCKET (Art Unit OPAP)
Status Docketed New Case - Ready for Examination (Apr 10, 2025)
Document 20 claims

How Microsoft's AI coding assistant finds the right context

Imagine you ask a coding assistant to build a feature for your app. The assistant doesn't just start typing. It first goes looking for relevant background information, like API guides, code examples, or library documentation, so the code it writes actually fits your setup.

The problem is that a single search can miss things. You might find one useful document, only to realize it references something else you also needed. Microsoft's patent describes a system that does a second search, informed by what the first search already found, to catch those related pieces too.

The result is that the AI model writing your code gets a richer, more complete picture before it starts. Less guessing, fewer hallucinated function calls, and output that's more likely to work in your actual environment.

From the filing · CLAIM 1
identifying, from a first corpus of code resource data, a first set of code resource data relevant to an input; using the input and the first set of code resource data identified from the first corpus of code resource data to identify, from a second corpus of code resource data, a second set of code resource data relevant to the input and the first set of code resource data …

Translation: The system searches through two separate sets of code libraries to find useful programming examples based on your request.

Inside the two-corpus retrieval chain

The system works in a chain of three steps before any code is generated.

  • First retrieval: The system takes your input (a plain-English request or a partial code snippet) and searches a first corpus (a library of code resources, think documentation, APIs, example files) to pull out the most relevant material.
  • Second retrieval: It then combines your original input and the material from the first search, and uses that combined context to search a second corpus for additional relevant material. The second search is smarter because it knows what the first one found.
  • Code generation: A generative AI model (or multiple models) receives the original input plus both sets of retrieved material, and generates code intended to fulfill the request.

The key technical insight is that the second retrieval is conditioned on the first. In retrieval-augmented generation (RAG, the technique of giving an AI model outside documents to read before answering), a single retrieval step can leave gaps. By chaining two searches, where the second knows the output of the first, the system can surface dependencies and related references that a one-shot search would miss. The generated code is then surfaced to the user or executed directly.

From the filing · THE ABSTRACT
An indication of the input, the first set of code resource data, and the second set of code resource data is used by one or more generative artificial intelligence models to generate code relevant to the input.

Translation: The AI uses both your prompt and the two discovered sets of code references to write the final program.

What this means for AI-assisted coding tools

For everyday users of AI coding tools like GitHub Copilot or similar assistants, the gap between a plausible-looking answer and a working one often comes down to whether the AI knew about the right libraries and dependencies upfront. A two-stage retrieval approach directly targets that gap.

Microsoft's long bet on AI-assisted development tools means improvements at this layer (what the model knows before it writes) could ripple across a wide range of products. If the system fetches better context, developers spend less time debugging AI-generated code that looked right but referenced the wrong version of a package or a function that doesn't exist in their project.

Microsoft's 62nd filing in the Language AI patents we've tracked since May follows a code translation system and a section-by-section document reader.

Editorial take

The two-stage retrieval design makes a real tradeoff: you get better context at the cost of two lookup operations instead of one. That adds latency (a delay between your request and the first character of output), and in a coding assistant where fast responses matter for flow, that's a genuine cost to weigh.

Whether it's worth it depends on use case. For quick autocomplete, a slower but more accurate system might frustrate more than it helps. For longer code generation tasks (writing a whole module, scaffolding a new feature) where a wrong answer costs an hour of debugging, the extra lookup time is almost certainly a good trade.

The patent doesn't specify hard limits on corpus size or retrieval time, which leaves the real-world performance question open. The design is sound, but the proof will be in whether the second search adds enough signal to justify the wait.

There are more where this came from

We read every patent application Big Tech publishes and send you the ones worth knowing. Plain English, free, every week.

The drawings

11 drawing sheets from US 2026/0277563 A1 · click any drawing to enlarge

Patent filing page

Source. Full patent text and figures from the official USPTO publication PDF.