Question and answer method, device, apparatus, and storage medium

By constructing knowledge graphs and using retrieval-enhanced generation technologies, combined with end-to-end local deployment, the challenge of semantic understanding of large language models in multi-document environments has been solved, improving the code parsing efficiency and security of automotive software projects and providing more accurate cross-file support.

CN119884299BActive Publication Date: 2025-12-26SHENZHEN FARBEN INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411860508.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-17
Publication Date
2025-12-26
Estimated Expiration
2044-12-17

AI Technical Summary

Technical Problem

Existing large language models struggle to achieve unified semantic understanding in multi-document environments. In particular, they lack the ability to perform global correlation parsing across files and modules and ensure data security in automotive software projects, which increases the difficulty of development and debugging.

Method used

By constructing a knowledge graph, relevant locations are located based on the pre-built knowledge graph, multi-document content is retrieved, and natural language answers are generated by combining retrieval enhancement generation technology to achieve multi-file association parsing. At the same time, data security is ensured by adopting full-process local deployment.

Benefits of technology

It enables unified semantic understanding in a multi-document environment, improves the global understanding of project-level code, enhances the accuracy and efficiency of question answering, and meets the automotive industry's needs for data autonomy, controllability, and security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119884299B_ABST
    Figure CN119884299B_ABST
Patent Text Reader

Abstract

The application discloses a question and answer method, device and equipment and a storage medium, relates to the technical field of information retrieval, and comprises the following steps: in response to a first query request, locating a relevant position based on a pre-constructed knowledge graph; retrieving multiple document contents based on the relevant position; and generating a natural language answer by using a retrieval enhancement generation technology in combination with the multiple document contents, so that unified semantic understanding can be performed in a multiple document environment.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of information retrieval, and particularly relates to a question answering method and device, equipment and a storage medium. BACKGROUND

[0002] With the development of deep learning, big data and high-performance computing, people have begun to build more and more powerful large language models. Through training on a large amount of text data, the large language model has the ability to understand and generate human language.

[0003] However, the existing large language model is difficult to perform unified semantic understanding in a multi-document environment.

[0004] The above content is only used to assist in understanding the technical solutions of the present application, and does not represent the acknowledgement of the above content as prior art. SUMMARY

[0005] The main purpose of the present application is to provide a question answering method, device, equipment and storage medium, which aims to solve the technical problem that the existing large language model is difficult to perform unified semantic understanding in a multi-document environment.

[0006] To achieve the above purpose, the present application provides a question answering method, which comprises:

[0007] In response to a first query request, locating a relevant position based on a pre-constructed knowledge graph;

[0008] Retrieving multi-document content based on the relevant position;

[0009] Generating a natural language answer through retrieval enhancement generation technology in combination with the multi-document content.

[0010] In an embodiment, the step of locating a relevant position based on a pre-constructed knowledge graph in response to a first query request comprises:

[0011] Extracting key entities from project code;

[0012] Constructing the knowledge graph based on the association relationship between the key entities.

[0013] In an embodiment, the step of constructing the knowledge graph based on the association relationship between the key entities comprises:

[0014] Performing data processing on the project code to obtain a processed document;

[0015] Constructing a knowledge base based on the processed document and the knowledge graph.

[0016] In an embodiment, the step of locating the relevant location based on the pre-constructed knowledge graph in response to the first query request comprises:

[0017] In response to the first query request, a question raised by a user is obtained in the first query request;

[0018] A context structure prompt word is constructed based on the question raised by the user;

[0019] The relevant location is located in the knowledge base through the context structure prompt word.

[0020] In an embodiment, the step of generating a natural language answer through retrieval augmented generation technology in combination with multi-document content comprises:

[0021] The natural language answer is generated through retrieval augmented generation technology in combination with the context structure prompt word, the question raised by the user and the multi-document content.

[0022] In an embodiment, the step of generating a natural language answer through retrieval augmented generation technology in combination with multi-document content comprises:

[0023] In response to a second query request, a corresponding subgraph is output based on the knowledge graph.

[0024] In an embodiment, the step of outputting a corresponding subgraph based on the knowledge graph in response to a second query request comprises:

[0025] In response to the second query request, a request for displaying a corresponding structure graph is obtained in the second query request;

[0026] The request for displaying the corresponding structure graph is converted into a declarative graph query language;

[0027] A query is performed in the knowledge graph through the declarative graph query language, and the corresponding subgraph is output.

[0028] In addition, to achieve the above-mentioned purposes, the present application further provides a question and answer device, which comprises:

[0029] A locating module is configured to locate a relevant location based on a pre-constructed knowledge graph in response to a first query request;

[0030] A retrieval module is configured to retrieve multi-document content based on the relevant location;

[0031] An answer generation module is configured to generate a natural language answer through retrieval augmented generation technology in combination with the multi-document content.

[0032] In addition, to achieve the above object, the present application further provides a question and answer device, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the question and answer method as described above.

