Urban rail transit emergency field question and answer method and system based on optimized RAG

By optimizing RAG technology and combining it with stylized prompts for urban rail transit and document block vectorization, the problems of time-consuming emergency plan preparation and lack of emergency knowledge among passengers have been solved, enabling efficient and logical emergency knowledge retrieval and presentation.

CN119311793BActive Publication Date: 2025-11-04TONGJI UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411105322.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-13
Publication Date
2025-11-04
Estimated Expiration
2044-08-13

AI Technical Summary

Technical Problem

The development of emergency plans for urban rail transit is time-consuming and labor-intensive, passengers lack emergency response strategies, and existing technologies are unable to efficiently provide logical emergency knowledge dissemination.

Method used

The question-answering method for urban rail transit emergency response based on the optimized RAG combines questions with stylized prompt templates for urban rail transit, parses multiple document types to form parent-child document blocks, generates vectors using word embedding models, calculates similarity to recall relevant documents, rearranges the document set, and generates responses in a large language model.

Benefits of technology

It simplifies knowledge base maintenance, improves the efficiency of emergency knowledge retrieval and the logical consistency of answers, and provides a more user-friendly information presentation, making it suitable for urban rail transit emergency scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119311793B_ABST
    Figure CN119311793B_ABST
Patent Text Reader

Abstract

The application discloses a city rail transit emergency field question and answer method and system based on optimized RAG, and relates to the technical field of artificial intelligence, comprising: first, rewriting the user question into a new question conforming to the style of city rail transit, and then analyzing different types of documents in the knowledge base. Next, the documents are cut and vector embedded, and the new question is converted into a vector. Then, by calculating the similarity of the question vector and the document block vector, the most relevant document block is selected to form a recall set. After that, the recall documents are reordered using a cross-encoder, and the most relevant ones are selected to form a rearranged document set. Finally, the new question and the rearranged document set are input into a large language model that has been fine-tuned, and the final answer is generated. Through question rewriting, accurate document cutting and vectorization, multi-level retrieval and rearrangement, and domain fine-tuned large language model, the application significantly improves the accuracy and relevance of city rail transit emergency field question and answer, and realizes more professional and reliable intelligent question and answer service.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence, in particular to a city rail transit emergency domain question answering method and system based on optimized RAG. BACKGROUND

[0002] RAG refers to Retrieval-Augmented Generation (RAG) technology based on large language model fine-tuning and retrieval enhancement. With the rapid development of city rail transit systems, there are more and more emergency incidents. The compilation of city rail emergency plans and the popularization of emergency knowledge have become key measures to ensure operational safety and reduce accident damage. However, city rail emergency-related knowledge is diverse and usually distributed in different locations such as the Internet and literature in a multi-source and heterogeneous form. The cost of manual retrieval and sorting is high, and the compilation of city rail emergency plans is time-consuming and labor-intensive. At the same time, city rail passengers lack the processing ideas for common emergency incidents and often panic in the face of complex situations and changing information, causing unnecessary casualties.

[0003] Therefore, it is necessary to develop a city rail transit emergency domain question answering method and system based on optimized RAG to assist manual compilation of emergency plans and set up in subway stations for passenger knowledge popularization. SUMMARY

[0004] In view of the above problems, the present application is proposed.

[0005] Therefore, the technical problem solved by the present application is how to provide a city rail transit emergency domain question answering method and system based on optimized RAG.

[0006] To solve the above technical problems, the present application provides the following technical scheme: a city rail transit emergency domain question answering method based on optimized RAG, comprising: combining a question Q and a city rail transit stylized prompt template into a new question Q'; identifying different document types in a city rail emergency knowledge base and performing file analysis; segmenting the analyzed city rail emergency knowledge base documents to form a plurality of parent document blocks, obtaining child document blocks according to the parent document blocks, and obtaining a new question vector Q'E according to a word embedding model, parent document blocks, child document blocks, and the new question Q'; calculating the similarity between the new question vector Q'E and each parent document block or child document block vector, respectively, recalling according to the similarity, and forming a recall document set D most relevant to the question; performing relevance scoring on the document blocks in the recall document set D and reordering to form a reordered document set D'; constructing a model reply prompt template, inputting the new question Q' and the reordered document set D' into the model reply prompt template, and inputting the model reply prompt template into a base large language model that is not adjusted or is adjusted and optimized in the city rail emergency field to obtain a large language model generation reply A.

