Language model enhanced search apparatus

By combining vector databases and language model modules, the retrieval process was optimized, solving the problem of errors generated by large language models, achieving faster and more accurate responses, and improving the user experience.

CN118210903BActive Publication Date: 2025-12-19MINJIANG UNIVERSITY

Patent Information

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

AI Technical Summary

Technical Problem

Existing large language models are prone to errors when generating knowledge beyond the training data, leading to illusions, and retrieval augmentation techniques increase time and cost, impacting user experience.

Method used

By combining the vector database module, interaction module, first index module, and language model module, keyword retrieval and near nearest neighbor search algorithm optimization are performed through the vector database. Search parameters are optimized and enhanced response statements are generated. The response statements are displayed when the evaluation results are satisfactory; otherwise, model response statements are generated through the large language model.

Benefits of technology

It improved the accuracy and speed of responses, reduced user waiting time, saved computing power, and enhanced the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118210903B_ABST
    Figure CN118210903B_ABST
Patent Text Reader

Abstract

The application discloses a language large model enhanced retrieval device, which comprises a vector database module, an interaction module, a first index module and a language model module.The vector database module is used for the following steps: S111, collecting preset corpus, and pre-segmenting the corpus; S112, converting the pre-segmented corpus into a numerical vector; and S113, establishing a vector index by using the numerical vector.The interaction module is used for the following steps: S20, acquiring a first input sentence; and S21, analyzing the first input sentence to obtain a first keyword.The first index module is used for the following step: S22, searching in a first database according to the first keyword as an index to obtain a preset reply sentence.The application can preferentially search in the first database after acquiring a user input sentence, and a language large model can be nested and generated according to the search in the first database and the first input sentence, so that a more suitable reply to the user can be finally generated.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of automated reply artificial intelligence, in particular to an enhanced retrieval device combined with a language large model. BACKGROUND

[0002] At present, leading large language models are trained based on a large amount of data, aiming to enable them to master extensive general knowledge, which is stored in the weights of their neural networks. However, if we require the large language model to generate answers involving knowledge outside its training data, such as the latest, proprietary or certain domain-specific information, factual errors may occur, which cannot meet the needs of different users, i.e. hallucination. Retrieval enhancement technology is usually used to solve the hallucination problem, but it increases the time overhead, increases the cost or affects the user experience. SUMMARY

[0003] Therefore, it is necessary to provide an automatic retrieval reply method that can combine the respective advantages of existing databases and language models to improve the accuracy and speed of replies.

[0004] To achieve the above-mentioned purpose, the inventor provides a language large model enhanced retrieval device, comprising a vector database module, an interaction module, a first index module and a language model module. The vector database module is used to perform the following steps: S111, collecting a preset corpus, pre-segmenting the corpus, S112, converting the pre-segmented corpus into a numerical vector, and S113, establishing a vector index using the numerical vector. The interaction module is used to perform the following steps: S20, obtaining a first input sentence, S21, parsing the first input sentence to obtain a first keyword, and S22, retrieving in the first database according to the first keyword as an index to obtain a preset reply sentence. The language model module is used to nest the index result of the vector database and the first input sentence as a new input into the language large model to generate an enhanced reply sentence.

[0005] In an embodiment of the present application, the language model module is further used to: S23, inputting the preset reply sentence into the language large model, and the language large model evaluating the matching degree of the preset reply sentence and the first input sentence to obtain an evaluation result.

[0006] The device further comprises a display module, which is used to display the preset reply sentence to the user when the evaluation result is greater than a first preset value, and otherwise not to display the preset reply sentence.

[0007] In an embodiment of the present application, the language model module is further configured to, when determining that the evaluation result is less than a first preset value, run the large language model to generate a model reply sentence based on the first input sentence, and the display module is further configured to display the model reply sentence to the user.

[0008] In an embodiment of the present application, a first database module is further included, and the first database module is configured to: S10, construct a first database, wherein the first database includes a plurality of QA question and answer pairs, each QA includes a question and a reply sentence, and a keyword index relationship between the question and the reply sentence.

[0009] In an embodiment of the present application, the vector database module is specifically configured to: S113, establish a vector index using an approximate nearest neighbor search algorithm.

