Model prompt generation method and device, electronic equipment and computer medium
By generating reasonable and complete model prompts in the private knowledge domain and using vector databases and parent-child relationships to filter and process text fragments, the problem of inaccurate and incomplete answers from language models is solved, improving the accuracy and stability of answers while reducing computational costs.
Patent Information
- Application Number
- CN202311177222.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-12
- Publication Date
- 2026-02-13
- Estimated Expiration
- 2043-09-12
AI Technical Summary
When dealing with private knowledge domains, existing technologies often result in inaccurate and incomplete answers from language models, primarily due to unreasonable document segmentation and insufficient matching processing. This leads to inadequate prompts obtained by the language model, affecting the accuracy of the responses.
By acquiring the input question text vector, matching it with text fragment vectors in the vector database, and filtering and processing candidate text fragments based on parent-child relationships, a more reasonable and complete model prompt is generated. The vector database is used for computation to reduce the amount of computation.
It improves the accuracy and stability of language models in the private knowledge domain, reduces errors caused by insufficient document fragment content and poor readability, and lowers computational costs.
Smart Images

Figure CN119621951B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of artificial intelligence, in particular to a model prompt generation method, a model prompt generation device, an electronic device and a computer readable medium. BACKGROUND
[0002] At present, LLM (Large Language Model) is leading a new round of technological innovation. LLM supports natural language understanding, and users can interact with LLM through chat, so that LLM can answer questions and perform tasks.
[0003] In the field of private knowledge, private knowledge AI (artificial intelligence based on LLM to answer user private knowledge) is in its infancy. How to process private knowledge documents and how to obtain and send private knowledge prompts to LLM are two key problems for private knowledge AI to maintain a high level of accuracy and promote its use.
[0004] Therefore, there is an urgent need in the art for a model prompt generation method that can make the content of the extracted language model prompt more reasonable and sufficient, thereby improving the accuracy of the language model in the field of private knowledge.
[0005] It should be noted that the information disclosed in the above background section is only used to strengthen the understanding of the background of the present disclosure, and therefore can include information that does not constitute prior art known to those of ordinary skill in the art. SUMMARY
[0006] The purpose of the present disclosure is to provide a model prompt generation method, a model prompt generation device, an electronic device and a computer readable medium, which can at least to some extent make the content of the extracted language model prompt more reasonable and sufficient, thereby improving the accuracy of the language model in the field of private knowledge.
[0007] According to a first aspect of the present disclosure, a model prompt generation method is provided, comprising:
[0008] obtaining an input question text and obtaining a corresponding input question vector according to the input question text;
[0009] match the input question vector with each text segment vector in a vector database, and determine a plurality of candidate text segment vectors from the text segment vectors according to a matching result; wherein the text segment vectors in the vector database include a plurality of parent segment vectors obtained from private knowledge documents, and a sub-segment vector contained in each of the parent segment vectors;
[0010] convert the candidate text segment vectors into corresponding candidate text segments respectively, and screen and process the candidate text segments according to parent-child relationship data between the candidate text segments, to obtain at least one target text segment;
[0011] obtain a target text prompt according to all the target text segments, and obtain a language model prompt for inputting into a language model according to the input question text and the target text prompt.
[0012] According to a second aspect of the present disclosure, a model prompt generation apparatus is provided, comprising:
[0013] a question text acquisition module configured to acquire an input question text, and obtain a corresponding input question vector according to the input question text;
[0014] a candidate text matching module configured to match the input question vector with each text segment vector in a vector database, and determine a plurality of candidate text segment vectors from the text segment vectors according to a matching result; wherein the text segment vectors in the vector database include a plurality of parent segment vectors obtained from private knowledge documents, and a sub-segment vector contained in each of the parent segment vectors;
[0015] a target text determination module configured to convert the candidate text segment vectors into corresponding candidate text segments respectively, and screen and process the candidate text segments according to parent-child relationship data between the candidate text segments, to obtain at least one target text segment;
[0016] a model prompt generation module configured to obtain a target text prompt according to all the target text segments, and obtain a language model prompt for inputting into a language model according to the input question text and the target text prompt.
[0017] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory configured to store executable instructions of the processor; wherein the processor is configured to execute the model prompt generation method according to any one of the above aspects by executing the executable instructions.
[0018] According to a fourth aspect of the present disclosure, a computer readable medium is provided, which stores a computer program, and the computer program, when executed by a processor, implements the method for generating a model prompt of any one of the above aspects.
[0019] The exemplary embodiments of the present disclosure can have the following beneficial effects:
[0020] In the method for generating a model prompt of the exemplary embodiments of the present disclosure, on one hand, by matching the input question vector with the text segment vectors in the vector database and filtering and expanding the candidate text segments according to the parent-child relationship, the model prompt obtained by the language model is more reasonable, complete and readable, and the situation of language model answer error caused by insufficient and poor readability of the document segment content is reduced, thereby improving the accuracy and stability of the language model in the private knowledge field; for the natural language model, the private knowledge used by the natural language model when identifying and executing the task can be more comprehensive and complete, and the accuracy when executing the customized task is also higher; on the other hand, the calculation process only needs to be constructed around the data of the vector database, and compared with training a language model, the calculation amount is greatly reduced, and it is more convenient.
[0021] It should be understood that the foregoing general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure. BRIEF DESCRIPTION OF DRAWINGS
[0022] The accompanying drawings, which are incorporated into and form part of the specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure. Obviously, the drawings in the following description are only some embodiments of the present disclosure, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.
[0023] Figure 1 A flowchart of the method for generating a model prompt in one related embodiment of the present disclosure is shown;
[0024] Figure 2 A flowchart of the method for generating a model prompt of the exemplary embodiments of the present disclosure is shown;
[0025] Figure 3 A flowchart of the method for generating a vector database of the exemplary embodiments of the present disclosure is shown;
[0026] Figure 4 A flowchart of the method for converting data in a worksheet into text data of the exemplary embodiments of the present disclosure is shown;
[0027] Figure 5A flowchart illustrating the content block merging process of an example embodiment of the present disclosure is shown.
[0028] Figure 6 A flowchart illustrating the sub-fragment splitting process of an example embodiment of the present disclosure is shown.
[0029] Figure 7 A flowchart illustrating the determination of a candidate text segment vector of an example embodiment of the present disclosure is shown.
[0030] Figure 8 A flowchart illustrating the determination of a target text segment of an example embodiment of the present disclosure is shown.
[0031] Figure 9 A flowchart illustrating the sub-fragment extension process of an example embodiment of the present disclosure is shown.
[0032] Figure 10 A flowchart illustrating the generation method of a model prompt of an example embodiment of the present disclosure is shown.
[0033] Figure 11 A flowchart illustrating the content block splitting process of an example embodiment of the present disclosure is shown.
[0034] Figure 12 A flowchart illustrating the content block merging process of an example embodiment of the present disclosure is shown.
[0035] Figure 13 A flowchart illustrating the document segment secondary process of an example embodiment of the present disclosure is shown.
[0036] Figure 14 A block diagram of a model prompt generation apparatus of an example embodiment of the present disclosure is shown.
[0037] Figure 15 A structural diagram of a computer system of an electronic device suitable for implementing an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0038] Example implementations will now be described more fully with reference to the accompanying drawings. Example implementations can be implemented in any number of ways, and example implementations should not be construed as limited to only those described herein; rather, embodiments should be construed more broadly. It will be appreciated that aspects of the disclosure described herein can be implemented in any of numerous ways, as the disclosed aspects should not be construed as limited to only the embodiments set forth herein; rather, aspects can be implemented in any number of different total systems, components, and signals, any or all of which could incorporate any one or more of the disclosed aspects, without departing from the spirit or essential characteristics of the present disclosure. The specific embodiments will now be described with reference to the drawings, but those of skill in the art will recognize that the application can be practiced with modification within the spirit and scope of the disclosure.
[0039] Furthermore, the accompanying drawings are merely ideal representations and are not necessarily drawn to scale. Like reference numerals can be used to denote like components throughout the several views. Some of the block components shown in the drawings can be functional blocks that do not necessarily have a corresponding structure in a physical or logical implementation. These functional blocks can be implemented in software, hardware, or a combination thereof, and can be implemented in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0040] LLM (Large Language Model) refers to a natural language processing model trained using a large-scale dataset, usually using deep learning algorithms. These models can be used to predict the next word or entire sentence, and can also be used for text classification, sentiment analysis, question and answer systems, and other tasks.
[0041] In some related embodiments, the private knowledge documents can be split to keep the number of characters in each segment equal, and the vectors of the embedded documents are stored in a vector database. The embedding space is a common technique in natural language processing, which maps each word in the vocabulary to a vector in a high-dimensional vector space, capturing the semantic relationship between words, thereby improving the efficiency of computer processing of natural language.
[0042] Next, the vector data of the user input word is used to find the nearest vectors in the vector database and convert them to the corresponding document segments to obtain the private knowledge segments related to the question. The LLM will answer the input question according to the high correlation information in these private knowledge segments.
[0043] Since there is an upper limit on tokens for LLM input text, it is neither realistic nor safe to send all documents directly to LLM to answer private knowledge. Therefore, the private knowledge document can be equally divided, converted to Embedding to generate a vector containing semantic relationships and stored in a vector database; then, through the approximation calculation, the document fragments related to the user input words are obtained as prompts, which are sent to LLM for reference and answer the question. Among them, the prompt is a short text fragment that guides the computer to generate the corresponding output text in natural language processing technology.
[0044] As Figure 1 The flowchart of the method for generating model prompts in one related embodiment of the present disclosure is shown. The specific steps of the flowchart are as follows:
[0045] Step S110. Document denoising.
[0046] Delete special symbols in the original document data, such as @, *, and emoticons, etc.
[0047] Step S120. Document equal division.
[0048] The document is divided into several segments according to the rated character number, which is determined by the rated Tokens, that is, the character number after Embedding will not exceed the rated Tokens. Since there is an upper limit on Tokens for Embedding Model, the Tokens of the divided document segments will not generally exceed the upper limit of Tokens for Embedding Model.
[0049] Among them, Tokens are tokens, which refer to the division of a piece of text into individual units in natural language processing, usually words or subwords. Tokens are the basic unit for further processing and analysis of text, which can be used for text classification, part-of-speech tagging, named entity recognition, etc. Different natural language processing models have different Tokens calculation algorithms. Rated Tokens refers to the maximum number of Tokens that the model can handle. If the Tokens of the text segment exceed the rated Tokens, it may not perform well. For Embedding Model, the semantic relationship of the calculated vector is not clear. For LLM, it cannot handle the received data (LLM rejects input data exceeding the rated Tokens). In actual processing, the rated Tokens can be determined as needed.
[0050] Step S130. Document segment Embedding.
[0051] The obtained segments are respectively subjected to Embedding to obtain a plurality of vector data.
[0052] Step S140. Vector storage.
[0053] The obtained plurality of vector data is stored in a vector database.
[0054] Step S150. Question text Embedding.
[0055] The question text input by the user is subjected to Embedding to obtain vector data corresponding to the question text.
[0056] Step S160. Vector matching.
[0057] The vector data corresponding to the question text is subjected to similarity calculation with the vector data in the vector database, and then the top several vectors with the highest similarity are returned according to the similarity. The specific similarity calculation method can be selected according to the actual situation, and common methods include cosine similarity, Euclidean distance, etc.
[0058] Step S170. Vector to text conversion and output of text.
[0059] The corresponding document segment is obtained according to the most similar vector, and the document segment is the private knowledge document segment most related to the question text. Since the LLM has an upper limit on the input Tokens, the number of output document segments is also limited by Tokens.
[0060] The above technical solution can solve most private knowledge question and answer cases that only require one-sentence explanation of the original text, but in most cases where more original text is required to explain, the private knowledge AI may not be accurate and complete. The specific reasons for the above problems are as follows:
[0061] 1. Unreasonable document segment division: Generally speaking, the content logic of a document is related to the document structure, and the content described by the document is distinguished and logically refined according to the document structure. However, equal division of the document will destroy the original description logic of the document. The following situations may occur:
[0062] (1) The description content is split into two segments: due to the equal division algorithm ignoring the document structure logic, this situation occurs frequently.
[0063] For the Embedding Model, this division method may result in low similarity between the vector data converted from the two document segments obtained by dividing the description content. The former may retain the characteristic words of the description content, while the latter does not retain them, or vice versa. In vector matching, only one of them may be considered as a high-relevance segment.
[0064] Submitting incomplete document fragments to an LLM will result in an incomplete or insufficient response from the LLM, and may even lead to the generation of unrelated information that misleads the user due to the LLM's text prediction function.
[0065] (2) The fragment contains incomplete information of two adjacent descriptions: Due to the equal segmentation algorithm, there is a probability that a fragment contains two adjacent descriptions, neither of which is complete.
[0066] For the Embedding Model, such incomplete and inconsistent fragments will lead to inaccurate and chaotic word meaning relation vectors calculated by the Embedding Model. As a result, it is difficult for this fragment to be calculated as a high similarity vector of the input question text, or it may be calculated as a non-"high similarity vector" of the input question text.
[0067] For LLM (Limited Management Module), because LLM prioritizes the use of textual materials provided by users and attempts to understand the core meaning conveyed by incomplete or erroneous document fragments in order to answer user questions, the presence of errors in the provided text increases the difficulty for LLM to provide the correct answer.
[0068] 2. Insufficient document fragment matching: Although the document fragments obtained by vector similarity calculation provide reference information for LLM to some extent, there may be a descriptive order relationship between the document fragments, and some document fragments may also have incomplete descriptions.
[0069] (1) If the document fragments are not merged in the order of description, although the LLM has a certain ability to analyze which fragments are related to the question, the LLM trusts the fragment description logic provided by the user. Therefore, the LLM may give the wrong answer with the wrong fragment description order.
[0070] (2) Incomplete descriptions of document fragments can lead to incomplete LLM responses or incorrect predictions of user responses.
[0071] In other related embodiments, a new LLM can be trained using private knowledge, enabling it to inherently possess private knowledge and thus answer users' private knowledge-based questions. This approach is costly to implement, including hardware and time costs, and has a long iteration cycle.
[0072] To address the aforementioned issues, this example implementation first provides a method for generating model prompts. (Reference) Figure 2 As shown, the method for generating the above model prompts may include the following steps:
[0073] Step S210. Obtain the input question text, and obtain the corresponding input question vector according to the input question text.
[0074] Step S220. Match the input question vector with each text segment vector in the vector database, and determine a plurality of candidate text segment vectors from the text segment vectors according to the matching result.
[0075] The text segment vectors in the vector database include a plurality of parent segment vectors obtained from the private knowledge document, and each parent segment vector includes a sub-segment vector.
[0076] Step S230. Convert the candidate text segment vectors into corresponding candidate text segments respectively, and filter and process the candidate text segments according to the parent-child relationship data between the candidate text segments, to obtain at least one target text segment.
[0077] Step S240. Obtain the target text prompt according to all target text segments, and obtain the language model prompt used in the input language model according to the input question text and the target text prompt.
[0078] In the model prompt generation method of the example embodiment of the present disclosure, on the one hand, by matching the input question vector with the text segment vectors in the vector database and filtering and expanding the candidate text segments according to the parent-child relationship, the model prompt obtained by the language model is more reasonable, complete, and readable, and the situation of language model answer error caused by insufficient and poor readability of document segment content is reduced, thereby improving the accuracy and stability of the language model in the private knowledge field; for the natural language model, the private knowledge used by the natural language model when identifying and executing the task can be more comprehensive and complete, and the accuracy of executing the customized task is also higher; on the other hand, the calculation process only needs to be constructed around the data of the vector database, which greatly reduces the calculation amount compared with training a language model, and is more portable.
[0079] Next, the example embodiment will be described in detail in combination with Figures 3 to 9 The above steps of the example embodiment will be described in more detail.
[0080] In the model prompt generation method according to the example embodiment as shown in Figure 2 Before obtaining the language model prompt used in the input language model in the model prompt generation method, the example embodiment further includes a vector database generation method, as shown in Figure 3 The vector database generation method can include the following steps:
[0081] Step S310. Obtain the private knowledge document to be processed, and perform content block segmentation processing on the private knowledge document based on the document type of the private knowledge document, to obtain a plurality of parent text segments in the private knowledge document.
[0082] In the example embodiment, after obtaining the private knowledge document to be processed, the private knowledge document to be processed can be first denoised, and irrelevant characters in the private knowledge document, such as @, *, and special symbols such as emoticons, are deleted.
[0083] In the example embodiment, before performing content block segmentation processing on the private knowledge document, the document token number corresponding to the private knowledge document needs to be judged. First, the embedding model rating token number corresponding to the embedding model used for vector conversion is obtained, and the first token number threshold and the second token number threshold are determined according to the embedding model rating token number. The first token number threshold is less than the embedding model rating token number, and the second token number threshold is greater than the embedding model rating token number. For example, the first token number threshold can be 0.5 times the Embedding Model rating Tokens, and the second token number threshold can be 2 times the Embedding Model rating Tokens.
[0084] On this basis, it is first judged whether the document token number corresponding to the private knowledge document is less than the second token number threshold; if the document token number corresponding to the private knowledge document is less than the second token number threshold, the private knowledge document is directly taken as a parent text segment; if the document token number corresponding to the private knowledge document is greater than or equal to the second token number threshold, the subsequent step is continued to perform content block segmentation processing on the private knowledge document.
[0085] Since part of the document itself only describes an object content, to a certain extent, it does not need to be segmented. The feature of this kind of document is that the length is small. Through practice, it can be determined whether to segment after the document Tokens are checked, if the document Tokens are less than 2 times the Embedding Model rating Tokens, the document does not need to be segmented, and the answer effect of the private knowledge AI will be better.
[0086] In order to improve the correct rate of the private knowledge AI, one of the core ideas is to "make the word meaning relationship vector calculated by each Embedding Model more accurate". Different Embedding Models have different rating Tokens requirements, in general, "the shorter the sentence, the more single the description content, the more accurate the word meaning relationship vector". Therefore, the segmentation process of the document can be divided into two parts, including content block segmentation and sub-segment segmentation.
[0087] Content block segmentation of a document refers to segmentation of parent segments of the document, i.e., first-level segments; different document types have different segmentation algorithms / strategies. Sub-segment segmentation refers to segmentation of parent segments according to line breaks and tokens, resulting in sub-segments, i.e., second-level segments, and establishing parent-child relationships between document segments; the algorithm / strategy of sub-segment segmentation is applicable to different types of documents.
[0088] In the example embodiment, different types of documents are compatible, and the different types of documents can be used for private knowledge AI question answering, and there is no difference between the data of different types of documents.
[0089] It has been verified that if the document segments submitted to the LLM are all complete paragraph sets describing content, the accuracy of the LLM's answers to private knowledge will remain at a high level. A complete paragraph set describing content refers to a complete description of the object being described, which can be a complete description of a tool or a complete description of a function of the tool. In the example embodiment, it is named as a content block.
[0090] The purpose of content block segmentation is to segment parent segments, i.e., an aggregation of complete paragraph sets describing content. Different content blocks of different documents have different division strategies, so different algorithms / strategies are applied to different document types for content block segmentation. Different document types can refer to different document file types or different application scenarios of the same file type, such as Markdown (lightweight markup language) documents and PDF (Portable Document Format) documents, PDF specification documents and PDF general articles (such as novels, diaries, etc.).
[0091] In the example embodiment, if the document type of the private knowledge document is a text document containing a document title, the private knowledge document is segmented into content blocks according to the document title.
[0092] According to the document title of a given level, the document is segmented into several segments, each of which is a content block describing complete content corresponding to the document title. This method is applicable to technical documents with clear structure, such as design documents and specification documents, and is also applicable to file types with explicit title information, such as Markdown documents and some PDF documents.
[0093] For example, the content of a private knowledge document is as follows:
[0094] I. Design topic and description
[0095] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX.
[0096] II. Investigation and analysis
[0097] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. III. Design scheme
[0098] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
[0099] IV. Design summary
[0100] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
[0101] The private knowledge document of the above type can be directly subjected to content block segmentation processing according to the four document titles.
[0102] In the example embodiment, if the document type of the private knowledge document is a text document that does not contain a document title, the private knowledge document is subjected to content block segmentation processing according to the line breaks in the private knowledge document.
[0103] According to the line breaks in the document, the document is segmented into a plurality of segments, and each segment is a content block that describes complete content. This method is suitable for narrative texts that do not have explicit document structures or file types that cannot obtain explicit title information.
[0104] In the example embodiment, if the document type of the private knowledge document is an electronic table document, the private knowledge electronic table document is subjected to content block segmentation processing in units of each worksheet in the private knowledge electronic table document.
[0105] In some game development companies, game planners are used to using Excel (electronic table) to produce game function documents and design documents. After logical refinement of the writing habits of game planner Excel documents, the segmentation strategy of such documents is also designed in the example embodiment.
[0106] In the content block segmentation processing of the private knowledge electronic spreadsheet document, the data in each sheet of the private knowledge electronic spreadsheet document can be converted into text data.
[0107] The data in each sheet is segmented as a content block with a complete description of the content corresponding to the sheet title. Meanwhile, the data in the cells of the sheet is transcribed into text data.
[0108] In the example embodiment, the data in each sheet is converted into text data, which can include the following steps: Figure 4
[0109] Step S410. All cells in the sheet except empty cells are read in the preset reading order.
[0110] All cells in the sheet are read from left to right and top to bottom, and empty cells / cells with only spaces are not read.
[0111] Step S420. The cell data read in each cell is concatenated with the corresponding number of indentation symbols before each cell data and a line feed symbol after each cell data.
[0112] The cell data read in each cell is concatenated with the corresponding number of indentation symbols before the cell data and a line feed symbol after the cell data.
[0113] Step S430. All cell data read in the sheet is combined into sheet text data corresponding to the sheet in the preset reading order.
[0114] Finally, all the cell data obtained is combined into text data in the reading order. This method is suitable for planning output documents written on Excel.
[0115] After the content block segmentation processing of the private knowledge document, the content block segmentation processing of the private knowledge document can be performed according to the content block mark number corresponding to each content block obtained after the content block segmentation processing of the private knowledge document, to determine whether the content block needs to be merged with other content blocks, and to perform content block merging processing on the content blocks that need to be merged.
[0116] After the content blocks are segmented, some content blocks need to be attached to their adjacent content blocks to fully understand their description content due to less description content. Meanwhile, the LLM supports identifying the number of content blocks according to the document fragment structure, and merging several small content blocks into one content block does not affect the LLM's analysis of the required information for the question. Therefore, the content blocks segmented according to the main strategy need to be processed twice, that is, content block merging.
[0117] In the example embodiment, as shown in Figure 5 According to the content block marker number corresponding to each content block obtained after the content block segmentation processing of the private knowledge document, it is determined whether the content block needs to be merged with other content blocks, and the content block merging processing is performed on the content blocks that need to be merged. Specifically, it can include the following steps:
[0118] Step S510. Obtain the embedding model rating token number corresponding to the embedding model used for vector conversion, and determine the first token number threshold and the second token number threshold according to the embedding model rating token number.
[0119] The first token number threshold is less than the embedding model rating token number, and the second token number threshold is greater than the embedding model rating token number. For example, the first token number threshold can be 0.5 times the Embedding Model rating Tokens, and the second token number threshold can be 2 times the Embedding Model rating Tokens.
[0120] Step S520. If the content block marker number corresponding to the content block is less than the first token number threshold, the content block is merged with the next content block corresponding to the content block to obtain a merged content block.
[0121] If the content block marker number corresponding to the content block is less than the first token number threshold, for example, less than 0.5 times the Embedding Model rating Tokens, it is merged with the next content block to obtain a new content block.
[0122] Step S530. If the content block marker number corresponding to the content block is greater than or equal to the embedding model rating token number, it is determined that the content block does not need to be processed by the content block merging processing.
[0123] Step S540. If the content block marker number corresponding to the content block is greater than or equal to the first token number threshold and less than the embedding model rating token number, the content block is merged with the next content block corresponding to the content block to obtain a merged content block to be judged.
[0124] If the content block mark number corresponding to the content block is greater than or equal to the first mark number threshold, for example, greater than or equal to 0.5 times the Embedding Model rated Tokens, and less than the Embedding Model rated Tokens, the next content block is attempted to be merged to obtain a merged content block to be judged.
[0125] Step S550. If the content block mark number corresponding to the content block to be judged is greater than the second mark number threshold, the content block merging process with the next content block is cancelled.
[0126] If the new content block Tokens after merging exceed the second mark number threshold, for example, 2 times the Embedding Model rated Tokens, the merging is cancelled.
[0127] Step S560. If the content block mark number corresponding to the content block to be judged is less than or equal to the second mark number threshold, the content block to be judged is taken as a merged content block.
[0128] If the new content block Tokens after merging are less than or equal to the second mark number threshold, for example, 2 times the Embedding Model rated Tokens, the content block to be judged is taken as a new content block.
[0129] The content block segmentation can make the document segment describe the content body single without other interference. By using the content block segmentation step, the document content unit is divided before the Embedding, reducing the poor readability of the document segment caused by unreasonable segmentation (which can also be understood as that the corresponding word meaning relationship vector description feature is not clear and not prominent), thereby improving the integrity and content unity of the document segment obtained by the LLM.
[0130] With reference to the foregoing description of the content block segmentation step, the parent text segment is divided into a plurality of sub-text segments. Figure 3 As shown, step S320. The number of sub-segment segmentations corresponding to the parent text segment is obtained, and the parent text segment is subjected to sub-segment segmentation processing according to the number of sub-segment segmentations to obtain a plurality of sub-text segments respectively contained in each parent text segment.
[0131] Relying on the data obtained by the content block (parent segment) segmentation, the sub-segment segmentation only needs to be performed in the parent segment. The sub-segment only uses the line feed character as the segmentation identifier to segment the content block, without distinguishing the document type / file type.
[0132] In order to make the semantic relationship vector of the Embedding Model more clear and highlight the features, the content block needs to be sub-fragmented. Usually, the Tokens length of the content block exceeds the rated Tokens of the Embedding Model, which will cause the calculated vector to be unable to accurately express the semantic relationship of a certain feature word, so that the score is low when calculating the similarity, and the correct output cannot be obtained. By sub-fragmenting the content block according to a specific strategy, the semantic relationship of the feature word can be ensured not to be diluted by other words, so that it can be correctly output in the vector similarity calculation.
[0133] In the example embodiment, the sub-fragment rated token number can be determined according to the first token number threshold, and the number of sub-fragment divisions corresponding to the parent text segment can be determined according to the parent text token number corresponding to the parent text segment and the sub-fragment rated token number.
[0134] In the example embodiment, the formula for obtaining the theoretical sub-fragment number is:
[0135]
[0136] Wherein: Count is the number of theoretical sub-fragment divisions; T is the Tokens of the content block; R is the rated Tokens of the sub-fragment.
[0137] The rated Tokens of the sub-fragment (R) can be determined according to the rated Tokens of the Embedding Model used, and in the example embodiment, the R obtained from practice is best when it is less than 0.5 times the rated Tokens of the Embedding Model.
[0138] The theoretical sub-fragment number obtained by dividing the Tokens of the content block by the rated Tokens of the sub-fragment and taking the integer part downward will often result in a situation where the Tokens of the sub-fragment are greater than the rated Tokens of the sub-fragment, but the rated Tokens of the sub-fragment are less than the rated Tokens of the Embedding Model at the beginning of determination, so it has little effect on the calculated semantic relationship vector of the sub-fragment. The probability of the Tokens of the sub-fragment being greater than the rated Tokens of the Embedding Model is relatively low.
[0139] In the example embodiment, as shown in Figure 6 The sub-fragment division processing of the parent text segment according to the number of sub-fragment divisions can include the following steps:
[0140] Step S610. Determine the theoretical division point in the parent text segment according to the number of characters in the parent text segment and the number of sub-fragment divisions corresponding to the parent text segment.
[0141] According to the number of theoretical sub-segments, the content block is equally divided into segments with the same number of characters, and the corresponding division point is the theoretical division point.
[0142] Step S620. The nearest line break after each theoretical division point is taken as the real division point in the parent text segment, and the parent text segment is sub-segmented according to the real division point to obtain a plurality of sub-text segments contained in the parent text segment.
[0143] The nearest line break after the theoretical division point is taken as the real division point, and the content block is divided into a plurality of sub-segments to obtain a plurality of sub-text segments contained in the parent text segment.
[0144] The above division method may have a probability of less than the number of theoretical sub-segments or the number of Tokens of sub-segments greater than the rated Tokens of the Embedding Model. The occurrence of these two cases is generally due to the fact that some paragraphs have too many words, but based on the technical solution idea of the present disclosure, this paragraph describes the content, and even if the number of words is too long, it should not be split.
[0145] In the example embodiment, the content block can be divided into short segments by sub-segmentation, and the integrity of the sentence is preserved. By using the sub-segmentation step, the content block is subjected to secondary division for Embedding, which shortens the length of each document segment while still maintaining the integrity of the paragraph, further highlighting the descriptive features of the word meaning relationship vector of the document segment, and also compatible with the rated Tokens performance requirements of different Embedding Models. The division of private knowledge documents is reasonable, which makes the word meaning relationship vector calculated by the Embedding Model more descriptive of the segment.
[0146] Continuing to refer to Figure 3 As shown, step S330. Each parent text segment and each sub-text segment is converted into a corresponding parent segment vector and a sub-segment vector, respectively, and the parent segment vector and the sub-segment vector are stored in the vector database.
[0147] In the example embodiment, each parent text segment and each sub-text segment can be converted into a corresponding parent segment vector and a sub-segment vector, respectively, by an embedding model.
[0148] The parent and child segments obtained by twice division are used to calculate a plurality of vector data by the Embedding Model, and are stored in the vector database.
[0149] The private knowledge document is reasonably divided twice by content block division and sub-fragment division to ensure that the document fragments are relatively complete, so that the Embedding Model can calculate the correct semantic relationship vector, and the LLM can also perform more suggested analysis based on the complete document fragments.
[0150] The two-step processing can improve the accuracy of the semantic relationship vector of the vector database, make the high-correlation document fragments obtained by calculating the similarity more reliable, and also provide reference data, i.e., the parent-child relationship data of the document fragments, for subsequent secondary processing of the document fragments.
[0151] In the example embodiment, the parent-child relationship data between the parent text fragments and the sub-text fragments can also be established when the sub-fragment division processing is performed on the parent text fragments, and the parent-child relationship data is placed in the parent-child relationship database.
[0152] The parent-child relationship data of the content blocks (parent fragments) and the sub-fragments is constructed for the secondary processing of the document fragments in the subsequent process. The relationship data structure constructed in the example embodiment may, for example, include:
[0153]
[0154] In the example embodiment, another core idea for improving the correct rate of the private knowledge AI is to "make the LLM obtain clear and highly readable document fragments". In order to make the Embedding Model play the best Embedding ability, the document fragments used for vector conversion are generally not too long, and therefore the document fragments corresponding to the high-approximation vectors are not sufficient as reference materials.
[0155] In the secondary processing step of the document fragments, the disclosure performs secondary processing on the high-correlation document fragments based on the original text, and utilizes the "document fragment parent-child relationship data" to arrange, merge and expand the document fragments, so that the LLM obtains more complete and more readable document fragment content, thereby improving the correct rate of the private knowledge AI.
[0156] After the vector database is established, as shown in FIG. 2, in step S210, the input question text is obtained, and the corresponding input question vector is obtained according to the input question text. Figure 2
[0157] In the example embodiment, the input question text can be converted into the corresponding input question vector by the Embedding Model. The question text input by the user is embedded to obtain the corresponding input question vector.
[0158] In step S220, the input question vector is matched with each text fragment vector in the vector database, and a plurality of candidate text fragment vectors are determined from the text fragment vectors according to the matching result.
[0159] The text segment vectors in the vector database include a plurality of parent segment vectors obtained from the private knowledge document, and each parent segment vector includes a plurality of child segment vectors.
[0160] In the example embodiment, as shown in Figure 7 The input question vector is matched with each text segment vector in the vector database, and a plurality of candidate text segment vectors are determined from the text segment vectors according to the matching results, which can include the following steps:
[0161] Step S710. Similarity calculation is performed between the input question vector and each text segment vector in the vector database, to obtain the similarity between the input question vector and each text segment vector.
[0162] The similarity calculation is performed between the input question vector and each vector data in the vector database. The specific similarity calculation method can be selected according to the actual situation, including cosine similarity, Euclidean distance, etc.
[0163] Step S720. Each text segment vector is sorted according to the similarity between the input question vector and each text segment vector.
[0164] Each text segment vector in the vector database is sorted in descending order of similarity.
[0165] Step S730. A plurality of candidate text segment vectors are determined from the text segment vectors according to the sorting results of the text segment vectors and the preset number of candidate segments.
[0166] According to the similarity sorting results, a plurality of text segment vectors most similar to the input question vector are returned as the selected candidate text segment vectors.
[0167] Referring back to Figure 2 In step S230, the candidate text segment vectors are converted into corresponding candidate text segments respectively, and the candidate text segments are filtered and processed according to the parent-child relationship data between the candidate text segments, to obtain at least one target text segment.
[0168] To make the vectors calculated by the embedded model more characteristic, the document segments (sub-segments) segmented in the foregoing are usually short and insufficient to support the LLM to answer the private knowledge question. Therefore, it is necessary to arrange and expand the candidate text segments according to the parent-child relationship data of the document segments until the total Prompt composed of the question text input by the user and the document segments is close to the rated Tokens of the LLM. The core purpose of this function is to expand and perfect the text segments obtained by vector matching according to the parent-child relationship data of the foregoing, so that the LLM can obtain more sufficient and complete private knowledge segments.
[0169] In the example embodiment, as shown in Figure 8 According to the parent-child relationship data between the respective candidate text segments, the candidate text segments are screened and processed to obtain at least one target text segment, which can specifically include the following steps:
[0170] Step S810. If there is a parent text segment in the candidate text segment, the parent text segment in the candidate text segment is put into the high-relevance text segment list.
[0171] Step S820. According to the parent-child relationship data between the respective candidate text segments, it is judged whether there is a child text segment having a parent-child relationship with a parent text segment in the candidate text segment.
[0172] Step S830. If there is, the child text segment having a parent-child relationship with the parent text segment in the candidate text segment is deleted, and the remaining child text segments in the candidate text segment are put into the high-relevance text segment list.
[0173] First, the parent-child segment coexistence screening is performed on all candidate text segments. Since the content blocks (parent segments) segmented and the child segments are both embedded and stored in the vector database, there is a probability that the scores of the parent-child segments are both high and are output at the same time when the similarity with the input text vector is calculated. It has been verified by practice that in this case, the LLM can better answer the private knowledge question by using the parent segment for reference, and therefore it can be considered that the parent segment has higher relevance with the input text of the user at this time.
[0174] Based on the above screening, the processing mode here is that when there are paired parent-child relationship segments in the high-relevance document segment, the private knowledge segment submitted to the LLM will retain the parent segment and delete the child segment. Such processing can save Tokens space and provide more Tokens quota for the expansion of other child segments.
[0175] Step S840. According to the parent-child relationship data related to the child text segment, the child text segment in the high-relevance text segment list is subjected to child segment expansion processing.
[0176] In the example embodiment, the subtext segments can be expanded layer by layer from high to low according to the similarity score order of the subtext segments in the current high correlation text segment list; the parent text segments in the high correlation text segment list do not need to be expanded and can be directly retained in the list.
[0177] In the example embodiment, as shown in Figure 9 the parent-child relationship data related to the subtext segments, the subtext segments in the high correlation text segment list are subjected to sub-segment expansion processing, which can specifically include the following steps:
[0178] Step S910. The expansion processing order of each subtext segment is determined according to the similarity between each subtext segment in the high correlation text segment list and the input question vector.
[0179] First, the expansion processing order of each subtext segment is determined in turn according to the similarity from high to low. The similarity score of the sub-segment vector determines the order of sub-segment expansion during vector matching. The sub-segment with a high score is considered to have relatively higher correlation with the input question text and should be expanded first.
[0180] Step S920. According to the expansion processing order of each subtext segment, one subtext segment is selected from the subtext segments in the high correlation text segment list as a to-be-expanded subtext segment.
[0181] Step S930. From the parent text segment where the to-be-expanded subtext segment is located, the previous subtext segment and the next subtext segment adjacent to the to-be-expanded subtext segment are obtained.
[0182] Step S940. The to-be-expanded subtext segment is expanded according to the previous subtext segment and the next subtext segment to obtain an expanded subtext segment.
[0183] The score of the sub-segment vector can only relatively represent the correlation with the input question text vector, but it is not completely correct. Therefore, during sub-segment expansion, layer-by-layer expansion is adopted, that is, after expanding the nearest layer of all sub-segments, the next layer is expanded, rather than expanding a sub-segment to the content block boundary and then expanding the next sub-segment.
[0184] Sub-segment expansion is bilateral expansion, that is, the nearest upper and lower layers of the sub-segment are expanded at the same time; when the sub-segment expansion reaches a certain layer and reaches the top / bottom sub-segment of the content block, the sub-segment expansion starts unilateral expansion, that is, only the other side of the top / bottom sub-segment is expanded.
[0185] Step S950. According to the expanded subtext segment, it is judged whether all sub-segment expansion stop conditions and the current sub-segment expansion stop condition are met.
[0186] In the example embodiment, the current text token number total sum can be obtained according to the number of text tokens corresponding to the input question text, the number of text token corresponding to the expanded subtext segment, and the number of text token corresponding to all other text segments in the high-relevance text segment list. Then, the rated token number of the language model is obtained. If the current text token number total sum is greater than the rated token number of the language model, it is determined that the overall sub-segment expansion stop condition is met.
[0187] If the total Prompt composed of the input question text of the user and the document segment exceeds the rated Tokens of the LLM after the expansion of a certain sub-segment layer, the expansion of all sub-segments is stopped, and the total Prompt obtained after the expansion of the last sub-segment layer is taken as the high-quality Prompt output.
[0188] In the example embodiment, if the expanded subtext segment is identical to the parent text segment in which the expanded subtext segment is located, it is determined that the current sub-segment expansion stop condition is met.
[0189] If a certain sub-segment is expanded to be equal to the content block to which it belongs, the expansion of the sub-segment is stopped.
[0190] Step S960. If the overall sub-segment expansion stop condition is met, the expansion processing of all subtext segments in the high-relevance text segment list is stopped, and the result of the last round of sub-segment expansion processing is taken as the final result of the sub-segment expansion processing.
[0191] Step S970. If the overall sub-segment expansion stop condition is not met, but the current sub-segment expansion stop condition is met, the next subtext segment is selected as the to-be-expanded subtext segment from the subtext segments in the high-relevance text segment list according to the expansion processing order of each subtext segment.
[0192] Step S980. If the overall sub-segment expansion stop condition is not met, and the overall sub-segment expansion stop condition is not met, it is determined whether there is a mergable subtext segment adjacent to the expanded subtext segment and belonging to the same parent text segment in the high-relevance text segment list.
[0193] Step S990. If there is a mergable subtext segment, the expanded subtext segment and the mergable subtext segment are merged, and the high-relevance text segment list is updated according to the merged subtext segment.
[0194] There is a probability that the sub-segments are from the same parent segment, and these sub-segments have a probability of expanding to the same adjacent sub-segments in the expansion process. The expanded document segments obtained in this way are submitted to the LLM as reference materials for private knowledge question answering, which may mislead the LLM and reduce the accuracy of the answers.
[0195] In the sub-segment expansion process, the misdirection can be avoided by certain checking and merging of sub-segments; it has been verified that the merging of sub-segments will not cause significant changes to Tokens.
[0196] The sub-segment merging process is as follows: after a certain sub-segment is expanded by one layer, the other same parent sub-segments (expanded) are checked according to the parent-child relationship to see if they are adjacent to the current sub-segment. If there are other same parent sub-segments that are adjacent, they are merged into a new document segment, and then the sub-segment expansion continues.
[0197] For example, the list of high-relevance document segments (represented by sub-segment IDs) after the expansion of a certain sub-segment is as follows:
[0198] [(2003, 2004, 2005), (6003, 6004, 6005), (2006, 2007, 2008), 9005]
[0199] The sub-segment merging check is met (2005 and 2006 are adjacent), and the high-relevance document segment list is changed to:
[0200] [(2003, 2004, 2005, 2006, 2007, 2008), (6003, 6004, 6005), 9005]
[0201] Referring back to Figure 8 , at step S850, the high-relevance text segment list is updated according to the sub-text segments after the sub-segment expansion process, until there is no sub-text segment that needs to be expanded in the high-relevance text segment list, and the target text segment is obtained according to the updated high-relevance text segment list.
[0202] If there is no expandable sub-segment in the high-relevance document segment, the sub-segment expansion is stopped, and the last total Prompt is output, or the first total Prompt is output if no sub-segment expansion has been performed.
[0203] Referring back to Figure 2 , in step S240, the target text prompt is obtained according to all target text segments, and the language model prompt for inputting into the language model is obtained according to the input question text and the target text prompt.
[0204] Finally, the total Prompt closest to the upper limit of LLM Tokens is obtained according to all target text segments and the input question text, which is the high-quality Prompt finally submitted to the LLM. The high-quality Prompt is the most reasonable, complete and readable language model prompt.
[0205] As Figure 10 shown is a complete flowchart of the method for generating the model prompt in one specific embodiment of the present disclosure, which is an example illustration of the above steps in the present example embodiment, and the specific steps of the flowchart are as follows:
[0206] Step S1010. Document denoising.
[0207] Special symbols in the original document data are deleted, such as @, *, and emoticons, etc.
[0208] Step S1020. Content block segmentation.
[0209] The content block segmentation of the document is to segment the parent segment of the document, that is, the first-level segment; the segmentation algorithm / strategy is different for different types of documents.
[0210] Step S1030. Sub-segment segmentation.
[0211] The sub-segment segmentation is to segment the parent segment according to the line break and the rated Tokens to obtain the sub-segment, that is, the second-level segment, and to construct the parent-child relationship between the document segments; the algorithm / strategy of the sub-segment segmentation is suitable for different types of documents.
[0212] Step S1040. Document segment Embedding.
[0213] The parent and child segments obtained by twice segmentation are both calculated by the Embedding Model to obtain a plurality of vector data.
[0214] Step S1050. Data storage.
[0215] The vector data is stored in the vector database, and the parent-child relationship data between the segments is also stored in the parent-child relationship database.
[0216] Step S1060. Question text Embedding.
[0217] The question text input by the user is embedded to obtain the vector data corresponding to the question text.
[0218] Step S1070. Vector matching.
[0219] The vector data corresponding to the question text is calculated for similarity with the vector data in the vector database, and then sorted according to the similarity, and the most similar several vectors are returned. The specific similarity calculation method can be selected according to the actual situation, and the commonly used methods include cosine similarity, Euclidean distance, etc.
[0220] Step S1080. Vector reverse text.
[0221] The most similar several vectors are reversed to the corresponding high-correlation document fragments as candidate text fragments.
[0222] Step S1090. Document fragment secondary processing.
[0223] The high-correlation document fragments are sorted and expanded according to the document fragment parent-child relationship data until the input question text of the user and the total Prompt composed of the document fragments approach the rated Tokens of the LLM. Finally, the total Prompt closest to the upper limit of the Tokens of the LLM is output, which is the high-quality Prompt submitted to the LLM.
[0224] wherein, Figure 10 The detailed process of the content block segmentation, content block merging, and document fragment secondary processing in the content block segmentation is as follows:
[0225] As Figure 11 shown is a complete flowchart of the content block segmentation processing in one specific embodiment of the present disclosure, which is a detailed description of the above-mentioned content block segmentation processing process in the present example embodiment. The specific steps of the flowchart are as follows:
[0226] Step S1110. Determine whether the Tokens of the document itself are greater than 2 times the rated Tokens of the Embedding Model.
[0227] Part of the document itself only describes the content of an object. The characteristic of this kind of document is that the length is small. Through practice, it can be determined whether to perform content block segmentation after the document Tokens are checked. If the Tokens of the document itself are less than 2 times the rated Tokens of the Embedding Model, the document does not need to be segmented, and the answer effect of the private knowledge AI will be better.
[0228] Step S1120. Content block segmentation.
[0229] Different content blocks of different documents have different division strategies, so different algorithm strategies need to be applied for content block segmentation of different document types, including document title segmentation, line feed segmentation, and Excel document segmentation strategy.
[0230] Step S1130. Content block merging.
[0231] After the content blocks are segmented, some content blocks need to be attached to their adjacent content blocks to fully understand their description content due to less description content. Meanwhile, the LLM supports identifying the number of content described according to the document fragment structure, and merging several small content blocks into one without affecting the analysis of the required information of the LLM to the question. Therefore, the content blocks segmented according to the main strategy need to be processed twice, that is, content block merging.
[0232] As Figure 12 shown is a complete flowchart of content block merging processing in one specific embodiment of the present disclosure, which is a detailed description of the above-mentioned content block merging process in the present example embodiment. The specific steps of the flowchart are as follows:
[0233] Step S1210. Segmentation to obtain content blocks.
[0234] Step S1220. Determine whether the original document Tokens is less than 0.5 times the rated Tokens of the Embedding Model.
[0235] Step S1230. Merge the next content block to form a new content block.
[0236] If the content block itself is less than 0.5 times the rated Tokens of the Embedding Model, merge the next content block.
[0237] Step S1240. Determine whether the content block Tokens is less than the rated Tokens of the Embedding Model.
[0238] Step S1250. Try to merge the next content block to form a new content block.
[0239] If the content block itself is less than the rated Tokens of the Embedding Model, try to merge the next content block and proceed to step S1260.
[0240] Step S1260. Determine whether the Tokens of the new content block is greater than 2 times the rated Tokens of the Embedding Model.
[0241] If the Tokens of the new content block after merging exceeds 2 times the rated Tokens of the Embedding Model, cancel the merging.
[0242] As Figure 13 shown is a complete flowchart of document fragment secondary processing in one specific embodiment of the present disclosure, which is a detailed description of the above-mentioned document fragment secondary processing process in the present example embodiment. The specific steps of the flowchart are as follows:
[0243] Step S1301. Parent-child fragment coexistence screening.
[0244] When there is a paired parent-child relationship fragment in the high-correlation document fragment, the private knowledge fragment submitted to the LLM will retain the parent fragment and delete the child fragment.
[0245] Step S1302. Determine whether there is an expandable child fragment.
[0246] The child fragments are expanded layer by layer from high to low according to the similarity score order of the child fragments; the parent fragment does not need to be expanded.
[0247] Step S1303. Obtain the child fragments in the score order.
[0248] The score of the child fragment vector determines the order of expansion of the child fragment in vector matching. The child fragment with a higher score is considered to have a higher correlation (relatively) with the input question text and should be expanded first.
[0249] Step S1304. Expand the child fragment by one layer.
[0250] In the expansion of the child fragment, layer-by-layer expansion is adopted, i.e., after expanding the last layer of all child fragments, the next layer will be expanded.
[0251] Step S1305. Determine whether the total Prompt Tokens is greater than the LLM rated Tokens.
[0252] After the child fragment is expanded by one layer, if the total Prompt composed of the user's question words and the document fragments exceeds the LLM rated Tokens, stop expanding all child fragments, and take the total Prompt obtained after expanding the last layer of the child fragment as the high-quality Prompt output.
[0253] Step S1306. Determine whether the child fragment (after expansion) is equal to the content block.
[0254] Step S1307. Mark the child fragment for stopping expansion.
[0255] If a child fragment is equal to the content block itself after expansion, the child fragment stops expanding.
[0256] Step S1308. Merge and check the child fragments.
[0257] There is a certain probability that the high-correlation document fragments obtained by matching are all from the same parent fragment, and these child fragments have a probability of expanding to the same adjacent child fragment during the expansion process. Thus, the document fragments obtained by expansion are submitted to the LLM as reference materials for private knowledge question answering, which may mislead the LLM and reduce the accuracy of the answer. During the expansion of the child fragment, certain checking and merging of the child fragments can avoid the occurrence of such misleading situations.
[0258] Step S1309. Merge sub-segments.
[0259] After a certain sub-segment is expanded by one layer, it is checked according to the parent-child relationship whether the current other sibling sub-segment (after expansion) is adjacent to it. If so, they are merged into a new document segment, and then the sub-segment expansion is continued.
[0260] Step S1310. Update the high-correlation document segment list.
[0261] Finally, the high-correlation document segment list is updated according to the sub-segments obtained after the sub-segment expansion and merging.
[0262] It should be noted that although the steps of the method in the present disclosure are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. In addition or alternatively, some steps can be omitted, multiple steps can be combined into one step, and / or one step can be divided into multiple steps, etc.
[0263] Further, the present disclosure also provides a model prompt generation device. Referring to Figure 14 shown, the model prompt generation device can include a question text acquisition module 1410, a candidate text matching module 1420, a target text determination module 1430, and a model prompt generation module 1440.
[0264] Among them:
[0265] The question text acquisition module 1410 can be used to acquire an input question text, and obtain a corresponding input question vector according to the input question text;
[0266] The candidate text matching module 1420 can be used to match the input question vector with each text segment vector in the vector database, and determine a plurality of candidate text segment vectors from the text segment vectors according to the matching result; wherein the text segment vectors in the vector database include a plurality of parent segment vectors obtained from private knowledge documents, and sub-segment vectors respectively contained in each parent segment vector;
[0267] The target text determination module 1430 can be used to convert the candidate text segment vectors into corresponding candidate text segments respectively, and filter and process the candidate text segments according to the parent-child relationship data between each candidate text segment, to obtain at least one target text segment;
[0268] The model prompt generation module 1440 can be used to obtain a target text prompt according to all target text segments, and obtain a language model prompt used in an input language model according to the input question text and the target text prompt.
[0269] In some example embodiments of the present disclosure, the model prompt generation apparatus provided by the present disclosure can further comprise a vector database generation module, which can comprise a content block segmentation unit, a sub-fragment segmentation unit, and a vector database generation unit. Wherein:
[0270] The content block segmentation unit can be used to obtain a private knowledge document to be processed, and perform content block segmentation processing on the private knowledge document based on the document type of the private knowledge document, to obtain a plurality of parent text fragments in the private knowledge document;
[0271] The sub-fragment segmentation unit can be used to obtain a sub-fragment segmentation quantity corresponding to the parent text fragment, and perform sub-fragment segmentation processing on the parent text fragment according to the sub-fragment segmentation quantity, to obtain a plurality of sub-text fragments respectively contained in each parent text fragment;
[0272] The vector database generation unit can be used to convert each parent text fragment and each sub-text fragment into a corresponding parent fragment vector and sub-fragment vector respectively, and put the parent fragment vector and the sub-fragment vector into a vector database.
[0273] In some example embodiments of the present disclosure, the vector database generation module can further comprise a parent-child relationship database generation unit, which can be used to establish parent-child relationship data between the parent text fragment and the sub-text fragment when performing sub-fragment segmentation processing on the parent text fragment, and put the parent-child relationship data into a parent-child relationship database.
[0274] In some example embodiments of the present disclosure, the content block segmentation unit can comprise a document title segmentation unit, a line break segmentation unit, and a worksheet segmentation unit. Wherein:
[0275] The document title segmentation unit can be used to perform content block segmentation processing on the private knowledge document according to the document title if the document type of the private knowledge document is a text document containing a document title;
[0276] The line break segmentation unit can be used to perform content block segmentation processing on the private knowledge document according to the line break in the private knowledge document if the document type of the private knowledge document is a text document not containing a document title;
[0277] The worksheet segmentation unit can be used to perform content block segmentation processing on the private knowledge electronic spreadsheet document by taking each worksheet in the private knowledge electronic spreadsheet document as a unit if the document type of the private knowledge document is an electronic spreadsheet document.
[0278] In some example embodiments of the present disclosure, the worksheet segmentation unit can include a text data conversion unit, which can be configured to perform content block segmentation on the private knowledge spreadsheet document in units of each worksheet in the private knowledge spreadsheet document, and convert data in each worksheet into text data.
[0279] In some example embodiments of the present disclosure, the text data conversion unit can include a cell reading unit, a line feed splicing unit, and a text data composition unit. Wherein:
[0280] The cell reading unit can be configured to read all cells in the worksheet except empty cells in a predetermined reading order;
[0281] The line feed splicing unit can be configured to splice an indentation corresponding to the column number before each cell data read in each cell, and splice a line feed after each cell data;
[0282] The text data composition unit can be configured to compose all cell data read in the worksheet into worksheet text data corresponding to the worksheet in a predetermined reading order.
[0283] In some example embodiments of the present disclosure, the content block segmentation unit can further include a content block merging unit, which can be configured to determine whether a content block needs to be merged with other content blocks according to the content block marker number corresponding to each content block obtained after performing content block segmentation on the private knowledge document, and perform content block merging processing on the content block that needs to be merged.
[0284] In some example embodiments of the present disclosure, the content block merging unit can include a marker number threshold determination unit, a first content block merging unit, a content block merging determination unit, a to-be-determined content block generation unit, a content block merging cancellation unit, and a second content block merging unit. Wherein:
[0285] The marker number threshold determination unit can be configured to obtain an embedding model rated marker number corresponding to an embedding model used for vector conversion, and determine a first marker number threshold and a second marker number threshold according to the embedding model rated marker number, wherein the first marker number threshold is less than the embedding model rated marker number, and the second marker number threshold is greater than the embedding model rated marker number;
[0286] The first content block merging unit can be configured to merge the content block with the next content block corresponding to the content block if the content block marker number corresponding to the content block is less than the first marker number threshold, to obtain a merged content block;
[0287] The content block merging determination unit can be configured to determine that the content block does not need to be subjected to the content block merging processing if the content block mark quantity corresponding to the content block is greater than or equal to the embedding model rated mark quantity.
[0288] The content block to be judged generation unit can be configured to merge the content block with a next content block corresponding to the content block if the content block mark quantity corresponding to the content block is greater than or equal to the first mark quantity threshold and less than the embedding model rated mark quantity, to obtain a merged content block to be judged.
[0289] The content block merging cancellation unit can be configured to cancel the content block merging processing of the content block and the next content block if the content block mark quantity corresponding to the content block to be judged is greater than the second mark quantity threshold.
[0290] The second content block merging unit can be configured to take the content block to be judged as a merged content block if the content block mark quantity corresponding to the content block to be judged is less than or equal to the second mark quantity threshold.
[0291] In some example embodiments of the present disclosure, the content block splitting unit can further include a second mark quantity threshold determination unit, a parent text segment generation unit, and a content block splitting continuation unit. Wherein:
[0292] The second mark quantity threshold determination unit can be configured to determine whether the document mark quantity corresponding to the private knowledge document is less than the second mark quantity threshold.
[0293] The parent text segment generation unit can be configured to directly take the private knowledge document as a parent text segment if the document mark quantity corresponding to the private knowledge document is less than the second mark quantity threshold.
[0294] The content block splitting continuation unit can be configured to continue to execute subsequent steps to perform content block splitting processing on the private knowledge document if the document mark quantity corresponding to the private knowledge document is greater than or equal to the second mark quantity threshold.
[0295] In some example embodiments of the present disclosure, the sub-segment splitting unit can include a sub-segment rated mark quantity determination unit and a sub-segment splitting quantity determination unit. Wherein:
[0296] The sub-segment rated mark quantity determination unit can be configured to determine the sub-segment rated mark quantity according to the first mark quantity threshold.
[0297] The sub-segment splitting quantity determination unit can be configured to determine the sub-segment splitting quantity corresponding to the parent text segment according to the parent text mark quantity corresponding to the parent text segment and the sub-segment rated mark quantity.
[0298] In some example embodiments of the present disclosure, the sub-segment splitting unit can further include a theoretical splitting point determination unit and a real splitting point determination unit. Wherein:
[0299] The theoretical split point determination unit can be configured to determine a theoretical split point in the parent text segment according to a number of characters in the parent text segment and a number of sub-segment splits corresponding to the parent text segment;
[0300] The real split point determination unit can be configured to take a nearest line break after each theoretical split point as a real split point in the parent text segment, and perform sub-segment split processing on the parent text segment according to the real split points to obtain a plurality of sub-text segments contained in the parent text segment.
[0301] In some example embodiments of the present disclosure, the vector database generation unit can include a text segment vector conversion unit, which can be configured to convert each parent text segment and each sub-text segment into a corresponding parent segment vector and sub-segment vector, respectively, through an embedding model.
[0302] In some example embodiments of the present disclosure, the vector database generation module can further include a knowledge document denoising unit, which can be configured to denoise the private knowledge document to be processed and delete irrelevant characters in the private knowledge document.
[0303] In some example embodiments of the present disclosure, the question text acquisition module 1410 can include a question text vector conversion unit, which can be configured to convert the input question text into a corresponding input question vector through an embedding model.
[0304] In some example embodiments of the present disclosure, the candidate text matching module 1420 can include a similarity calculation unit, a similarity sorting unit, and a candidate text screening unit. Wherein:
[0305] The similarity calculation unit can be configured to calculate the similarity between the input question vector and each text segment vector in the vector database to obtain the similarity between the input question vector and each text segment vector;
[0306] The similarity sorting unit can be configured to sort each text segment vector according to the similarity between the input question vector and each text segment vector;
[0307] The candidate text screening unit can be configured to determine a plurality of candidate text segment vectors from the text segment vectors according to the sorting results of the text segment vectors and a preset number of candidate segments.
[0308] In some example embodiments of the present disclosure, the target text determination module 1430 can include a parent text segment screening unit, a parent-child relationship judgment unit, a sub-text segment deletion unit, a sub-segment expansion unit, and a text segment list updating unit. Wherein:
[0309] The parent text segment screening unit can be configured to put the parent text segment in the candidate text segment into the high-correlation text segment list if the parent text segment exists in the candidate text segment;
[0310] The parent-child relationship judging unit can be configured to judge whether a child text segment having a parent-child relationship with the parent text segment exists in the candidate text segment according to the parent-child relationship data between the respective candidate text segments;
[0311] The child text segment deleting unit can be configured to delete the child text segment having the parent-child relationship with the parent text segment in the candidate text segment if the child text segment exists, and put the remaining child text segments in the candidate text segment into the high-correlation text segment list;
[0312] The child segment expanding unit can be configured to perform child segment expansion processing on the child text segments in the high-correlation text segment list according to the parent-child relationship data related to the child text segments;
[0313] The text segment list updating unit can be configured to update the high-correlation text segment list according to the child text segments after the child segment expansion processing until no child text segment needing expansion exists in the high-correlation text segment list, and obtain the target text segment according to the updated high-correlation text segment list.
[0314] In some example embodiments of the present disclosure, the child segment expanding unit can include an expansion processing order determining unit, a to-be-expanded child text segment determining unit, a neighboring child text segment obtaining unit, an expanded child text segment generating unit, an expansion stop condition judging unit, a whole child segment expansion stop unit, a current child segment expansion stop unit, a mergable child text segment determining unit, and a text segment merging unit. Wherein:
[0315] The expansion processing order determining unit can be configured to determine an expansion processing order of each child text segment according to a similarity between each child text segment in the high-correlation text segment list and the input question vector;
[0316] The to-be-expanded child text segment determining unit can be configured to select a child text segment from the child text segments in the high-correlation text segment list as a to-be-expanded child text segment according to the expansion processing order of each child text segment;
[0317] The neighboring child text segment obtaining unit can be configured to obtain a previous child text segment and a next child text segment adjacent to the to-be-expanded child text segment from a parent text segment where the to-be-expanded child text segment is located;
[0318] The expanded child text segment generating unit can be configured to expand the to-be-expanded child text segment according to the previous child text segment and the next child text segment to obtain an expanded child text segment;
[0319] The expansion stop condition judging unit can be configured to judge whether the overall sub-fragment expansion stop condition and the current sub-fragment expansion stop condition are met according to the expanded sub-text fragment;
[0320] The overall sub-fragment expansion stop unit can be configured to stop the sub-fragment expansion processing of all sub-text fragments in the high-relevance text fragment list if the overall sub-fragment expansion stop condition is met, and take the sub-fragment expansion processing result of the last round as the final sub-fragment expansion processing result;
[0321] The current sub-fragment expansion stop unit can be configured to select the next sub-text fragment as the to-be-expanded sub-text fragment from the sub-text fragments in the high-relevance text fragment list according to the expansion processing order of each sub-text fragment if the overall sub-fragment expansion stop condition is not met but the current sub-fragment expansion stop condition is met;
[0322] The mergable sub-text fragment determining unit can be configured to judge whether there is a mergable sub-text fragment adjacent to the expanded sub-text fragment and belonging to the same parent text fragment in the high-relevance text fragment list if the overall sub-fragment expansion stop condition is not met and the overall sub-fragment expansion stop condition is not met;
[0323] The text fragment merging unit can be configured to merge the expanded sub-text fragment with the mergable sub-text fragment if the mergable sub-text fragment exists, and update the high-relevance text fragment list according to the merged sub-text fragment.
[0324] In some example embodiments of the present disclosure, the expansion stop condition judging unit can include a text mark number total sum determining unit and an overall sub-fragment expansion stop condition judging unit. Wherein:
[0325] The text mark number total sum determining unit can be configured to obtain the current text mark number total sum according to the problem text mark number corresponding to the input problem text, the text fragment mark number corresponding to the expanded sub-text fragment, and the text fragment mark numbers corresponding to all other text fragments in the high-relevance text fragment list;
[0326] The overall sub-fragment expansion stop condition judging unit can be configured to obtain the language model rated mark number corresponding to the language model, and determine that the overall sub-fragment expansion stop condition is met if the current text mark number total sum is greater than the language model rated mark number.
[0327] In some example embodiments of the present disclosure, the expansion stop condition judging unit can further include a current sub-fragment expansion stop condition judging unit, which can be configured to determine that the current sub-fragment expansion stop condition is met if the expanded sub-text fragment is completely the same as the parent text fragment in which the expanded sub-text fragment is located.
[0328] The specific details of the modules / units in the model prompt generation apparatus described above have been described in detail in the corresponding method embodiment part, and will not be described here.
[0329] Figure 15 A structural schematic diagram of a computer system of an electronic device suitable for implementing the embodiments of the present disclosure is shown.
[0330] It should be noted that, Figure 15 The computer system 1500 of the electronic device shown is only an example, and should not bring any limitation to the functions and use range of the embodiments of the present disclosure.
[0331] As Figure 15 shown, the computer system 1500 includes a central processing unit (CPU) 1501, which can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 1502 or programs loaded from a storage portion 1508 into a random access memory (RAM) 1503. In the RAM 1503, various programs and data required for system operation are also stored. The CPU 1501, the ROM 1502, and the RAM 1503 are connected to each other through a bus 1504. An input / output (I / O) interface 1505 is also connected to the bus 1504.
[0332] The following components are connected to the I / O interface 1505: an input portion 1506 including a keyboard, a mouse, and the like; an output portion 1507 including a cathode ray tube (CRT), a liquid crystal display (LCD), and the like, and a speaker, and the like; a storage portion 1508 including a hard disk, and the like; and a communication portion 1509 including a network interface card such as a LAN card, a modem, and the like. The communication portion 1509 performs communication processing via a network such as the Internet. A drive 1510 is also connected to the I / O interface 1505 as necessary. A removable medium 1511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, and the like is mounted on the drive 1510 as necessary, so that a computer program read therefrom is installed into the storage portion 1508 as necessary.
[0333] In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts can be implemented as a computer software program. For example, the embodiments of the present disclosure include a computer program product including a computer program carried on a computer readable medium, the computer program containing program codes for executing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network by the communication portion 1509, and / or installed from the removable medium 1511. When the computer program is executed by the central processing unit (CPU) 1501, various functions defined in the system of the present disclosure are performed.
[0334] Note that the computer-readable medium shown in the disclosure can be a computer-readable signal medium or a computer-readable storage medium or any combination thereof. The computer-readable storage medium may, for example, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any combination thereof. More specific examples of the computer-readable storage medium can include, but are not limited to, an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the disclosure, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device. In the disclosure, the computer-readable signal medium can include a data signal that propagates in a baseband or as part of a carrier wave, carrying computer-readable program code. Such a propagated data signal can take on many forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable medium that is not a storage medium and that can communicate, transmit, or propagate programs for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wireline, optical fiber, RF, etc., or any suitable combination thereof.
[0335] The flow diagrams and block diagrams in the drawings are illustrations of possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the disclosure. In this regard, each block in the flow diagrams or block diagrams can represent a module, a segment, or a portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently or the blocks can sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and / or flow diagrams, and combinations thereof, can be implemented by special purpose hardware-based systems that perform the specified functions or operations, or combinations of special purpose hardware and computer instructions.
[0336] As another aspect, the present disclosure also provides a computer readable medium, which can be included in the electronic device described in the above embodiments, or can exist separately without being assembled into the electronic device. The above computer readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to implement the method described in the above embodiments.
[0337] It should be noted that, although several modules of the device for action execution are mentioned in the above detailed description, such a division is not mandatory. Indeed, according to embodiments of the present disclosure, the features and functions of two or more modules described above can be embodied in one module. Conversely, the features and functions of one module described above can be further divided into modules embodied by several modules.
[0338] Other embodiments of the present disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the features of the present disclosure disclosed herein. It is intended that the present disclosure cover any and all variations of the present disclosure including those variations contained within the scope of the features of the present disclosure and those adaptations made by those skilled in the art using, or combinations of, the features of the present disclosure, and incorporating techniques that are presently or subsequently developed.
[0339] It is to be understood that the present disclosure is not limited to the precise construction that has been described above and shown in the accompanying drawings, and that various modifications and changes can be effected thereon without departing from the scope thereof. The scope of the present disclosure is defined by the appended claims.
Claims
1. A method for generating a model prompt, the method comprising: The method comprises the following steps: obtaining input question text and obtaining a corresponding input question vector according to the input question text; matching the input question vector with each text segment vector in a vector database, and determining a plurality of candidate text segment vectors from the text segment vectors according to a matching result; wherein the text segment vectors in the vector database include a plurality of parent segment vectors obtained from private knowledge documents, and each parent segment vector includes a child segment vector; the matching of the input question vector with each text segment vector in the vector database and the determination of a plurality of candidate text segment vectors from the text segment vectors according to a matching result comprise: calculating the similarity between the input question vector and each text segment vector in the vector database to obtain the similarity between the input question vector and each text segment vector; sorting each text segment vector according to the similarity between the input question vector and each text segment vector; and determining a plurality of candidate text segment vectors from the text segment vectors according to the sorting result of the text segment vectors and a preset number of candidate segments; converting the candidate text segment vectors into corresponding candidate text segments respectively, screening and processing the candidate text segments according to parent-child relationship data between each candidate text segment, and obtaining at least one target text segment; the screening and processing of the candidate text segments according to the parent-child relationship data between each candidate text segment and the obtaining of at least one target text segment comprise: if there is a parent text segment in the candidate text segments, putting the parent text segment in the candidate text segments into a high-relevance text segment list; judging whether there is a child text segment having a parent-child relationship with the parent text segment in the candidate text segments according to the parent-child relationship data between each candidate text segment; if there is, deleting the child text segment having a parent-child relationship with the parent text segment in the candidate text segments, and putting the remaining child text segments in the candidate text segments into the high-relevance text segment list; performing child segment expansion processing on the child text segments in the high-relevance text segment list according to the parent-child relationship data related to the child text segments; updating the high-relevance text segment list according to the child text segments after the child segment expansion processing until there is no child text segment needing to be expanded in the high-relevance text segment list, and obtaining the target text segment according to the updated high-relevance text segment list; obtaining a target text prompt according to all the target text segments, and obtaining a language model prompt for use in an input language model according to the input question text and the target text prompt.
2. The method of claim 1, wherein, The method further comprises a generation method of the vector database, which comprises the following steps: Acquire a private knowledge document to be processed, and perform content block segmentation processing on the private knowledge document based on a document type of the private knowledge document, to obtain a plurality of parent text segments in the private knowledge document; Acquire a sub-segment segmentation number corresponding to the parent text segment, and perform sub-segment segmentation processing on the parent text segment according to the sub-segment segmentation number, to obtain a plurality of sub-text segments respectively contained in each of the parent text segments; Convert each of the parent text segments and each of the sub-text segments into a corresponding parent segment vector and a sub-segment vector respectively, and put the parent segment vector and the sub-segment vector into the vector database.
3. The method of claim 2, wherein, The method further comprises: When performing sub-segment segmentation processing on the parent text segment, establish parent-child relationship data between the parent text segment and the sub-text segment, and put the parent-child relationship data into a parent-child relationship database.
4. The method of claim 2, wherein, The content block segmentation processing on the private knowledge document based on the document type of the private knowledge document comprises: If the document type of the private knowledge document is a text document containing a document title, perform content block segmentation processing on the private knowledge document according to the document title; If the document type of the private knowledge document is a text document not containing a document title, perform content block segmentation processing on the private knowledge document according to a line break in the private knowledge document; If the document type of the private knowledge document is an electronic spreadsheet document, perform content block segmentation processing on the private knowledge electronic spreadsheet document in units of each worksheet in the private knowledge electronic spreadsheet document.
5. The method of claim 4, wherein, The content block segmentation processing on the private knowledge electronic spreadsheet document in units of each worksheet in the private knowledge electronic spreadsheet document comprises: Perform content block segmentation processing on the private knowledge electronic spreadsheet document in units of each worksheet in the private knowledge electronic spreadsheet document, and convert data in each of the worksheets into text data.
6. The method of claim 5, wherein, The conversion of the data in each of the worksheets into text data comprises: Read all cells in the worksheet except empty cells in a preset reading order; Splice an indentation symbol corresponding to a column number before each of the cell data read in each of the cells, and splice a line break after each of the cell data; According to the preset reading order, all the cell data read in the worksheet are composed into worksheet text data corresponding to the worksheet.
7. The method of claim 2, wherein, After the content block segmentation processing on the private knowledge document, the method further comprises: According to the content block label number corresponding to each of the content blocks obtained after the content block segmentation processing on the private knowledge document, determine whether the content blocks need to be merged with other content blocks, and perform content block merging processing on the content blocks that need to be merged.
8. The method of claim 7, wherein, The content block mark number corresponding to each content block obtained after the content block segmentation processing of the private knowledge document is used to determine whether the content block needs to be merged with other content blocks, and the content block merging processing is performed on the content block that needs to be merged, comprising: An embedding model rating mark number corresponding to an embedding model used for vector conversion is obtained, and a first mark number threshold and a second mark number threshold are determined according to the embedding model rating mark number, wherein the first mark number threshold is less than the embedding model rating mark number, and the second mark number threshold is greater than the embedding model rating mark number; If the content block mark number corresponding to the content block is less than the first mark number threshold, the content block is merged with the next content block corresponding to the content block to obtain a merged content block; If the content block mark number corresponding to the content block is greater than or equal to the embedding model rating mark number, it is determined that the content block does not need to be subjected to content block merging processing; If the content block mark number corresponding to the content block is greater than or equal to the first mark number threshold and less than the embedding model rating mark number, the content block is merged with the next content block corresponding to the content block to obtain a merged content block to be determined; If the content block mark number corresponding to the content block to be determined is greater than the second mark number threshold, the content block merging processing of the content block and the next content block is cancelled; If the content block mark number corresponding to the content block to be determined is less than or equal to the second mark number threshold, the content block to be determined is taken as a merged content block.
9. The method of claim 8, wherein, Before the content block segmentation processing of the private knowledge document, the method further comprises: determining whether the document mark number corresponding to the private knowledge document is less than the second mark number threshold; If the document mark number corresponding to the private knowledge document is less than the second mark number threshold, the private knowledge document is directly taken as a parent text segment; If the document mark number corresponding to the private knowledge document is greater than or equal to the second mark number threshold, subsequent steps are continued to perform the content block segmentation processing on the private knowledge document.
10. The method of claim 8, wherein, The obtaining of the sub-segment segmentation number corresponding to the parent text segment comprises: determining a sub-segment rating mark number according to the first mark number threshold; determining the sub-segment segmentation number corresponding to the parent text segment according to the parent text mark number corresponding to the parent text segment and the sub-segment rating mark number.
11. The method of claim 2, wherein, The sub-segment segmentation processing of the parent text segment according to the sub-segment segmentation number to obtain a plurality of sub-text segments respectively contained in each of the parent text segments comprises: determining a theoretical segmentation point in the parent text segment according to the number of characters in the parent text segment and the sub-segment segmentation number corresponding to the parent text segment; taking the nearest line break after each of the theoretical segmentation points as a real segmentation point in the parent text segment, and performing the sub-segment segmentation processing on the parent text segment according to the real segmentation point to obtain a plurality of sub-text segments contained in the parent text segment.
12. The method of claim 2, wherein, The converting each parent text segment and each child text segment into a corresponding parent segment vector and child segment vector respectively comprises: Converting each parent text segment and each child text segment into a corresponding parent segment vector and child segment vector respectively by an embedding model.
13. The method of claim 2, wherein, After obtaining the private knowledge document to be processed, the method further comprises: Carrying out denoising on the private knowledge document to be processed, and deleting irrelevant characters in the private knowledge document.
14. The method of claim 1, wherein, The obtaining a corresponding input question vector according to the input question text comprises: Converting the input question text into a corresponding input question vector by an embedding model.
15. The method of claim 1, wherein, The child segment expansion processing of the child text segments in the high-correlation text segment list according to the parent-child relationship data related to the child text segments comprises: Determining an expansion processing order of each child text segment according to a similarity between each child text segment in the high-correlation text segment list and the input question vector; Selecting a child text segment from the child text segments in the high-correlation text segment list as a to-be-expanded child text segment according to the expansion processing order of each child text segment; Obtaining a previous child text segment and a next child text segment adjacent to the to-be-expanded child text segment from a parent text segment in which the to-be-expanded child text segment is located; Expanding the to-be-expanded child text segment according to the previous child text segment and the next child text segment to obtain an expanded child text segment; Determining whether a full child segment expansion stop condition and a current child segment expansion stop condition are met according to the expanded child text segment; If the full child segment expansion stop condition is met, stopping the child segment expansion processing of all the child text segments in the high-correlation text segment list, and taking a last round of child segment expansion processing result as a final child segment expansion processing result; If the full child segment expansion stop condition is not met, but the current child segment expansion stop condition is met, selecting a next child text segment from the child text segments in the high-correlation text segment list as a to-be-expanded child text segment according to the expansion processing order of each child text segment; If the full child segment expansion stop condition and the current child segment expansion stop condition are not met, determining whether there is a mergable child text segment adjacent to the expanded child text segment and belonging to a same parent text segment as the expanded child text segment in the high-correlation text segment list; If the mergable child text segment exists, merging the expanded child text segment and the mergable child text segment, and updating the high-correlation text segment list according to the merged child text segment.
16. The method of claim 15, wherein, Determining whether a full child segment expansion stop condition is met comprises: Obtaining a current text mark number total sum according to a question text mark number corresponding to the input question text, a text segment mark number corresponding to the expanded child text segment, and text segment mark numbers corresponding to all other text segments in the high-correlation text segment list. Obtaining a language model rated token number corresponding to the language model, and if the current text token number sum is greater than the language model rated token number, it is determined that all sub-fragment expansion stop conditions are met.
17. The method of claim 15, wherein, Determine whether the current sub-fragment expansion stop condition is met, comprising: If the expanded sub-text fragment is completely identical to the parent text fragment where the expanded sub-text fragment is located, it is determined that the current sub-fragment expansion stop condition is met.
18. An apparatus for generating a model prompt, comprising: Comprising: A question text acquisition module is configured to obtain an input question text and obtain a corresponding input question vector according to the input question text; A candidate text matching module is configured to match the input question vector with each text fragment vector in a vector database, and determine a plurality of candidate text fragment vectors from the text fragment vectors according to the matching result; wherein the text fragment vectors in the vector database include a plurality of parent fragment vectors obtained from a private knowledge document, and each parent fragment vector includes a sub-fragment vector; the matching of the input question vector with each text fragment vector in the vector database, and the determination of a plurality of candidate text fragment vectors from the text fragment vectors according to the matching result, comprises: calculating the similarity between the input question vector and each text fragment vector in the vector database to obtain the similarity between the input question vector and each text fragment vector; sorting each text fragment vector according to the similarity between the input question vector and each text fragment vector; and determining a plurality of candidate text fragment vectors from the text fragment vectors according to the sorting result of the text fragment vectors and a preset number of candidate fragments. The target text determination module is configured to convert the candidate text segment vectors into corresponding candidate text segments respectively, and filter and process the candidate text segments according to the parent-child relationship data between the candidate text segments, to obtain at least one target text segment. The filtering and processing of the candidate text segments according to the parent-child relationship data between the candidate text segments to obtain at least one target text segment includes: if there is a parent text segment in the candidate text segments, the parent text segment in the candidate text segments is put into a high-relevance text segment list; whether there is a child text segment having a parent-child relationship with the parent text segment in the candidate text segments is determined according to the parent-child relationship data between the candidate text segments; if there is, the child text segment having a parent-child relationship with the parent text segment in the candidate text segments is deleted, and the remaining child text segments in the candidate text segments are put into the high-relevance text segment list; the child text segments in the high-relevance text segment list are processed for child segment expansion according to the parent-child relationship data related to the child text segments; the high-relevance text segment list is updated according to the child text segments after the child segment expansion processing, until there is no child text segment needing expansion in the high-relevance text segment list, and the target text segments are obtained according to the updated high-relevance text segment list; The model prompt generation module is configured to obtain a target text prompt according to all the target text segments, and obtain a language model prompt used in a language model according to the input question text and the target text prompt.
19. An electronic device, comprising: The model prompt generation module includes: A processor; and A memory for storing one or more programs, which, when executed by the processor, cause the processor to implement the model prompt generation method according to any one of claims 1 to 17.
20. A computer readable medium having stored thereon a computer program, characterized in that, The programs are executed by the processor to implement the model prompt generation method according to any one of claims 1 to 17.
Citation Information
Patent Citations
Text generation method, device and equipment and readable storage medium
CN115146050A
Candidate paragraph generation and multi-hop question answering method based on text classification
CN115878794A