[0033] In addition, to achieve the above object, the present application further provides a storage medium, which is a computer readable storage medium, and the storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the question and answer method as described above.

[0034] The one or more technical solutions provided by the present application have at least the following technical effects:

[0035] The present application can realize multi-file correlation analysis by combining knowledge graph and retrieval and enhanced generation technology, so as to realize unified semantic understanding in a multi-document environment. BRIEF DESCRIPTION OF DRAWINGS

[0036] The accompanying drawings incorporated in and forming a part of the specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the application.

[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced as follows. Obviously, for those skilled in the art, other drawings can also be obtained based on these drawings without creative labor.

[0038] Figure 1 Flowchart for question and answer method embodiment one of the present application;

[0039] Figure 2 Flowchart for retrieving multi-document content in the question and answer method of the present application;

[0040] Figure 3 Flowchart for generating natural language answers in the question and answer method of the present application;

[0041] Figure 4 Flowchart for constructing knowledge graph in the question and answer method of the present application;

[0042] Figure 5 Effect diagram for generating knowledge graph in the question and answer method of the present application;

[0043] Figure 6A flowchart of a word segmentation operation in the question and answer method of the present application;

[0044] Figure 7 A flowchart of the overall question and answer method of the present application;

[0045] Figure 8 A module structure diagram of the question and answer device of the embodiment of the present application;

[0046] Figure 9 A device structure diagram of the hardware operating environment involved in the question and answer method in the embodiment of the present application.

[0047] The object implementation, functional features and advantages of the present application will be further described with reference to the accompanying drawings in conjunction with the embodiments. 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 do not limit the present application.

[0049] In order to better understand the technical solutions of the present application, the following will be described in detail in conjunction with the drawings and specific embodiments of the specification.

[0050] The main solution of the embodiment of the present application is: in response to a first query request, locating a relevant position based on a pre-constructed knowledge graph; retrieving multiple document contents based on the relevant position; and generating a natural language answer through retrieval enhancement generation technology in combination with the multiple document contents.

[0051] In the embodiment, for the convenience of description, the following is described with the question and answer system as the execution subject.

[0052] Since the existing large language model is difficult to perform unified semantic understanding in a multi-document environment.

[0053] The present application provides a solution, which generates a natural language answer through retrieval enhancement generation technology in combination with the multiple document contents based on the pre-constructed knowledge graph and the relevant position retrieved based on the relevant position in response to a first query request, so that the multi-file correlation analysis can be realized by combining the knowledge graph and the retrieval enhancement generation technology, and thus unified semantic understanding can be performed in a multi-document environment.

[0054] It should be noted that the execution subject of the 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 will be described with the question and answer system as an example.

[0055] Currently, code-assisted tools play an increasingly important role in the software development process. Taking the development of automotive software as an example, automotive software development has high complexity and high reliability requirements, involving cross-module, cross-system code dependencies and interface relationships. Many code analysis tools can help developers understand, debug and optimize code, but existing mainstream tools have significant shortcomings in multi-document association analysis, cross-language support and data security, especially when supporting complex automotive software projects.

[0056] The prior art solutions and their shortcomings are as follows:

[0057] 1. Limitations of single-document analysis tools. Most existing code-assisted tools, such as static code analysis tools (e.g., SonarQube, PMD) and some integrated development environments (IDE) code analysis features (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, making it difficult to meet the modular analysis and system-level collaboration needs in automotive software development, thereby affecting developers' understanding of the overall structure and logic, especially in terms of cross-file calls, module dependency relationship analysis, etc., forming information silos and increasing the difficulty of development and debugging.

[0058] 2. Limitations of code plugins based on large language models. Current code plugins based on large language models (e.g., GitHub Copilot, Tabnine, etc.) can generate code snippets through natural language and support code completion, error suggestions, etc., but they are mainly based on single-file or single-context analysis. For deep analysis of global association information across files and modules in automotive software, such plugins 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 plugins are mainly limited to single-document processing and cannot achieve global analysis of multi-file associations in automotive software development projects, making it difficult to support cross-file call chains and dependency relationship queries.

[0060] 4. Lack of support for multi-document comprehensive query: Existing large language model plugins have difficulty in performing unified semantic understanding in a multi-document environment, and cannot identify complex association information between functions, classes, and modules scattered in different files in a car software project, which brings inconvenience to developers in understanding the system architecture.

[0061] 5. Lack of global perspective of project-level code: Large car software projects often require developers to understand the global structure and logic of the code, but existing tools fail to provide this global perspective, and developers need to manually search for file associations, increasing the difficulty of development and debugging.

[0062] 6. Data security and privacy protection issues: Some code assistance tools, especially cloud-based code analysis and question-answering tools (such as GitHub Copilot, Tabnine), require users to upload their code to cloud servers for processing. Although such cloud services provide powerful computing resources, they also pose data privacy and security risks. For enterprise users in the automotive software development industry, code content often involves business secrets and cannot be easily uploaded to external servers. Enterprise users face the risk of data leakage when using cloud-based code assistance tools, especially for enterprises in the automotive industry that require high data autonomy and compliance. These cloud services cannot meet the strict data privacy needs of such enterprises. Enterprise users often need to balance data privacy and tool functionality. Many existing code analysis tools rely on cloud services for computation, which poses a risk of data leakage when processing enterprise-level car software project code. The automotive industry has strict requirements for data security, and code content is the core asset of the enterprise, requiring processing in a localized environment to ensure data autonomy.

[0063] Based on this, the embodiments of the present application provide a question-answering method, referring to Figure 1 , Figure 1 the flowchart provided by the first embodiment of the question-answering method of the present application.

[0064] In this embodiment, the question-answering method includes steps S50-S70:

[0065] Step S50, in response to a first query request, locating a relevant position based on a pre-constructed knowledge graph;

[0066] It should be noted that the knowledge graph is used to store and manage semantic information in the project-level code, facilitating subsequent multi-document association retrieval.

[0067] Among them, based on the retrieval module of the knowledge graph, according to the query request input by the user, the relevant nodes and edges in the knowledge graph are located to realize multi-document association retrieval.

[0068] Among them, the knowledge graph-based semantic retrieval supports code parsing across files and multiple documents.

[0069] Step S60: Retrieve multiple document contents based on the relevant locations;

[0070] The retrieval module supports searching by semantic relationships, ensuring that the found code snippets or documents are logically related.

[0071] You can refer to Figure 2 , Figure 2 This is a flowchart illustrating the process of retrieving multi-document content using the question-and-answer method described in this application.

[0072] like Figure 2 As shown, various attributes (packages, classes, methods, etc.) are extracted from project-level source files to construct a Neo4j graph database, thus obtaining a knowledge graph. By adding structural information to the knowledge graph, a knowledge base is obtained. Based on user-input query requests, the knowledge base is searched to obtain query results, i.e., multi-document content.

[0073] Unlike existing code assistance tools that are typically limited to single-document parsing, this invention focuses on multi-document association parsing for 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: Based on the content of the multiple documents, a natural language answer is generated using retrieval enhancement generation technology.

[0075] Specifically, a natural language response can be generated by combining the content of the multiple documents through a generation module and by using retrieval-enhanced generation technology.

[0076] Among them, retrieval-enhanced generation technology is a natural language processing (NLP) technique that combines the advantages of information retrieval and text generation. It aims to enhance the generative capabilities of large language models (LLMs) by utilizing external knowledge sources. Through retrieval-enhanced generation technology, the content of multiple documents is aggregated into natural language responses.

[0077] The generation module can extract key content from complex multi-document information and present the answer in a user-readable format.

[0078] Reference Figure 3 , Figure 3 A flowchart illustrating the process of generating natural language answers for the question-answering method in this application;

[0079] like Figure 3 As shown, based on the user's input query request and the query results retrieved from the knowledge base, the answer is generated using the Large Language Model (LLM).

[0080] The present application combines the retrieval augmented generation (RAG) technology with the knowledge graph (Knowledge Graph), builds a KG-RAG system suitable for automotive software development, and realizes the multi-document association processing of project-level code. Through the system, the global understanding and question answering ability of the code can be improved, and more accurate cross-file support can be provided 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 for multi-round dialogue 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 understanding ability of project-level code can be improved by increasing the pre-training amount of automotive software data.

[0082] As another implementation, a traditional full-text retrieval tool such as Elasticsearch can also be used as a retrieval module, and the retrieved content can be directly handed over to the code parsing module. This solution is suitable for short question parsing scenarios in automotive software and reduces the generation step and system complexity.

[0083] For data security issues, the present application provides a whole-process local deployment scheme, all data processing is completed locally to prevent data leakage and meet the demand for data self-controlling.

[0084] As an implementation, in automotive software projects with low data security requirements, a cloud isolation environment such as a virtual private cloud (VPC) can also 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, which is suitable for small and medium-sized enterprises in automotive R&D and provides a compromise data privacy protection scheme.

[0086] The embodiment provides a question and answer method, the application positions a relevant position based on a pre-constructed knowledge graph in response to a first query request, retrieves multi-document content based on the relevant position, generates a natural language answer through retrieval enhancement generation technology in combination with the multi-document content, and thus can realize multi-file correlation analysis by combining the knowledge graph and the retrieval enhancement generation technology, so that unified semantic understanding can be realized in a multi-document environment. Moreover, the application combines the knowledge graph (KG) and the retrieval enhancement generation (RAG) technology to construct a KG-RAG system, which can realize multi-document correlation analysis of the automobile software at the project level. The system can analyze function calls, class inheritance, module dependencies and other relationships in the code across files, fills the gap of single-document analysis, and provides developers with more comprehensive and accurate code understanding and question and answer capabilities to improve the application effect in complex automobile software projects.

[0087] Moreover, to meet the strict requirements of automobile enterprises on data security, the application provides a full-process local deployment solution, which keeps all data processing processes in the enterprise intranet to ensure the autonomy and privacy security of data, avoid data leakage risks, and meet the high-standard management requirements of enterprises on information security.

[0088] The current technology still faces the following technical problems when processing project-level code, taking an automobile software project as an example:

[0089] Poor adaptability of project-level code analysis: Many automobile software projects use multiple programming languages to develop systems and components, and a specific segmentation strategy should be used for each language, but existing tools cannot accurately analyze and segment different languages, making it difficult to meet the analysis needs in a multi-language project environment.

[0090] Based on the above problems, based on the first embodiment of the application, in the second embodiment of the application, the same or similar content as the above first embodiment can be referred to the above introduction, and the following will not be repeated. On this basis, step S50, in response to the first query request, before positioning the relevant position based on the pre-constructed knowledge graph, the question and answer method further includes steps S10-S20:

[0091] Step S10, extracting key entities from project code;

[0092] Step S20, constructing the knowledge graph based on the association relationship between the key entities.

[0093] It should be noted that the key entities (such as functions, classes, and variables) and their association relationships (such as call relationships and dependency relationships) can be extracted from the project code and constructed into a knowledge graph.

[0094] Reference Figure 4 ,Figure 4 Flowchart of the process of constructing the knowledge graph of the question and answer method of the present application;

[0095] As shown in the figure, various attributes (packages, classes, methods, etc.) are extracted from the project-level original file to construct a Neo4j graph database, thereby obtaining a knowledge graph. Figure 4

[0096] Referring to Figure 5 , Figure 5 Effect diagram of the knowledge graph of the question and answer method of the present application;

[0097] As shown in the figure, the BluetoothPairListLiveData class contains or references numerous files and methods, such as the BluetoothPairListLiveData.java file, the HfpDeviceListLiveData class, the onInactive method, the onActive method, the updateList method, the onReceive method, 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; and the MiniActivity.java file references the BluetoothPairListLiveData class, the BluetoothStateLiveData class, and the HfpDeviceListLiveData class. Figure 5 As another embodiment, a graph database can also be used to construct the relationship between nodes and edges of various code documents, which is suitable for complex code dependency scenarios in automotive software development. A hierarchical structure file based on JSON or XML can be used to construct the dependency structure between documents according to the hierarchical relationship, which is suitable for modular structure management in automotive software and achieves a similar multi-document association effect.

[0098]

[0099] ​​Further, the application designs a multi-language segmentation module for the multiple programming languages involved in the project code. The module supports code analysis of different programming languages, applies specific segmentation strategies according to the characteristics of different programming languages (such as Java, Python, etc.), ensures the accuracy of segmentation, improves the question and answer effect of the system in multi-language projects, and refers to Figure 6 , Figure 6 The flowchart of the segmentation operation in the question and answer method of the application is shown. As another implementation, a special segmenter can also be replaced by a general regular expression segmentation method, which is suitable for scenarios where different languages are mixed in automotive software but the segmentation accuracy requirement is not high, and provides simple multi-language support.

[0100] In automotive software projects, multiple programming languages are usually involved, and the application designs specific segmentation methods and strategies for different programming languages, thereby improving the code analysis and question and answer effect of the KG-RAG system in a multi-language environment, and ensuring efficient support for code understanding and problem solving in a multi-language code environment.

[0101] As another implementation, natural language processing libraries (such as NLTK or SpaCy) can also be used in conjunction with custom dictionaries, which are suitable for automotive software projects with lower segmentation accuracy requirements and can meet basic code snippet extraction needs.

[0102] The application embodiment visualizes the entity relationship in the code by constructing a knowledge graph, records the dependencies and associations between codes, and thereby improves the code management efficiency.

[0103] The application designs a multi-language segmentation module, develops specific segmentation strategies for multiple programming languages commonly used in automotive software development, improves the accuracy of code analysis and the question and answer effect in multi-language projects, ensures accurate understanding of code semantics and logical structure in different language environments, and thereby supports cross-module and cross-language collaborative development.

[0104] Based on the second embodiment of the application, in the third embodiment of the application, the same or similar content as the above-mentioned second embodiment can refer to the above introduction, and will not be repeated hereinafter. On this basis, step S20, after the knowledge graph is constructed based on the association relationship between the key entities, the question and answer method further includes steps S30-S40:

[0105] Step S30, data processing of the project code to obtain a processed document;

[0106] For example, the project code can be converted into a markdown format file.

[0107] Step S40, constructing a knowledge base based on the processed document and the knowledge graph.

[0108] The structural information is added to the knowledge graph, and a large language model is combined with a markdown format file and the knowledge graph with added structural information through an open source framework such as langchain to obtain a knowledge base.

[0109] The embodiment of the application can reduce the construction complexity of the knowledge base by processing the project code and constructing the knowledge base based on the processed document and the knowledge graph.

[0110] Based on the third embodiment of the application, in the fourth embodiment of the application, the same or similar content as the above-mentioned third embodiment can be referred to in the foregoing description, and will not be described in detail hereinafter. On this basis, step S50, in response to the first query request, the relevant position is located based on the pre-constructed knowledge graph, including steps S51-S53:

[0111] Step S51, in response to the first query request, the question raised by the user is obtained in the first query request;

[0112] The user can raise a question to construct the first query request.

[0113] Step S52, constructing a context structure prompt word based on the question raised by the user;

[0114] The context structure prompt word is a simplification or abstraction of the user's question, which can guide the system to search for relevant information in the knowledge base more efficiently.

[0115] The construction of the context structure prompt word can involve extraction of key words, semantic analysis, and rule matching based on a specific domain or knowledge base.

[0116] Step S53, locating the relevant position in the knowledge base through the context structure prompt word.

[0117] The context structure prompt word can be used as a search keyword to locate the position of information or data related to the question in the knowledge base.

[0118] The embodiment of the application can more accurately understand the user's question and more efficiently locate the relevant information in the knowledge base by constructing the context structure prompt word. The query time can be significantly shortened, and the user experience can be improved.

[0119] Based on the fourth embodiment of the application, in the fifth embodiment of the application, the same or similar content as the above-mentioned fourth embodiment can be referred to in the foregoing description, and will not be described in detail hereinafter. On this basis, step S70, combining the content of multiple documents, generating a natural language answer through retrieval enhancement generation technology includes step S71:

[0120] Step S71, in combination with the context structure prompt word, the question raised by the user and the multi-document content, the natural language answer is generated by retrieval enhancement generation technology.

[0121] First, the context structure prompt word is parsed to understand the background of the user's question and the scope of the required information.

[0122] Then, natural language understanding (NLU) technology is used to parse and understand the question raised by the user, including identifying key concepts, intent and type of required information in the question.

[0123] Then, based on the user's question and the context structure prompt word, information retrieval technology is used to retrieve the most relevant documents or paragraphs from the multi-document content to the user's question. Further, the most relevant documents or paragraphs to the user's question can be retrieved by indexing, query construction and matching algorithm, etc.

[0124] Finally, natural language generation technology is used to generate a natural language answer from the relevant documents retrieved. Further, the extraction, integration, reorganization and expression of the retrieved information can be performed.

[0125] The embodiments of the present application generate the natural language answer by combining the context structure prompt word, the question raised by the user and the multi-document content, and use retrieval enhancement generation technology to retrieve the most relevant documents or paragraphs from the multi-document content to the user's question, and generate a natural language answer based on the most relevant documents or paragraphs.

[0126] Based on the first embodiment of the present application, in the sixth embodiment of the present application, the same or similar content as the above-mentioned first embodiment can refer to the above introduction, and the following will not be described in detail. On this basis, step S70, after generating a natural language answer by retrieval enhancement generation technology in combination with the multi-document content, step S80 is included:

[0127] Step S80, in response to a second query request, outputs a corresponding subgraph based on the knowledge graph.

[0128] Wherein, the user can request to obtain a corresponding structure graph to construct a second query request.

[0129] Step S80 includes steps S81-S83:

[0130] Step S81, in response to the second query request, obtains a request to display a corresponding structure graph in the second query request;

[0131] Step S82, the request to display the corresponding structure graph is converted into a declarative graph query language;

[0132] The declarative graph query language is a language specially used for querying and operating graph data, allowing users to specify the information they want to retrieve from a graph database (such as a knowledge graph) in a declarative manner.

[0133] Step S83: Querying in the knowledge graph through the declarative graph query language, and outputting the corresponding subgraph.

[0134] Through the query, the system can find entities and relationships related to the request and construct a subgraph according to this information. This subgraph is the structural diagram that the user wants to show, which contains the 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 a certain data format.

[0135] The embodiment of the present application can quickly query in the knowledge graph through the declarative graph query language and improve the query efficiency by responding to the second query request, obtaining the request to show the corresponding structural diagram in the second query request, converting the request to show the corresponding structural diagram into a declarative graph query language, querying in the knowledge graph through the declarative graph query language, and outputting the corresponding subgraph.

[0136] For the sake of understanding the implementation process of the question and answer method obtained after combining the above-mentioned embodiment one with the present embodiment, please refer to Figure 7 , Figure 7 for the overall flowchart of the question and answer method of the present application.

[0137] Specifically, the flowchart includes the following steps:

[0138] (1) The administrator uploads files and decompresses project files or packaged files. Decompression supports multiple formats, such as zip, 7z, rar, etc.

[0139] (2) Knowledge graph construction: The script preprocesses the decompressed project original files, identifies all entities (such as functions, classes, variables) and relationships (such as calls, dependencies, etc.), and constructs these information into a knowledge graph. The knowledge graph is stored in a graph database or other data structure, forming a semantic network of project code.

[0140] (3) User input query: The user inputs a natural language query question in the interface, such as "What is the calling relationship of the function getData?"

[0141] (4) Retrieval module retrieves relevant documents: The retrieval module of the system uses the knowledge graph to identify the definition and call locations related to getData, and finds multiple documents involving the function. For example, the system identifies that getData is defined in the A.java file and called in the B.java and C.java files.

[0142] (5) Multiple document content is passed to the generation module: The retrieval module returns multiple documents containing the definition and call information of getData, and inputs these contents as context to the generation module.

[0143] (6) Generation module generates answers: The generation module uses the RAG technique to generate natural language answers in combination with the context. For example, the answer can be "The getData function is defined in the A.java file and called in the Y method of the B.java file and the Z method of the C.java file."

[0144] (7) Data processing is performed on the decompressed project original file to obtain an md document, and a knowledge base is generated by combining the knowledge graph with added structural information through the langchain framework.

[0145] (8) The user selects to display the corresponding structure diagram, and converts the request to display the corresponding structure diagram into a declarative graph query language cypher language to obtain a cypher command.

[0146] (9) Query in the knowledge graph through the declarative graph query language, and output the corresponding subgraph.

[0147] (10) Data security guarantee: The entire processing process is carried out in a local deployment environment, and all data operations are completed within the enterprise internal network to ensure data security and privacy protection.

[0148] It should be noted that the question and answer system can include the following five modules:

[0149] (1) Knowledge graph construction module: provides a semantic network of project-level code, providing basic associated information for the retrieval module.

[0150] (2) Retrieval module: finds relevant code snippets and their associated files from the knowledge graph according to the user's input query conditions, and passes these information to the generation module.

[0151] (3) Generation module: uses the RAG technique to generate natural language answers from the retrieved multiple document content, allowing users to clearly understand the cross-file code relationship.

[0152] (4) Code language-specific segmentation module: supports the system to parse different language codes, ensuring the accuracy of cross-language project question and answer.

[0153] (5)Data security and local deployment module: ensures the data privacy of enterprise users, runs locally throughout, and ensures data security.

[0154] In order to more clearly show the operation flow of the present scheme, a specific scenario is assumed below for illustration.

[0155] Suppose there is a complex project containing 100 Java files, and the user wants to know the calling situation of the function getData in the project.

[0156] In the traditional code auxiliary tool, the user needs to open the files one by one to find the definition and calling situation of the getData function, which not only consumes time, but also easily misses the cross-file associated information. However, through the project-level code analysis and question-answering platform of the present application, the user can quickly obtain the complete calling relationship and position of the getData function. The following is the specific implementation process.

[0157] 1. User input query: The user inputs a question in the platform, for example, "How is the function getData called in the project?"

[0158] 2. Retrieval module calls knowledge graph: The retrieval module will first call the knowledge graph to identify the definition position and calling relationship of the getData function in the code.

[0159] The knowledge graph takes the definition of the getData function and all associated calling positions as nodes, and takes the calling relationship 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 is referenced in B.java and C.java files.

[0161] 3. Multi-document content is delivered to the generation module: The retrieval module delivers the multi-document information of the definition and calling of the getData function found to the generation module.

[0162] At this time, the context information received by the generation module includes the definition position (A.java) of the getData function and the reference position (Y method in B.java and Z method in C.java).

[0163] 4. The generation module generates a natural language answer: The generation module generates a natural language answer in combination with the user's question and the context information provided by the retrieval module.

[0164] An example answer could be: "The 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."

[0165] 5. Output the result to the user: The system presents the generated answer to the user through the user interface. The user can obtain the calling situation of the getData function in the project through a simple natural language query.

[0166] The advantage of this multi-document parsing is that the system can complete the cross-file code call parsing within a few seconds, enabling users to obtain a comprehensive understanding of the project-level code.

[0167] As an implementation, a multi-document parsing system based on code snippet annotation can also be designed to replace the KG-RAG technical architecture. The core code snippets in the automotive software project are pre-annotated to generate metadata index libraries such as calling and definition. This solution is suitable for automotive software projects with simple code structures, avoiding the complexity of knowledge graph construction and meeting basic multi-document parsing needs.

[0168] As another implementation, a multi-document code parsing platform using API integration can also be designed to build code assistance tools. By integrating with project management platforms such as GitHub and GitLab through API, the code file organization structure and calling relationship of the automotive software project can be directly obtained. 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, a question and answer system based on project code analysis library can also be designed. Open-source code analysis libraries such as CodeQL and JDT are used to build the parsing system, which supports question and answer functions by generating code dependency relationships between multiple documents. This solution is particularly suitable for complex code dependency analysis in automotive software projects, reducing the complexity of graph construction and RAG processes through automated generation of dependency information.

[0170] The beneficial effects of this solution include the following four aspects:

[0171] 1. Improved efficiency of project-level multi-document parsing: Compared with existing code assistance tools, the invention significantly improves the efficiency of multi-document association parsing in automotive software projects. In experimental tests, the parsing speed of the 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 more quickly understand the global structure of complex projects, improving the efficiency of the automotive software development process.

[0172] 2. Question and answer accuracy improvement: By combining RAG and knowledge graph technology, a KG-RAG system optimized for automotive software development is constructed, which significantly improves the accuracy of project-level code question and answer. Experimental data shows that the system's accuracy in handling multi-document question and answer tasks in automotive software projects is 20%-25% higher than that of single-document processing tools, effectively improving the developer's problem-solving effect for cross-module and cross-file problems.

[0173] 3. Code tokenization precision optimization: For the multiple programming languages commonly used in automotive software projects, the invention designs specific tokenization strategies, which improve the precision of the KG-RAG system in multi-language code analysis by 15%-20%. Tests on Java, Python, JavaScript and other languages show that the invention reduces the question and answer errors caused by incorrect tokenization, reduces the question and answer error rate in cross-language automotive software projects by 18%, and improves the accuracy of code understanding.

[0174] 4. Data security and confidentiality protection: Considering the data security needs of automotive enterprises, the invention adopts whole-process local deployment to ensure the autonomous controllability of data. Compared with code-assisted tools that rely on the cloud, the local deployment scheme of the invention effectively avoids data leakage risks and meets the information security management requirements of the automotive industry. Experiments show that the satisfaction of automotive R&D enterprises has increased by about 30%, and the security compliance cost has been reduced by about 20%.

[0175] It should be noted that the above examples are only for understanding the present application and do not limit the question and answer method of the present application. More forms of simple changes based on this technical concept are within the scope of protection of the present application.

[0176] The present application also provides a question and answer device, please refer to Figure 8 , the question and answer device comprises:

[0177] The positioning module 10 is configured to locate the relevant position based on the pre-constructed knowledge graph in response to the first query request.

[0178] The retrieval module 20 is configured to retrieve the multi-document content based on the relevant position.

[0179] The answer generation module 30 is configured to generate natural language answers by combining the multi-document content and using retrieval enhancement generation technology.

[0180] The question and answer device provided in the present application adopts the question and answer method in the above embodiments, 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 question and answer device provided in the present application has the same beneficial effects as the question and answer method provided in the above embodiments, and other technical features in the question and answer 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 comprises at least one processor and a memory connected with 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 to enable the at least one processor to perform the question and answer method in the above embodiment one.

[0182] Reference will be made to the accompanying drawings Figure 9 which shows a structural schematic diagram of a question and answer device suitable for implementing the embodiments of the present application. The question and answer device in the embodiments of the present application can include but is not limited to mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (Personal Digital Assistant), PADs (Portable Application Description), PMPs (Portable Media Player), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), and the like, and fixed terminals such as digital TVs, desktop computers, and the like. Figure 9 The question and answer device shown is only an example, and should not bring any limitation to the functions and use range of the embodiments of the present application.

[0183] As Figure 9As shown, the question-answering device can include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 1002 or loaded from a storage device 1003 into a random access memory (RAM) 1004. Various programs and data required for operation of the question-answering device are also stored in the RAM 1004. The processing device 1001, the ROM 1002, and the RAM 1004 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: input devices 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; the 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 wirelessly or wired with other devices to exchange data. Although the question-answering device with various systems is shown in the figure, it should be understood that all the shown systems are not required to be implemented or possessed. More or fewer systems can be alternatively implemented or possessed.

[0184] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer readable medium, the computer program containing program codes for executing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network through the communication device, or installed from the storage device 1003, or installed from the ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the methods of the embodiments disclosed in the present application are performed.

[0185] The question-answering device provided in the present application adopts the question-answering method in the above-mentioned embodiments, 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 question-answering device provided in the present application has the same beneficial effects as the question-answering method provided in the above-mentioned embodiments, and other technical features in the question-answering device are the same as the features disclosed in the above-mentioned method, which will not be repeated here.

[0186] It should be understood that various aspects of the disclosure can be implemented in 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 appropriate manner in any one or more embodiments or examples.

[0187] The above description is merely illustrative of the application and is not intended to limit the scope of the application. Any variations and modifications that can be made by any person skilled in the art within the spirit and scope of the application are intended to be encompassed by the application. Therefore, the scope of the application should be determined by the appended claims.

[0188] The application provides a computer readable storage medium having stored thereon computer readable program instructions (i.e., a computer program) for performing the question and answer method in the above embodiments.

[0189] The computer readable storage medium provided by the application may, for example, be a U disk, but is not limited to an electric, magnetic, optical, electromagnetic, infrared, or semiconductor system, system, or device, or any combination thereof. More specific examples of the computer readable storage medium can include, but are not limited to, an electric connection with one or more conductive 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 appropriate combination thereof. In the present embodiment, the computer readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer readable storage medium can be transmitted by any appropriate medium, including but not limited to an electric wire, an optical cable, an RF (Radio Frequency), etc., or any appropriate combination thereof.

[0190] The above computer readable storage medium can be contained in a question and answer device; or can exist separately without being assembled into a question and answer device.

[0191] The computer readable storage medium described above carries one or more programs, when the one or more programs are executed by the question and answer device, the question and answer device is caused to: in response to a first query request, locate a relevant position based on a pre-constructed knowledge graph; retrieve multi-document content based on the relevant position; and generate a natural language answer by using a retrieval enhancement generation technology in combination with the multi-document content.

[0192] Computer program code for carrying out operations of the present application can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can 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 the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).