[0010] In an embodiment of the present application, the vector database module is configured to establish a vector index using a nearest neighbor search algorithm, and optimize a search parameter Search K of the nearest neighbor search algorithm, so that an average search time of the vector database is not greater than a maximum search time of the first database + a preset delay.

[0011] In an embodiment of the present application, the language model module is configured to, after the evaluation result is less than the first preset value, nest the index result of the vector database, the first input sentence, and the preset reply sentence to generate an enhanced reply sentence.

[0012] In an embodiment of the present application, the nested preset template is: Q*B*P*B*LS*R*LR, wherein Q is a user question, * is a connector, B is a separator, LS and LR are left and right containing symbols, P is a guide word, and R is a retrieved reply; wherein P is set as a guide word for the large model to refer to the text description of the reply in R.

[0013] Through the above device, the present application can prioritize the retrieval of the first database after obtaining the user input sentence, and the large language model can generate a nested reply based on the retrieval of the first database and the first input sentence, thereby achieving the technical effect of generating a more suitable reply for the user. BRIEF DESCRIPTION OF DRAWINGS

[0014] Figure 1 The language model enhanced retrieval method flowchart described in the specific embodiment of the present application;

[0015] Figure 2 The language model enhanced retrieval method construction stage flowchart described in the specific embodiment of the present application;

[0016] Figure 3The language large model enhanced retrieval method construction phase flow chart language large model enhanced retrieval device module graph according to another embodiment of the present application;

[0017] Figure 4 The language large model enhanced retrieval device module graph according to the specific embodiment of the present application;

[0018] Figure 5 The language large model enhanced retrieval device module graph according to another embodiment of the present application. DETAILED DESCRIPTION

[0019] In order to make the technical content, structural features, purposes and effects of the technical scheme clear, the following will be described in detail in combination with specific embodiments and the accompanying drawings.

[0020] Please refer to Figure 1 The language large model enhanced retrieval method comprises an interaction phase; the interaction phase performs the following steps:

[0021] S20, obtaining a first input sentence,

[0022] S21, parsing the first input sentence to obtain a first keyword,

[0023] S22, performing retrieval in a first database according to the first keyword as an index to obtain a preset reply sentence;

[0024] S23, inputting the preset reply sentence into a language large model, the language large model evaluating the matching degree of the preset reply sentence and the first input sentence to obtain an evaluation result;

[0025] S24, if the evaluation result is greater than a first preset value, the preset reply sentence is displayed to the user, otherwise the preset reply sentence is not displayed.

[0026] The first database can be set with reference to the prior art, and the first database only needs to be able to match the corresponding reply statement according to the keyword, and the search result corresponding to the keyword is taken as the preset reply statement, and the following steps are continued. The form of the evaluation result can be a score, and the first preset value can be an arbitrary constant, for example, the full score is set to 100 points, and the first preset value is set to 50 points or 60 points. The language large model can be a language large model trained for the question and answer related field. The language large model can also be a language large model trained to be able to output a score for the answer. For example, the first input statement and the preset reply statement can be input into the language large model, and the vector correlation degree of the two is calculated by weighting. Preferably, the language large model is not trained for the first database, and in this scenario, the language large model can be an open source technology product, which can be directly applied without training after being accessed to any quick question and answer system, and can assist the first database to output effective reply statements through the scoring mode. Those skilled in the art can imagine that even if the language large model is trained for the first database, the above beneficial effects can also be obtained.

[0027] In some further embodiments, the application can also perform the step of generating a model reply statement from the language large model according to the first input statement and displaying the model reply statement to the user if the evaluation result is less than the first preset value. The language large model can be a language large model trained for the question and answer related field, and thus can complete the above task. However, the actual operation of the language large model requires a lot of computing power and a lot of time, so by prepositioning the first database keyword search step, the database can first search for a reply, reduce the waiting time of the user, and save computing power.

[0028] Some embodiments as shown in Figure 2 As shown in the figure, the construction stage further includes the following steps: S10, constructing a first database, the first database includes a plurality of QA question and answer pairs, each QA includes a question and a reply statement, and a keyword index relationship between the question and the reply statement. By establishing the first database through the QA question and answer pair, the reply closer to the user input keyword can be retrieved and referenced more quickly.