[0007] As a preferred scheme of the urban rail transit emergency field question and answer method based on the optimized RAG of the application, wherein: the split analysis of the urban rail transit emergency knowledge base after the document forms a plurality of parent document blocks, and the parent document blocks obtain the sub-document blocks, including the following steps: the parsed document is divided into a plurality of parent document blocks, and the maximum threshold is L p-max ; the parent document blocks are added with a preset ID in the form of key-value pair, and the parent document blocks are divided into n sub-document blocks with a maximum threshold of L s-max , and the ID of the parent document blocks and the sub-document blocks are consistent, wherein n=L p-max / L s-max , and the parent document blocks are divided into n sub-document blocks with a maximum threshold of L r ; according to the word embedding model, the parent document blocks, the sub-document blocks, and the new question Q', the new question vector Q'E is obtained, including the following steps: all document blocks are embedded using the word embedding model to obtain the vector representation of all document blocks; the vector representation of all document blocks is persistently stored in the local vector database; the new question Q' is embedded to obtain the new question vector Q'E.

[0008] As a preferred scheme of the urban rail transit emergency field question and answer method based on the optimized RAG of the application, wherein: the word embedding model is selected by preliminary screening evaluation using an artificially constructed urban rail transit emergency field data set, and is selected by secondary fine-tuning training using a plurality of high-quality urban rail transit emergency field corpora.

[0009] As a preferred scheme of the urban rail transit emergency field question and answer method based on the optimized RAG of the application, wherein: the similarity between the new question vector Q'E and each of the parent document block or sub-document block vector is calculated, the recall is performed according to the similarity, and the most relevant recall document set D of the question is formed, including the following steps: the word embedding model is input into the query engine Q-Engine; the similarity between the new question vector Q'E and the vector of all document blocks is calculated using the word embedding model, and the top K document blocks with the highest similarity are recalled; the top K document blocks recalled are merged according to the ID, and only the parent document is taken for the parent and child document blocks with the same ID; K r document blocks are obtained, and the most relevant recall document set D of the question is formed.

[0010] As a preferred scheme of the urban rail transit emergency field question and answer method based on the optimized RAG of the application, wherein: the relevance of the document blocks in the recall document set D is scored, and the document set D' is reordered, including the following steps: the re-ranker Reranker is loaded, and the re-ranker Reranker is input into the query engine Q-Engine; the K rEach document block is fed into the Reranker, and the new question vector Q'E is respectively compared with the K... r Each document block is fed into a trained cross-encoder, and deep learning modeling is performed using a deep neural network to obtain the correlation between vectors; based on the deep neural network, the new question vector Q'E and the K are calculated respectively. r The relevance scores of each document block are calculated; the relevance scores are then sorted from highest to lowest, and the top K most relevant blocks are selected. r 'A set of documents is formed by 'a set of documents D'.

[0011] As a preferred embodiment of the urban rail transit emergency response question-answering method based on the optimized RAG described in this invention, it further includes the self-generation of the vertical domain dataset used for fine-tuning the large language model, specifically including the following steps: constructing the prompt template required when generating the vertical domain dataset instruction I. instruction And the prompt template required when generating output O. output Manually annotated 20 vertical domain seed instruction sets D S-I The seed instruction set D S-I The elements should consist of instruction I and output O; simultaneously, a literature library D for storing vertical domain references should be constructed. ur ; in the seed instruction set D S-I Two seed instructions are randomly selected from the self-generated instruction set D'. S-I Randomly select one self-generated instruction from the set of self-generated instructions D'. S-I If it is empty, then it will be retrieved from the seed instruction set D. S-I Select one instruction, for a total of three instructions, as the input instruction set D. I Input into the large language model; randomly selected input instruction set D I With the aforementioned prompt template Prompt instruction After concatenation, this becomes a new problem. Based on the optimized retrieval enhancement generation method, the unadjusted large language model is used, resulting in a large model response A containing n vertical domain instructions. I ; Reply A to the large model I Parsing according to a specific format yields n structured vertical domain instructions I1-I n And save the self-generated instructions as a self-generated instruction set D' S-I Repeat the above process until the number of instructions in the vertical domain reaches a preset threshold m, then proceed to the next step. The number of iterations is δ = m / n, and δ is rounded up. The self-generated instruction set D' is then... S-I All commands in the prompt template are displayed sequentially. outputAfter splicing, as a new question, according to the optimization retrieval enhancement generation method, a large language model that has not been fine-tuned is used at this time to obtain m large model replies A O Finally, m outputs O corresponding to the instructions I are obtained; the instruction set D' S-I All instructions in the instruction set D'

[0012] As a preferred scheme of the urban rail transit emergency domain question answering method based on the optimized RAG, wherein: the document analysis includes the following steps: judging whether the document is an xlsx or xls type file, if it is the xlsx or xls file, using the pandas library to convert it into a csv file, and then using PagedCSVReader to analyze the file; judging whether the document is a pdf type file, if it is the pdf file, using PyMuPDFReader to analyze the file; judging whether the document is a csv type file, if it is the csv file, using PagedCSVReader to analyze the file; judging whether the document is a doc type file, if it is the doc file, using DocxReader to analyze the file.