[0193] The flow diagrams and the block diagrams in the drawings are illustrations of architectures, functionalities, and operations of possible implementations of systems, methods, and computer program products according to various embodiments of present application. In this regard, each block in the flow diagrams or block diagrams can represent a module, a procedure, or a part of code, which comprises one or more executable instructions for implementing the specified functions. It should also be noted in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the figures. For example, two blocks depicted in succession can in fact be executed substantially concurrently or the blocks can sometimes be executed in the reverse order, depending upon the functionality involved. It is also noted that each block in the block diagrams and / or flow diagrams and combinations of blocks in the block diagrams and / or flow diagrams can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0194] The modules involved in the embodiments of the present application can be implemented in a software manner or in a hardware manner. In some cases, the name of the module does not constitute a limitation on the module itself.

[0195] The readable storage medium provided by the application is a computer readable storage medium, which stores computer readable program instructions (i.e., computer programs) for executing the above-mentioned question and answer 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 by the application are the same as those of the question and answer method provided by the above-mentioned embodiments, and are not described here.

[0196] The above is only part of the embodiments of the application, and does not limit the patent scope of the application. Any equivalent structural transformation made by using the contents of the application specification and drawings, or direct / indirect application in other related technical fields is included in the patent protection scope of the application.

Claims

1. A question and answer method, characterized by, The method comprises: extracting project attributes from project code according to different programming language characteristics by applying corresponding segmentation strategies through a multi-language segmentation module; constructing a Neo4j graph database based on the project attributes; constructing a knowledge graph based on the Neo4j graph database; performing data processing on the project code to obtain processed documents; based on the processed documents, adding structural information to the knowledge graph to construct a knowledge base; in response to a first query request, obtaining a question raised by a user in the first query request; constructing a context structure prompt word based on the question raised by the user; locating a relevant position in the knowledge base through the context structure prompt word; retrieving multi-document content based on the relevant position, including performing multi-file association analysis based on the relevant position in combination with a knowledge graph and retrieval enhancement generation technology, cross-file analyzing at least one relationship in function calls, class inheritance, and module dependencies in the project code to obtain the multi-document content; generating a natural language answer through retrieval enhancement generation technology in combination with the context structure prompt word, the question raised by the user, and the multi-document content.

