Power knowledge service method and device for multi-path recall retrieval, equipment and medium
Through multi-channel recall retrieval and security protection models, the problems of ambiguous answers and information security in power standard knowledge services are solved, the retrieval accuracy and answer security are improved, and the diverse needs of users are met.
Patent Information
- Application Number
- CN202410862725.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-10-01
AI Technical Summary
The answers in the existing power standard knowledge services are vague and lack details, which cannot meet the precise and diverse needs of users. There is also a lack of knowledge enhancement technology in the field of power standards, and there are missing key documents and information security issues.
The multi-path recall retrieval method is used to generate retrieval vectors through vectorization processing of query information. It combines dense and sparse retrieval methods, uses hybrid retrieval and multi-path recall strategies to match and reorder in the vector database, and combines the security protection model to ensure the security of the answer. and accuracy.
It improves the retrieval accuracy and generalization ability of electric power knowledge services, avoids the output of wrong answers, enhances the relevance, accuracy and interpretability of answers, and provides highly accurate and safe knowledge services through security protection.
Smart Images

Figure CN118733732A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of power systems, and in particular to a method, device, equipment and medium for multi-channel recall retrieval of power knowledge services. Background Art
[0002] At present, the power standard knowledge service mainly relies on the traditional entry-based retrieval of small model-related technologies. Due to the diversified development of interactive content and forms, and limited by the knowledge quality and scale of the knowledge base, it cannot meet the needs of accurate user demand analysis, diversified question-and-answer task response, real-time and efficient dialogue response, etc. At the same time, although large-scale models have the ability to emerge knowledge and understand user intentions, they lack knowledge enhancement technology that is deeply integrated with them in the field of power standards, and there are problems such as missing key documents, too long context, vague answers lacking details, and information security. Summary of the invention
[0003] In order to solve the technical problem that the answers in the current power standard knowledge service are vague and lack details, the present invention provides a multi-channel recall retrieval power knowledge service method, device, equipment and medium.
[0004] In a first aspect, the present invention provides a multi-channel recall retrieval power knowledge service method, the method comprising:
[0005] Vectorizing the query information to obtain a search vector, and searching the search vector using a searcher to obtain search information;
[0006] Using a preset recall strategy to match the search information in a vector database to obtain matching results, and reordering the matching results through hybrid retrieval;
[0007] The reordered matching results are input into the power knowledge service model to generate answer results, and the query information and the answer results are input into the security protection model. If the output result indicates that the security test has passed, the answer result is output.
[0008] Based on the above technical solution, further, vectorizing the query information to obtain a search vector, and searching the search vector by a searcher to obtain search information specifically includes:
[0009] The query information q and the instruction are input into the semantic big model to generate multiple pseudo documents [d1, d2, ..., d n ];
[0010] The pseudo document [d1, d2, ..., d n ] is input into the text vector model for encoding to obtain the first dense vector f(d k), where encoder f is a lossy compressor;
[0011] Input the query information q into the text vector model for encoding to obtain a second dense vector f(q);
[0012] For the first dense vector f(d k ) and the second dense vector f(q) to obtain the retrieval vector
[0013] Retrieving the search vector in the vector database by the retriever to obtain a preliminary search result;
[0014] The position of the text vector in the preliminary search result in the vector database is obtained as the center position, and the text vector in a preset range centered on the center position in the vector database is extracted, and the extracted result is placed in the preliminary search result to obtain the search result.
[0015] Based on the above technical solution, further, the vector database is established by the following method:
[0016] Segmenting the electric power knowledge base document into independent sentence segments or fixed-length sentence windows, wherein the sentence window includes a plurality of consecutive sentence segments;
[0017] The sentence segments or fixed-length sentence windows are input into the text vector model to generate text vectors, and the text vectors are stored in the vector database.
[0018] Based on the above technical solution, further, the preset recall strategy is used to match the search information in the vector database to obtain the matching result, which specifically includes:
[0019] The search information is matched in the vector database in parallel using a content-based recall strategy, a collaborative filtering recall strategy and a user portrait recall strategy, and the matching results obtained are merged to obtain the matching result, wherein the matching result also includes the search vector and the search result.
[0020] Based on the above technical solution, further, the reordering of the matching results by hybrid retrieval specifically includes:
[0021] Perform dense search on the matching results to obtain the first candidate result s dense ;
[0022] And, simultaneously, sparse search is performed on the matching results to obtain a second candidate result s sparse ;
[0023] After combining the first candidate result and the second candidate result, the combined result is reordered. rank ←s dense +s sparse .
[0024] Based on the above technical solution, further, the dense search of the matching results to obtain the first candidate result specifically includes:
[0025] The search vector Vec in the matching result q After normalization using the preset special characters, the first normalized vector e is obtained q , e q = norm(Vec q [0]), where norm(·) represents the normalization function;
[0026] The search result Vec in the matching result p After normalization using the preset special characters, the second normalized vector e is obtained p , e p = norm(Vec p [0]);
[0027] Calculate the first normalized vector e q and the second normalized vector e p The inner product between them gives the first candidate result s dense ,s dense ← <e p ,e q >
[0028] The performing sparse search on the matching results to obtain the second candidate results specifically includes:
[0029] For the search vector Vec in the matching result q Calculate the character weight for each character t in
[0030] in, Matrix mapping the retrieved vector Vec q is a floating point number, ReLU(·) is a nonlinear activation function;
[0031] For the search result Vec in the matching result p Calculate the character weight for each character t in
[0032] According to the retrieval vector Vec q and the search result Vec pThe coexistence term q∩p in
[0033] According to the coexistence term q∩p, respectively in the search vector Vec q Character weights in and the search result Vec p The character weights in , calculate the joint importance to get the second candidate result s sparse ,
[0034] Based on the above technical solution, further, the step of inputting the query information and the answer result into the security protection model specifically includes:
[0035] Inputting the query information into the security protection model to obtain a prompt classification;
[0036] Inputting the answer result into the security protection model to obtain a response classification;
[0037] According to the prompt classification, determining whether the query information is safe information or unsafe information;
[0038] According to the response classification, it is determined whether the answer result is safe information or unsafe information.
[0039] In a second aspect, the present invention further provides an electric power knowledge service device based on hybrid retrieval and multi-way recall retrieval, the device comprising:
[0040] A first processing module, configured to perform vectorization processing on the query information to obtain a search vector, and to retrieve the search vector through a retriever to obtain search information;
[0041] A second processing module is used to match the search information in the vector database using a preset recall strategy to obtain matching results, and re-rank the matching results through hybrid retrieval;
[0042] The third processing module is used to input the re-ordered matching results into the power knowledge service model to generate answer results, and input the query information and the answer results into the security protection model. If the output result indicates that the security check has passed, the answer result is output.
[0043] Based on the above technical solution, further, the first processing module is specifically used to input the query information q and the instruction into the semantic big model to generate multiple pseudo documents [d1, d2, ..., d n ];
[0044] The pseudo document [d1, d2, ..., d n ] is input into the text vector model for encoding to obtain the first dense vector f(d k), where encoder f is a lossy compressor;
[0045] Input the query information q into the text vector model for encoding to obtain a second dense vector f(q);
[0046] For the first dense vector f(d k ) and the second dense vector f(q) to obtain the retrieval vector
[0047] Retrieving the search vector in the vector database by the retriever to obtain a preliminary search result;
[0048] The position of the text vector in the preliminary search result in the vector database is obtained as the center position, and the text vector in a preset range centered on the center position in the vector database is extracted, and the extracted result is placed in the preliminary search result to obtain the search result.
[0049] Based on the above technical solution, further, the first processing module is specifically used to divide the power knowledge base document into independent sentence fragments or sentence windows of fixed length, wherein the sentence window includes a plurality of continuous sentence fragments;
[0050] The sentence segments or fixed-length sentence windows are input into the text vector model to generate text vectors, and the text vectors are stored in the vector database.
[0051] Based on the above technical solution, further, the second processing module is specifically used to use the content-based recall strategy, the collaborative filtering recall strategy and the user portrait recall strategy to match the retrieval information in the vector database in parallel, and merge the matching results obtained separately to obtain the matching result, wherein the matching result also includes the retrieval vector and the retrieval result.
[0052] Based on the above technical solution, further, the second processing module is specifically used to perform dense search on the matching results to obtain the first candidate result s dense ;
[0053] And, simultaneously, sparse search is performed on the matching results to obtain a second candidate result s sparse ;
[0054] After combining the first candidate result and the second candidate result, the combined results are re-ranked according to the relevance score. rank ←s dense +s sparse .
[0055] Based on the above technical solution, further, the second processing module is specifically used to process the search vector Vec in the matching result. q After normalization using the preset special characters, the first normalized vector e is obtained q , e q = norm(Vec q [0]), where norm(·) represents the normalization function;
[0056] The search result Vec in the matching result p After normalization using the preset special characters, the second normalized vector e is obtained p , e p = norm(Vec p [0]);
[0057] Calculate the first normalized vector e q and the second normalized vector e p The inner product between them gives the first candidate result s dense ,s dense ← <e p ,e q >
[0058] Based on the above technical solution, further, the second processing module is specifically used for the search vector Vec in the matching result q Calculate the character weight for each character t in
[0059] in, Matrix mapping the retrieved vector Vec q is a floating point number, ReLU(·) is a nonlinear activation function; for the retrieval result Vec in the matching result p Calculate the character weight for each character t in
[0060] According to the retrieval vector Vec q and the search result Vec p The coexistence term q∩p in
[0061] According to the coexistence term q∩p, respectively in the search vector Vec q The character weight w in qt and the search result Vec p The character weights in are calculated to obtain the second candidate result s sparse ,
[0062] Based on the above technical solution, further, the third processing module is specifically used to input the query information into the security protection model to obtain a prompt classification;
[0063] Inputting the answer result into the security protection model to obtain a response classification;
[0064] According to the prompt classification, determining whether the query information is safe information or unsafe information;
[0065] According to the response classification, it is determined whether the answer result is safe information or unsafe information.
[0066] In a third aspect, the present invention also provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, it implements the electric power knowledge service method based on hybrid retrieval and multi-way recall retrieval as described in any one of the above technical solutions.
[0067] In a fourth aspect, the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the multi-channel recall retrieval power knowledge service method described in any one of the above technical solutions is implemented.
[0068] The present invention provides a method for a multi-way recall retrieval of electric power knowledge service, including vectorizing query information to obtain a retrieval vector, retrieving the retrieval vector through a retriever to obtain retrieval information; matching the retrieval information in a vector database using a preset recall strategy to obtain a matching result, and reordering the matching result through a hybrid retrieval; inputting the reordered matching result into a large model of electric power knowledge service to generate an answer result, and inputting the query information and the answer result into a safety protection model, and if the output result is that the safety detection is passed, outputting the answer result. The present invention combines the actual situation of electric power standard knowledge service, mixes dense retrieval and sparse retrieval methods, and adopts a multi-way recall strategy to optimize multi-functional retrieval and reordering on high-quality and diversified data, and finally forms a large model of electric power standard knowledge service enhanced based on hybrid retrieval and multi-way recall retrieval, and designs a reasonable prompt template to imitate the logical thinking of business personnel to assist in carrying out electric power knowledge question and answer service business, so that the model has higher retrieval accuracy and stronger generalization ability, avoids the model outputting wrong answers while improving the relevance, accuracy and interpretability of the model, and provides users with high-accuracy and security knowledge services through safety protection. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:
[0070] Figure 1 It is a flow chart of a method for providing electric power knowledge service based on hybrid retrieval and multi-channel recall retrieval provided by an embodiment of the present invention;
[0071] Figure 2 An operation flow chart of an electric power knowledge service method based on hybrid retrieval and multi-way recall retrieval provided by an embodiment of the present invention;
[0072] Figure 3 A schematic diagram of a retrieval enhancement process of hybrid retrieval and multi-way recall provided in an embodiment of the present invention;
[0073] Figure 4 A module schematic diagram of an electric power knowledge service device based on hybrid retrieval and multi-way recall retrieval provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0074] The present invention will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present invention can be combined with each other without conflict.
[0075] The following detailed description is an exemplary description, which is intended to provide further detailed description of the present invention. Unless otherwise specified, all technical terms used in the present invention have the same meaning as those generally understood by those skilled in the art to which the present invention belongs. The terms used in the present invention are only for describing specific embodiments, and are not intended to limit the exemplary embodiments according to the present invention.
[0076] The following will be combined with the attached Figure 1 , a multi-channel recall retrieval power knowledge service method provided by an embodiment of the present invention is described, comprising the following steps:
[0077] 110. Perform vectorization processing on the query information to obtain a search vector, and perform a search on the search vector by a searcher to obtain search information;
[0078] 120. Using a preset recall strategy to match the search information in a vector database to obtain matching results, and reordering the matching results through hybrid retrieval;
[0079] 130. Input the re-ordered matching results into the power knowledge service model to generate answer results, and input the query information and the answer results into the security protection model. If the output result indicates that the security check has passed, output the answer result.
[0080] Based on the above embodiment, further, step 110 specifically includes:
[0081] The query information q and the instruction are input into the semantic big model to generate multiple pseudo documents [d1, d2, ..., d n ];
[0082] The pseudo document [d1, d2, ..., d n ] is input into the text vector model for encoding to obtain the first dense vector f(d k ), where encoder f is a lossy compressor;
[0083] Input the query information q into the text vector model for encoding to obtain a second dense vector f(q);
[0084] For the first dense vector f(d k ) and the second dense vector f(q) to obtain the retrieval vector
[0085] Retrieving the search vector in the vector database by the retriever to obtain a preliminary search result;
[0086] The position of the text vector in the preliminary search result in the vector database is obtained as the center position, and the text vector in a preset range centered on the center position in the vector database is extracted, and the extracted result is placed in the preliminary search result to obtain the search result.
[0087] It should be understood that the text vector model uses the RetroMAE pre-training method to provide a text vector model that can support a length of 8192 characters. Specifically, in the encoding process, the input with a low mask rate is encoded into a semantic vector, and then the input with a high mask rate is concatenated with the semantic vector to reconstruct the original input. In terms of the model structure, an asymmetric structure is adopted. Among them, the encoder is a full-size BERT, which is used to generate sentence vectors; and the decoder is a single-layer Transformer, which is used to reconstruct the input sentence. Through this training algorithm, a text vector model is constructed to provide vectorization functions for user queries and document segmentation, and to provide support for measuring the correlation between data samples in retrieval.
[0088] The semantic big model is an artificial intelligence model based on deep learning. Through learning and training of massive data, it can generate continuous text with semantic coherence and logic. The content generation method of the semantic big model can be applied to natural language processing tasks. By inputting a piece of original text, the model can generate coherent text that conforms to grammatical and semantic rules, improve the efficiency and accuracy of text processing, and provide convenience for people's daily work and study; the semantic big model can generate more diverse and flexible text content by learning a large amount of text data to meet the personalized needs of users; the semantic big model can generate logical and semantic answers based on the questions input by the user, and realize a more natural and smooth conversation experience. The semantic big model in this embodiment can be a general semantic big model or a semantic big model for power services.
[0089] Based on the above embodiment, further, step 200 is included, and step 200 includes:
[0090] Segmenting the electric power knowledge base document into independent sentence segments or fixed-length sentence windows, wherein the sentence window includes a plurality of consecutive sentence segments;
[0091] The sentence segments or fixed-length sentence windows are input into the text vector model to generate text vectors, and the text vectors are stored in the vector database.
[0092] Specifically, parent-child document retrieval can also be used. Parent-child document retrieval splits the text into large parent blocks and small child blocks to achieve document retrieval. The child blocks are stored in the vector storage due to their precise semantic embedding, while the parent blocks are stored in the memory storage and indexed by a unique ID. When adding documents, the parent block is split and stored, and the child blocks are further split and stored with the ID of the parent block. When searching, the relevant parent block is found and returned through the similarity matching of the child blocks, which not only takes advantage of the precise matching of the child blocks, but also provides rich context of the parent block.
[0093] Based on the above embodiment, further, the step 120 of using a preset recall strategy to match the search information in the vector database to obtain a matching result specifically includes:
[0094] The search information is matched in the vector database in parallel using a content-based recall strategy, a collaborative filtering recall strategy and a user portrait recall strategy, and the matching results obtained are merged to obtain the matching result, wherein the matching result also includes the search vector and the search result.
[0095] Specifically, content-based recall is based on the similarity of content; collaborative filtering recall is performed by constructing a user-document content matrix, in which each element represents the user's preference for a document; user portrait recall focuses on understanding the characteristics and needs of users, by constructing user portraits such as region, age, gender, time, etc., and assigning a series of labels to each user, and matching is performed based on the user portrait to recall content that better matches the user portrait.
[0096] Based on the above embodiment, further, the step 120 of reordering the matching results by hybrid retrieval specifically includes:
[0097] 121. Perform dense search on the matching results to obtain the first candidate result s dense ;
[0098] 122. Simultaneously, a sparse search is performed on the matching results to obtain a second candidate result s sparse ;
[0099] 123. After combining the first candidate result and the second candidate result, reorder the combined results according to the relevance score. rank ←s dense +s sparse .
[0100] Based on the above embodiment, further, step 121 specifically includes:
[0101] The search vector Vec in the matching result q After normalization using special characters, we get the first normalized vector e q , e q = norm(Vec q [0]), where norm(·) represents the normalization function;
[0102] The search result Vec in the matching result p After normalization using special characters, the second normalized vector e is obtained p , e p = norm(Vec p [0]);
[0103] Calculate the first normalized vector e q and the second normalized vector e p The inner product between them gives the first candidate result s dense ,s dense ← <e p ,e q >
[0104] Based on the above embodiment, further, step 122 specifically includes:
[0105] For the search vector Vec in the matching result q Calculate the character weight for each character t in
[0106] in, Matrix mapping the retrieved vector Vec q is a floating point number, ReLU(·) is a nonlinear activation function;
[0107] For the search result Vec in the matching result p Calculate the character weight for each character t in
[0108] According to the retrieval vector Vec q and the search result Vec p The coexistence term q∩p in
[0109] According to the coexistence term q∩p, respectively in the search vector Vec q Character weights in and the search result Vec p The character weights in are calculated to obtain the second candidate result s sparse ,
[0110] Based on the above embodiment, further, in step 130, the query information and the answer result are input into the security protection model, which specifically includes:
[0111] Inputting the query information into the security protection model to obtain a prompt classification;
[0112] Inputting the answer result into the security protection model to obtain a response classification;
[0113] According to the prompt classification, determining whether the query information is safe information or unsafe information;
[0114] According to the response classification, it is determined whether the answer result is safe information or unsafe information.
[0115] The present embodiment provides a method for a multi-way recall retrieval of electric power knowledge service, including vectorizing query information to obtain a retrieval vector, retrieving the retrieval vector through a retriever to obtain retrieval information; matching the retrieval information in a vector database using a preset recall strategy to obtain a matching result, and reordering the matching result through a hybrid retrieval; inputting the reordered matching result into a large model of electric power knowledge service to generate an answer result, and inputting the query information and the answer result into a safety protection model, and if the output result is that the safety detection is passed, outputting the answer result. The present invention combines the actual situation of electric power standard knowledge service, mixes dense retrieval and sparse retrieval methods, and uses a multi-way recall strategy to optimize multi-functional retrieval and reordering on high-quality and diversified data, and finally forms a large model of electric power standard knowledge service enhanced by hybrid retrieval and multi-way recall retrieval, and designs a reasonable prompt template to imitate the logical thinking of business personnel to assist in carrying out electric power knowledge question and answer service business, so that the model has higher retrieval accuracy and stronger generalization ability, avoids the model outputting wrong answers while improving the relevance, accuracy and interpretability of the model, and provides users with high-accuracy and security knowledge services through safety protection. 。
[0116] It should be understood that the present invention is based on existing power standard data, knowledge and expert experience, combined with the actual situation of power standard knowledge services, to form a large model of power knowledge question-and-answer services based on hybrid retrieval and multi-way recall retrieval enhancement, and adopts RetroMAE pre-training to provide a text vector model that can support 8192 characters in length; it mixes multiple retrieval methods, including dense retrieval and sparse retrieval, and adopts a multi-way recall strategy to optimize multi-functional retrieval and re-ranking on high-quality and diversified data, so that the model has higher retrieval accuracy and stronger generalization ability. In order to solve the problem of inconsistency and incoherence between queries and replies during the generation process, a query conversion method is used to modify the input query to generate a pseudo-document, and the document is used as the key for retrieval to make the generated content more coherent and accurate; the sentence window document segmentation method is used to retrieve the specific sentence that is most relevant to the query answer, and by returning more text around the sentence, a wider context is provided in the model as the basis for its response, thereby enhancing the consistency of the generation. Based on the retrieval-enhanced big model of electric power standard knowledge service, the common forms that appear in the knowledge service process are summarized, and reasonable prompt templates are designed to assist the semantic big model to accurately generate the content required by users; according to security requirements, a data security module based on the semantic big model is introduced to reduce security risks in intelligent knowledge services.
[0117] The present invention optimizes the data processing stage, converts user queries into more detailed pseudo-documents, uses sentence window segmentation to perform text segmentation after loading the knowledge base document, returns the text around the sentence after retrieval, and uses RetroMAE pre-training to provide a text vector model that can support a length of 8192 characters for text vectorization; secondly, based on the existing power standard data, knowledge and expert experience, combined with the actual situation of power standard knowledge services, hybrid dense retrieval and sparse retrieval methods are used, and a multi-way recall strategy is used to optimize multi-functional retrieval and re-ranking on high-quality and diversified data to form a large model of power standard knowledge services based on hybrid retrieval and multi-way recall retrieval enhancement; finally, based on the model, for the common forms that appear in the standard knowledge service process, a reasonable prompt template is designed and a data security module is introduced to generate user replies.
[0118] like Figure 2 As shown, the specific steps proposed by the present invention are as follows:
[0119] Step 1: Optimize the input of the power standard knowledge service. For the two parts of the input (query and document knowledge base) of the power standard knowledge service, query transformation and sentence window document fragmentation methods are used to rewrite and reconstruct it so that the model can produce accurate and consistent answers.
[0120] Step 1.1: Query transformation. Modify the input query to generate a pseudo document, align the semantic space of the query and the document through the pseudo document, and use the pseudo document as the retrieval key. First, use the semantic big model to generate multiple pseudo documents [d1, d2, ..., d n ] is used to obtain relevant patterns and explain user queries. Secondly, the pseudo document input is encoded into a dense vector f(d k ), where the encoder f is a lossy compressor that filters out extra details and noise and removes them from the vector. Finally, the query and the generated pseudo-documents are averaged:
[0121]
[0122] Step 1.2: Sentence window document fragmentation. First, the knowledge base document is segmented into independent sentences or fixed-length sentence windows, containing one or more consecutive sentences. The fragment blocks are vectorized and enter the vector database to provide knowledge for the retriever. After the retrieval process is completed, since the sentence fragments are small, two additional fragments above and below the retrieved sentence fragments are taken from the original fragment block and output to the generation model to provide it with sufficient context to answer the query.
[0123] Step 1.3: Text vectorization. RetroMAE pre-training is used to provide a text vector model that can support 8192 characters in length. Specifically, in the encoding process, the input with low mask rate is encoded into a semantic vector, and then the input with high mask rate is concatenated with the semantic vector to reconstruct the original input. In terms of model structure, an asymmetric structure is adopted. Among them, the encoder is a full-size BERT, which is used to generate sentence vectors; and the decoder is a single-layer Transformer, which is used to reconstruct the input sentence. Through this training algorithm, a text vector model is constructed to provide vectorization functions for user queries and document segmentation, and to provide support for measuring the correlation between data samples in retrieval.
[0124] like Figure 3 As shown in the figure, step 2: Retrieval enhances the construction of a large model of power standard knowledge service. Design hybrid retrieval and multi-way recall retrieval methods and power field instruction fine-tuning learning methods to optimize the power standard knowledge large model and provide more accurate and scenario-specific answers.
[0125] Step 2.1: Multi-way recall. Retrieve information in parallel through multiple different strategies or features, and then merge the results of these strategies to obtain richer and more diverse recall results. Recall strategies include content-based recall, collaborative filtering recall, and user portrait recall. Among them, content-based recall recalls based on content similarity; collaborative filtering recall builds a user-document content matrix, and each element in the matrix represents the user's preference for the document; user portrait recall focuses on understanding the characteristics and needs of users, and by building user portraits (such as region, age, gender, time, etc.), a series of labels are added to each user, and matching is assisted by user portraits to recall content that better matches the user portrait.
[0126] Step 2.2: Hybrid retrieval. Hybrid retrieval includes dense retrieval and sparse retrieval. Depending on the recall strategy, the dense retrieval input query q is converted into the hidden state Vec of the corresponding strategy based on the text vector model. q , normalized vector Vec using special characters [CLS] q [0] to represent the query:
[0127] e q = norm(Vec q [0])
[0128] Among them, norm(·) represents the normalization function. Similarly, the input document fragment can also be converted into the corresponding hidden state representation:
[0129] e p = norm(Vec p [0])
[0130] The relevance score between the query and the document shard is expressed by two vectors e p and e q The inner product between them is obtained:
[0131] s dense ← <e p ,e q
[0132] Sparse retrieval is a word-level retrieval method used to estimate the importance of each word. For each character t in the query, the character weight is calculated as:
[0133]
[0134] in, The matrix maps the hidden state vector to a floating point number, and ReLU(·) is the nonlinear activation function. If a character t appears multiple times in the query, only its maximum weight is retained. The same method is used to calculate the weight of each item in the document shard. Based on the estimated series of weights, the relevance score between the query and the document shard is calculated by the joint importance of the co-existing items in the query and the document shard (denoted as q∩p):
[0135]
[0136] Due to the versatility of the embedding model, the retrieval process can be performed as a hybrid process. Candidates are checked by each method individually and the final retrieval results are re-ranked based on the combined relevance score:
[0137] s rank ←s dense +s sparse
[0138] Step 3: Fine-tune the instructions of the large model of power standard knowledge service. Collect power standard instruction data to form an instruction data set in the form of (instruction, input, output) triples. Among them, the power standard instruction data includes power standard knowledge, basic power theory, typical cases of standard knowledge services, and manually annotated business standard questions and standard answers, etc., to ensure that the model can learn a wide range of real operating scenarios. In order to build a high-quality and diverse instruction data set, power business experts are invited to check and correct the wrong answers in the instruction data set, and rewrite the instruction sentences to expand the form of instructions in the data set. After the experts correct and expand the instruction data, the power standard knowledge service instruction data set is obtained. In the model training stage, the instructions of the power semantic large model are fine-tuned to establish two retrieval functions corresponding to the three recall methods, so that the model is more suitable for the enhanced generation method of power standard knowledge retrieval.
[0139] Step 4: Design of prompt template for power standard knowledge service. Based on the retrieval-enhanced power knowledge question-and-answer service model, use the knowledge retrieval matching results to design prompt templates for common forms that appear in the knowledge service process, use the retrieved documents to form context related to the question, and provide the question and context together to the power knowledge question-and-answer service model to generate an answer.
[0140] Step 5: Model security protection. Introduce an input-output security protection model to combat problems such as prompt injection and malicious questioning, handle unsafe outputs, prevent the leakage of sensitive information, and enhance the security of AI dialogue. First, design seven typical security scenarios, including swearing insults, prejudice discrimination, crimes, physical harm, mental health, property privacy, and moral ethics; as well as three types of instruction attack scenarios, including prompt leakage, role-playing instructions, and sensitive instruction topics. Use an LLaMa Guard-based model to check and classify inputs (through prompt classification) and outputs (through response classification) to determine whether a specific prompt or response is considered safe or unsafe. If the root identification content is unsafe, the category of the violation is prompted.
[0141] Specifically, the security protection module can use factual error correction to change erroneous generated text, align the output of the model with human values, and make it consistent with the provided knowledge; and use a banned word list to prohibit the output of text containing banned words.
[0142] Based on the problems that existing general retrieval generation technologies lack research on knowledge services and the generated results are inconsistent and incoherent with the subject, the present invention adopts a query conversion method and a sentence window document segmentation method to avoid answers lacking necessary details or specificity and enhance the consistency and coherence of answers; a multi-way recall strategy is adopted to optimize multi-functional retrieval and re-ranking on high-quality and diversified data, and a reasonable prompt template is designed to imitate the logical thinking of business personnel to assist in carrying out power knowledge question and answer service business, so that the model has higher retrieval accuracy and stronger generalization ability, avoids the model outputting wrong answers while improving the relevance, accuracy and interpretability of the model; an input-output safety protection model is introduced to provide users with highly accurate and secure knowledge services.
[0143] The present invention is based on the existing power standard data, summarizes the actual situation of power knowledge question-and-answer services, adopts a multi-way recall strategy and two retrieval methods, and re-sorts by mixing multiple scores to obtain the document fragments most relevant to the query, providing a knowledge basis for the accurate generation of the model.
[0144] In order to address the inconsistency and discontinuity between queries and responses in the power standard knowledge service, the power document segmentation method is optimized to retrieve specific sentences that are most relevant to answering queries and return more text around the sentence; the power user queries in the service are modified to generate pseudo-documents as retrieval keys, which helps to retrieve accurate results and enrich the answer details.
[0145] Seven typical security scenarios and three instruction attack scenarios are designed, and a model based on LLaMa Guard is used to check and classify the content of input and output to determine whether a specific prompt or response is considered safe or unsafe.
[0146] like Figure 4 As shown, the present invention also provides a multi-channel recall retrieval power knowledge service device, the device comprising:
[0147] A first processing module, configured to perform vectorization processing on the query information to obtain a search vector, and to retrieve the search vector through a retriever to obtain search information;
[0148] A second processing module is used to match the search information in the vector database using a preset recall strategy to obtain matching results, and re-rank the matching results through hybrid retrieval;
[0149] The third processing module is used to input the re-ordered matching results into the power knowledge service model to generate answer results, and input the query information and the answer results into the security protection model. If the output result indicates that the security check has passed, the answer result is output.
[0150] Based on the above embodiment, further, the first processing module is specifically used to input the query information q and the instruction into the semantic big model to generate multiple pseudo documents [d1, d2, ..., d n ];
[0151] The pseudo document [d1, d2, ..., d n ] is input into the text vector model for encoding to obtain the first dense vector f(d k ), where encoder f is a lossy compressor;
[0152] Input the query information q into the text vector model for encoding to obtain a second dense vector f(q);
[0153] For the first dense vector f(d k ) and the second dense vector f(q) to obtain the retrieval vector
[0154] Retrieving the search vector in the vector database by the retriever to obtain a preliminary search result;
[0155] The position of the text vector in the preliminary search result in the vector database is obtained as the center position, and the text vector in a preset range centered on the center position in the vector database is extracted, and the extracted result is placed in the preliminary search result to obtain the search result.
[0156] Based on the above embodiment, further, the first processing module is specifically used to divide the power knowledge base document into independent sentence segments or sentence windows of fixed length, wherein the sentence window includes a plurality of continuous sentence segments;
[0157] The sentence segments or fixed-length sentence windows are input into the text vector model to generate text vectors, and the text vectors are stored in the vector database.
[0158] Based on the above embodiments, further, the second processing module is specifically used to use the content-based recall strategy, the collaborative filtering recall strategy and the user portrait recall strategy to match the retrieval information in the vector database in parallel, and merge the matching results obtained separately to obtain the matching result, wherein the matching result also includes the retrieval vector and the retrieval result.
[0159] Based on the above embodiment, further, the second processing module is specifically used to perform dense search on the matching results to obtain the first candidate result s dense ;
[0160] And, simultaneously, sparse search is performed on the matching results to obtain a second candidate result s sparse ;
[0161] After combining the first candidate result and the second candidate result, the combined result is reordered. rank ←s dense +s sparse .
[0162] Based on the above embodiment, further, the second processing module is specifically used to process the search vector Vec in the matching result. q After normalization using special characters, we get the first normalized vector e q , e q = norm(Vec q [0]), where norm(·) represents the normalization function;
[0163] The search result Vec in the matching result p After normalization using special characters, the second normalized vector e is obtained p , e p = norm(Vecp [0]);
[0164] Calculate the first normalized vector e q and the second normalized vector e p The inner product between them gives the first candidate result s dense ,s dense ← <e p ,e q >
[0165] Based on the above embodiment, further, the second processing module is specifically used for the search vector Vec in the matching result q Calculate the character weight for each character t in
[0166] in, Matrix mapping the retrieved vector Vec q is a floating point number, ReLU(·) is a nonlinear activation function;
[0167] For the search result Vec in the matching result p Calculate the character weight for each character t in
[0168] According to the retrieval vector Vec q and the search result Vec p The coexistence term q∩p in
[0169] According to the coexistence term q∩p, respectively in the search vector Vec q Character weights in and the search result Vec p The character weights in are calculated to obtain the second candidate result s sparse ,
[0170] Based on the above embodiment, further, the third processing module is specifically used to input the query information into the security protection model to obtain a prompt classification;
[0171] Inputting the answer result into the security protection model to obtain a response classification;
[0172] According to the prompt classification, determining whether the query information is safe information or unsafe information;
[0173] According to the response classification, it is determined whether the answer result is safe information or unsafe information.
[0174] The present invention combines the actual situation of electric power standard knowledge service, mixes dense retrieval and sparse retrieval methods, and adopts a multi-way recall strategy to optimize multi-functional retrieval and reordering on high-quality and diversified data, and finally forms a large model of electric power standard knowledge service based on hybrid retrieval and multi-way recall retrieval enhancement. It also designs reasonable prompt templates to imitate the logical thinking of business personnel to assist in carrying out electric power knowledge question and answer service business, so that the model has higher retrieval accuracy and stronger generalization ability, avoids the model outputting wrong answers while improving the relevance, accuracy and interpretability of the model, and provides users with high-accuracy and security knowledge services through security protection.
[0175] The present invention also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, it implements a multi-channel recall retrieval power knowledge service method described in any one of the above technical solutions.
[0176] The present invention also provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the computer program implements a multi-channel recall retrieval power knowledge service method described in any one of the above technical solutions.
[0177] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes. The schemes in the embodiments of the present invention may be implemented in various computer languages, for example, object-oriented programming language Java and literal scripting language JavaScript, etc.
[0178] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0179] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0180] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0181] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0182] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
[0183] The above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit the same. Although the present invention has been described in detail with reference to the above embodiments, a person skilled in the art should understand that the specific implementation modes of the present invention can still be modified or replaced by equivalents, and any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be included in the scope of protection of the claims of the present invention.
Claims
1. A multi-channel recall retrieval power knowledge service method, characterized in that: The method comprises: Vectorizing the query information to obtain a search vector, and searching the search vector using a searcher to obtain search information; Using a preset recall strategy to match the search information in a vector database to obtain matching results, and reordering the matching results through hybrid retrieval; The reordered matching results are input into the power knowledge service model to generate answer results, and the query information and the answer results are input into the security protection model. If the output result indicates that the security test has passed, the answer result is output.
2. The method according to claim 1, characterized in that The vectorization processing of the query information to obtain a search vector, and the searching of the search vector by a searcher to obtain search information specifically includes: The query information q and the instruction are input into the semantic big model to generate multiple pseudo documents [d1, d2, ..., d n ]; The pseudo document [d1, d2, ..., d n ] is input into the text vector model for encoding to obtain the first dense vector f(d k ), where encoder f is a lossy compressor; Input the query information q into the text vector model for encoding to obtain a second dense vector f(q); For the first dense vector f(d k ) and the second dense vector f(q) to obtain the retrieval vector Retrieving the search vector in the vector database by the retriever to obtain a preliminary search result; The position of the text vector in the preliminary search result in the vector database is obtained as the center position, and the text vector in a preset range centered on the center position in the vector database is extracted, and the extracted result is placed in the preliminary search result to obtain the search result.
3. The method according to claim 1, characterized in that The vector database is established by the following method: Segmenting the electric power knowledge base document into independent sentence segments or sentence windows of fixed length, wherein the sentence window includes a plurality of consecutive sentence segments; The sentence segments or fixed-length sentence windows are input into the text vector model to generate text vectors, and the text vectors are stored in the vector database.
4. The method according to claim 1, characterized in that: The using of a preset recall strategy to match the search information in a vector database to obtain a matching result specifically includes: The search information is matched in the vector database in parallel using a content-based recall strategy, a collaborative filtering recall strategy and a user portrait recall strategy, and the matching results obtained respectively are merged to obtain the matching result, wherein the matching result also includes the search vector and the search result.
5. The method according to claim 4, characterized in that The reordering of the matching results by hybrid retrieval specifically includes: Perform dense search on the matching results to obtain the first candidate result s dense ; And, simultaneously, sparse search is performed on the matching results to obtain a second candidate result s sparse ; After combining the first candidate result and the second candidate result, the combined result is reordered. rank ←s dense +s sparse .
6. The method according to claim 5, characterized in that The dense search of the matching results to obtain the first candidate result specifically includes: The search vector Vec in the matching result q After normalization using the preset special characters, the first normalized vector e is obtained q , e q = norm(Vec q [0]), where norm(·) represents the normalization function; The search result Vec in the matching result p After normalization using the preset special characters, the second normalized vector e is obtained p , e p = norm(Vec p [0]); Calculate the first normalized vector e q and the second normalized vector e p The inner product between them gives the first candidate result s dense ,s dense ← <e p ,e q > The performing sparse search on the matching results to obtain the second candidate results specifically includes: For the search vector Vec in the matching result q Calculate the character weight for each character t in in, Matrix mapping the retrieved vector Vec q is a floating point number, ReLU(·) is a nonlinear activation function; for the retrieval result Vec in the matching result p Calculate the character weight for each character t in According to the retrieval vector Vec q and the search result Vec p The coexistence term q∩p in According to the coexistence term q∩p, respectively in the search vector Vec q Character weights in and the search result Vec p The character weights in get the second candidate result s sparse , 7. The method according to claim 1, characterized in that The inputting the query information and the answer result into the security protection model specifically includes: Inputting the query information into the security protection model to obtain a prompt classification; Inputting the answer result into the security protection model to obtain a response classification; According to the prompt classification, determining whether the query information is safe information or unsafe information; According to the response classification, it is determined whether the answer result is safe information or unsafe information.
8. A multi-channel recall retrieval power knowledge service device, characterized in that: The device comprises: A first processing module, configured to perform vectorization processing on the query information to obtain a search vector, and to retrieve the search vector through a retriever to obtain search information; A second processing module is used to match the search information in the vector database using a preset recall strategy to obtain matching results, and re-rank the matching results through hybrid retrieval; The third processing module is used to input the re-ordered matching results into the power knowledge service model to generate answer results, and input the query information and the answer results into the security protection model. If the output result indicates that the security check has passed, the answer result is output.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the electric power knowledge service method of multi-channel recall retrieval described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the electric power knowledge service method of multi-channel recall retrieval described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Digital extraction and retrieval method and device for power grid emergency service file
CN114238559A
Semantic-based deep multi-instance weak supervision text classification method
CN115563284A
Power data information extraction method and device based on large language model
CN117828099A
Cited By
Automobile intelligent question-answering system and method based on large model and retrieval enhancement
CN119202206A
Large-model multi-agent collaborative machine manufacturing knowledge question-answering method
CN119227817A
Retrieval enhancement generation method and device, equipment and storage medium
CN119903079A
Information retrieval system and method based on multi-path recall, terminal, medium and product
CN120407870A
Bid invitation information retrieval method and device based on multi-path mixed recall mechanism
CN120763307A