[0013] To further solve the above technical problems, the present application provides the following technical scheme: an urban rail transit emergency domain question answering system based on the optimized RAG, comprising: a question construction module for combining a question Q proposed by a user with a city rail transit stylized prompt template to form a new question Q'; a document type identification module for identifying different document types in the urban rail transit emergency knowledge base and performing corresponding file analysis; a document segmentation and vectorization module for segmenting the analyzed urban rail transit emergency knowledge base documents to form a plurality of parent document blocks, obtaining child document blocks according to the parent document blocks, and obtaining a new question vector Q'E according to a word embedding model, the parent document blocks, the child document blocks, and the new question Q'; a calculation recall module for calculating the similarity between the new question vector Q'E and each parent document block or child document block vector, respectively, and forming a recall document set D most relevant to the question according to the similarity; a scoring and sorting module for performing relevance scoring on the document blocks in the recall document set D and reordering to form a reordered document set D'; a reply generation module for constructing a model reply prompt template, inputting the new question Q' and the reordered document set D' into the model reply prompt template, and inputting the model reply prompt template into a base large language model that has not been adjusted or has been adjusted and optimized in the urban rail transit emergency domain to obtain a large language model generated reply A.

[0014] A computer device comprises a memory and a processor, the memory stores a computer program, characterized in that the processor implements the steps of the above-mentioned urban rail transit emergency domain question and answer method based on the optimized RAG when executing the computer program.

[0015] A computer readable storage medium having a computer program stored thereon, characterized in that the computer program, when executed by a processor, implements the steps of the above-mentioned urban rail transit emergency domain question and answer method based on the optimized RAG.

[0016] The beneficial effects of the present application are: (1) through the semantic understanding ability based on the large language model, the vectorized corpus index is established by using the optimized retrieval enhancement generation technology, and the information query and integration are provided in the form of natural language question and answer, which can simplify the maintenance of the knowledge base while providing more friendly and more logical answer presentation; (2) compared with the traditional knowledge base which needs to prepare fixed question and answer pairs, the present application converts different types of files into document blocks, and retrieves through the vectorized corpus, which greatly simplifies the process of knowledge input and maintenance; (3) the files are divided into a plurality of sub-document blocks, and the plurality of document blocks are converted into word embedding vectors using the fine-tuned word embedding model, and are combined to form a vectorized corpus, which is helpful to build a vectorized corpus more suitable for the urban rail transit emergency scene; (4) the rearrangement model is introduced to rearrange the first recall result, and the document block recall quality is higher; (5) the large language model is fine-tuned through high-quality urban rail emergency data, the user's question is integrated into a paragraph with a format by using the fine-tuned large model, the answer is presented in a logical way, and the efficiency and quality of the domain problem query are improved. BRIEF DESCRIPTION OF DRAWINGS