2. The method of claim 1, wherein, The step of generating a natural language answer through retrieval enhancement generation technology in combination with the multi-document content includes: in response to a second query request, outputting a corresponding subgraph based on the knowledge graph.

3. The method of claim 2, wherein, The step of outputting a corresponding subgraph based on the knowledge graph in response to a second query request includes: in response to the second query request, obtaining a request to display a corresponding structure graph in the second query request; converting the request to display the corresponding structure graph into a declarative graph query language; querying the knowledge graph through the declarative graph query language to output the corresponding subgraph.

4. A question answering apparatus characterized by comprising: The apparatus comprises: a positioning module for extracting project attributes from project code according to different programming language characteristics by applying corresponding segmentation strategies through a multi-language segmentation module, constructing a Neo4j graph database based on the project attributes, constructing a knowledge graph based on the Neo4j graph database, performing data processing on the project code to obtain processed documents, adding structural information to the knowledge graph based on the processed documents to construct a knowledge base, obtaining a question raised by a user in a first query request in response to the first query request, constructing a context structure prompt word based on the question raised by the user, and locating a relevant position in the knowledge base through the context structure prompt word; a retrieval module for retrieving multi-document content based on the relevant position; the retrieval module is further configured to perform multi-file association analysis based on the relevant position in combination with a knowledge graph and retrieval enhancement generation technology, cross-file analyze at least one relationship in function calls, class inheritance, and module dependencies in the project code to obtain the multi-document content; a response generation module for generating a natural language answer through retrieval enhancement generation technology in combination with the context structure prompt word, the question raised by the user, and the multi-document content.

5. A question answering apparatus characterized by comprising: The device comprises a memory, a processor, and a computer program stored on the memory and executable on the processor, the computer program being configured to implement the steps of the question-answering method according to any one of claims 1 to 3.

6. A storage medium, characterized by The storage medium is a computer-readable storage medium, and the storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the question-answering method according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Traditional Chinese medicine question and answer method and device based on long document retrieval enhancement generation and medium

    CN117828050A

  • Dynamic correlation enhancement retrieval generation system and method driven by intelligent knowledge graph

    CN118839021A