Question and answer method and device, equipment and storage medium
By using knowledge graphs and retrieval enhancement generation techniques in a multi-document environment, natural language answers are generated, and the problem of semantic understanding of large language models in a multi-document environment is solved, and multi-file association parsing and unified semantic understanding are realized.
Patent Information
- Application Number
- CN202411860508.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-17
AI Technical Summary
Existing large language models are difficult to achieve unified semantic understanding in a multi-document environment.
In response to the first query request, the relevant location is positioned based on the pre-constructed knowledge graph, and the multi-document content is retrieved based on the relevant location, and combined with the multi-document content, a natural language answer is generated through the search enhancement generation technology.
It realizes multi-file association parsing, can perform unified semantic understanding in a multi-document environment, and improves the global understanding and question-and-answer capabilities of the code.
Smart Images

Figure CN119884299A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information retrieval technology, and in particular to a question-answering method, apparatus, device, and storage medium. Background Art
[0002] With the development of deep learning, big data and high-performance computing, people have begun to build increasingly powerful large language models. Large language models are trained on massive amounts of text data and have the ability to understand and generate human language.
[0003] However, existing large language models have difficulty in achieving unified semantic understanding in a multi-document environment.
[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of this application is to provide a question-answering method, apparatus, device and storage medium, aiming to solve the technical problem that existing large language models are difficult to perform unified semantic understanding in a multi-document environment.
[0006] To achieve the above purpose, the present application proposes a question-answering method, wherein the method comprises:
[0007] In response to the first query request, locate the relevant location based on the pre-built knowledge graph;
[0008] Retrieving multiple document contents based on the relevant locations;
[0009] Combining the multi-document contents, a natural language answer is generated through retrieval-enhanced generation technology.
[0010] In one embodiment, the step of locating the relevant location based on the pre-built knowledge graph in response to the first query request includes:
[0011] Extract key entities from project code;
[0012] The knowledge graph is constructed based on the association relationship between the key entities.
[0013] In one embodiment, the step of constructing the knowledge graph based on the association relationship between the key entities includes:
[0014] Performing data processing on the project code to obtain a processed document;
[0015] A knowledge base is constructed based on the processed documents and the knowledge graph.
[0016] In one embodiment, the step of locating the relevant location based on the pre-built knowledge graph in response to the first query request includes:
[0017] In response to the first query request, obtaining a question raised by a user in the first query request;
[0018] Constructing context structure prompt words based on the question raised by the user;
[0019] The relevant position is located in the knowledge base through the context structure prompt word.
[0020] In one embodiment, the step of combining the contents of multiple documents and generating a natural language answer by using a search-enhanced generation technique includes:
[0021] The natural language answer is generated by combining the context structure prompt words, the question raised by the user and the multi-document content through retrieval enhancement generation technology.
[0022] In one embodiment, the step of combining the multi-document contents and generating a natural language answer by using a search-enhanced generation technique comprises:
[0023] In response to the second query request, a corresponding subgraph is output based on the knowledge graph.
[0024] In one embodiment, the step of outputting a corresponding subgraph based on the knowledge graph in response to the second query request includes:
[0025] In response to the second query request, obtaining a request for displaying a corresponding structure diagram in the second query request;
[0026] Converting the request for displaying the corresponding structure graph into a declarative graph query language;
[0027] The declarative graph query language is used to query the knowledge graph and output the corresponding subgraph.
[0028] In addition, to achieve the above purpose, the present application also proposes a question-answering device, which includes:
[0029] A positioning module, configured to locate a relevant location based on a pre-built knowledge graph in response to the first query request;
[0030] A retrieval module, used for retrieving multiple document contents based on the relevant positions;
[0031] The answer generation module is used to combine the multi-document contents and generate a natural language answer through retrieval enhancement generation technology.
[0032] In addition, to achieve the above-mentioned purpose, the present application also proposes a question-and-answer device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the question-and-answer method described above.
[0033] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the question-and-answer method described above are implemented.
[0034] One or more technical solutions proposed in this application have at least the following technical effects:
[0035] The present application locates the relevant position based on a pre-built knowledge graph in response to a first query request, retrieves multiple document contents based on the relevant position, combines the multiple document contents, and generates a natural language answer through retrieval enhancement generation technology. Thus, by combining the knowledge graph and retrieval enhancement generation technology, multi-file association analysis can be achieved, thereby achieving unified semantic understanding in a multi-document environment. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0037] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0038] Figure 1 A flowchart diagram of the first embodiment of the question-and-answer method of this application;
[0039] Figure 2 A flowchart of the question-and-answer method for this application for retrieving the contents of multiple documents;
[0040] Figure 3 A schematic diagram of the process of generating natural language answers for the question-answering method of this application;
[0041] Figure 4 A schematic diagram of the process of constructing the knowledge graph for the question-answering method of this application;
[0042] Figure 5 Generate a rendering of the knowledge graph of the question-answering method for this application;
[0043] Figure 6This is a flowchart of the word segmentation operation in the question-answering method of this application;
[0044] Figure 7 This is a schematic diagram of the overall process of the question-and-answer method for this application;
[0045] Figure 8 This is a schematic diagram of the module structure of the question-answering device according to an embodiment of the present application;
[0046] Fig. 9 A schematic diagram of the device structure of the hardware operating environment involved in the question-and-answer method in the embodiment of the present application.
[0047] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0048] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0049] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0050] The main solution of the embodiment of the present application is: in response to the first query request, locate the relevant position based on the pre-built knowledge graph; retrieve multiple document contents based on the relevant position; combine the multiple document contents and generate a natural language answer through retrieval enhancement generation technology.
[0051] In this embodiment, for ease of description, the question-answering system is used as the execution subject for explanation below.
[0052] Existing large language models are difficult to perform unified semantic understanding in a multi-document environment.
[0053] The present application provides a solution. The present application locates the relevant position based on a pre-built knowledge graph in response to a first query request, retrieves multiple document contents based on the relevant position, combines the multiple document contents, and generates a natural language answer through retrieval enhancement generation technology. In this way, multi-file association analysis can be achieved by combining the knowledge graph and retrieval enhancement generation technology, so that unified semantic understanding can be performed in a multi-document environment.
[0054] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device, a question-and-answer device, etc. that can realize the above functions, or an electronic system, a question-and-answer system, etc. that can realize the above functions. The following takes the question-and-answer system as an example to illustrate this embodiment and the following embodiments.
[0055] Currently, code assistance tools play an increasingly important role in the software development process. Taking automotive software development as an example, automotive software development has high complexity and high reliability requirements, involving cross-module and cross-system code dependencies and interface relationships. Many code parsing tools can help developers understand, debug and optimize code, but existing mainstream tools have significant deficiencies in multi-document association parsing, cross-language support, and data security, especially when supporting complex automotive software projects.
[0056] The existing technical solutions and their shortcomings are as follows:
[0057] 1. Limitations of single document parsing tools. Most existing code assistance tools, such as static code analysis tools (e.g. SonarQube, PMD) and code parsing functions in some integrated development environments (IDEs) (e.g. IntelliJ IDEA, Visual Studio Code), mainly perform syntax checking, error detection, and basic code refactoring on a single file. Although these tools play an important role in improving code quality and detecting potential problems, they lack multi-document association analysis capabilities and cannot handle cross-file call relationships and dependency paths in complex automotive software projects. They are unable to meet the modular analysis and system-level collaboration requirements in automotive software development, which affects developers' understanding of the global structure and logic, especially in terms of cross-file calls and module dependency resolution, forming information islands and increasing the difficulty of development and debugging.
[0058] 2. Insufficient code plug-ins based on large language models. Although current code plug-ins based on large language models (such as GitHub Copilot, Tabnine, etc.) can generate code snippets through natural language and support functions such as code completion and error suggestions, they are mainly based on single-file or single-context analysis. For the in-depth analysis of global correlation information across files and modules in automotive software, such plug-ins cannot provide sufficient support and lack project-level multi-document association capabilities and system structure perspectives. This is particularly inconvenient for understanding complex automotive electronic system code structures, interface dependencies, etc.
[0059] 3. Lack of cross-file association analysis: Existing code analysis tools and large language model plug-ins are mainly limited to single document processing, making it difficult to achieve global analysis of multi-file associations in automotive software development projects, and unable to support cross-file call chains and dependency queries.
[0060] 4. Does not support multi-document comprehensive query: Existing large language model plug-ins are difficult to perform unified semantic understanding in a multi-document environment, and cannot identify the complex association information between functions, classes, and modules scattered in different files in automotive software projects, which makes it inconvenient for developers to understand the system architecture.
[0061] 5. Lack of a global perspective of project-level code: Large-scale automotive software projects often require developers to understand the global structure and logic of the code. However, existing tools fail to provide this global perspective. Developers need to manually find the connections between files, which increases the difficulty of development and debugging.
[0062] 6. Data security and privacy protection issues: Some code assistance tools, especially cloud-based code analysis and Q&A tools (such as GitHub Copilot and Tabnine), need to upload user code to cloud servers for processing. Although this cloud service provides powerful computing resources, it brings data privacy and security risks. For enterprise users in automotive software development, the code content often involves commercial secrets and is difficult to upload to external servers easily. When using cloud code assistance tools, enterprise users face the risk of data leakage, especially for enterprises in the automotive industry that require data to be highly autonomous, controllable and compliant. These cloud services cannot meet their strict data privacy requirements. Enterprise users often need to balance data privacy and tool functions. Many existing code parsing tools rely on cloud services for computing, which brings the risk of data leakage when processing enterprise-level automotive software project code. The automotive industry has strict requirements for data security. Code content is the core asset of the enterprise and requires processing in a localized environment to ensure data autonomy and control.
[0063] Based on this, the embodiment of the present application provides a question-answering method, referring to Figure 1 , Figure 1 A flowchart diagram is provided for Example 1 of the question-and-answer method of this application.
[0064] In this embodiment, the question-answering method includes steps S50 to S70:
[0065] Step S50, in response to the first query request, locating the relevant location based on the pre-built knowledge graph;
[0066] It should be noted that the knowledge graph is used to store and manage semantic information in project-level codes to facilitate subsequent multi-document association retrieval.
[0067] Among them, the retrieval module based on the knowledge graph can locate the relevant nodes and edges in the knowledge graph according to the query request input by the user to realize multi-document related retrieval.
[0068] Among them, semantic retrieval based on knowledge graph supports code parsing across files and multiple documents.
[0069] Step S60, retrieving and obtaining multiple document contents based on the relevant positions;
[0070] Among them, the retrieval module supports retrieval based on semantic relationships to ensure that the found code snippets or documents have logical associations.
[0071] You can refer to Figure 2 , Figure 2 A flowchart of retrieving multiple document contents by the question-and-answer method of this application.
[0072] like Figure 2 As shown, various attributes (packages, classes, methods, etc.) are extracted from the project-level source files to build a Neo4j graph database, thereby obtaining a knowledge graph. By adding structural information to the knowledge graph, a knowledge base is obtained. Based on the query request input by the user, the query result, that is, the multi-document content, can be obtained by searching in the knowledge base.
[0073] Unlike existing code assistance tools that are usually limited to single document parsing, the present invention focuses on multi-document association parsing of automotive software projects. It can analyze complex dependencies and module call paths in automotive software across files, filling the gap in project-level code association parsing in this field.
[0074] Step S70, combining the multi-document contents and generating a natural language answer through retrieval enhancement generation technology.
[0075] Among them, the multi-document content can be combined through a generation module to generate a natural language answer through retrieval enhancement generation technology.
[0076] Among them, retrieval-enhanced generation technology is a natural language processing technology (NLP) that combines the advantages of information retrieval and text generation. It aims to enhance the generation capability of the large language model (LLM) by utilizing external knowledge sources. Through retrieval-enhanced generation technology, multi-document content is aggregated into natural language answers.
[0077] Among them, the generation module can extract key content from complex multi-document information and present the answer in a user-readable form.
[0078] Reference Figure 3 , Figure 3 A schematic diagram of the process of generating natural language answers for the question-answering method of this application;
[0079] like Figure 3 As shown, based on the query request input by the user and the query results retrieved from the knowledge base, the answer result is generated by the large language model LLM.
[0080] This application combines the Retrieval Enhanced Generation (RAG) technology with the Knowledge Graph to build a KG-RAG system suitable for automotive software development, which implements multi-document association processing of project-level code. Through this system, the global understanding and question-answering capabilities of the code can be improved, providing more accurate cross-file support for the complex code structure of automotive software.
[0081] As another implementation, an end-to-end pre-trained model (such as GPT or BERT) can also be used to perform multi-round conversational multi-document parsing, which is suitable for providing basic code understanding and question-answering support in automotive software development projects. Although there is no advantage of retrieval-generation separation, the ability to understand project-level code can be improved by increasing the amount of pre-training on automotive software data.
[0082] As another implementation, a traditional full-text search tool (such as Elasticsearch) can be used as a search module, and the retrieved content can be directly handed over to the code parsing module. This solution is suitable for short problem parsing scenarios in automotive software, reducing the generation steps and reducing system complexity.
[0083] In response to data security issues, this application provides a full-process local deployment solution, where all data processing is completed locally to prevent data leakage and meet the needs of data autonomy and control.
[0084] As an implementation method, in automotive software projects where data security requirements are not high, a cloud-based isolation environment (such as a virtual private cloud VPC) can be used instead of local deployment to ensure data security through strict permission management and data isolation strategies.
[0085] As another implementation, client data encryption can also be used to transmit encrypted data to the cloud for processing. This is suitable for small and medium-sized enterprises in automobile research and development, and provides a compromise data privacy protection solution.
[0086] This embodiment provides a question-and-answer method, which locates the relevant position based on a pre-built knowledge graph in response to a first query request, retrieves multiple document contents based on the relevant position, and generates natural language answers through retrieval enhancement generation technology in combination with the multiple document contents. Thus, by combining the knowledge graph and retrieval enhancement generation technology, multi-file association parsing can be achieved, so that unified semantic understanding can be performed in a multi-document environment. In addition, this application constructs a KG-RAG system by combining the knowledge graph (KG) and retrieval enhancement generation (RAG) technology, which can achieve multi-document association parsing of automotive software at the project level. The system can analyze the relationships such as function calls, class inheritance, module dependencies, etc. in the code across files, filling the gap of single document parsing, and providing developers with more comprehensive and accurate code understanding and question-and-answer capabilities to improve the application effect in complex automotive software projects.
[0087] In addition, to meet the strict data security requirements of automobile companies, this application provides a full-process local deployment solution, which keeps all data processing processes within the enterprise intranet to ensure the autonomy and privacy of data, avoid data leakage risks, and meet the company's high-standard management requirements for information security.
[0088] When dealing with project-level code, current technologies face the following technical problems, taking automotive software projects as an example:
[0089] Poor adaptability of project-level code parsing: Many automotive software projects use multiple programming languages to develop systems and components. Each language should adopt a specific word segmentation strategy, but existing tools cannot accurately parse and segment different languages, making it difficult to meet the parsing needs in a multi-language project environment.
[0090] Based on the above problems, based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as the first embodiment can be referred to the above introduction, and will not be repeated later. On this basis, step S50, in response to the first query request, before locating the relevant position based on the pre-built knowledge graph, the question-answering method also includes steps S10 to S20:
[0091] Step S10, extracting key entities from the project code;
[0092] Step S20, constructing the knowledge graph based on the association relationship between the key entities.
[0093] It should be noted that key entities (such as functions, classes, variables) and their associations (such as calling relationships, dependency relationships, etc.) can be extracted from the project code and constructed into a knowledge graph.
[0094] Reference Figure 4 , Figure 4 A schematic diagram of the process of constructing the knowledge graph for the question-answering method of this application;
[0095] like Figure 4 As shown, various attributes (packages, classes, methods, etc.) are extracted from the project-level original files, and a Neo4j graph database is constructed to obtain a knowledge graph.
[0096] Reference Figure 5 , Figure 5 Generate a rendering of the knowledge graph of the question-answering method for this application;
[0097] like Figure 5 As shown, the BluetoothPairListLiveData class contains or references many files and methods, such as the BluetoothPairListLiveData.java file, the HfpDeviceListLiveData class, the onInactive method, the onActive method, the updateList method, the onReceive method, and the BluetoothPairListLiveData method; the HfpDeviceListLiveData class contains the onInactive method, the onActive method, and the onReceive method; the BluetoothStateLiveData class contains the onInactive method, the onActive method, and the onReceive method; the MainActivity.java file references the BluetoothPairListLiveData class, the BluetoothStateLiveData class, and the HfpDeviceListLiveData class; the MiniActivity.java file references the BluetoothPairListLiveData class, the BluetoothStateLiveData class, and the HfpDeviceListLiveData class.
[0098] As another implementation method, a graph database can also be used to build the relationship between nodes and edges between code documents, which is suitable for complex code dependency scenarios in automotive software development. Hierarchical structure files based on JSON or XML can be used to build the dependency structure between documents according to the hierarchical relationship, which is suitable for modular structure management in automotive software and achieves similar multi-document association effects.
[0099] Furthermore, for the multiple programming languages involved in the project code, this application has designed a multilingual word segmentation module. This module supports code parsing in different programming languages, applies specific word segmentation strategies according to the characteristics of different programming languages (such as Java, Python, etc.), ensures the accuracy of word segmentation, and improves the question-answering effect of the system in multilingual projects. Figure 6 , Figure 6 This is a flowchart of the word segmentation operation in the question-and-answer method of this application. As another implementation method, the dedicated word segmenter can also be replaced with a general regular expression word segmentation method, which is suitable for scenarios where different languages are mixed in automotive software but the word segmentation accuracy requirement is not high, providing simple multi-language support.
[0100] In automotive software projects, multiple programming languages are usually involved. The present invention designs specific word segmentation methods and strategies for different programming languages, thereby improving the code parsing and question-answering effects of the KG-RAG system in a multi-language environment, ensuring efficient support for code understanding and problem-solving in a multi-language code environment.
[0101] As another implementation, a natural language processing library (such as NLTK or SpaCy) may be used in conjunction with a custom dictionary, which is suitable for automotive software projects that require lower word segmentation accuracy and can meet basic code snippet extraction requirements.
[0102] The embodiment of the present application visualizes the entity relationships in the code by constructing a knowledge graph, records the dependencies and associations between the codes, and thus improves the efficiency of code management.
[0103] This application designs a multilingual word segmentation module and develops specific word segmentation strategies for multiple programming languages commonly used in automotive software development. It improves the accuracy of code parsing and the effect of question and answer in multilingual projects, ensures that the semantics and logical structure of the code in different language environments are accurately understood, and thus supports cross-module and cross-language collaborative development.
[0104] Based on the second embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those in the second embodiment can be referred to the above description, and will not be repeated in the following. On this basis, in step S20, after the knowledge graph is constructed based on the association relationship between the key entities, the question-answering method further includes steps S30 to S40:
[0105] Step S30, performing data processing on the project code to obtain a processed document;
[0106] For example, you can convert project code into a file in markdown format.
[0107] Step S40, constructing a knowledge base based on the processed documents and the knowledge graph.
[0108] Add structural information to the knowledge graph, and combine the large language model with the markdown format file and the knowledge graph with added structural information through open source frameworks such as langchain to obtain a knowledge base.
[0109] The embodiment of the present application can reduce the construction complexity of the knowledge base by performing data processing on the project code and building a knowledge base based on the processed documents and knowledge graphs.
[0110] Based on the third embodiment of the present application, in the fourth embodiment of the present application, the same or similar contents as those in the third embodiment can be referred to the above description, and will not be described in detail later. On this basis, step S50, in response to the first query request, locates the relevant position based on the pre-built knowledge graph, including steps S51 to S53:
[0111] Step S51, in response to the first query request, obtaining a question raised by a user in the first query request;
[0112] The user may ask a question to construct a first query request.
[0113] Step S52, constructing context structure prompt words based on the question raised by the user;
[0114] Among them, the context structure prompt words are simplifications or abstractions of user questions, which can guide the system to search for relevant information more efficiently in the knowledge base.
[0115] The construction of context structure prompt words may involve the extraction of question keywords, semantic analysis, and rule matching based on specific fields or knowledge bases.
[0116] Step S53: locate the relevant position in the knowledge base through the context structure prompt word.
[0117] Among them, context structure prompt words can be used as search keywords to locate the location of information or data related to the problem in the knowledge base.
[0118] By constructing context structure prompt words, the embodiment of the present application can more accurately understand the user's questions and more efficiently locate relevant information in the knowledge base, which can significantly shorten the query time and improve the user experience.
[0119] Based on the fourth embodiment of the present application, in the fifth embodiment of the present application, the same or similar contents as those in the fourth embodiment can be referred to the above description, and will not be repeated hereafter. On this basis, step S70, combining the multi-document content, generating a natural language answer through retrieval enhancement generation technology includes step S71:
[0120] Step S71, combining the context structure prompt words, the question raised by the user and the multi-document content, and generating the natural language answer through retrieval enhancement generation technology.
[0121] First, the context structure clues are parsed to understand the background of the user's question and the scope of the information required.
[0122] Natural language understanding (NLU) technology is then used to parse and understand the questions asked by users, including identifying key concepts in the questions, intent, and type of information required.
[0123] Then, based on the user's question and context structure prompt words, information retrieval technology is used to retrieve the documents or paragraphs most relevant to the user's question from the multi-document content. Furthermore, the documents or paragraphs most relevant to the user's question can be retrieved through indexing, query construction and matching algorithms of the document content.
[0124] Finally, natural language generation technology is used to generate natural language answers from the retrieved relevant documents. Furthermore, the retrieved information can be extracted, integrated, reorganized and expressed.
[0125] The embodiment of the present application generates the natural language answer by combining the context structure prompt words, the question raised by the user and the multi-document content through retrieval enhancement generation technology, retrieves the document or paragraph most relevant to the user question from the multi-document content, and generates a natural language answer based on the most relevant document or paragraph.
[0126] Based on the first embodiment of the present application, in the sixth embodiment of the present application, the same or similar contents as those in the first embodiment can be referred to the above description, and will not be described in detail later. On this basis, step S70, combining the multi-document content, and generating a natural language answer through the retrieval enhancement generation technology includes step S80:
[0127] Step S80, in response to the second query request, output a corresponding subgraph based on the knowledge graph.
[0128] The user may request to obtain the corresponding structure diagram to construct a second query request.
[0129] Step S80 includes steps S81 to S83:
[0130] Step S81, in response to the second query request, obtaining a request for displaying a corresponding structure diagram in the second query request;
[0131] Step S82, converting the request for displaying the corresponding structure diagram into a declarative graph query language;
[0132] Among them, the declarative graph query language is a language specifically designed for querying and manipulating graph data, allowing users to specify the information they want to retrieve from a graph database (such as a knowledge graph) in a declarative way.
[0133] Step S83, querying the knowledge graph using the declarative graph query language, and outputting the corresponding subgraph.
[0134] By executing the query, the system can find entities and relationships related to the request and build a subgraph based on this information. This subgraph is the structural diagram that the user wants to display, which contains a part of the knowledge graph content that the user is interested in. Finally, the system outputs this subgraph as the query result, which may be displayed to the user in the form of a graphical interface, or returned to the caller in some data format.
[0135] The embodiment of the present application responds to the second query request, obtains a request for displaying the corresponding structure graph in the second query request, converts the request for displaying the corresponding structure graph into a declarative graph query language, queries the knowledge graph through the declarative graph query language, and outputs the corresponding subgraph. The declarative graph query language can be used to quickly query the knowledge graph, thereby improving query efficiency.
[0136] For example, to help understand the implementation process of the question-answering method obtained by combining this embodiment with the above-mentioned embodiment 1, please refer to Figure 7 , Figure 7 This is a schematic diagram of the overall process of the question-and-answer method for this application.
[0137] Specifically, the process includes the following steps:
[0138] (1) The administrator uploads files and decompresses project files or packaged files. The decompression supports multiple formats, such as zip, 7z, rar, etc.
[0139] (2) Knowledge graph construction: Use scripts to preprocess the unzipped original project files, identify all entities (such as functions, classes, variables) and relationships (such as calls, dependencies, etc.), and construct this information into a knowledge graph. The knowledge graph is stored in a graph database or other data structure to form a semantic network of the project code.
[0140] (3) User input query: The user enters a natural language query question in the interface, such as “What is the calling relationship of the function getData?”
[0141] (4) Retrieval module retrieves related documents: The system’s retrieval module uses the knowledge graph to identify definitions and call locations related to getData and find multiple documents involving the function. For example, the system recognizes that getData is defined in file A.java and is called in files B.java and C.java.
[0142] (5) Multiple document contents are passed to the generation module: The retrieval module returns multiple documents containing getData definitions and call information, and these contents are input into the generation module as context.
[0143] (6) Generate answers by the generation module: The generation module uses RAG technology to generate natural language answers based on the context. For example, the answer may be "getData function is defined in file A.java and is called in method Y of file B.java and method Z of file C.java".
[0144] (7) The unzipped original project file is processed to obtain the md document, which is combined with the knowledge graph after adding structural information to generate the knowledge base through the langchain framework.
[0145] (8) The user selects to display the corresponding structure diagram, and the request to display the corresponding structure diagram is converted into a declarative graph query language cypher to obtain a cypher command.
[0146] (9) Performing a query in the knowledge graph using the declarative graph query language and outputting the corresponding subgraph.
[0147] (10) Data security assurance: The entire processing process is carried out in a local deployment environment, and all data operations are completed within the enterprise's internal network to ensure data security and privacy protection.
[0148] It should be noted that the question-answering system can include the following five modules:
[0149] (1) Knowledge graph construction module: It provides a semantic network of project-level codes and provides basic association information for the retrieval module.
[0150] (2) Retrieval module: Based on the query conditions entered by the user, relevant code snippets and their associated files are found from the knowledge graph, and this information is passed to the generation module.
[0151] (3) Generation module: Use RAG technology to generate natural language answers from the retrieved multi-document content, so that users can clearly understand the code relationship across files.
[0152] (4) Code language specific word segmentation module: supports the system to parse codes in different languages and ensure the accuracy of question and answer in cross-language projects.
[0153] (5) Data security and local deployment module: It protects the data privacy of enterprise users and runs locally throughout the process to ensure data security.
[0154] In order to more clearly demonstrate the operation process of this solution, a specific scenario is assumed for illustration below.
[0155] Suppose there is a complex project containing 100 Java files, and the user wants to know "how the function getData is called in the project".
[0156] In traditional code assistance tools, users need to open files one by one to find the definition and call status of the getData function, which is not only time-consuming, but also easy to miss cross-file related information. However, through the project-level code parsing and question-answering platform of the present invention, users can quickly obtain the complete call relationship and location of the getData function. The following is a specific implementation process.
[0157] 1. User input query: The user enters a question in the platform, such as "How is the function getData called in the project?".
[0158] 2. The retrieval module calls the knowledge graph: The retrieval module will first call the knowledge graph to identify the definition location and calling relationship of the getData function in the code.
[0159] The knowledge graph uses the definition of the getData function and all associated call locations as nodes, and uses the call relationships as edges to connect these nodes.
[0160] The retrieval module determines through graph structure analysis that the getData function is defined in file A.java and referenced in files B.java and C.java.
[0161] 3. Passing multi-document content to the generation module: The retrieval module passes the multi-document information of the getData function definition and call found to the generation module.
[0162] At this time, the context information received by the generation module includes: the definition location (A.java) and the reference location (method Y in B.java and method Z in C.java) of the getData function.
[0163] 4. The generation module generates a natural language answer: The generation module combines the user's question and the context information provided by the retrieval module to generate a natural language answer.
[0164] A sample answer might be: "The getData function is defined in file A.java and is called in method Y in file B.java and method Z in file C.java."
[0165] 5. Output results to users: The system displays the generated answers to users through the user interface. Users can obtain the call status of the getData function in the project through simple natural language queries.
[0166] The advantage of this multi-document parsing is that the system can complete cross-file code call parsing within a few seconds, allowing users to gain a comprehensive understanding of project-level code.
[0167] As an implementation method, a multi-document parsing system based on code snippet annotation can be designed to replace the KG-RAG technical architecture, pre-annotate the core code snippets in the automotive software project, and generate metadata index libraries such as calls and definitions. This solution is suitable for automotive software projects with simple code structures, avoids the complexity of knowledge graph construction, and meets basic multi-document parsing requirements.
[0168] As another implementation method, a multi-document code parsing platform integrated with API can be designed to build a code assistance tool, which can be integrated with project management platforms (such as GitHub and GitLab) through API to directly obtain the code file organization structure and call relationship of the automotive software project. This solution reduces the use of local storage resources and is suitable for cross-module dependency parsing of large automotive software projects.
[0169] As another implementation, you can also design a question-and-answer system based on the project code analysis library, use open source code analysis libraries (such as CodeQL, JDT) to build a parsing system, and support the question-and-answer function by generating code dependencies between multiple documents. This solution is particularly suitable for complex code dependency analysis in automotive software projects, and reduces the complexity of graph construction and RAG processes through the automatic generation of dependency information.
[0170] The beneficial effects of this program include the following four aspects:
[0171] 1. Improved efficiency of project-level multi-document parsing: Compared with existing code-assisted tools, the present invention significantly improves the efficiency of multi-document association parsing in automotive software projects. In experimental tests, the parsing speed of the present invention is about 30% to 40% faster than that of single-document parsing tools, and the response time is reduced by about 35% when processing automotive software projects containing more than 50 code files. This improvement enables developers to understand the global structure of complex projects more quickly, improving the efficiency of the automotive software development process.
[0172] 2. Improvement of Q&A accuracy: By combining RAG and knowledge graph technology, a KG-RAG system optimized for automotive software development was built, which significantly improved the accuracy of project-level code Q&A. Experimental data shows that when the system handles multi-document Q&A tasks in automotive software projects, the accuracy is 20% to 25% higher than that of single-document processing tools, effectively improving developers' ability to solve cross-module and cross-file problems.
[0173] 3. Code segmentation accuracy optimization: For the various programming languages commonly used in automotive software projects, the present invention designs a specific segmentation strategy, which improves the accuracy of the KG-RAG system in multi-language code parsing by 15% to 20%. Tests on languages such as Java, Python, and JavaScript show that the present invention reduces the question-answering error caused by incorrect segmentation, reduces the question-answering error rate in cross-language automotive software projects by 18%, and improves the accuracy of code understanding.
[0174] 4. Data security and confidentiality guarantee: Considering the data confidentiality requirements of automobile companies, the present invention adopts full-process local deployment to ensure the autonomous controllability of data. Compared with code-assisted tools that rely on the cloud, the local deployment solution of the present invention effectively avoids the risk of data leakage and meets the information security management requirements of the automobile industry. Experiments show that the satisfaction of automobile R&D companies has increased by about 30%, while reducing security compliance costs by about 20%.
[0175] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the question-and-answer method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0176] This application also provides a question-and-answer device, please refer to Figure 8 , the question-answering device comprises:
[0177] A positioning module 10, configured to locate a relevant location based on a pre-built knowledge graph in response to a first query request;
[0178] A retrieval module 20, configured to retrieve multiple document contents based on the relevant positions;
[0179] The answer generation module 30 is used to combine the multi-document contents and generate a natural language answer through retrieval enhancement generation technology.
[0180] The question-answering device provided by the present application adopts the question-answering method in the above embodiment, which can solve the technical problem that the existing large language model is difficult to perform unified semantic understanding in a multi-document environment. Compared with the prior art, the beneficial effects of the question-answering device provided by the present application are the same as the beneficial effects of the question-answering method provided by the above embodiment, and the other technical features in the question-answering device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0181] The present application provides a question-and-answer device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the question-and-answer method in the above-mentioned embodiment 1.
[0182] Reference below Fig. 9 , which shows a schematic diagram of the structure of a question-answering device suitable for implementing the embodiment of the present application. The question-answering device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig. 9 The question-and-answer device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0183] like Fig. 9As shown, the question-answering device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the question-answering device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the question-answering device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a question-answering device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0184] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0185] The question-answering device provided by the present application adopts the question-answering method in the above embodiment, which can solve the technical problem that the existing large language model is difficult to perform unified semantic understanding in a multi-document environment. Compared with the prior art, the beneficial effects of the question-answering device provided by the present application are the same as the beneficial effects of the question-answering method provided by the above embodiment, and other technical features in the question-answering device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0186] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0187] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0188] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the question-answering method in the above-mentioned embodiment.
[0189] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0190] The computer-readable storage medium may be included in the question-answering device; or may exist independently without being assembled into the question-answering device.
[0191] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the question-and-answer device, the question-and-answer device: responds to a first query request, locates a relevant position based on a pre-built knowledge graph; retrieves multiple document contents based on the relevant positions; and generates a natural language answer by combining the multiple document contents through retrieval enhancement generation technology.
[0192] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0193] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0194] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0195] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned question-answering method, and can solve the technical problem that the existing large language model is difficult to perform unified semantic understanding in a multi-document environment. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the question-answering method provided in the above-mentioned embodiment, and will not be repeated here.
[0196] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A question-answering method, characterized in that: The method comprises: In response to the first query request, locate the relevant location based on the pre-built knowledge graph; Retrieving multiple document contents based on the relevant locations; Combining the multi-document contents, a natural language answer is generated through retrieval-enhanced generation technology.
2. The method according to claim 1, characterized in that The step of locating the relevant location based on the pre-built knowledge graph in response to the first query request includes: Extract key entities from project code; The knowledge graph is constructed based on the association relationship between the key entities.
3. The method according to claim 2, characterized in that The step of constructing the knowledge graph based on the association relationship between the key entities includes: Performing data processing on the project code to obtain a processed document; A knowledge base is constructed based on the processed documents and the knowledge graph.
4. The method according to claim 3, characterized in that The step of locating the relevant location based on the pre-built knowledge graph in response to the first query request includes: In response to the first query request, obtaining a question raised by a user in the first query request; Constructing context structure prompt words based on the question raised by the user; The relevant position is located in the knowledge base through the context structure prompt word.
5. The method according to claim 4, characterized in that The step of combining the contents of multiple documents and generating a natural language answer by using the retrieval enhancement generation technology comprises: The natural language answer is generated by combining the context structure prompt words, the question raised by the user and the multi-document content through retrieval enhancement generation technology.
6. The method according to claim 1, characterized in that The step of combining the multi-document contents and generating a natural language answer by using a search enhancement generation technique comprises: In response to the second query request, a corresponding subgraph is output based on the knowledge graph.
7. The method according to claim 6, characterized in that The step of outputting a corresponding subgraph based on the knowledge graph in response to the second query request includes: In response to the second query request, obtaining a request for displaying a corresponding structure diagram in the second query request; Converting the request for displaying the corresponding structure graph into a declarative graph query language; The declarative graph query language is used to query the knowledge graph and output the corresponding subgraph.
8. A question-answering device, characterized in that: The device comprises: A positioning module, configured to locate a relevant location based on a pre-built knowledge graph in response to the first query request; A retrieval module, used for retrieving multiple document contents based on the relevant positions; The answer generation module is used to combine the multi-document contents and generate a natural language answer through retrieval enhancement generation technology.
9. A question-answering device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the question-answering method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the question-and-answer method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method and system for extracting knowledge graph from software project data and answering knowledge graph
CN108959433A
Traditional Chinese medicine question and answer method and device based on long document retrieval enhancement generation and medium
CN117828050A
Question and answer method and device based on large language model, electronic equipment and storage medium
CN117891927A
Knowledge retrieval enhancement generation method and system based on large language model
CN118394890A
Text generator training method and device
CN118410140A
Cited By
Markdown Zip packaging method and security enhancement method
CN121256862A
A Markdown Zip Packaging Method and Security Enhancement Method
CN121256862B