[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creating laborious work.

[0018] Figure 1 The overall flowchart of the urban rail transit emergency domain question and answer method based on the optimized RAG provided by an embodiment of the present application is shown.

[0019] Figure 2 The exemplary flowchart of the parent document segmentation into sub-documents of the urban rail transit emergency domain question and answer method based on the optimized RAG of the present application is shown.

[0020] Fig. 3(a), Fig. 3(b) and Fig. 3(c) are evaluation effect diagrams drawn after the semantic recognition and evaluation of the word embedding model of the urban rail transit emergency domain question and answer method based on the optimized RAG of the present application.

[0021] Fig. 4(a), Fig. 4(b) and Fig. 4(c) are effect diagrams drawn after the recall document evaluation of the word embedding model of the urban rail transit emergency field question answering method based on the optimized RAG of the present application.

[0022] Fig. 5(a), Fig. 5(b) are effect diagrams drawn after the re-evaluation after the fine-tuning of the preferred word embedding model of the urban rail transit emergency field question answering method based on the optimized RAG of the present application.

[0023] Figure 6 Fig. 1 is a flow chart of the urban rail transit emergency field data set self-generation method for base model fine-tuning of the present application.

[0024] Figure 7 Fig. 1 is a flow chart of the urban rail transit emergency field data set self-generation method for base model fine-tuning of the present application. DETAILED DESCRIPTION

[0025] In order to make the above objectives, features and advantages of the present application more obvious and easy to understand, the specific embodiments of the present application will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor should belong to the protection scope of the present application.

[0026] In the following description, many specific details are set forth in order to provide a thorough understanding of the present application. However, the present application can be practiced in other ways different from those described herein without departing from the spirit and scope of the present application, and those skilled in the art can make similar generalizations without departing from the spirit and scope of the present application. Therefore, the present application is not limited to the specific embodiments disclosed below.

[0027] Embodiment 1

[0028] Reference Figures 1-6 For an embodiment of the present application, an urban rail transit emergency field question answering method based on optimized RAG is provided, comprising:

[0029] S1: question rewriting: constructing an urban rail transit stylized prompt template, combining the question Q and the urban rail transit stylized prompt template into a new question Q'.

[0030] Specifically, the incoming question first needs to import a question q. In general production practice, the incoming question may be simple and cannot fully contain the semantics of the urban rail emergency field, which may lead to the recall of non-symmetric semantic document blocks. Therefore, the incoming question q needs to be combined with the prompt template of the urban rail emergency style to form a new question q'. The prompt template can be a sentence, a question or a topic related to the urban rail emergency field, which can guide the large language model to generate information or answers related to the prompt word, for example, the prompt template can be "Please answer in combination with the characteristics of the station hall facility equipment of the urban rail transit station:". The template is combined with the incoming question to form a new question q'.

[0031] S2: Document parsing: identify different document types in the urban rail emergency knowledge base, and use specific document readers for file parsing according to different types.

[0032] Specifically, the urban rail emergency field knowledge base is constructed, and different types of files such as urban rail transit emergency organization and management field dissertations, journal articles, and related statistical tables are collected. According to the designed file processing logic, different types of files are read and parsed.

[0033] Further, it is judged whether the document is an xlsx or xls type file. If it is the xlsx or xls file, it is converted to a csv file using the pandas library, and then the file is parsed using PagedCSVReader.

[0034] It is judged whether the document is a pdf type file. If it is the pdf file, the file is parsed using PyMuPDFReader.

[0035] It is judged whether the document is a csv type file. If it is the csv file, the file is parsed using PagedCSVReader.

[0036] It is judged whether the document is a doc type file. If it is the doc file, the file is parsed using DocxReader.

[0037] S3: The parsed urban rail emergency knowledge base document is segmented to form a plurality of parent document blocks, and the parent document blocks are obtained. According to the word embedding model, the parent document blocks, the sub-document blocks, and the new question Q', a new question vector Q' E is obtained.

[0038] Specifically, the step mainly includes document segmentation and vector embedding. The parsed files in the urban rail transit emergency knowledge base are segmented into parent document blocks. Each parent document block is segmented into a finer-grained sub-document block, and the sub-document block has the same ID as the parent document block. The document blocks are embedded using a word embedding model to obtain a plurality of document block vectors. The user's new question Q' is embedded using the word embedding model to obtain a new question vector Q'E.

[0039] Further, the parsed files are segmented according to a certain threshold. The document is segmented into parent document blocks not greater than L p-max and not less than L p-min . At the same time, a sliding window is set between adjacent document blocks to ensure semantic coherence. According to the need, each parent document block can be further segmented into a sub-document block, that is, the parent document block is added with a preset ID in the form of a key-value pair, and the parent document block is divided into n sub-document blocks with a maximum threshold of L s-max by mapping, so that the parent document block and the sub-document block have the same ID, where n = L p-max / L s-max , and the upper limit is taken.

[0040] In actual application, whether to adopt the segmentation form can be selected according to the recall effect after the segmentation of the parent and child document blocks. Specifically, if the recall effect is worse than that without the segmentation of the parent document block, the parent document block can not be segmented into a sub-document block.

[0041] In actual application, the threshold L p-max and L p-min of the document block segmentation need to be debugged according to the requirement.

[0042] Further, the new question vector Q'E is obtained according to the word embedding model, the parent document block, the sub-document block, and the new question Q', including the following steps:

[0043] All document blocks are embedded using the word embedding model to obtain vector representations of all document blocks. The vector representations of all document blocks are persistently stored in a local vector database. Persistent storage of document vectors persistently stores document vectors in a vector database, avoiding repeated loading of data in each question and answer. The new question Q' is embedded to obtain a new question vector Q'E.

[0044] Preferably, the word embedding model is selected by preliminary screening and evaluation using an artificially constructed urban rail transit emergency field dataset, and is further fine-tuned and trained using a plurality of high-quality urban rail transit emergency field corpora.

[0045] The step uses a preferred and fine-tuned word embedding model. The word embedding model is selected after preliminary screening evaluation using artificially constructed urban rail emergency field data set, and is fine-tuned again using hundreds of high-quality urban rail emergency field corpus, so that the word embedding model has greatly improved in correct recall and semantic discrimination of urban rail emergency field corpus.

[0046] S4: Calculate the similarity between the new question vector Q'E and each parent document block or sub-document block vector respectively, and perform recall according to the similarity to form the most relevant recall document set D.

[0047] Specifically, the step is mainly vector retrieval and document recall. Specifically, the similarity between the new question vector Q'E and each parent document block or sub-document block vector is calculated respectively, and the top K most relevant document blocks are recalled according to the similarity. The parent document block is taken for the parent and child document blocks with the same ID. Finally, K r document blocks are obtained, and the most relevant recall document set D is formed.

[0048] Further, a plurality of candidate word embedding models are selected, which can be based on Word2Vec, GloVe or any word embedding method. The model structure of the word vector embedding model is not limited in this embodiment. The plurality of word embedding models are evaluated, and the most suitable word embedding model for urban rail emergency corpus is selected. The word embedding model is used to embed and calculate the similarity between the new question vector Q'E and each parent document block or sub-document block vector, and the top K most relevant document blocks are recalled according to the similarity. The parent document block is taken for the parent and child document blocks with the same ID. Finally, K r document blocks are obtained, and the most relevant recall document set D is formed.

[0049] Further, it is specifically understood that Figures 3(a)-3(c) , please refer to FIG. 4(a), FIG. 4(b) and FIG. 4(c). In an embodiment, the word embedding model selection in S4 includes the following steps:

[0050] S4.1: Obtain the urban rail emergency field industry specification or standard.

[0051] According to the content of the National Urban Rail Transit Operation Emergency Plan, the urban rail emergency field semantic pairs are manually labeled and added to the test set of the chinese-sts-b data set. At the same time, data is self-generated according to the content to obtain a corpus pair composed of one-to-one corresponding questions and question related corpus, and the training and test sets are divided according to a certain proportion;

[0052] S4.2: Randomly select a number of data set pairs in the test set of the chinese-sts-b data set added with the city rail emergency field semantic pairs, evaluate the selected word embedding model, and draw a scatter plot as shown in FIG. 3(a), to determine the word embedding model with the best effect in the city rail emergency semantic judgment level; Figures 3(a)-3(c)

[0053] S4.3: Randomly select a number of data set pairs in the test set of the chinese-sts-b data set added with the city rail emergency field semantic pairs, evaluate the selected word embedding model, and draw a scatter plot as shown in FIG. 3(b), to determine the word embedding model with the best effect in the city rail emergency semantic judgment level; Figures 3(a)-3(c)

[0054] S4.4: Use the test set of the self-generated data set in S4.1 to evaluate the recall of the selected word embedding model, and draw a combination diagram as shown in FIG. 4(a), FIG. 4(b) and FIG. 4(c), to determine the word embedding model with the best recall effect in the city rail corpus;

[0055] S4.5: According to the evaluation results, in this embodiment, the selected word embedding model most suitable for the city rail emergency corpus is the bge-base-zh-v1.5 model.

[0056] S4.6: Further fine-tune the selected word embedding model.

[0057] In actual application, the data set format of the word embedding model fine-tuning is <q i , c>, where c is a corpus block divided by file segmentation, and q i is a question corresponding to the corpus block, and the large model for data set self-generation is not limited in this specification.

[0058] In actual application, the index type for embedding the document block can be various, which can be an index based on different vector databases, an article abstract index, etc., and the index type is not limited in this specification.

[0059] S5: Use the cross encoder to score the relevance of the document blocks in the recall document set D, and reorder them, and select the top K r document blocks in the document set D most relevant to the question to form a reordered document set D'.

[0060] Specifically, in an embodiment, the specific process of the cross encoder scoring the relevance of the document blocks in the recall document set d is as follows:

[0061] Use the supervised training cross encoder to score the relevance of the user new question q' and the document blocks d_c i ​​Each pair is concatenated as an encoder input <q', d_c i > and modeled through deep neural networks transformers to obtain a representation of deep interactions;

[0062] A multi-layer perceptron is applied on top of the deep interaction representation to predict the user new question combined with the document blocks <q', d_c i > relevance scores in the embedding space;

[0063] The relevance scores are re-ranked to take the top k r documents blocks that are most relevant to the new question to form a re-ranked document set d'.

[0064] S6: A prompt template is constructed for the model to reply, in which the new question Q' and the re-ranked document set D' are passed in, and the prompt template is passed into a base large language model that is not fine-tuned or fine-tuned and optimized in the urban rail emergency field, to obtain a generated reply A of the large language model.

[0065] Specifically, please refer to Figure 6 In an embodiment, the base large language model in S6 can be fine-tuned with a high-quality urban rail emergency field self-generated data set, including the following steps:

[0066] S6.1: Obtain high-quality files in the urban rail emergency field, and construct the prompt template Prompt instruction required by the vertical field data set instruction I generated and the prompt template Prompt output required by the output O generated.

[0067] In actual applications, knowledge in the vertical field can be extracted from specialized files in the vertical field, including journal articles, degree papers, etc. For example, knowledge can be extracted from domestic and foreign relevant literature research on urban rail emergencies, urban rail emergency plan national standards and industry specifications.

[0068] In actual applications, the prompt template can be a paragraph or a topic that is conducive to the self-generation of a high-quality data set. The prompt template can guide the large language model to generate information or answers related to the prompt words, for example, the prompt template Prompt instructionCan be: "Please refer to the strict reference to generate some instructions, {context_str}, and these instructions must meet the following requirements, requirements are: {query_str}" Where, {context_str} is the recall content, {query_str} can be a paragraph or a topic that is conducive to the generation of a high-quality data set related to, for example: "You are an expert in urban rail emergency field, and you are required to provide 5 questions, the following are 3 example instructions, you continue to write 5 according to the data, the questions belong to urban rail emergency. The following are the requirements that you need to meet to provide instructions: 1. The generated questions must be detailed, and the content must belong to urban rail emergency 2. The generated questions must be closely related to the provided data, and cannot be generated with prior knowledge. 3. The instructions should be in Chinese. The following are 3 example instructions: [instruction generation]". The prompt template Prompt output Can be: "In combination with the context, {context} to give the following question answer from the perspective of a subway operation expert, the question is: {query}, answer: " {context} is the recall content, {query} is the self-generated instruction I.

[0069] S6.2: According to the high-quality file, manually label 20 seed instruction sets D in the urban rail emergency field S-I The elements of the seed instruction set should be composed of instruction I and output O. At the same time, a literature database D ur for storing urban rail field references is constructed

[0070] S6.3: Randomly select 2 seed instructions from the seed instruction set D S-I , randomly select 1 self-generated instruction from the self-generated instruction set D' S-I , if D' S-I is empty, then select 1 instruction from D S-I , a total of 3 instructions as input instruction set D I input into the large language model

[0071] S6.4: Concatenate the randomly selected instruction set D I with the prompt template Prompt instruction as a new question, process it according to the urban rail transit emergency field question and answer method based on optimized RAG generated based on optimized retrieval enhancement, at this time, the article abstract index is used to get the large model reply A I containing n urban rail emergency field instructions; parse the model reply A I according to a specific format to get n structured vertical field instructions I1-I n , and save the self-generated instruction as the self-generated instruction set D' S-I ;

[0072] S6.5: Repeat the above process until the number of vertical field instructions reaches the set threshold m, then proceed to the next step, the number of iterations δ = m / n, δ is rounded up;

[0073] S6.7: The self-generated instruction set D' S-I are sequentially combined with the prompt template Prompt output after splicing as a new question, and processed according to the city rail transit emergency field question and answer method based on the optimized RAG generated by the optimized retrieval enhancement, at this time, the index based on the vector database is used, and m large model replies A O are obtained. The instructions in the instruction set D' S-I are sequentially combined with the corresponding outputs O and saved to obtain m city rail emergency field data sets for fine-tuning of large language models;

[0074] S6.8: The self-generated city rail emergency field data set is cleaned to remove low-quality and duplicate data. After obtaining high-quality data, the base model is fine-tuned using LoRA and / or QLoRA or method. The two fine-tuning techniques are efficient parameter fine-tuning techniques that freeze the pre-training model weights, simulate parameter updates through low-rank decomposition, and only train a few additional parameters, enabling efficient fine-tuning.

[0075] In summary, the main process of the embodiment is to first construct a city rail emergency field knowledge base and a retrieval enhancement generation application, enhance retrieval generation in the city rail emergency field using methods such as splitting parent-child documents, fine-tuning word embedding models, and using rearrangement models, then fine-tune the base model ChatGLM3-6B using the self-generated high-quality city rail emergency field data set, and evaluate the fact knowledge of the fine-tuned model to obtain a large language model for subsequent reasoning. When the user inputs a question to the LLM, the word embedding model is used to match the user question vector with the document block vector of the knowledge base, and the rearrangement model is used for recall vector block rearrangement to complete relevant knowledge retrieval. Finally, the integrated prompt template is used as the actual input of the large language model to complete the current question and answer. Repeat the online process for multiple rounds of dialogue.

[0076] Embodiment 2

[0077] Referring to Figures 1-7 For an embodiment of the present application, an RAG-based city rail transit emergency field question and answer system is provided, which includes:

[0078] A data acquisition module is configured to acquire initial user question data and user uploaded files, pre-process the initial user question to obtain a new question, and embed the document blocks and the question. In an embodiment, the data acquisition module can acquire a natural language query request through user input. When a user raises a query, a request, or an instruction, the user can input the natural language query request through a human-computer interaction port (e.g., a user terminal). In an embodiment, the data acquisition module can accept other forms of user input, such as a pdf, an xls file, and the like, and embed and store the files using the knowledge base construction module.

[0079] A question construction module is configured to combine the question Q raised by the user and a city rail transit stylized prompt template into a new question Q'.

[0080] A document type identification module is configured to identify different document types in the city rail transit emergency knowledge base and perform corresponding file parsing.

[0081] A document segmentation and vectorization module is configured to segment the parsed city rail transit emergency knowledge base document to form a plurality of parent document blocks, obtain child document blocks from the parent document blocks, and obtain a new question vector Q'E from a word embedding model, the parent document blocks, the child document blocks, and the new question Q'.

[0082] A calculation recall module is configured to calculate the similarity between the new question vector Q'E and each parent document block or child document block vector, respectively, perform recall according to the similarity, and form a recall document set D most relevant to the question.

[0083] A scoring and sorting module is configured to score the relevance of the document blocks in the recall document set D and reorder them to form a reordered document set D'.

[0084] A reply generation module is configured to construct a model reply prompt template, input the new question Q' and the reordered document set D' into the model reply prompt template, and input the model reply prompt template into a base large language model that is not adjusted or is adjusted and optimized in the city rail emergency field to obtain a large language model generated reply A.

[0085] A user management module is configured to manage usernames and passwords. In an embodiment, the user management module can hash the usernames and passwords of the users, add new users, and modify and delete existing user information.

[0086] Embodiment 3

[0087] For an embodiment of the present application, which is different from the previous embodiment:

[0088] If the functions are implemented in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the parts of the technical solutions that essentially contribute to the prior art or the parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

[0089] The logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as a list of executable instructions for implementing logic functions, which can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus or device, such as a computer-based system, a system including a processor or other system that can fetch the instructions from the instruction execution system, apparatus or device and execute the instructions, or in conjunction with these instructions execution systems, apparatus or devices. For the purpose of this specification, the "computer-readable medium" can be any device that can contain, store, communicate, propagate or transport programs for use by or in connection with an instruction execution system, apparatus or device, or in conjunction with these instruction execution systems, apparatus or devices.

[0090] More specific examples (a non-exhaustive list) of the computer-readable medium include the following: an electrical connection having one or more wires (electrical devices), a portable computer diskette (magnetic devices), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). In addition, the computer-readable medium can even be paper or other suitable medium on which the program can be printed, as the program can be electronically obtained, for example, by optical scanning of the paper or other medium, followed by editing, interpreting or otherwise processing, if necessary, in other suitable ways to be electronically obtained, and then stored in the computer memory.

