Method and system for automated code retrieval and code generation
Abstract
Disclosed is method for automated code retrieval and code generation, comprising: receiving code repository ( 302 ); extracting coding components (CC); generating knowledge graph (KG) comprising nodes representing extracted CC, and edges representing relationships between the extracted CC; identifying node(s) in generated KG for indexing; creating first index (FI) ( 406, 512 ) and second index (SI) ( 408, 514 ) of generated KG; receiving user request ( 502 ) for generating code; searching FI and SI based on entity(s) ( 510 ) extracted from user query (UQ) and embeddings ( 506 ) of UQ, respectively, for identifying predefined number of nodes (PNN) ( 516, 520 A) in KG; retrieving identified PNN from KG; retrieving neighbouring nodes (NN) ( 520 B-C); generating subgraph of retrieved NN and relationships between retrieved NN; filtering generated subgraph (GS); retrieving code snippets ( 404 C) of retrieved NN; generating contextualized subgraph; and prompting Large Language Model ( 608 ) with generated contextualized subgraph, predefined KG ontology and area of interest(s), for generating code ( 610 ).
Interactive Citation Constellation Global Citation Ranking
Interactive SVG Citation Constellation renders in Rust/WebAssembly. Prior art cited: 2 · Forward citations: 0.
Claims (8 — 1 Independent, 7 Dependent)
- Claim 1Independent Claim
A method for automated code retrieval and code generation, the method comprising: receiving a code repository ( 302) comprising a plurality of codes stored in a plurality of files; extracting a plurality of coding components from the plurality of codes; generating a knowledge graph comprising a plurality of nodes representing the extracted plurality of coding components, and a plurality of edges representing relationships between the extracted plurality of coding components, wherein the knowledge graph is generated based on a predefined knowledge graph ontology ( 208, 312); identifying at least one node in the generated knowledge graph, for indexing the generated knowledge graph; creating a first index ( 406, 512) and a second index ( 408, 514) of the generated knowledge graph, based on a complete information and embeddings of the identified at least one node, respectively; receiving a user request ( 502) for generating a code ( 610), from a user device; searching the first index and t
- Claim 2Depends on #1
The method of claim 1, wherein the step of extracting a plurality of coding components from the plurality of codes further comprises: identifying one or more parsable files from amongst the plurality of files, based on a coding language of the plurality of codes; parsing the identified one or more parsable files for extracting the plurality of coding components.
- Claim 3Depends on #1
The method of claim 1, wherein the extracted plurality of coding components comprises at least one of: modules, classes, methods, code snippets ( 404 C).
- Claim 4Depends on #1
The method of claim 1, wherein the relationships between the extracted plurality of coding components comprises at least one of: imports, usage.
- Claim 5Depends on #1
The method of claim 1, further comprising generating a description of each code snippet represented in the generated knowledge graph, using a Small Language Model (SLM).
- Claim 6Depends on #5
The method of claim 5, wherein the at least one node identified in the generated knowledge graph comprises at least one of: a function name, a class name ( 404 A), a module name, a file documentation ( 404 B), the code snippets ( 404 C), the generated description ( 404 D) of corresponding code snippets.
- Claim 7Depends on #1
The method of claim 1, wherein the at least one entity ( 510) extracted from the user query ( 502) is at least one of: a class name ( 404 A), a function name.
- Claim 8Depends on #1
The method of claim 1, wherein the embeddings ( 506) of the user query ( 502) are generated using an encoder model ( 410).
Technical Overview & Description
FIELD OF TECHNOLOGY The present disclosure relates to a general field of software development. Specifically, the present disclosure relates to a method and a system for code retrieval and code generation. BACKGROUND Generally, efficient and accurate software development is a cornerstone of modern technology, as software powers countless applications across industries. Developers rely heavily on reusable code, libraries, and frameworks to speed up development and ensure reliability. However, the vast and growing volume of code repositories creates significant challenges in discovering relevant code snippets or components that align with specific requirements. Furthermore, understanding how the components interact within larger systems is a time-consuming and error-prone process, often leading to delays, inefficiencies, and inconsistencies in the software development lifecycle. Existing solutions and tools attempt to address the problem of discovering relevant code snippets or components that align with specific requirements by providing search capabilities within the code repositories. The existing tools like basic text-based search engines and code analysers allow the developers to locate code snippets by keyword matching or file name identification. Moreover, other approaches include version control platforms, which facilitate collaborative development by tracking changes and dependencies between files. Additionally, large language models and generative AI systems have started assisting developers by suggesting code snippets or even generating simple functions. However, the existing solutions are often fails to account for the deeper relationships or contextual understanding required to fully harness the interconnected nature of modern codebases. Despite advancements, the existing solutions still exhibit significant limitations. The text-based search engines lack the ability to comprehend the meaning of code, leading to irrelevant or incomplete results in downstrea
Cited By — Indexed Forward Citations (0 of 0 total)
No indexed citing patents in this generation yet. Ingest USPTO/PatentsView bulk citation tables via patents-ingest to expand the local forward citation graph.
References Cited — Backward Prior Art (2)
| Patent | Title | Year | Citations |
|---|