[0029] Please continue to refer to Figure 2 In the construction stage, the following steps are further performed: S11, constructing a vector database; see Figure 3The construction stage includes the following steps: S111, collecting preset corpus, pre-segmenting the corpus; S112, converting the pre-segmented corpus into a numerical vector; and S113, establishing a vector index using the numerical vector. The preset corpus can be obtained in a manner known in the art, for example, by crawling common question and answer, user communication records, professional literature, and online resources. The pre-segmented corpus can be converted into a numerical vector using an embedding model such as Word2Vec, GloVe, BERT, etc. In some specific embodiments, the length of a paragraph obtained by pre-segmenting the preset corpus is not less than the length of the longest preset reply in the QA question and answer pair in the first database, and the paragraph can be segmented by using word-by-word or +2-byte or +4-byte or +8-byte cyclic segmentation. The above pre-segmentation method can greatly increase the amount of information in the vector database compared to the first database constructed in a simple QA question and answer manner, thereby improving the quality of replies and user experience.

[0030] In some specific embodiments, it can be seen that step S113 specifically involves establishing a vector index using an approximate nearest neighbor search algorithm. The approximate nearest neighbor search algorithm (Annoy Approximate Nearest Neighbor, ANN) is a commonly used method for solving the nearest neighbor problem in high-dimensional space. In practical applications, it can greatly reduce the search time and space complexity while ensuring high accuracy. Let n represent the number of existing documents. If a brute-force search method is used, the time consumption of each query is O(n). Using a suitable data structure can effectively reduce the time consumption of the query. In the annoy algorithm, the authors use a binary tree data structure to improve the efficiency of the query, with the goal of reducing the time consumption of the query to O(ln(n)). By applying the approximate nearest neighbor search algorithm, the efficiency of the vector index can be greatly improved.

[0031] In further embodiments, the step of establishing the vector index using the approximate nearest neighbor search algorithm is further included, and the search parameter Search K of the approximate nearest neighbor search algorithm is optimized to make the average search time of the vector database not greater than the maximum search time of the first database + preset delay. The value of Search K is one of the parameters of the approximate nearest neighbor search algorithm, which can be used to adjust the complexity and search time of the search. In specific applications, the preset delay can be set according to experience, and can generally be set to the time that the user query can tolerate, such as 1-2S. The maximum search time of the first database is obtained according to the real-time running index. After the value of Search K is set, the average search time of the vector database can be estimated and calculated or obtained by actual running. If the average search time of the vector database is less than the maximum search time of the first database + preset delay, the value of Search K is increased. If the average search time of the vector database is greater than the maximum search time of the first database + preset delay, the value of Search K is decreased.

[0032] In some further embodiments, the accuracy of the output result can be improved by combining the expected manner. Specifically, if the evaluation result is less than the first preset value, the index result of the vector database and the first input sentence are nested as new inputs, input into the language large model, and an enhanced reply sentence is generated. The evaluation result less than the first preset value indicates that the index result of the vector database is difficult to satisfy, and the result obtained by keyword indexing may not be relevant, but keyword indexing also has its value. By nesting the index result and the first input sentence as new inputs to obtain an enhanced reply sentence, the language large model can obtain better output results. The language large model that has not been trained by the first database can have better performance in test results.

[0033] In some further embodiments, if the evaluation result is less than the first preset value, the index result of the vector database and the first input sentence and the preset reply sentence are nested as new inputs, input into the language large model, and an enhanced reply sentence is generated. The evaluation result less than the first preset value indicates that the index result of the vector database is difficult to satisfy, and the result obtained by keyword indexing may not be relevant, but keyword indexing also has its value. By nesting the index result and the first input sentence and the preset reply sentence as new inputs to obtain an enhanced reply sentence, the language large model can obtain better output results. The language large model that has not been trained by the first database can have better performance in test results. In order to save computing power, the generation step of nesting to generate an enhanced reply sentence can be preceded by a user satisfaction inquiry step, which inquires the user's satisfaction with the model reply sentence. When the user's feedback on the model reply sentence is negative, the step of nesting to generate an enhanced reply sentence is performed, and the enhanced reply sentence is displayed to the user.