[0091] It should be understood that portions of the present application can be implemented in hardware, software, firmware, or combinations thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, implementation can be with any or a combination of the following technologies, which are all well known in the art: a discrete logic circuit having logic gates for implementing logic functions upon an application of data signals, an application specific integrated circuit having appropriate combinational logic gates, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0092] It should be noted that the above examples are only used to illustrate the technical solutions of the present application but not limit the present application. Although the present application is described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present application can be modified or replaced equivalently without departing from the spirit and scope of the present application, and all should be covered in the scope of the claims of the present application.

Claims

1. A question-and-answer method for urban rail transit emergency response based on optimized RAG, characterized in that, include: Combine question Q with a stylized prompt template for urban rail transit to create a new question Q'; Identify and parse different document types within the urban rail emergency knowledge base; After segmenting and parsing the documents in the urban rail emergency knowledge base, multiple parent document blocks are formed. Sub-document blocks are obtained based on the parent document blocks. Based on the word embedding model, parent document blocks, sub-document blocks, and the new question Q′, a new question vector Q′E is obtained. Calculate the similarity between the new question vector Q'E and each parent document block or child document block vector, and perform recall based on the similarity to form the recall document set D most relevant to the question; The document blocks in the recalled document set D are relevance scored and reordered to form a rearranged document set D'; Construct a prompt template for the model response, and input the new question Q′ and rearranged document set D′ into the prompt template for the model response. Input the prompt template for the model response into the base large language model that has not been adjusted or has been adjusted and optimized in the field of urban rail emergency response, and obtain the generated response A of the large language model. It also includes the self-generation of vertical domain datasets used for fine-tuning large language models, specifically including the following steps: The prompt template required when constructing the vertical domain dataset instruction I is generated. instruction And the prompt template required when generating output O. output ; Manually annotate 20 vertical domain seed instruction sets D S-I The seed instruction set D S-I The elements consist of instruction I and output O; simultaneously, a literature library D is constructed to store references in the vertical field. ur ; In the seed instruction set D S-I Two seed instructions are randomly selected from the self-generated instruction set D. ′ S-I One self-generated instruction is randomly selected from the set of self-generated instructions D. ′ S-I If it is empty, then it will be retrieved from the seed instruction set D. S-I Select one instruction, for a total of three instructions, as the input instruction set D. I Input into the large language model; The randomly selected input instruction set D I With the aforementioned prompt template Prompt instruction After concatenation, this becomes a new problem. Based on the optimized retrieval enhancement generation method, the unadjusted large language model is used, resulting in a large model response A containing n vertical domain instructions. I ; Reply A to the large model I After parsing, n structured vertical domain instructions I1-I are obtained. n And save the self-generated instructions as a self-generated instruction set D. ′ S-I ; Repeat the above process until the number of instructions in the vertical domain reaches the preset threshold m, then proceed to the next step. The number of iterations is δ = m / n, and δ is rounded up. The self-generated instruction set D ′ S-I All commands in the prompt template are displayed sequentially. output After being concatenated, the results are used as a new question. Based on the optimized retrieval enhancement generation method, an untuned large language model is used, resulting in a response A containing m large models. O Finally, m outputs O are obtained, each corresponding to instruction I; The instruction set D ′ S-I All instructions are sequentially combined with their corresponding outputs O and saved to obtain m vertical domain datasets used for fine-tuning of large language models.

