A private intelligent code collaboration optimization method and system based on graph search
By constructing and updating a code knowledge graph in real time, and dynamically associating runtime logs with function nodes in the graph, the problem of isolation between code knowledge and runtime logs is solved. This achieves deep integration of code structure and runtime behavior, improving the efficiency and accuracy of troubleshooting and system understanding.
Patent Information
- Application Number
- CN202511888319.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-15
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2045-12-15
AI Technical Summary
In existing technologies, the code knowledge and runtime logs of private projects are isolated from each other, lacking a unified and interconnected knowledge system. This leads to a disconnect between "discovering problems" and "locating code," and the static code analysis results cannot respond in real time to project iterations and changes, posing a risk of information lag.
By acquiring the source code and runtime log data of a private project, an abstract syntax tree is generated using a Tree-sitter parser, a code knowledge graph is constructed, the code knowledge graph is updated in real time, runtime logs are associated with function nodes, and a smart agent is used to parse natural language questions into Cypher query statements to obtain query results from a graph database.
It achieves deep integration of code structure and runtime behavior, builds a unified and interconnected dynamic knowledge system, improves the efficiency and accuracy of fault diagnosis, impact analysis and system understanding, and enables developers to instantly trace from log events to specific function logic, dependent modules and change history.
Smart Images