[0034] In some specific embodiments of the present application, the nested preset template is: Q*B*P*B*LS*R*LR; wherein Q is a user question, * is a connector, B is a separator, LS and LR are left and right inclusion symbols, P is a guide word, and R is a retrieved reply; wherein P is set to guide the large model to refer to the text description of the reply in R. P is set to guide the large model to refer to the text description of the reply in R, which needs to include two parts: 1) prompt the large model to check the relevance of Q and R; 2) prompt the large model to generate a statement reminding the user to pay attention to the accuracy of the answer when Q and R do not have relevance. By optimizing the design of the nested template, the generation quality of the enhanced reply sentence can be effectively improved.

[0035] In other embodiments, referring to Figure 4 A language large model enhanced retrieval device, comprising a vector database module 400, an interaction module 402, a first index module 404, and a language model module 406, the vector database module 400 is used to perform the following steps: S111, collect a preset corpus, pre-segment the corpus, S112, convert the pre-segmented corpus into a numerical vector, S113, establish a vector index with the numerical vector, the interaction module is used to perform the following steps: S20, obtain a first input sentence, S21, analyze the first input sentence to obtain a first keyword, the first index module is used to: S22, retrieve in the first database according to the first keyword as an index to obtain a preset reply sentence; the language model module is used to nest the index result of the vector database and the first input sentence as a new input, input into the language large model, and generate an enhanced reply sentence.

[0036] The first database can be set with reference to the prior art. The first database only needs to be able to match the corresponding reply statement according to the keyword. The retrieval result corresponding to the keyword is taken as the preset reply statement, and the following steps are continued. The acquisition method of the preset corpus can refer to the prior art, for example, by using a crawler to crawl common question and answer, user communication records, professional literature and online resources. The pre-segmentation of the preset corpus can be specifically: using an embedding model (such as Word2Vec, GloVe, BERT, etc.) to convert the text into a numerical vector. In some specific embodiments, when the preset corpus is pre-segmented, the paragraph length is not less than the length of the longest preset reply in the QA question and answer pair in the first database, and the segmentation method can use word-by-word or +2 bytes or +4 bytes or +8 bytes cyclic segmentation. Through the above pre-segmentation method, the amount of information in the vector database can be much larger than the first database constructed in a simple QA question and answer manner, which can improve the reply quality and user experience of the application. The language large model can be a language large model trained for a question and answer related field. The language large model can also be a language large model trained to output a score for the answer. For example, the first input statement and the preset reply statement can be input into the language large model, and the vector correlation degree of the two is calculated by weighting. Preferably, the language large model is not trained for the first database. In this scenario, the language large model can be an open source technology product that can be directly applied without training after being accessed to any fast question and answer system. In the above language large model enhanced retrieval device, the language large model can quickly integrate into an unknown first database, and quickly generate an enhanced reply statement for the user to view in combination with the information of the first database.

[0037] In an embodiment of the application, the language model module 406 is further configured to: S23, input the preset reply statement into a language large model, and the language large model evaluates the matching degree of the preset reply statement and the first input statement to obtain an evaluation result; please continue to refer to Figure 5 The device further includes a display module 408, which is configured to display the preset reply statement to the user when the evaluation result is greater than a first preset value, and otherwise not to display the preset reply statement. Displaying the preset reply statement by scoring can improve the response efficiency of the device.

[0038] In an embodiment of the application, the language model module is further configured to, when it is determined that the evaluation result is less than the first preset value, run the language large model to generate a model reply statement according to the first input statement, and the display module is further configured to display the model reply statement to the user.

[0039] In an embodiment of the present application, the first database module is configured to: S10, construct a first database, wherein the first database comprises a plurality of QA question and answer pairs, each QA question and answer pair comprises a question and a reply, and a keyword index relationship between the question and the reply.

[0040] In an embodiment of the present application, the vector database module 400 is configured to: S113, establish a vector index using an approximate nearest neighbor search algorithm, and optimize a search parameter Search K of the approximate nearest neighbor search algorithm, so that an average search time of the vector database is not greater than a maximum search time of the first database + a preset delay.

[0041] In an embodiment of the present application, the vector database module 400 is configured to: S113, establish a vector index using an approximate nearest neighbor search algorithm, and optimize a search parameter Search K of the approximate nearest neighbor search algorithm, so that an average search time of the vector database is not greater than a maximum search time of the first database + a preset delay.