2. The question-and-answer method for urban rail transit emergency response based on the optimized RAG as described in claim 1, characterized in that: The documents in the urban rail emergency knowledge base, after being segmented and parsed, form multiple parent document blocks. Child document blocks are then obtained based on these parent blocks, including the following steps: The parsed document is divided into multiple parent document blocks, with a maximum threshold of L. p-max ; The parent document block is added with a preset ID in key-value pair format, and then the parent document block is divided into n blocks with a maximum threshold of L through mapping. s-max The child document block is defined such that the IDs of the parent document block and the child document block are identical, where n = L. p-max / L s-max Round up; The process of obtaining the new question vector Q′E based on the word embedding model, parent document block, child document block, and new question Q′ includes the following steps: All document blocks are embedded using a word embedding model to obtain vector representations of all document blocks; Persistently store the vector representations of all document blocks in a local vector database; Embedding the new problem Q' yields a new problem vector Q'E.

3. The question-and-answer method for urban rail transit emergency response based on the optimized RAG as described in claim 2, characterized in that: The word embedding model was initially screened and evaluated using a manually constructed urban rail transit emergency domain dataset, and then selected as the best. After selection, it was further fine-tuned and trained using multiple high-quality urban rail transit emergency domain corpora.

4. The question-and-answer method for urban rail transit emergency response based on the optimized RAG as described in claim 3, characterized in that: The step of calculating the similarity between the new question vector Q'E and each parent document block or child document block vector, and then performing recall based on the similarity to form the most relevant recall document set D includes the following steps: The word embedding model is then passed into the query engine Q-Engine; The word embedding model is used to calculate the similarity between the new question vector Q'E and all document block vectors, and the top K document blocks with the highest similarity are recalled. The first K document blocks that are recalled are merged according to their IDs, and parent and child document blocks with the same ID are taken only from the parent document. Get K r Each document block is used to form a recall document set D that is most relevant to the problem.