Figure CN121326348B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of intelligent auxiliary tools for software engineering, and in particular to a private intelligent code collaboration optimization method and system based on graph retrieval. BACKGROUND
[0002] In the process of software development and operation, the source code and running logs of a private project are two important assets. The source code carries the business logic and design ideas of the system, while the running logs record the behavior state of the system in real time. As the project scale expands and the architecture becomes more complex, the dependency relationship between code modules becomes increasingly complex, and it is difficult to directly associate massive log data with specific code logic.
[0003] Currently, private intelligent code collaboration optimization based on graph retrieval mainly uses some tools based on static code analysis to generate call graphs, dependency graphs, etc. by parsing source code to help developers understand the code structure. There are also independent log management platforms for collecting, storing and keyword searching of logs. These technologies usually operate independently.
[0004] However, code knowledge and runtime logs are in a state of mutual isolation, lacking a unified and correlated knowledge system, resulting in a disconnection between the two links of "finding problems" and "locating code". The code analysis results of the existing technology are often static and cannot respond to project iterations and changes in real time, posing a risk of information lag. SUMMARY
[0005] In view of the above deficiencies of the prior art, the purpose of the embodiments of the present application is to provide a private intelligent code collaboration optimization method based on graph retrieval, which can solve the technical problems that the code knowledge and runtime logs are in a state of mutual isolation, lacking a unified and correlated knowledge system, resulting in a disconnection between the two links of "finding problems" and "locating code". The code analysis results of the existing technology are often static and cannot respond to project iterations and changes in real time, posing a risk of information lag.
[0006] The first aspect of the embodiments of the present application proposes a private intelligent code collaboration optimization method based on graph retrieval, comprising:
[0007] S1: obtaining source code files and running log data of a private project;
[0008] S2: performing syntax tree analysis on the source code files by a Tree-sitter parser to generate corresponding abstract syntax trees;
[0009] S3: based on the abstract syntax trees, constructing a code knowledge graph by analyzing function call relationships, inheritance relationships and module dependency relationships;
[0010] S4: monitoring, by the code change event processor, changes of project files in the code knowledge graph, and updating the code knowledge graph in real time when the files are changed;
[0011] S5: establishing a correlation relationship between the running log data and the corresponding function node in the code knowledge graph;
[0012] S6: based on the correlation relationship, parsing, by the intelligent Agent, the natural language question of the developer into a Cypher query statement;
[0013] S7: obtaining, according to the Cypher query statement, a query result from the graph database;
[0014] S8: formatting the query result to generate a final result.
[0015] The second aspect of the embodiment of the application provides a private intelligent code collaboration optimization system based on graph retrieval, comprising a processor and a memory.
[0016] The memory stores programs or instructions executable on the processor, and the programs or instructions are executed by the processor to implement the steps of the private intelligent code collaboration optimization method based on graph retrieval as described in the first aspect.
[0017] The third aspect of the embodiment of the application provides a readable storage medium, and the readable storage medium stores programs or instructions, and the programs or instructions are executed by the processor to implement the steps of the private intelligent code collaboration optimization method based on graph retrieval as described in the first aspect.
[0018] The technical scheme provided by the embodiment of the application has at least the following beneficial effects:
[0019] In the embodiment of the application, by constructing and updating the code knowledge graph in real time, the running log is dynamically associated with the function node in the graph, effectively solving the problem of mutual isolation of code knowledge and running time log, and the problem of static lag of traditional code analysis. This innovation realizes the deep integration of code structure and runtime behavior, and constructs a unified and associated dynamic knowledge system, thereby seamlessly connecting the log link of "finding problems" and the analysis link of "locating code", so that the developer can trace back to the specific function logic, dependent module and change history based on the latest code context, greatly improving the efficiency and accuracy of fault troubleshooting, impact analysis and system understanding. BRIEF DESCRIPTION OF DRAWINGS
[0020] The accompanying drawings are included to provide a further understanding of embodiments of the application, and are incorporated in and constitute a part of this specification. The drawings illustrate embodiments of the application and, together with the description, serve to explain principles of the application. In the drawings:
[0021] Figure 1 is a flowchart of a private intelligent code collaboration optimization method based on graph search provided by an embodiment of the application.
[0022] Figure 2 is a graph database schematic diagram provided by an embodiment of the application.
[0023] Figure 3 is a structural schematic diagram of a private intelligent code collaboration optimization system based on graph search provided by an embodiment of the application. DETAILED DESCRIPTION
[0024] In order for those skilled in the art to better understand the technical solutions in the embodiments of the application, the technical solutions of the application will be described clearly and completely below with reference to the drawings. Obviously, the described embodiments are only some of the embodiments of the application, rather than all the embodiments. It should be understood that these descriptions are only exemplary, and are not intended to limit the scope of the application. Based on the embodiments of the application, all other embodiments obtained by those of ordinary skill in the art without creative labor should fall within the scope of the application.
[0025] The private intelligent code collaboration optimization method based on graph search provided by the embodiments of the application will be described in detail below with reference to the drawings, specific embodiments and application scenarios.
[0026] Referring to the accompanying drawings, the flowchart of the private intelligent code collaboration optimization method based on graph search provided by an embodiment of the application is shown in Figure 1
[0027] The private intelligent code collaboration optimization method based on graph search provided by the embodiments of the application can include the following steps:
[0028] S1: Obtain source code files and running log data of a private project.
[0029] The private project refers to a software development project whose source code access permission is strictly limited and not open to the public.
[0030] The source code file refers to a text file written by a developer, containing program logic and data structure, and saved in a specific programming language format.
[0031] wherein, the running log data refers to the time series data stream generated automatically by the software system during the running, recording the internal state, key events and error information.
[0032] Specifically, the system first scans the project root directory, automatically identifies the package (Package) and folder (Folder) hierarchy of the code, and provides path indexing for subsequent entity extraction and dependency analysis.
[0033] S2: through the Tree-sitter parser, the syntax tree analysis is performed on the source code file, and the corresponding abstract syntax tree is generated.
[0034] wherein, the Tree-sitter parser is an incremental parser tool capable of processing multiple programming languages, used for real-time analysis of source code structure.
[0035] wherein, the syntax tree analysis refers to a computing process of constructing a structured tree representation by parsing the syntax rules of the source code as input
[0036] wherein, the abstract syntax tree (AST) refers to a tree-like abstract representation that discards parentheses, semicolons and other specific syntax details, and only retains the logical structure of the program.
[0037] In the embodiment of the application, by converting the text form of the source code into a structured tree data model, a precise syntax structure foundation is laid for subsequent automatic construction of the code knowledge graph.
[0038] In one possible implementation, S2 specifically includes:
[0039] S201: initializing the Tree-sitter parser.
[0040] S202: generating a query mode based on the initialized Tree-sitter parser.
[0041] S203: under the query mode, performing syntax analysis on each source code file to generate a corresponding abstract syntax tree.
[0042] Specifically, a Tree-sitter parser is used to analyze the syntax tree of each source code file, extract code entity information such as functions, classes, methods, variables, and comments, and generate the corresponding abstract syntax tree (AST) to establish structured nodes subsequently. The parser is loaded and initialized, and the language parser is loaded. The system loads all available Tree-sitter parsers through the load_parsers() function. Query patterns are generated, and the system generates Tree-sitter query patterns for each language. Syntax tree parsing is performed, and the file is parsed to generate an AST for each source code file. Finally, module qualified name construction is performed.
[0043] In the embodiments of the present application, the standardized parsing process ensures that source code in different programming languages can be accurately and consistently converted into a structured abstract syntax tree, providing a reliable syntax foundation for subsequent analysis.
[0044] S3: Based on the abstract syntax tree, the function call relationship, inheritance relationship, and module dependency relationship are analyzed to construct a code knowledge graph.
[0045] The function call relationship refers to the order and dependency relationship between different functions in a program, and the program execution flow and data flow can be understood by analyzing the call chain.
[0046] The inheritance relationship refers to the parent-child hierarchical relationship between classes in object-oriented programming, which allows the child class to inherit the characteristics and methods of the parent class, forming the core reuse mechanism of object-oriented programming.
[0047] The module dependency relationship refers to the organizational structure relationship between different code modules, reflecting the organization architecture and coupling degree between components.
[0048] The code knowledge graph refers to a knowledge representation form that organizes and manages code elements and their relationships in a graph structure, which completely presents the structured information of the code through nodes and edges.
[0049] In the embodiments of the present application, discrete code elements and their complex relationships are integrated into a unified and interconnected knowledge graph, realizing the systematic and visual representation of code structure and logical dependencies.
[0050] In one possible implementation, S3 specifically includes:
[0051] S301: Based on the abstract syntax tree, extract function definitions, class definitions, and qualified names to generate code entity nodes.
[0052] wherein the function definition refers to an executable code block declared in the source code by a specific syntax structure, containing elements such as function name, parameter list, return value type, and function body, used to encapsulate specific functional logic.
[0053] wherein the class definition refers to a code structure in object-oriented programming that describes the blueprint of an object, declared by a keyword and containing elements such as attributes, methods, inheritance relationships, etc., used to create specific objects with the same characteristics and behaviors.
[0054] wherein the qualified name refers to a complete naming path used in programming to uniquely identify a code entity, usually containing multiple namespace information such as module / package name, class name, etc., to avoid naming conflicts and ensure accurate reference.
[0055] wherein the code entity node refers to a basic graph node in the code knowledge graph that represents a specific program element (such as function, class, variable, etc.), containing the complete meta-information of the entity and serving as the endpoint of the relationship connection.
[0056] S302: Based on the code entity node, the function call relationship is established through function call relationship analysis.
[0057] S303: According to the class definition in the code entity node, the class inheritance relationship is established through inheritance relationship analysis.
[0058] S304: Based on the code entity node, the module dependency relationship is established through module dependency relationship analysis.
[0059] S305: Integrate all code entity nodes, function call relationships, class inheritance relationships, and module dependency relationships to construct the code knowledge graph.
[0060] Specifically, first, through pattern matching, all function definition nodes and class definition nodes are identified and extracted. Then, to avoid naming conflicts and accurately locate entities, a globally unique qualified name is constructed for each extracted function or class. The qualified name is achieved by hierarchically concatenating the entity name with its module name, and possibly the parent class name, thus clearly representing its complete namespace path in the code project.
[0061] Further, starting from the abstract syntax tree node of the function, all descendant nodes of the calling expression are extracted through pattern matching. For each calling node, by parsing its syntax structure, the name of the called target is extracted, which may come from the function name field, identifier field, or operator overload. Finally, the system uses a name resolution function to combine the extracted target name with the context information of the current module, and resolves its complete qualified name, thus accurately establishing the "CALLS" relationship edge from the caller to the callee, and storing it in the code knowledge graph.
[0062] Specifically, different pattern recognition methods are adopted for the characteristics of different programming languages. For prototype-based languages (such as JavaScript), the system recognizes inheritance relationships by querying specific assignment patterns in the syntax tree (for example, child.prototype = Object.create(parent.prototype)). For class-based languages (such as C++, Java), the system extracts direct inheritance relationships by directly parsing superclass or base class declarations in class nodes. In either case, the system ultimately constructs the identified inheritance relationships in the form of "child class INHERITS parent class" as a directed edge into the code knowledge graph.
[0063] Further, by parsing import statements (such as import, require) in the source code, a mapping table is constructed from the names used in the current module to their complete external module paths. Subsequently, the system uses this mapping table, combined with a predefined function registry and standard library path rules, to resolve the entity names used in the code to their respective module paths. Finally, these resolved module paths are used to create "DEPENDS_ON" relationship edges in the knowledge graph, accurately representing the dependencies of the current module on other internal modules or external libraries.
[0064] Specifically, the system traverses the AST cache, analyzes function call relationships, inheritance relationships, and module dependency relationships, and automatically establishes "CALLS", "IMPORTS", "EXTENDS", and other semantic edges in the knowledge graph to form a complete project-level code semantic network.
[0065] In the embodiments of the present application, by systematically extracting code entities and accurately establishing their call, inheritance, and dependency relationships, a comprehensive and interconnected code knowledge graph is constructed, providing a structured semantic foundation for deep code analysis and intelligent query.
[0066] S4: Through the code change event processor, monitor the changes of project files in the code knowledge graph, and update the code knowledge graph in real time when the files are changed.
[0067] Among them, the code change event processor refers to a system component that continuously monitors the source code repository (such as Git). When version control events such as commits and merges are detected, the incremental update process of the code knowledge graph is automatically triggered to ensure that the graph and the code repository are kept in real-time synchronization.
[0068] Among them, the project file refers to the basic organizational unit constituting the software project, which not only contains the source code file (such as.py,.java) storing program logic, but also covers configuration files, documents, build scripts and various files supporting project development and operation.
[0069] Referring to the accompanying drawings Figure 2 , a diagram of a graph database provided by an embodiment of the application is shown.
[0070] Project 1 as the root node, subordinate package 1 and file 2, wherein file 1 belongs to package 1 and the function A in it directly calls the function in file 2 B . At the same time, file 2 is associated with success logs through the running instance of version 1, and aggregates related news submitted by users, historical conversation records (including Debug records) and general inquiry records, thereby establishing a multi-dimensional association between static code structure (package, file, function call relationship) and dynamic runtime data (version, log) and development collaboration information (news, conversation), and building a unified knowledge network supporting intelligent question answering and fault tracing.
[0071] In an embodiment of the application, the real-time synchronization of the code knowledge graph and the project source code is ensured through an event-driven mechanism, effectively solving the problem that traditional static analysis lags behind code iteration, and providing continuous and accurate code knowledge support for development and operation.
[0072] In a possible implementation, S4 specifically includes:
[0073] S401: In response to a change in a project file, deleting the historical node corresponding to the changed project file and the associated edge from the graph database.
[0074] Among them, the graph database refers to a database system specially used for storing and querying graph structure data, which uses nodes, edges and attributes to represent and store data, and is particularly suitable for processing data with complex association relationships, providing underlying storage and efficient relationship query support for the code knowledge graph.
[0075] Among them, the historical node refers to the node in the code knowledge graph, which is used to represent a specific state (such as a submission, a version or a release) in the evolution process of the software project, records the metadata (such as timestamp, submitter, version number) of the state, and associates the code entity with dynamic information such as running log and news record in the time dimension.
[0076] Among them, the associated edge refers to the directed or undirected edge connecting two nodes in the graph database, which is used to clearly represent the specific semantic relationship (such as call, inheritance, contain, dependency, generation, etc.) between nodes, and is the basis for building and traversing the complex relationship network in the code knowledge graph.
[0077] S402: Clear the abstract syntax tree cache and function registry in memory associated with the changed project file.
[0078] Wherein, the abstract syntax tree cache refers to a memory or disk cache mechanism for storing the parsed abstract syntax tree corresponding to the source code file, and its core purpose is to avoid repeated parsing of unmodified files, thereby significantly improving performance when updating the code knowledge graph incrementally or multiple times.
[0079] Wherein, the function registry refers to a centralized index or dictionary created and maintained during the construction of the code knowledge graph, which stores the mapping relationship between the qualified name of all functions extracted from the project and its corresponding AST node or graph node, mainly used for fast target analysis and association when analyzing function call relationships.
[0080] S403: Re-parsing the changed project file to generate a first abstract syntax tree.
[0081] S404: Based on the first abstract syntax tree, re-execute function call relationship analysis, inheritance relationship analysis, and module dependency relationship analysis.
[0082] S405: Update the nodes and relationship edges obtained by analysis to the graph database, and update the code knowledge graph in real time.
[0083] Wherein, the node refers to the most basic data unit in the knowledge graph, used to represent an independent entity or object. In the code knowledge graph, nodes can represent functions, classes, modules, versions, developers, and other specific elements, each node contains a unique identifier and a set of attributes describing the characteristics of the entity.
[0084] Wherein, the relationship edge refers to a directed or undirected edge connecting two nodes, used to accurately describe the association type and semantics between nodes. In the code knowledge graph, relationship edges define specific logical relationships through labels (such as CALLS, INHERITS, CONTAINS), forming a structured network between nodes, supporting complex graph traversal and query operations.
[0085] Specifically, the system is built-in CodeChangeEventHandler (code change event handler) to continuously monitor the changes of project files (including adding, modifying, deleting, etc.). When the file is changed, the system automatically performs the following procedures: deleting the old data nodes and edges corresponding to the file in the Neo4j graph database. Clearing the AST cache and function registry associated with the file in memory. Parsing the modified file and generating a new syntax tree. Recalculating function calls and dependencies based on the updated AST. Real-time updating of knowledge graph nodes and edges to ensure global consistency and integrity. Through this mechanism, the application realizes the dynamic maintenance and continuous evolution of the code knowledge graph, ensuring the timeliness and accuracy of knowledge.
[0086] In the embodiments of the application, through the event-driven incremental update mechanism, the real-time performance of the knowledge graph is ensured while effectively avoiding the performance overhead of full reconstruction, significantly improving the analysis and response efficiency of large-scale code libraries.
[0087] S5: Establishing an association relationship between the running log data and the corresponding function node in the code knowledge graph.
[0088] Among them, the function node refers to a node in the code knowledge graph that represents a specific function definition. This node not only contains the basic identity information of the function (such as its qualified name), but also stores various attributes related to the function (such as parameter list, return value type, file path, etc.), which is the core entity in the graph that carries function-level code knowledge.
[0089] Among them, the association relationship refers to the connection between any two or more entity nodes in the code knowledge graph, which has a specific semantic meaning. It is a general term that covers all types of relationship edges (such as call, inheritance, containment, dependency, etc.), describing the mutual connection between entities in structure, logic or behavior, and together forming the semantic network of the graph.
[0090] Specifically, the system automatically captures log information of the project during compilation, running and testing through the LogMonitor (log monitoring module), including error stack, warning information, execution time and running environment parameters, etc. The captured log data is preprocessed and associated with the corresponding function node in the code knowledge graph (such as "TRIGGERED_BY", "FAILED_AT", etc.), realizing the semantic binding of runtime behavior and code structure. Through this module, the system can directly locate the specific function, call chain and corresponding commit record that caused the exception when the developer queries, thereby realizing automatic problem tracing and repair suggestion generation based on GraphRAG.
[0091] In the embodiment of the application, by establishing an explicit association between the running log and the code structure, the information barrier between the dynamic running state and the static code state is successfully broken down, providing key support for log-based fault diagnosis and code positioning.
[0092] S6: Based on the association relationship, the natural language question of the developer is parsed into a Cypher query statement through an intelligent agent.
[0093] Among them, the intelligent agent refers to a software agent with autonomous reasoning and learning ability, which receives the natural language input of the developer in the system, and automatically completes the whole process task from question analysis to code knowledge graph query through a series of actions such as understanding, planning, knowledge calling, etc.
[0094] Among them, the natural language question refers to the query request of the developer in daily language (such as Chinese and English) instead of programming syntax, for example, "find all modules that call function A", the system needs to understand its semantics and convert it into a structured query.
[0095] Among them, the Cypher query statement is a declarative query language specially designed for graph databases (such as Neo4j), which uses intuitive symbolic patterns to describe the nodes, relationships and paths to be found.
[0096] In the embodiment of the application, the natural language intention is accurately converted into a structured query through an intelligent agent, which significantly reduces the technical threshold for developers to query the code knowledge graph, and realizes the naturalization and intelligentization of human-computer interaction.
[0097] In one possible implementation, S6 specifically includes:
[0098] S601: Receive the natural language question of the developer.
[0099] S602: Recall the most relevant recall context from the code knowledge graph through the RAG structure.
[0100] Among them, the RAG structure refers to the system architecture of retrieval and generation, and its core process is "retrieval-generation". First, the user query is encoded into a vector, and the relevant documents or information fragments (recall context) are retrieved from the knowledge base. Then, these contexts and the original query are submitted to the large language model together to guide it to generate a more fact-based final answer. This structure effectively combines the knowledge accuracy of dense retrieval and the powerful reasoning ability of large models.
[0101] Among them, the recall context refers to the set of information fragments related to the current question retrieved from external knowledge sources (such as code knowledge graph, document library) through the retrieval augmented generation (RAG) process. These fragments are provided as supplementary evidence to the large language model, aiming to improve the accuracy and factualness of its generated answers, and avoid "hallucinations" produced purely by model parameters.
[0102] In one possible implementation, S602 specifically includes:
[0103] S6021: encode the natural language question into a vector:
[0104] .
[0105] Among them, represents the natural language question, represents the vector representation of the natural language question.
[0106] S6022: based on the vector, retrieve similar nodes from the vector database to obtain a set of similar nodes:
[0107] .
[0108] Among them, V represents the set of candidate vectors of entities in the code knowledge graph, represents the maximum value parameter, represents the similarity function, represents the i th candidate vector, represents the set of similar nodes.
[0109] Among them, the vector database is a database system specially used for storing, indexing and retrieving high-dimensional vector data. It realizes efficient approximate nearest neighbor search by calculating the similarity (such as cosine similarity) between vectors, and is used in this system to store the vectorized representation of entity nodes in the code knowledge graph, so as to realize fast similarity retrieval based on semantics.
[0110] Among them, the similar node refers to the node with similar distance to the query vector in the vector space. In the RAG process, the natural language question is encoded into a query vector, and the K nodes with the highest similarity are searched in the vector database. These retrieved nodes are the similar nodes, which constitute the recall context required for generating answers.
[0111] S6023: based on the set of similar nodes, extract the description information and associated relationships of the corresponding similar nodes from the code knowledge graph to form the recall context.
[0112] Among them, the description information refers to the attribute data used to depict and explain the characteristics of the nodes or relationship edges in the knowledge graph. For nodes, the description information can include metadata such as name, type, code location, creation time, etc. For relationship edges, the description information can define its type, strength, direction, etc. semantic characteristics, which is the core embodiment of the semantic richness of the graph.
[0113] In the embodiments of the present application, by combining semantic vector retrieval with graph relationship extraction, an enhanced context rich in semantic and structural information is constructed, which provides key support for subsequent accurate understanding of complex code query intent.
[0114] S603: Based on the recalled context, the natural language question is semantically analyzed and the intent is identified to determine the query target.
[0115] Among them, semantic analysis refers to the process of converting the user's natural language query into a standardized logical form or structured query that can be understood and executed by machines. In this system, it is responsible for deeply understanding the entities, relationships and constraints in the question, and mapping them into the core elements of the knowledge graph query, laying the foundation for generating accurate Cypher statements.
[0116] Among them, intent recognition is a key task in natural language processing, aiming to determine the true purpose or operation type that the user wants to perform behind the input. In this scenario, it needs to accurately identify whether the developer's question is to "query the calling relationship", "trace the code change history" or "get the running log", etc. to determine the overall structure and target of the query.
[0117] S604: Through the named entity recognition model, the entities involved in the natural language question are identified:
[0118] .
[0119] Among them, represents the i th entity name identified, represents the i th entity type, represents the named entity recognition model, represents the entity set involved in the natural language question.
[0120] Among them, the named entity recognition model refers to a natural language processing model used to automatically identify and classify specific entity information from natural language text. In the present application, this model is responsible for accurately identifying key entities such as function names, class names, module names, developer names, etc. from the questions raised by developers, and labeling their pre-defined types, laying the foundation for accurately mapping these entities to the corresponding nodes in the knowledge graph.
[0121] S605: Map the entity to the corresponding entity node in the code knowledge graph:
[0122] .
[0123] wherein, denotes a set of entities of the i th entity type, denotes a max value parameter, denotes a similarity function, denotes a text encoder, denotes the j th candidate node vector, denotes a mapping function.
[0124] S606: Generate a Cypher query statement based on the query target and the entity node.
[0125] Specifically, the developer inputs a natural language question through the Agent interface, such as: "In which module is this function called?" or "Why did the recent build fail?". Using the RAG (Retrieval-Augmented Generation) structure, the most relevant node descriptions, relationships, and code snippets are recalled from the code knowledge graph or knowledge base.
[0126] Further, under the RAG (Retrieval-Augmented Generation) framework, the system first vectorizes and encodes the user's natural language question and performs semantic retrieval to recall the most relevant code knowledge context. Specifically, the system uses a pre-trained text encoder (such as BERT, CodeBERT) to map the question Q into a high-dimensional vector q . Subsequently, by calculating the cosine similarity between the vector q and all entity vectors v i in the knowledge graph, the top K nodes with the highest similarity are retrieved from the vector database (such as Milvus). Finally, these recalled node information (including function descriptions, class definitions, associated logs, etc.) are combined into a context set , providing key structured knowledge support for subsequent large model generation of accurate answers.
[0127] For example, the similarity function commonly uses cosine similarity:
[0128] .
[0129] wherein, denotes the cosine similarity, denotes the norm.
[0130] Specifically, the large model understands the user's query intent (query structure, operation type, constraint condition, etc.). The entities involved in the question are identified and mapped to entity types in Neo4j. After obtaining the recall context, the large model first performs semantic analysis and intent recognition on the natural language question, outputting the core elements of the query in a structured form, including target entities, operation types, and constraint conditions. Subsequently, the system identifies specific entity names and their types (such as functions, classes, etc.) mentioned in the question through a named entity recognition model, and maps these entities to corresponding nodes in the knowledge graph. Finally, the system integrates the parsed query intent and mapped entity nodes to automatically generate accurate Cypher graph query statements, thereby realizing intelligent querying and knowledge acquisition of the code knowledge graph.
[0131] For example, the Cypher output by the model can generally follow the following form: MATCH (f1:Function {name: 'function A'}) - [:CALLS] -> (f2:Function). RETURN f2.name, or a more general form:
[0132] .
[0133] The specific splicing logic can be defined by rules or let the model learn by itself: the components include MATCH, which is used to define nodes and relationships in the graph. WHERE, which is used for filtering conditions (time, author, submission times, etc.). And RETURN, which is used to specify output fields. For example:
[0134] .
[0135] For example, in the full flow example, the input query statement is "Query all functions that call function foo foo", the output process is as follows: In the vector retrieval stage, the system recalls the node context related to function foo foo. In the intent recognition stage, the system identifies that the user's intent is "query function call relationship". In the entity recognition stage, the system identifies the entity e 1 = f foo and its type t 1 = Function . Finally, in the Cypher generation stage, the system automatically generates the graph query statement "MATCH (f:Function) - [:CALLS] -> (g:Function {name: 'foo'}) RETURN f".
[0136] In the embodiments of the present application, by fusing semantic retrieval, intent recognition and entity linking technologies, ambiguous natural language questions are accurately converted into executable graph query commands, realizing end-to-end intelligent conversion from user intent to code knowledge retrieval.
[0137] S7: Obtain the query result from the graph database according to the Cypher query statement.
[0138] In the embodiments of the present application, by efficiently executing structured graph queries, abstract code knowledge is converted into specific node relationship data, providing accurate and reliable information sources for problem solving.
[0139] In a possible implementation, S7 specifically includes:
[0140] S701: Execute the Cypher query statement to obtain a preliminary query result set from the graph database.
[0141] S702: Detect the integrity of the preliminary query result set.
[0142] S703: When the preliminary query result set is incomplete, obtain the completion information by extended query or calling external tools.
[0143] S704: Concatenate the completion information with the preliminary query result set to form an enhanced context.
[0144] Among them, the enhanced context refers to a set of information fragments highly related to the current question obtained by searching external knowledge sources (such as code knowledge graph, document library) in the RAG (retrieval enhancement generation) process.
[0145] S705: Based on the enhanced context, the result is merged by calling the LLM to generate the query result:
[0146] .
[0147] Among them, represents the final output query result, represents the fusion function, represents the preliminary query result set, represents the external tool output, represents the large language model processing.
[0148] LLM refers to a large language model, which is a deep learning model trained on massive text data with hundreds of billions or even trillions of parameters. It can understand and generate natural language, complete complex tasks such as question answering, translation, and code generation. In a private environment, LLM provides intelligent assistance to the development team on the premise of ensuring the internal code, technical solutions, and business data of the enterprise are not leaked.
[0149] Specifically, the system executes the generated Cypher statement to obtain the query result from the graph database. If the result is insufficient, the Agent can call external tools (such as source code file reading, running log analyzer, etc.) for information completion. The system first executes the Cypher query generated by the large model, for example:
[0150] MATCH (f:Function)-[:CALLS]->(g:Function {name: "foo"})
[0151] RETURN f.name
[0152] Then execute through the Neo4j driver:
[0153] results = neo4j_driver.run(cypher_query).data()
[0154] At this time, the result set is recorded as:
[0155] .
[0156] For example, defining "insufficient results" usually has three types: insufficient number of results, incomplete information dimension, and semantic inconsistency or context ambiguity.
[0157] Insufficient number of results specifically refers to the query result being empty or the number being lower than the expected threshold , , for example, the user asks "which functions call A ", and the result is empty, indicating that the calling edge information is missing in the graph.
[0158] Incomplete information dimension specifically refers to the lack of key fields required by the problem semantics in the returned result. For example, the user asks: "which functions call foo and throw exceptions in the log?" But the query result only contains the calling relationship, without the "exception log" field, which is a dimension missing. Field checking function can be used:
[0159] .
[0160] If , then it needs to be completed.
[0161] Specifically, semantic inconsistency or ambiguous context refers to the semantic inconsistency between the query return result and the question, for example: the user asks "the last submission", but the query result does not contain timestamp or the sorting field. The user asks "the same module containing function foo and bar ", and the result does not contain module-level aggregation information. Such cases can be checked by the large model on the result:
[0162] .
[0163] If the score is less than the threshold τ , it is determined to be "insufficient". When the result is detected to be insufficient, the Agent enters the "information completion" link.
[0164] Further, the completion path can be divided into two types: internal graph completion and external completion. The first type of internal graph completion specifically refers to automatically expanding the neighborhood query if there are related nodes in the graph but not directly associated, which can be expanded by adjacency:
[0165] .
[0166] Wherein, represents the order neighbor of node k . Indirect calls across one layer are allowed to complete potential association functions. Then through attribute reasoning, if some attributes are missing, they can be estimated by the attributes of similar nodes:
[0167] .
[0168] For example, if the module label of the function is missing, it can be estimated by the module label of other functions in the same file.
[0169] The second type of external completion specifically refers to when the internal information of the graph is insufficient, the Agent can call external tool chains.
[0170] In the embodiments of the present application, through multi-source information fusion and intelligent result optimization, the completeness, accuracy and readability of the query result are significantly improved, and the information returned to the developer is comprehensive and directly usable.
[0171] S8: Format the query result to generate the final result.
[0172] Specifically, the query result is displayed in Markdown form after formatting, including function definition, call chain relationship diagram, running log summary and other contents.
[0173] Among them, the format processing refers to the process of converting the original data or non-regular query result according to the pre-defined specification format which is easy for human to read or for machine to further process. The purpose is to improve the clarity, readability and usability of information, such as converting the graph query result into hierarchical JSON, clear table or concise natural language summary.
[0174] In the embodiment of the application, by converting the original graph data into clear and readable format, the presentation effect of the query result is significantly improved, so that the developer can quickly understand and apply the obtained information.
[0175] In a possible implementation, after S8, it further includes:
[0176] S9: structurally store the natural language question, Cypher query statement and final result of this interaction, and include them in the Graph RAG knowledge index to form a reusable semantic knowledge unit.
[0177] Among them, the structured storage refers to the way of organizing and managing data according to a specific data model (such as the table of relational database, the node and edge of graph database). It emphasizes the existence of clear association and constraint between data, which is different from the unstructured pure text, so as to support efficient and accurate query and calculation, such as storing code knowledge in the form of graph structure in Neo4j.
[0178] Among them, the Graph RAG knowledge index is a special index structure constructed for the realization of Graph RAG, which usually includes two parts: one is to convert the entities and relationships in the code knowledge graph into a vector index of high-dimensional vectors, which is used for semantic similarity retrieval. The second is the graph structure index which retains its original topological connection, which is used for relation reasoning. The two are combined to support information retrieval from both semantic and structural dimensions.
[0179] Among them, the semantic knowledge unit refers to the smallest logical block extracted from the code or document, which carries independent and complete semantic information. It is not only a keyword or a fragment, but also a whole with clear meaning in a specific context, such as a function definition, a class description, a complete API description or a solution record. It is the basic unit for building high-quality knowledge index and recalling context.
[0180] Specifically, the system structurally stores the content of this dialogue (including the question, the query statement and the execution result) into a JSON document, and automatically includes it in the Graph RAG knowledge index to form a reusable semantic knowledge unit, which provides quick retrieval and answer reuse for subsequent similar problems.
[0181] In the embodiment of the application, by continuously accumulating human-computer interaction experience, a self-evolving knowledge ecosystem is constructed, and the adaptability and accuracy of the system in dealing with complex queries are significantly improved, laying a foundation for long-term knowledge precipitation and intelligent optimization.
[0182] In actual application, an intelligent code collaboration system deeply integrating static code structure and dynamic running data is constructed. First, the source code is parsed by Tree-sitter to generate an abstract syntax tree, and then a code knowledge graph containing function calls, inheritance relationships and module dependencies is constructed. Through real-time monitoring of code changes, the graph is dynamically updated, and running logs are associated with function nodes. Finally, the natural language query is parsed into a Cypher statement by an intelligent Agent, and the retrieval is enhanced by combining GraphRAG and LLM intelligent processing to obtain accurate results from the code knowledge graph. The panoramic integration of code knowledge is realized, and the static code structure, dynamic running logs and development collaboration data are unified and integrated, breaking the information silos. An intelligent natural interaction experience is provided, and the query threshold is reduced through natural language understanding technology, enabling developers to quickly obtain deep code information. A self-evolving knowledge system is constructed, and the knowledge index is optimized by continuously accumulating interactive data, forming a virtuous cycle of getting smarter with use. This design significantly improves the code understanding efficiency, fault positioning speed and team collaboration efficiency.
[0183] The technical scheme provided by the embodiment of the application has at least the following beneficial effects:
[0184] In the embodiment of the application, by constructing and real-time updating the code knowledge graph, the running logs are dynamically associated with the function nodes in the graph, effectively solving the problem of isolation between code knowledge and running time logs, and the static lag problem of traditional code analysis. This innovation realizes the deep integration of code structure and runtime behavior, and constructs a unified and associated dynamic knowledge system, thereby seamlessly connecting the log link of "finding problems" and the analysis link of "locating code", enabling developers to trace back to specific function logic, dependent modules and change history based on the latest code context, greatly improving the efficiency and accuracy of fault troubleshooting, impact analysis and system understanding.
[0185] Reference is made to the accompanying drawings Figure 3 The accompanying drawings show a structure schematic diagram of a private intelligent code collaboration optimization system based on graph retrieval provided by the embodiment of the application.
[0186] The embodiment of the application provides a private intelligent code collaboration optimization system 20 based on graph retrieval, which comprises a processor 201 and a memory 202.
[0187] The memory 202 stores programs or instructions executable on the processor 201, which, when executed by the processor 201, implement the steps of the private intelligent code collaboration optimization method based on graph retrieval described above, and achieve the same technical effects. For the sake of brevity, the present application will not repeat the same.
[0188] It should be understood that the processor 201 in the embodiments of the present application can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), ready programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or can also be any conventional processor.
[0189] It should also be understood that the memory 202 in the embodiments of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM) or a flash memory. The volatile memory can be a random access memory (RAM) used as an external cache. By way of example but not limitation, many forms of random access memory are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct memory bus random access memory (Direct Rambus RAM, DR RAM).
[0190] The above-described embodiments can be implemented in whole or in part by software, hardware (e.g., circuitry), firmware, or any combination of the three. When implemented in software, the above-described embodiments can be implemented in the form of one or more computer programs that are stored in a computer-readable storage medium. The computer-readable storage medium can be loaded into a computer, and the computer can execute the computer program to wholly or partially produce the processes or functions described in the embodiments of the present application. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable apparatus. The computer program can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another computer-readable storage medium, for example, the computer program can be transferred from one website, computer, server, or data center to another website, computer, server, or data center through a wired (e.g., infrared, wireless, microwave, etc.) manner. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that includes one or a collection of available media. The available media can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium. The semiconductor medium can be a solid state disk.
[0191] It should be understood that the size of the sequence number of each process described above in various embodiments of the present application does not mean the order of execution, and the execution order of each process should be determined by its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0192] Those of ordinary skill in the art can realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be realized in electronic hardware, or a combination of computer software and electronic hardware. Whether the functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Those of ordinary skill in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0193] Those of ordinary skill in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the devices, apparatuses and units described above can refer to the corresponding processes in the foregoing method embodiments, which will not be described here.
[0194] In several embodiments provided by the present application, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other manners. For example, the embodiments of the apparatus described above are merely schematic. For example, the division of the units is only a logical function division. There can be another division manner for the actual implementation. For example, a plurality of units or components can be combined or integrated into another device, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections between different units, can be indirect couplings or communication connections through some interfaces, devices or units, and can be in electrical, mechanical or other forms.
[0195] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e., can be located in one place, or can be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0196] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can be physically present separately, or two or more units can be integrated into one unit.
[0197] If the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the part of the present application that essentially contributes to the prior art or the part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.
[0198] The embodiment of the present application provides a readable storage medium, which includes: a program or instruction stored on the readable storage medium, the program or instruction is executed by a processor to realize the steps of the private intelligent code collaboration optimization method based on image retrieval described above, and the same technical effect can be achieved. To avoid repetition, the present application will not be described again.
[0199] It should be pointed out finally that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present application, but not to limit them. Although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those skilled in the art that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced equivalently; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application. Any changes or replacements that can be easily thought of by those skilled in the art within the technical scope disclosed by the present application should be covered within the protection scope of the present application.
Claims
1. A private intelligent code collaboration optimization method based on graph search, characterized in that, Comprise: S1: acquire source code files and running log data of private projects; S2: parse the source code files through the Tree-sitter parser, and generate corresponding abstract syntax trees through syntax tree analysis; S3: based on the abstract syntax tree, analyze function call relationship, inheritance relationship and module dependency relationship, and construct code knowledge graph; S4: through the code change event processor, monitor the changes of project files in the code knowledge graph, and update the code knowledge graph in real time when the files are changed; S5: the running log data and the corresponding function node in the code knowledge graph are associated; S6: based on the association relationship, the natural language question of the developer is parsed into Cypher query statement through intelligent Agent; S7: according to the Cypher query statement, query result is obtained from the graph database; S8: the query result is formatted to generate the final result.
2. The graph search based private intelligent code collaboration optimization method according to claim 1, characterized in that, After S8, it further comprises: S9: the natural language question, the Cypher query statement and the final result of this interaction are stored in structure, and are included in Graph RAG knowledge index to form reusable semantic knowledge unit.
3. The graph search based private intelligent code collaboration optimization method according to claim 1, wherein, The S2 specifically comprises: S201: initialize the Tree-sitter parser; S202: based on the initialized Tree-sitter parser, generate query mode; S203: under the query mode, parse the syntax of each source code file to generate corresponding abstract syntax tree.
4. The graph search based private intelligent code collaboration optimization method according to claim 1, wherein, The S3 specifically comprises: S301: based on the abstract syntax tree, extract function definition, class definition and qualified name to generate code entity node; S302: based on the code entity node, the calling relationship between functions is established through function call relationship analysis; S303: according to the class definition in the code entity node, the class inheritance relationship is established through inheritance relationship analysis; S304: based on the code entity node, the inter module dependency relationship is established through module dependency relationship analysis; S305: integrate all the code entity nodes, the calling relationship between functions, the class inheritance relationship and the inter module dependency relationship to construct the code knowledge graph.
5. The graph search based private intelligent code collaboration optimization method according to claim 1, wherein, The S4 specifically comprises: S401: in response to the change of the project file, delete the historical nodes corresponding to the changed project file and the associated edges from the graph database; S402: clear the abstract syntax tree cache and function registry associated with the changed project file in the memory; S403: reanalyze the changed project file to generate the first abstract syntax tree; S404: based on the first abstract syntax tree, reexecute function call relationship analysis, inheritance relationship analysis and module dependency relationship analysis; S405: update the nodes and relationship edges obtained by analysis to the graph database to update the code knowledge graph in real time.
6. The graph search based private intelligent code collaboration optimization method according to claim 1, wherein, The S6 specifically comprises: S601: receive the natural language question of the developer; S602: Recall a recall context most relevant to the natural language question from the code knowledge graph through the RAG structure; S603: Perform semantic analysis and intent recognition on the natural language question based on the recall context to determine the query target; S604: Identify the entity involved in the natural language question through a named entity recognition model; ; wherein, denotes the identified i entity name, denotes the i entity type, denotes the named entity recognition model, denotes the set of entities involved in the natural language question; S605: Map the entity to the corresponding entity node in the code knowledge graph; ; wherein, represents a set of entities of a i represents a max-pooling parameter, represents a similarity function, represents a text encoder, represents a j represents a mapping function; S606: Generate the Cypher query statement based on the query target and the entity node.
7. The graph search based private intelligent code collaboration optimization method according to claim 6, wherein, The S602 specifically includes: S6021: Encode the natural language question into a vector; ; wherein, represents a natural language question, represents a vector representation of the natural language question; S6022: Retrieve similar nodes from a vector database based on the vector to obtain a similar node set; ; wherein, V represents a candidate vector set of an entity in a code knowledge graph, represents a maximum value parameter, represents a similarity function, represents a candidate vector, i represents a similar node set; S6023: Extract the description information and associated relationships of the similar nodes from the code knowledge graph based on the similar node set to form the recall context.
8. The graph search based private intelligent code collaboration optimization method according to claim 1, wherein, The S7 specifically includes: S701: Execute the Cypher query statement to obtain a preliminary query result set from the graph database; S702: Detect the integrity of the preliminary query result set; S703: When the preliminary query result set is incomplete, obtain completion information through extended query or call external tools; S704: Concatenate the completion information with the preliminary query result set to form an enhanced context; S705: Based on the enhanced context, perform result merging through calling LLM to generate the query result: ; wherein, represents the final output query result, represents a fusion function, represents a preliminary query result set, represents an external tool output, represents a large language model processing.
9. A private intelligent code collaboration optimization system based on graph search, characterized in that, Including: A processor and a memory; The memory stores programs or instructions that can be run on the processor, and the programs or instructions are executed by the processor to realize the steps of the private intelligent code collaboration optimization method based on graph retrieval as claimed in any one of claims 1 to 8.
10. A readable storage medium, characterized by, The readable storage medium stores programs or instructions, and the programs or instructions are executed by the processor to realize the steps of the private intelligent code collaboration optimization method based on graph retrieval as claimed in any one of claims 1 to 8.
Citation Information
Patent Citations
Warehouse level code problem solving system based on large language model
CN119576384A
Intelligent Bug management method and platform based on AI large model
CN120909929A