[0042] In an embodiment of the present application, the language model module is configured to, after the evaluation result is less than a first preset value, nest the index result of the vector database, the first input sentence and the preset reply sentence to generate a new input, and input the new input into the language model to generate an enhanced reply sentence.

[0043] In an embodiment of the present application, the nested preset template is: Q*B*P*B*LS*R*LR; wherein Q is a user question, * is a connector, B is a separator, LS and LR are left and right containing symbols, P is a guide word, and R is a retrieved reply; wherein P is set as a guide word for the language model to refer to a text description of the reply in R. The description needs to include two parts: 1) prompt the language model to check the relevance of Q and R; 2) prompt the language model to generate a statement to remind the user to pay attention to the accuracy of the answer when Q and R do not have relevance. By optimizing the design of the nested template, the generation quality of the enhanced reply sentence can be effectively improved. Through the above nested template design, the language model can better generate an enhanced reply sentence.

[0044] It should be noted that, although the above-mentioned embodiments have been described herein, the patent protection scope of the present application is not limited thereby. Therefore, based on the innovative idea of the present application, the changes and modifications made to the embodiments described herein, or the equivalent structures or equivalent process transformations made using the content of the present application specification and drawings, directly or indirectly apply the above technical solutions to other related technical fields, are all included in the patent protection scope of the present application.

Claims

1. A language large model enhanced retrieval apparatus, characterized by, The vector database module, the interaction module, the first index module, and the language model module, The vector database module is configured to perform the following steps, S111, collecting a preset corpus, and pre-segmenting the corpus, S112, converting the pre-segmented corpus into a numerical vector, S113, establishing a vector index using the numerical vector, The interaction module is configured to perform the following steps: S20, obtaining a first input sentence, S21, parsing the first input sentence to obtain a first keyword, The first index module is configured to: S22, performing a search in the first database according to the first keyword as an index to obtain a preset reply sentence; The language model module is configured to nest the index result of the vector database and the first input sentence as a new input into the language large model to generate an enhanced reply sentence, and is further configured to: S23, inputting the preset reply sentence into the language large model, and obtaining an evaluation result by evaluating the matching degree between the preset reply sentence and the first input sentence by the language large model; The device further comprises a display module configured to display the preset reply sentence to a user when the evaluation result is greater than a first preset value, and not to display the preset reply sentence otherwise. The language model module is configured to generate a model reply sentence according to the first input sentence by running the language large model when the evaluation result is less than the first preset value, and the display module is further configured to display the model reply sentence to the user. 2.The language large model enhanced retrieval apparatus of claim 1, wherein, The device further comprises a first database module configured to: S10, constructing a first database, wherein the first database comprises a plurality of QA question and answer pairs, each QA question and answer pair comprises a question and a reply sentence, and a keyword index relationship between the question and the reply sentence.

3. The language large model enhanced retrieval device according to claim 1, wherein The vector database module is specifically configured to establish the vector index using an approximate nearest neighbor search algorithm in step S113.

4. The language large model enhanced retrieval apparatus of claim 3, wherein, The vector database module is configured to establish the vector index using the approximate nearest neighbor search algorithm, and to optimize a search parameter SearchK of the approximate nearest neighbor search algorithm, so that an average search duration of the vector database is not greater than a maximum search duration of the first database plus a preset delay.

5. The language large model enhanced retrieval device according to claim 1, wherein The language model module is configured to input the index result of the vector database and the first input sentence and the preset reply sentence nested as a new input into the language large model to generate an enhanced reply sentence when the evaluation result is less than the first preset value.

6. The language large model enhanced retrieval apparatus of claim 5, wherein, The nested preset template is Q*B*P*B*LS*R*LR, wherein Q is a user question, * is a connector, B is a separator, LS and LR are left and right containing symbols, P is a leading word, and R is a retrieved reply; wherein P is set as a leading word for the language large model to refer to the text description of the reply in R.

Citation Information

Patent Citations

  • Natural language question answering method and device based on large language model, medium and equipment

    CN117473053A

  • Medical auxiliary question and answer method and system based on knowledge calibration and retrieval enhancement

    CN117573843A

Cited By

  • Large model vertical domain question answering method based on multi-granularity knowledge retrieval and adaptive reordering

    CN122088692A