5. The question-and-answer method for urban rail transit emergency response based on the optimized RAG as described in claim 4, characterized in that: The process of scoring the relevance of document blocks in the recalled document set D and reordering them to form a rearranged document set D' includes the following steps: Load the Reranker and pass it into the query engine Q-Engine; K r Each document block is fed into the Reranker, and the new question vector Q′E is respectively compared with the K... r Each document block is fed into the trained cross-encoder, and deep learning modeling is performed through a deep neural network to obtain the correlation between vectors; The new problem vector Q'E and the K are calculated based on a deep neural network. r Relevance score of each document block; The correlation scores are sorted from highest to lowest, and the top K most strongly correlated scores are selected. r 'A set of documents is formed by 'a set of documents D'.

6. The question-and-answer method for urban rail transit emergency response based on the optimized RAG as described in claim 5, characterized in that: Document parsing includes the following steps: Determine if the document is an xlsx or xls file. If it is, use the pandas library to convert it to a CSV file, and then use PagedCSVReader to parse the file. Determine if the document is a PDF file; if it is, use PyMuPDFReader to parse the file. Determine if the document is a CSV file; if it is, use PagedCSVReader to parse the file. Determine if the document is a .doc file. If it is a .doc file, use DocxReader to parse the file.

7. A system employing the question-and-answer method for urban rail transit emergency response based on any one of claims 1 to 6, characterized in that, include: The question construction module is used to combine a user-submitted question Q with a stylized prompt template for urban rail transit to create a new question Q'. The document type identification module is used to identify different document types within the urban rail emergency knowledge base and perform corresponding file parsing. The document segmentation and vectorization module is used to segment the parsed documents in the urban rail emergency knowledge base, forming multiple parent document blocks. Sub-document blocks are obtained based on the parent document blocks. Based on the word embedding model, parent document blocks, sub-document blocks, and new question Q', a new question vector Q'E is obtained. The recall calculation module is used to calculate the similarity between the new question vector Q'E and each parent document block or child document block vector, and to perform recall based on the similarity to form the recall document set D most relevant to the question; The scoring and sorting module is used to score the relevance of document blocks in the recalled document set D and re-sort them to form a rearranged document set D'. The response generation module is used to construct a prompt template for the model response. The new question Q' and the rearranged document set D' are passed into the prompt template for the model response. The prompt template for the model response is then passed into the base large language model that has not been adjusted or has been adjusted and optimized in the field of urban rail emergency response, so as to obtain the generated response A of the large language model.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the question-and-answer method for urban rail transit emergency response based on any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the question-and-answer method for urban rail transit emergency response based on the optimized RAG as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Statistical report generation method and system based on large language model

    CN117875296A

  • Large model-based vertical domain question and answer method and system

    CN118260393A