Language Server Context Retrieval for Accurate LLM Code Generation

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Large language models (LLMs) face limitations in generating correct and syntactically formatted compilable computer code due to limited context provision, especially when dealing with proprietary or difficult-to-change code types, and providing relevant context without overwhelming inference costs.

Innovation Solution

A language server connected to an integrated Development Environment (IDE) identifies code artifacts within a file being edited, searches a code repository for relevant declarations, definitions, and references, and passes this context to the LLM for improved code generation.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If comprehensive contextual information from code repositories is provided to the LLM, then code generation accuracy and relevance are improved, but inference costs and processing time increase

Engineering Contradiction:
Improvecode generation accuracyVSAvoidinference time
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The patent segments the codebase into modular units organized as a directed acyclic graph (DAG), where code artifacts are divided into discrete nodes representing individual functions, classes, or modules. This segmentation allows the system to retrieve only relevant code segments rather than processing entire codebases, reducing inference time while maintaining generation accuracy.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The system performs preliminary indexing and organization of code artifacts into a DAG structure before LLM inference occurs. Dependencies, imports, and relationships are pre-computed and stored in the graph structure, enabling rapid retrieval during code generation without requiring real-time analysis of the entire codebase.

Inventive Principle:
Principle #10Preliminary action

2Reliability

If comprehensive contextual information from code repositories is provided to the LLM, then code generation accuracy and relevance are improved, but inference costs increase

Engineering Contradiction:
Improvecode generation accuracyVSAvoidinference cost
Core Design Contradiction:
ReliabilityVSUse of energy by moving object

Solution Approach 1:

The patent extracts only the essential contextual information needed for code generation by querying the DAG for specific ancestors and descendants of the target code artifact. This extraction approach retrieves minimal necessary context (e.g., parent classes, imported modules, dependent functions) rather than providing comprehensive codebase information, reducing inference costs while maintaining generation accuracy.

Inventive Principle:
Principle #2Taking out (Extraction)

3Reliability

If the LLM is provided with more context about the codebase, then the reliability of code generation improves, but the complexity of the system increases

Engineering Contradiction:
Improvecode generation reliabilityVSAvoidsystem complexity
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The patent introduces a language server as an intermediary component that mediates between the LLM and the codebase. The language server handles the complex tasks of parsing code, building the DAG structure, and querying dependencies, while the LLM receives simplified contextual information. This intermediary approach improves code generation reliability by ensuring accurate context retrieval while containing system complexity in a dedicated component.

Inventive Principle:
Principle #24Intermediary (Mediator)

4Adaptability or versatility

If proprietary or difficult-to-change code types are handled by the LLM, then code generation capability is improved, but error rates increase

Engineering Contradiction:
Improvecode generation capabilityVSAvoidoutput correctness
Core Design Contradiction:
Adaptability or versatilityVSReliability

Solution Approach 1:

The patent applies local quality by providing targeted contextual information specific to the proprietary or difficult-to-change code type being generated. The DAG structure enables retrieval of context locally relevant to the target artifact (e.g., specific framework conventions, project-specific patterns) rather than generic codebase information, improving output correctness for specialized code types while maintaining versatility.

Inventive Principle:
Principle #3Local quality

Data Source

PatentEP4600807A1Server based context provisioning for code generation with large language models
Publication Date: 2025.08.13 SAP SE
  • EP4600807A1 patent drawingFigure 1
  • EP4600807A1 patent drawingFigure 2
  • EP4600807A1 patent drawingFigure 3

AI summary

In an example embodiment, a language server connected to an integrated Development Environment (IDE) is used to identify, from a given input code, various code artifacts, such as functions, variables, etc., and then to search a repository of code files for declarations, definitions, and references related to those identified code artifacts. The declarations, definitions, and references can then be passed as context into an LLM.