Model prompt generation method and device, electronic equipment and computer medium

By matching with the vector database and filtering processing based on parent-child relationships, reasonable and sufficient model prompts are generated, and the problem of low correctness of the language model in the private knowledge field is solved, which improves the correctness and stability of the answers.

CN119621951AActive Publication Date: 2025-03-14NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202311177222.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-12
Publication Date
2025-03-14
Estimated Expiration
2043-09-12

AI Technical Summary

Technical Problem

The prior art is difficult to effectively generate reasonable and sufficient model prompts, resulting in the low correctness of the language model's answers in the field of private knowledge.

Method used

The candidate text fragment vector is determined by obtaining the input problem text, converting it into an input problem vector, and matching it with the text fragment vector in the vector database. Based on the parent-child relationship data between candidate text fragments, the target text fragment is filtered and processed to generate a language model prompt for inputting the language model.

Benefits of technology

The correctness and stability of the language model in the private knowledge field is improved, making the prompts obtained by the model more reasonable and complete, and reducing answer errors caused by insufficient content of document fragments and poor readability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621951A_ABST
    Figure CN119621951A_ABST
Patent Text Reader

Abstract

The invention relates to a model cue generation method and device, electronic equipment and a computer readable medium, and belongs to the technical field of artificial intelligence. The method comprises the steps of obtaining a corresponding input question vector according to an input question text; matching the input problem vector with text fragment vectors in a vector database, and determining a plurality of candidate text fragment vectors; the text fragment vectors in the vector database comprise a plurality of parent fragment vectors and child fragment vectors in the parent fragment vectors; converting the candidate text fragment vectors into corresponding candidate text fragments, and performing screening and processing according to set membership data among the candidate text fragments to obtain target text fragments; and according to the input question text and the target text cue, obtaining a language model cue used for inputting a language model. According to the invention, the content of the language model prompt can be more reasonable and sufficient, so that the answer accuracy of the language model in the field of private knowledge is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of artificial intelligence technology, and in particular to a method for generating a model prompt, a device for generating a model prompt, an electronic device, and a computer-readable medium. Background Art

[0002] Currently, LLM (Large Language Model) is leading a new round of technological innovation. LLM supports natural language understanding. Users can interact with LLM through chat to enable LLM to answer questions and perform tasks.

[0003] In the field of private knowledge, LLM can be guided to answer user questions by referring to private knowledge fragments by sending prompts containing user questions and private knowledge fragments to LLM. This is the prototype of private knowledge AI (artificial intelligence based on LLM answering user private knowledge). How to process private knowledge documents and how to obtain private knowledge prompts and send them to LLM are two key issues to keep the accuracy of private knowledge AI answers at a high level and promote their use.

[0004] In view of this, there is an urgent need in this field for a method for generating model prompts that can make the content of the extracted language model prompts more reasonable and sufficient, thereby improving the accuracy of the language model's answers in the field of private knowledge.

[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

[0006] The purpose of the present disclosure is to provide a method for generating a model prompt, a device for generating a model prompt, an electronic device and a computer-readable medium, so as to make the content of the extracted language model prompt more reasonable and sufficient, at least to a certain extent, thereby improving the accuracy of the language model's answers in the field of private knowledge.

[0007] According to a first aspect of the present disclosure, a method for generating a model prompt is provided, comprising:

[0008] Obtaining an input question text, and obtaining a corresponding input question vector according to the input question text;

[0009] Matching the input question vector with each text segment vector in the vector database, and determining a plurality of candidate text segment vectors from the text segment vectors according to the matching results; wherein the text segment vectors in the vector database include a plurality of parent segment vectors obtained from private knowledge documents, and child segment vectors respectively 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 the parent-child relationship data between the candidate text segments to obtain at least one target text segment;

[0011] A target text prompt is obtained according to all the target text segments, and a language model prompt for input into a language model is obtained according to the input question text and the target text prompt.

[0012] According to a second aspect of the present disclosure, there is provided a device for generating a model prompt, comprising:

[0013] A question text acquisition module, used 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, 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 results; wherein the text segment vectors in the vector database include a plurality of parent segment vectors obtained from private knowledge documents, and child segment vectors respectively contained in each of the parent segment vectors;

[0015] A target text determination module, used to convert the candidate text segment vectors into corresponding candidate text segments respectively, and screen 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;

[0016] The model prompt generation module is used to obtain target text prompts according to all the target text segments, and to obtain language model prompts for input into the language model according to the input question text and the target text prompts.

[0017] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute any one of the above-mentioned methods for generating model prompts by executing the executable instructions.

[0018] According to a fourth aspect of the present disclosure, a computer-readable medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the method for generating a model prompt as described in any one of the above is implemented.

[0019] The exemplary embodiments of the present disclosure may have the following beneficial effects:

[0020] In the method for generating model prompts of the example implementation mode of the present disclosure, on the one hand, by matching the input question vector with the text fragment vector in the vector database, and screening and expanding the candidate text fragments according to the parent-child relationship, the model prompts obtained by the language model are made more reasonable, complete, and readable, and the situation where the language model gives incorrect answers due to insufficient content and poor readability of the document fragments is reduced, thereby improving the accuracy and stability of the language model in the field of private knowledge; for the natural language model, by completing any task performed in natural language, the more comprehensive and complete the private knowledge used by the natural language model to identify and perform the task, the higher the accuracy when performing customized tasks; on the other hand, the calculation process only needs to be built around the data in the vector database, which greatly reduces the amount of calculation compared to training a language model, and is more convenient.

[0021] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.

[0023] Figure 1 A schematic diagram showing a flow chart of a method for generating model prompts according to a related embodiment of the present disclosure;

[0024] Figure 2 A schematic diagram showing a flow chart of a method for generating model prompts according to an exemplary embodiment of the present disclosure;

[0025] Figure 3 A schematic diagram showing a flow chart of a method for generating a vector database according to an exemplary embodiment of the present disclosure;

[0026] Figure 4 A schematic diagram showing a flow chart of converting data in a worksheet into text data according to an exemplary embodiment of the present disclosure;

[0027] Figure 5A schematic diagram showing a flow chart of content block merging processing in an exemplary embodiment of the present disclosure;

[0028] Figure 6 A schematic diagram showing a process flow of sub-segment segmentation processing according to an exemplary embodiment of the present disclosure is shown;

[0029] Figure 7 A schematic diagram of a process for determining a candidate text segment vector according to an exemplary embodiment of the present disclosure is shown;

[0030] Figure 8 A schematic diagram showing a process of determining a target text segment according to an exemplary embodiment of the present disclosure;

[0031] Fig. 9 A schematic diagram showing a flow chart of a sub-segment expansion process according to an exemplary embodiment of the present disclosure;

[0032] Fig.10 A schematic diagram of a process for generating a model prompt in a specific implementation manner of the present disclosure is shown;

[0033] Fig.11 A schematic diagram of the process of content block segmentation processing according to a specific implementation of the present disclosure is shown;

[0034] Fig.12 A schematic diagram of a process flow of content block merging processing according to a specific implementation of the present disclosure is shown;

[0035] Fig.13 A schematic diagram of the process of secondary processing of document fragments according to a specific implementation of the present disclosure is shown;

[0036] Fig.14 A block diagram showing a device for generating model prompts according to an exemplary embodiment of the present disclosure is shown;

[0037] Fig.15 A schematic diagram of the structure of a computer system suitable for implementing the electronic device of the embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0038] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.

[0039] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.

[0040] LLM (Large Language Model) refers to a natural language processing model trained with large-scale data sets, usually using deep learning algorithms. These models can be used to predict the next word or the entire sentence, and can also be used for tasks such as text classification, sentiment analysis, and question-answering systems.

[0041] In some related embodiments, the private knowledge document can be segmented, the number of characters in each segment is kept equal, and the embedding vectors of these document segments are stored in a vector database. Among them, the embedding space is a commonly used technology in natural language processing, which captures the semantic relationship between words by mapping each word in the vocabulary into a vector in a high-dimensional vector space, thereby improving the efficiency of computer processing of natural language.

[0042] Next, the vector data after the user inputs the word Embedding is used to find the closest vectors in the vector database and convert them into corresponding document fragments to obtain private knowledge fragments related to the question. LLM will answer the input question based on the highly relevant information in these private knowledge fragments.

[0043] Since there is an upper limit on the number of tokens that can be input into LLM, it is neither realistic nor safe to directly send the entire document to LLM to answer private knowledge. Therefore, the private knowledge document can be divided into equal parts, and the embedding conversion can be performed to generate vectors containing word meanings and stored in the vector database; then, the document fragments that are highly related to the user input word can be obtained as prompts through proximity calculation, and sent to LLM for reference and answering questions. Among them, the prompt refers to a short text fragment that guides the computer to generate the corresponding output text in natural language processing technology.

[0044] like Figure 1 FIG. 1 is a flow chart of a method for generating a model prompt in a related embodiment of the present disclosure. The specific steps of the flow chart are as follows:

[0045] Step S110: Document denoising.

[0046] Delete special symbols in the original document data, such as @, *, and emoticons.

[0047] Step S120: Divide the document into equal parts.

[0048] The document is divided into several segments according to the rated number of characters. The rated number of characters is determined by the rated number of tokens, which means that the number of characters after embedding will not exceed the rated number of tokens. Since the Embedding Model has an upper limit on the number of tokens to be processed, the number of tokens of the document segments after segmentation will generally not exceed the upper limit of the number of tokens of the Embedding Model.

[0049] Tokens are tags, which refer to the decomposition of a text into individual units in natural language processing, usually words or subwords. Tokens are the basic units for further processing and analysis of text, and can be used for tasks such as text classification, part-of-speech tagging, and named entity recognition. Different natural language processing models have different Tokens calculation algorithms. The rated tokens are the maximum number of tokens that the model supports for processing text. If the number of tokens in a text segment exceeds the rated tokens, poor processing performance may occur. For the Embedding Model, the calculated vector word meaning relationship is unclear, and for the LLM, it is impossible to process the received data (LLM rejects input data that exceeds the rated tokens); in the actual processing process, the rated tokens can be determined by the model as needed.

[0050] Step S130: Document fragment Embedding.

[0051] The segments obtained by segmentation are embedded separately to obtain multiple vector data.

[0052] Step S140: Vector storage.

[0053] The obtained multiple vector data are stored in a vector database.

[0054] Step S150: Embedding the question text.

[0055] Embed the question text entered by the user to obtain the vector data corresponding to the question text.

[0056] Step S160: Vector matching.

[0057] The vector data corresponding to the question text is used to calculate the similarity with the vector data in the vector database, and then sorted by similarity to return the first several most similar vectors. The specific similarity calculation method can be selected according to the actual situation. Commonly used methods include cosine similarity, Euclidean distance, etc.

[0058] Step S170: Convert vector to text and output the text.

[0059] The corresponding document fragment is obtained based on the most similar vector. This document fragment is the private knowledge document fragment that is most relevant to the question text. Since LLM has an upper limit on the input Tokens, the number of output document fragments is also limited by Tokens.

[0060] The above technical solution can solve most private knowledge question-answering situations that only require a sentence of original text to explain, but in most cases where more original text is required to explain, private knowledge AI will have problems with inaccurate and incomplete answers. The specific reasons for the above problems are as follows:

[0061] 1. Unreasonable document segmentation: Generally speaking, the content logic of a document is related to its structure. The content described in a document is differentiated and logically refined based on the document structure. If the document is segmented equally, the original description logic of the document will be destroyed. Generally, the following situations will occur:

[0062] (1) The description content is split into two segments: Since the equal segmentation algorithm ignores the document structure logic, this situation occurs very frequently.

[0063] For the Embedding Model, this segmentation method may result in low similarity in the converted vector data of the two document segments obtained by segmenting the description content. The former may retain the characteristic words describing the content, while the latter does not, or vice versa. When matching vectors, it is likely that only one of them is considered a highly relevant segment.

[0064] For LLM, submitting document fragments with incomplete description content to LLM will result in incomplete and insufficient answers from LLM, and may even mislead users by generating irrelevant information due to the text prediction function of LLM.

[0065] (2) The fragment contains incomplete information of two adjacent description contents: Due to the equal-amount segmentation algorithm, there is a probability that a fragment contains two adjacent description contents, and both are incomplete.

[0066] For the Embedding Model, this incomplete and inconsistent information fragment will cause the word meaning relationship vector calculated by the Embedding Model to be inaccurate and chaotic, making it 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, since LLM first trusts the text materials provided by users and tries to understand the core meaning of the incomplete and erroneous document fragments to answer user questions, however, since the provided text already has errors, it increases the difficulty for LLM to answer the correct answer.

[0068] 2. Insufficient document fragment matching: Although several document fragments obtained by vector similarity calculation provide reference information for LLM to some extent, there may be a description order relationship between document fragments, and some document fragments may also have incomplete description content.

[0069] (1) When document fragments are not merged in the order of description, although LLM has a certain ability to analyze which fragments are related to the question, LLM trusts the fragment description logic provided by the user. Therefore, LLM has the probability of giving the wrong answer content with the wrong fragment description order.

[0070] (2) Incomplete description of the content in the document fragment will cause the LLM to give an incomplete answer or predict the wrong content to answer the user.

[0071] In other related embodiments, a new LLM can be trained with private knowledge so that it has private knowledge and can answer the user's private knowledge questions. This solution has high implementation costs, including hardware costs, time costs, and a long iteration cycle.

[0072] Based on the above problems, this example implementation first provides a method for generating model prompts. Figure 2 As shown, the method for generating the above model prompt may include the following steps:

[0073] Step S210: Obtain input question text, and obtain a 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 multiple candidate text segment vectors from the text segment vectors according to the matching results.

[0075] The text segment vectors in the vector database include a plurality of parent segment vectors obtained from the private knowledge document, and the child segment vectors respectively contained in each parent segment vector.

[0076] Step S230. Convert the candidate text segment vectors into corresponding candidate text segments respectively, and screen 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 target text prompts based on all target text segments, and obtain language model prompts for input into a language model based on the input question text and the target text prompts.

[0078] In the method for generating model prompts of the example implementation mode of the present disclosure, on the one hand, by matching the input question vector with the text fragment vector in the vector database, and screening and expanding the candidate text fragments according to the parent-child relationship, the model prompts obtained by the language model are made more reasonable, complete, and readable, and the situation where the language model gives incorrect answers due to insufficient content and poor readability of the document fragments is reduced, thereby improving the accuracy and stability of the language model in the field of private knowledge; for the natural language model, by completing any task performed in natural language, the more comprehensive and complete the private knowledge used by the natural language model to identify and perform the task, the higher the accuracy when performing customized tasks; on the other hand, the calculation process only needs to be built around the data in the vector database, which greatly reduces the amount of calculation compared to training a language model, and is more convenient.

[0079] Next, combine Figures 3 to 9 The above steps of this exemplary embodiment are described in more detail.

[0080] In accordance with Figure 2 Before obtaining the language model prompts for input into the language model, the present exemplary implementation also includes a method for generating a vector database, such as Figure 3 As shown, the method for generating the vector database may specifically include the following steps:

[0081] Step S310: Acquire the private knowledge document to be processed, and based on the document type of the private knowledge document, perform content block segmentation processing on the private knowledge document to obtain multiple parent text segments in the private knowledge document.

[0082] In this example implementation, after obtaining the private knowledge document to be processed, the private knowledge document to be processed may first be denoised to delete irrelevant characters in the private knowledge document, such as special symbols such as @, *, and emoticons.

[0083] In this example implementation, before the private knowledge document is segmented into content blocks, it is necessary to first determine the number of document tokens corresponding to the private knowledge document. First, the rated number of embedding model tokens corresponding to the embedding model used for vector conversion can be obtained, and the first token number threshold and the second token number threshold can be determined based on the rated number of embedding model tokens. Among them, the first token number threshold is less than the rated number of embedding model tokens, and the second token number threshold is greater than the rated number of embedding model tokens. For example, the first token number threshold can be, for example, 0.5 times the Embedding Model rated Tokens, and the second token number threshold can be, for example, 2 times the Embedding Model rated Tokens.

[0084] On this basis, first determine whether the number of document tags corresponding to the private knowledge document is less than the second tag number threshold; if the number of document tags corresponding to the private knowledge document is less than the second tag number threshold, the private knowledge document is directly used as a parent text fragment; if the number of document tags corresponding to the private knowledge document is greater than or equal to the second tag number threshold, continue to execute subsequent steps to perform content block segmentation on the private knowledge document.

[0085] Since some documents only describe the content of an object, they do not need to be segmented to a certain extent. The characteristic of such documents is that they are short. In practice, we can first verify the document tokens before determining whether to segment. If the document tokens are less than 2 times the rated tokens of the Embedding Model, the document does not need to be segmented, and the private knowledge AI will have a better answer effect.

[0086] In order to improve the accuracy of private knowledge AI answers, one of the core ideas is to "make each word meaning relationship vector calculated by the Embedding Model more accurate". Different Embedding Models have different requirements for rated tokens. Generally speaking, "the shorter the sentence, the simpler the description content, and the more accurate the word meaning relationship vector". Therefore, the document segmentation process can be divided into two parts, including content block segmentation and sub-segment segmentation.

[0087] Content block segmentation of a document refers to segmenting the parent segment of the document, that is, the first-level segment; different document types have different segmentation algorithms / strategies. Sub-segment segmentation refers to segmenting the parent segment according to line breaks and rated tokens, obtaining sub-segments, that is, second-level segments, and building parent-child relationships between document segments; the algorithm / strategy for sub-segment segmentation is applicable to different types of documents.

[0088] In this example implementation, the goal is to be compatible with different types of documents so that different types of documents can be used for private knowledge AI question and answer, and there will be no difference in data between different types of documents.

[0089] It has been verified that if the document fragments submitted to LLM are all paragraph sets with complete description content, LLM's correct answer rate for private knowledge will remain at a high level. A paragraph set with complete description content refers to a complete description of the described object, which can be a complete description of a tool or a complete description of one of the functions of the tool. In this example implementation, it is named content block.

[0090] The purpose of content block segmentation is to segment the parent segment, which is a paragraph that describes the complete content. Different documents have different division strategies for content blocks, so different document types need to apply different algorithm strategies for content block segmentation. Different document types can refer to different document file types, or documents of the same file type with different application scenarios, such as Markdown (Lightweight Markup Language) documents and PDF (Portable Document Format) documents, PDF description documents and PDF general articles (such as novels, diaries, etc.).

[0091] In this example implementation, if the document type of the private knowledge document is a text document including 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 divided into several fragments, and each fragment is a content block that corresponds to the document title and describes the content completely. This method is suitable for technical documents with clear document structure, such as design documents, instruction documents, etc., and also for file types with clear title information, such as Markdown documents and some PDF documents.

[0093] For example, the content of a private knowledge document is as follows:

[0094] 1. Design topic and description

[0095] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX.

[0096] II. Research and Analysis

[0097] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. 3. Design plan

[0098] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.

[0099] 4. Design Summary

[0100] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.

[0101] The above-mentioned type of private knowledge documents can be directly segmented into content blocks based on the four document titles.

[0102] In this example implementation, if the document type of the private knowledge document is a text document that does not include a document title, the private knowledge document is segmented into content blocks according to line breaks in the private knowledge document.

[0103] The document is divided into several segments according to the line breaks in the document, and each segment is a content block that describes the complete content. This method is suitable for narrative texts without a clear document structure or file types that cannot obtain clear title information.

[0104] In this example implementation, if the document type of the private knowledge document is a spreadsheet document, the private knowledge spreadsheet document is divided into content blocks based on each worksheet in the private knowledge spreadsheet document.

[0105] In some game development companies, game planners are used to using Excel (spreadsheets) to produce game function documents and design documents. After logically refining the game planners' Excel document writing habits, this example implementation also designs a segmentation strategy for such documents when they are implemented.

[0106] When the private knowledge spreadsheet document is divided into content blocks based on each worksheet in the private knowledge spreadsheet document, the private knowledge spreadsheet document can be divided into content blocks based on each worksheet in the private knowledge spreadsheet document, and the data in each worksheet can be converted into text data.

[0107] The document data is divided into Sheets (worksheets). The document data in each Sheet is the content block that corresponds to the Sheet title and describes the content completely. At the same time, the data in the cells in the Sheet are transcribed into text data.

[0108] In this example implementation, Figure 4 As shown, converting the data in each worksheet into text data can include the following steps:

[0109] Step S410. All cells except empty cells in the worksheet are read in sequence according to a preset reading order.

[0110] All cells in the worksheet are read from left to right and from top to bottom. Empty cells or cells with only spaces are not read.

[0111] Step S420. For the cell data read in each cell, an indentation character corresponding to the number of columns is added before each cell data, and a line break character is added after each cell data.

[0112] For the cell data read in each cell, an indent character corresponding to the number of columns is added before the cell data, and a line break character is added after the cell data.

[0113] Step S430. All the cell data read in the worksheet are assembled into worksheet text data corresponding to the worksheet according to a preset reading order.

[0114] Finally, all the acquired cell data are combined into text data in the order of reading. This method is suitable for planning output documents written on Excel.

[0115] In this example implementation, after the private knowledge document is segmented into content blocks, it is also possible to determine whether the content blocks need to be merged with other content blocks based on the number of content block tags corresponding to each content block obtained after the private knowledge document is segmented into content blocks, and 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 an adjacent content block to fully understand their descriptions because of the small amount of descriptions. At the same time, LLM supports identifying the amount of content described by the document fragment structure, and merging several small content blocks into one content block does not affect LLM's analysis of the information required for the problem. Therefore, the content blocks segmented according to the main strategy need to be processed twice, that is, content block merging.

[0117] In this example implementation, Figure 5 As shown, according to the number of content block tags corresponding to each content block obtained after the private knowledge document is segmented into content blocks, it is determined whether the content block needs to be merged with other content blocks, and the content block merging process is performed on the content blocks that need to be merged. Specifically, the following steps may be included:

[0118] Step S510. Obtain the embedding model rated number of tags corresponding to the embedding model used for vector conversion, and determine a first tag number threshold and a second tag number threshold according to the embedding model rated number of tags.

[0119] The first token number threshold is less than the rated token number of the embedding model, and the second token number threshold is greater than the rated token number of the embedding model. The first token number threshold may be, for example, 0.5 times the rated tokens of the Embedding Model, and the second token number threshold may be, for example, 2 times the rated tokens of the Embedding Model.

[0120] Step S520: 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.

[0121] If the content block token number corresponding to the content block is less than the first token number threshold, for example, less than 0.5 times the rated Tokens of the EmbeddingModel, it is merged with the next content block to obtain a new content block.

[0122] Step S530: If the content block tag number corresponding to the content block is greater than or equal to the embedded model rated tag number, it is determined that the content block does not need to be merged.

[0123] Step S540: If the content block tag number corresponding to the content block is greater than or equal to the first tag number threshold and less than the rated tag number of the embedding model, 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 token number corresponding to the content block is greater than or equal to the first token 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, try to merge the next content block to obtain the merged content block to be judged.

[0125] Step S550: 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 process of the content block and the next content block is cancelled.

[0126] If the Tokens of the merged new content block exceeds the second token number threshold, for example, 2 times the rated Tokens of the Embedding Model, the merge is canceled.

[0127] Step S560: 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 used as the merged content block.

[0128] If the merged new content block Tokens is less than or equal to the second token number threshold, for example, 2 times the EmbeddingModel rated Tokens, the content block to be judged is taken as a new content block.

[0129] Content block segmentation can make the document fragment description content body single without other interference. By using the content block segmentation step, the document description content units are divided before embedding, reducing the poor readability of the document fragment caused by unreasonable segmentation (which can also be understood as the unclear and unprominent description features of the corresponding word meaning relationship vector), thereby improving the integrity and content uniformity of the document fragment obtained by LLM.

[0130] Continue to refer Figure 3 As shown, step S320. Obtain the number of sub-segment segments corresponding to the parent text segment, and perform sub-segment segmentation processing on the parent text segment according to the number of sub-segment segments to obtain multiple sub-text segments respectively contained in each parent text segment.

[0131] Based on the data obtained by segmenting the content block (parent segment), the segmentation of the sub-segment only needs to be performed within the parent segment. The sub-segment only uses the line break as the segmentation mark 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 clearer and more prominent, the content block needs to be segmented into sub-segments. Usually, the length of the tokens of the content block will exceed 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, resulting in a low score during similarity calculation and inability to output correctly. By segmenting the content block into sub-segments with a specific strategy, it can be ensured that the semantic relationship of the feature word will not be diluted by other words, so that it can be better output correctly in the vector similarity calculation.

[0133] In this example implementation, the rated number of sub-segment tags can be determined according to the first tag number threshold, and the number of sub-segment segments corresponding to the parent text segment can be determined according to the parent text tag number corresponding to the parent text segment and the rated number of sub-segment tags.

[0134] In this example implementation, the formula for obtaining the theoretical number of sub-fragments is:

[0135]

[0136] Among them: Count is the theoretical number of sub-segment segments; T is the content block tokens; R is the sub-segment rated tokens.

[0137] R (sub-segment rated Tokens) can be determined according to the Embedding Model rated Tokens used. In this example implementation, the best effect is achieved when R obtained in practice is less than Embedding Model rated Tokens*0.5.

[0138] The theoretical number of sub-segments is obtained by rounding down content block tokens / sub-segment rated tokens. It is often the case that the sub-segment tokens are greater than the sub-segment rated tokens. However, the sub-segment rated tokens are smaller than the Embedding Model rated tokens at the beginning of determination, so it has little impact on the calculated sub-segment word meaning relationship vector. There is a low probability that the sub-segment tokens are greater than the Embedding Model rated tokens.

[0139] In this example implementation, Figure 6 As shown, the parent text segment is segmented into sub-segments according to the number of sub-segment segments to obtain multiple sub-text segments respectively contained in each parent text segment. Specifically, the following steps may be included:

[0140] Step S610: Determine theoretical segmentation points in the parent text segment according to the number of characters in the parent text segment and the number of sub-segment segments corresponding to the parent text segment.

[0141] The content block is divided into several segments with the same number of characters according to the theoretical number of sub-segments, and the corresponding segmentation points are the theoretical segmentation points.

[0142] Step S620: The line break nearest to each theoretical segmentation point is used as the actual segmentation point in the parent text segment, and the parent text segment is segmented into sub-segments according to the actual segmentation point to obtain multiple sub-text segments contained in the parent text segment.

[0143] The line break closest to the theoretical segmentation point is used as the actual segmentation point, and the content block is segmented into a number of sub-segments to obtain a plurality of sub-text segments contained in the parent text segment.

[0144] The above segmentation method has a probability that the number of sub-segments is less than the theoretical number of sub-segments, or the number of sub-segment tokens is greater than the rated number of tokens of the Embedding Model. These two situations are generally caused by the excessive length of some paragraphs, but based on the technical solution of the present disclosure, this paragraph is a description content and should not be split even if the number of words is too long.

[0145] In this example implementation, the content block can be split into short segments by sub-segment segmentation while retaining the integrity of the sentences. The sub-segment segmentation step is used to perform a second segmentation on the content block to be embedded, shortening 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 being compatible with the rated Tokens performance requirements of different Embedding Models. Reasonable segmentation of private knowledge documents will make the word meaning relationship vector calculated by the Embedding Model more fragment-descriptive.

[0146] Continue to refer Figure 3 As shown, step S330. Each parent text segment and each child text segment are converted into a corresponding parent segment vector and child segment vector, and the parent segment vector and child segment vector are put into a vector database.

[0147] In this example implementation, each parent text segment and each child text segment can be converted into a corresponding parent segment vector and child segment vector respectively through an embedding model.

[0148] The parent-child segments obtained from the two splits are calculated using the Embedding Model to obtain multiple vector data, which are stored in the vector database.

[0149] Private knowledge documents are divided twice reasonably through content block segmentation and sub-segment segmentation to ensure that the document segments are relatively complete, so that the Embedding Model can calculate the correct word meaning relationship vector, and LLM can also perform more recommended analysis based on the complete document segments.

[0150] These two steps can improve the accuracy of the word meaning relationship vectors in the vector database, make the highly correlated document fragments obtained by calculating the similarity more credible, and also provide reference data for subsequent secondary processing of document fragments - "document fragment parent-child relationship data".

[0151] In this example implementation, when the parent text segment is segmented into child segments, parent-child relationship data between the parent text segment and the child text segment can be established, and the parent-child relationship data can be put into a parent-child relationship database.

[0152] The parent-child relationship data is constructed for the content block (parent segment) and the child segment for secondary processing of the document segment in the subsequent process. The relationship data structure constructed in this example implementation may be, for example:

[0153]

[0154] In this example implementation, another core idea to improve the accuracy of private knowledge AI answers is to "let the LLM obtain clear and readable document fragments." In order to allow the Embedding Model to exert its best embedding capabilities, the document fragments used for vector conversion are generally not too long, so the document fragments corresponding to high-approximation vectors are not sufficient as reference materials.

[0155] In the secondary processing step of the document fragments, the present invention performs secondary processing on the highly relevant document fragments based on the original text, and uses the "document fragment parent-child relationship data" to organize, merge and expand the document fragments, so that the document fragment content obtained by LLM is more complete and more readable, thereby improving the accuracy of the private knowledge AI's answers.

[0156] After establishing the vector database, refer to Figure 2 As shown, in step S210, an input question text is obtained, and a corresponding input question vector is obtained according to the input question text.

[0157] In this example implementation, the input question text may be converted into a corresponding input question vector through an embedding model. The question text input by the user is embedded to obtain a corresponding input question vector.

[0158] In step S220, 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.

[0159] The text segment vectors in the vector database include a plurality of parent segment vectors obtained from the private knowledge document, and the child segment vectors respectively contained in each parent segment vector.

[0160] In this example implementation, Figure 7 As shown, the input question vector is matched with each text segment vector in the vector database, and multiple candidate text segment vectors are determined from the text segment vectors according to the matching results. Specifically, the following steps may be included:

[0161] Step S710: 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.

[0162] The similarity between the input question vector and each vector data in the vector database is calculated. The specific similarity calculation method can be selected according to the actual situation, including cosine similarity, Euclidean distance, etc.

[0163] Step S720: Sort the text segment vectors according to the similarity between the input question vector and the text segment vectors.

[0164] Sort the text segment vectors in the vector database in descending order of similarity.

[0165] Step S730. 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.

[0166] According to the similarity sorting results, several text segment vectors that are most similar to the input question vector are returned as the selected multiple candidate text segment vectors.

[0167] Continue to refer Figure 2 As shown, in step S230, the candidate text segment vectors are respectively converted into corresponding candidate text segments, and the candidate text segments are screened and processed according to the parent-child relationship data between the candidate text segments to obtain at least one target text segment.

[0168] In order to make the vectors calculated by the embedding model more characteristic, the document fragments (sub-fragments) segmented in the previous text are usually short and insufficient to support LLM to answer private knowledge questions. Therefore, the candidate text fragments need to be sorted and expanded according to the parent-child relationship data of the document fragments until the total prompt composed of the question text entered by the user and the document fragments is close to the LLM rated tokens. The core purpose of this function is to expand and improve the text fragments obtained by vector matching based on the parent-child relationship of the previous text, so that LLM can obtain more sufficient and complete private knowledge fragments.

[0169] In this example implementation, Figure 8 As shown, according to the parent-child relationship data between the candidate text segments, the candidate text segments are screened and processed to obtain at least one target text segment, which may 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 a highly relevant text segment list.

[0171] Step S820. Based on the parent-child relationship data between the candidate text segments, determine whether there is a child text segment in the candidate text segment that has a parent-child relationship with the parent text segment.

[0172] Step S830. If so, the child text segments in the candidate text segments that have a parent-child relationship with the parent text segment are deleted, and the remaining child text segments in the candidate text segments are placed in a highly relevant text segment list.

[0173] First, all candidate text segments are screened for coexistence of parent and child segments. Since both the segmented content blocks (parent segments) and child segments are embedded and stored in the vector database, when calculating the similarity with the input text vector, there is a probability that both the parent and child segments have high scores and are output at the same time. It has been verified in practice that in this case, LLM can better answer private knowledge questions by using the parent segment as a reference, so it can be considered that the parent segment has a higher correlation with the user's input text.

[0174] Based on the above analysis, the processing method here is: when there are paired parent-child relationship fragments in the highly relevant document fragments, the private knowledge fragment submitted to LLM will retain the parent fragment and delete the child fragment. This processing can save token space and provide more tokens for the expansion of other child fragments.

[0175] Step S840: Perform sub-segment expansion processing on the sub-text segments in the highly relevant text segment list according to the parent-child relationship data related to the sub-text segments.

[0176] In this example implementation, the sub-text segments can be expanded layer by layer from high to low according to the similarity score order of the sub-text segments in the current highly relevant text segment list; the parent text segments in the highly relevant text segment list do not need to be expanded and can be directly retained in the list.

[0177] In this example implementation, Fig. 9 As shown, according to the parent-child relationship data related to the sub-text fragments, the sub-text fragments in the highly relevant text fragment list are subjected to sub-segment expansion processing, which may specifically include the following steps:

[0178] Step S910: Determine the expansion processing order of each sub-text segment according to the similarity between each sub-text segment in the highly relevant text segment list and the input question vector.

[0179] First, the expansion processing order of each sub-text segment is determined in descending order of similarity. The similarity score of the sub-segment vector during vector matching determines the order of sub-segment expansion. The sub-segment with a high score is considered to have a relatively higher relevance to the input question text and should be expanded first.

[0180] Step S920. According to the expansion processing order of each sub-text segment, select a sub-text segment from the sub-text segments in the highly relevant text segment list as the sub-text segment to be expanded.

[0181] Step S930: From the parent text segment where the sub-text segment to be expanded is located, obtain the previous sub-text segment and the next sub-text segment adjacent to the sub-text segment to be expanded.

[0182] Step S940: Expand the sub-text segment to be expanded according to the previous sub-text segment and the next sub-text segment to obtain an expanded sub-text segment.

[0183] The score of the sub-segment vector can only relatively represent its correlation with the input question text vector, but it is not completely correct. Therefore, when expanding the sub-segment, layer-by-layer expansion is adopted, that is, after all sub-segments are expanded to the nearest layer, the next layer will be expanded, instead of expanding a sub-segment only after a sub-segment is expanded to the boundary of the content block.

[0184] Sub-segment expansion is bilateral expansion, that is, the nearest upper and lower sub-segments are expanded at the same time; when the sub-segment has reached the top / bottom sub-segment of the content block when expanding to a certain layer, the sub-segment expansion starts to expand unilaterally, that is, only the other side of the top / bottom sub-segment is expanded.

[0185] Step S950: Determine whether all sub-segment extension stop conditions and the current sub-segment extension stop condition are satisfied according to the expanded sub-text segment.

[0186] In this example implementation, the total number of current text tokens can be obtained based on the number of question text tokens corresponding to the input question text, the number of text segment tokens corresponding to the expanded sub-text segments, and the number of text segment tokens corresponding to all other text segments in the highly correlated text segment list; then the language model rated token number corresponding to the language model is obtained, and if the total number of current text tokens is greater than the language model rated token number, it is determined that the condition for stopping the expansion of all sub-segments is met.

[0187] After a sub-segment is expanded by one layer, if the total prompt composed of the user's input question text and the document fragment exceeds the LLM rated Tokens, the expansion of all sub-segments is stopped, and the total prompt obtained by expanding the previous sub-segment by one layer is the high-quality prompt output.

[0188] In this example implementation, if the expanded sub-text segment is completely identical to the parent text segment where the expanded sub-text segment is located, it is determined that the current sub-segment expansion stop condition is satisfied.

[0189] If a sub-fragment is equal to the content block after expansion, the sub-fragment stops expanding.

[0190] Step S960: If all sub-segment expansion stop conditions are met, the sub-segment expansion processing of all sub-text segments in the highly relevant text segment list is stopped, and the sub-segment expansion processing result of the previous round is used as the final sub-segment expansion processing result.

[0191] Step S970. If all sub-segment extension stop conditions are not met, but the current sub-segment extension stop conditions are met, then according to the expansion processing order of each sub-text segment, the next sub-text segment is selected from the sub-text segments in the highly relevant text segment list as the sub-text segment to be expanded.

[0192] Step S980. If the conditions for stopping the extension of all sub-segments are not met, it is determined whether there is a mergeable sub-text segment in the highly relevant text segment list that is adjacent to the extended sub-text segment and belongs to the same parent text segment as the extended sub-text segment.

[0193] Step S990: If there is a mergeable sub-text segment, merge the extended sub-text segment with the mergeable sub-text segment, and update the highly relevant text segment list according to the merged sub-text segment.

[0194] For the matched highly relevant document fragments, there is a certain probability that the sub-fragments all come from the same parent fragment, and these sub-fragments have a probability of expanding to the same adjacent sub-fragments during the expansion process. The document fragments obtained by expansion are submitted to LLM as reference materials for private knowledge question answering, which has a certain probability of misleading LLM and reducing the accuracy of the answer.

[0195] During the sub-segment expansion process, this misleading situation can be avoided by certain verification processing and merging sub-segments; it has been verified that merging sub-segments will not cause major changes to Tokens.

[0196] The sub-fragment merging process is as follows: after a sub-fragment is expanded by one layer, check whether the other current sub-fragments with the same parent (after expansion) are adjacent to it based on the parent-child relationship. If there are other adjacent sub-fragments with the same parent, they are merged into a new document fragment, and then the sub-fragment expansion continues.

[0197] For example, the list of highly relevant document fragments after a sub-fragment is expanded (indicated by sub-fragment ID) is as follows:

[0198] [(2003,2004,2005),(6003,6004,6005),(2006,2007,2008),9005]

[0199] The sub-segment merge check is met (2005 and 2006 are adjacent), and the list of highly relevant document segments is merged and changed to:

[0200] [(2003,2004,2005,2006,2007,2008),(6003,6004,6005),9005]

[0201] Continue to refer Figure 8 As shown, step S850. Update the highly relevant text segment list according to the sub-text segments after the sub-segment expansion processing until there is no sub-text segment to be expanded in the highly relevant text segment list, and obtain the target text segment according to the updated highly relevant text segment list.

[0202] If there is no expandable sub-fragment in the highly relevant document fragment, the sub-fragment expansion is stopped and the previous total prompt is output. If no sub-fragment expansion is performed, the first total prompt is output.

[0203] Continue to refer Figure 2 As shown, in step S240, target text prompts are obtained according to all target text segments, and language model prompts for input into the language model are obtained according to the input question text and the target text prompts.

[0204] Finally, the total prompt closest to the upper limit of LLM Tokens is obtained based on all target text segments and input question text. This is the high-quality prompt finally submitted to LLM. This high-quality prompt is the most reasonable, complete and readable language model prompt.

[0205] like Fig.10 The figure is a complete flow chart of a method for generating model prompts in a specific implementation of the present disclosure, which is an example of the above steps in this example implementation. The specific steps of the flow chart are as follows:

[0206] Step S1010: Document denoising.

[0207] Delete special symbols in the original document data, such as @, *, and emoticons.

[0208] Step S1020: Content block segmentation.

[0209] Content block segmentation of a document is to segment the parent segment of the document, that is, the first-level segment; different document types have different segmentation algorithms / strategies.

[0210] Step S1030: sub-segment segmentation.

[0211] Sub-fragment segmentation is to segment the parent fragment according to line breaks and rated tokens to obtain sub-fragments, that is, secondary fragments, and build parent-child relationships between document fragments; the algorithm / strategy of sub-fragment segmentation is applicable to different types of documents.

[0212] Step S1040: Document fragment Embedding.

[0213] The parent-child segments obtained from the two splits are calculated using the Embedding Model to obtain multiple 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 fragments is also stored in the parent-child relationship database.

[0216] Step S1060: Embedding the question text.

[0217] Embed the question text entered by the user 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 used to calculate the similarity with the vector data in the vector database, and then sorted by similarity to return the most similar vectors. The specific similarity calculation method can be selected according to the actual situation. Commonly used methods include cosine similarity, Euclidean distance, etc.

[0220] Step S1080. Vector reverse text.

[0221] The most similar vectors are reversed into corresponding highly relevant document fragments as candidate text fragments.

[0222] Step S1090: Secondary processing of document fragments.

[0223] The highly relevant document fragments are sorted and expanded according to the parent-child relationship data of the document fragments until the total prompt composed of the user's input question text and the document fragments is close to the LLM rated tokens. Finally, the total prompt closest to the upper limit of LLM tokens is output, which is the high-quality prompt submitted to LLM.

[0224] in, Fig.10 The detailed process of content block segmentation, content block merging, and document fragment secondary processing is as follows:

[0225] like Fig.11 The figure is a complete flow chart of content block segmentation processing in a specific implementation mode of the present disclosure, which is a detailed description of the above-mentioned content block segmentation processing process in this example implementation mode. The specific steps of the flow chart are as follows:

[0226] Step S1110. Determine whether the document's own Tokens are greater than twice the Embedding Model's rated Tokens.

[0227] Some documents only describe the content of an object, and the characteristic of such documents is that they are short. In practice, we can first verify the document tokens before determining whether to split the content blocks. If the document tokens are less than 2 times the rated tokens of the EmbeddingModel, the document does not need to be split, and the private knowledge AI will have a better answer effect.

[0228] Step S1120: Content block segmentation.

[0229] Different documents have different division strategies for content blocks, so different document types need to apply different algorithm strategies to divide content blocks, including division by document title, division by line break, and Excel document division strategy.

[0230] Step S1130: Merging content blocks.

[0231] After the content blocks are segmented, some content blocks need to be attached to an adjacent content block to fully understand their descriptions because of the small amount of descriptions; at the same time, LLM supports identifying the amount of content described by the document fragment structure, and merging several small content blocks into one without affecting LLM's analysis of the information required for the problem. Therefore, the content blocks segmented according to the main strategy need to be processed twice, that is, content block merging.

[0232] like Fig.12 The figure is a complete flow chart of content block merging processing in a specific implementation mode of the present disclosure, which is a detailed description of the above-mentioned content block merging process in this example implementation mode. The specific steps of the flow chart are as follows:

[0233] Step S1210: Divide and obtain content blocks.

[0234] Step S1220: Determine whether the original document Tokens are less than 0.5 times the Embedding Model rated Tokens.

[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 Embedding Model rated Tokens, the next content block is merged.

[0237] Step S1240: Determine whether the content block Tokens are less than the Embedding Model rated Tokens.

[0238] Step S1250: Try to merge the next content block to form a new content block.

[0239] If the content block itself is smaller than the Embedding Model rated Tokens, then try to merge the next content block and proceed to step S1260.

[0240] Step S1260: Determine whether the new content block Tokens are greater than 2 times the Embedding Model rated Tokens.

[0241] If the number of tokens in the merged new content block exceeds 2 times the rated number of tokens in the Embedding Model, the merge is canceled.

[0242] like Fig.13 The figure is a complete flow chart of the secondary processing of document fragments in a specific implementation mode of the present disclosure, which is a detailed description of the secondary processing process of the document fragments in this example implementation mode. The specific steps of the flow chart are as follows:

[0243] Step S1301. Coexistence screening of parent and child segments.

[0244] When there are paired parent-child relationship fragments in the highly relevant document fragments, the private knowledge fragment submitted to LLM will retain the parent fragment and delete the child fragment.

[0245] Step S1302: Determine whether there is an expandable sub-segment.

[0246] The sub-segments are expanded layer by layer from high to low according to the similarity score order of the sub-segments; the parent segment does not need to be expanded.

[0247] Step S1303: Get sub-segments in order of scores.

[0248] When matching vectors, the scores of sub-segment vectors determine the order of sub-segment expansion. Sub-segments with high scores are considered to have a higher relevance (relatively speaking) to the input question text and should be expanded first.

[0249] Step S1304: The sub-segment is expanded by one layer.

[0250] When the sub-segments are expanded, they are expanded layer by layer, that is, after the most recent layer of sub-segments of all sub-segments is expanded, the next layer will be expanded.

[0251] Step S1305: Determine whether the total Prompt Tokens are greater than the LLM rated Tokens.

[0252] After the current sub-segment is expanded by one layer, if the total prompt composed of the user's question words and the document segment exceeds the LLM rated tokens, the expansion of all sub-segments is stopped, and the total prompt obtained by expanding the previous sub-segment by one layer is the high-quality prompt output.

[0253] Step S1306: Determine whether the sub-segment (after expansion) is equal to the content block.

[0254] Step S1307: The sub-segment mark stops expanding.

[0255] If a sub-fragment is equal to the content block after expansion, the sub-fragment stops expanding.

[0256] Step S1308: Sub-segment merging verification.

[0257] For the matched highly relevant document fragments, there is a certain probability that the sub-fragments all come from the same parent fragment. These sub-fragments have a certain probability of being expanded to the same adjacent sub-fragments during the expansion process. The document fragments obtained in this way are submitted as reference materials to LLM for private knowledge questions and answers, which may mislead LLM and reduce the accuracy of the answer. In the process of sub-fragment expansion, certain verification processing and merging of sub-fragments can avoid this misleading situation.

[0258] Step S1309: Merge sub-segments.

[0259] After a sub-fragment is expanded by one layer, the parent-child relationship is used to check whether other current fragments with the same parent (after expansion) are adjacent to it. If so, they are merged into a new document fragment, and then the sub-fragment expansion is continued.

[0260] Step S1310: Update the list of highly relevant document fragments.

[0261] Finally, the list of highly relevant document fragments is updated based on the sub-fragments obtained after sub-fragment 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 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. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.

[0263] Furthermore, the present disclosure also provides a device for generating model prompts. Fig.14 As shown, the model prompt generation device may 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] in:

[0265] The question text acquisition module 1410 may 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 may 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 results; wherein the text segment vectors in the vector database include a plurality of parent segment vectors obtained from the private knowledge document, and the child segment vectors respectively contained in each parent segment vector;

[0267] The target text determination module 1430 may be used to convert the candidate text segment vectors into corresponding candidate text segments, and screen 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;

[0268] The model prompt generation module 1440 can be used to obtain target text prompts according to all target text segments, and obtain language model prompts for input into the language model according to the input question text and the target text prompts.

[0269] In some exemplary embodiments of the present disclosure, a model prompt generation device provided by the present disclosure may further include a vector database generation module, which may include a content block segmentation unit, a sub-segment segmentation unit, and a vector database generation unit. Wherein:

[0270] The content block segmentation unit can be used to obtain the private knowledge document to be processed, and based on the document type of the private knowledge document, perform content block segmentation processing on the private knowledge document to obtain multiple parent text segments in the private knowledge document;

[0271] The sub-segment segmentation unit can be used to obtain the number of sub-segment segments corresponding to the parent text segment, and perform sub-segment segmentation processing on the parent text segment according to the number of sub-segment segments to obtain multiple sub-text segments respectively contained in each parent text segment;

[0272] The vector database generation unit can be used to convert each parent text segment and each child text segment into a corresponding parent segment vector and child segment vector, and put the parent segment vector and child segment vector into a vector database.

[0273] In some exemplary embodiments of the present disclosure, the vector database generation module may also include a parent-child relationship database generation unit, which can be used to establish parent-child relationship data between the parent text segment and the child text segment when the parent text segment is segmented into child segments, and to place the parent-child relationship data into the parent-child relationship database.

[0274] In some exemplary embodiments of the present disclosure, the content block segmentation unit may include a document title segmentation unit, a line break segmentation unit, and a worksheet segmentation unit.

[0275] The document title segmentation unit may be used to segment the private knowledge document into content blocks 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 may be used to segment the private knowledge document into content blocks according to line breaks in the private knowledge document if the document type of the private knowledge document is a text document that does not contain a document title;

[0277] The worksheet segmentation unit may be used to segment the private knowledge electronic spreadsheet document into content blocks based on each worksheet in the private knowledge electronic spreadsheet document if the document type of the private knowledge document is an electronic spreadsheet document.

[0278] In some exemplary embodiments of the present disclosure, the worksheet segmentation unit may include a text data conversion unit, which can be used to perform content block segmentation processing on the private knowledge spreadsheet document based on each worksheet in the private knowledge spreadsheet document, and convert the data in each worksheet into text data.

[0279] In some exemplary embodiments of the present disclosure, the text data conversion unit may include a cell reading unit, a line break splicing unit, and a text data composition unit.

[0280] The cell reading unit can be used to read all cells except empty cells in the worksheet in sequence according to the preset reading order;

[0281] The line break splicing unit can be used to splice the cell data read in each cell with an indentation character of the corresponding number of columns before each cell data, and splice a line break character after each cell data;

[0282] The text data composition unit can be used to compose worksheet text data corresponding to the worksheet according to a preset reading order from all cell data read in the worksheet.

[0283] In some exemplary embodiments of the present disclosure, the content block segmentation unit may further include a content block merging unit, which may be used to determine whether a content block needs to be merged with other content blocks based on the number of content block tags corresponding to each content block obtained after content block segmentation processing is performed on the private knowledge document, and perform content block merging processing on the content blocks that need to be merged.

[0284] In some exemplary embodiments of the present disclosure, the content block merging unit may 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.

[0285] The tag number threshold determination unit may be used to obtain an embedded model rated tag number corresponding to the embedded model used for vector conversion, and determine a first tag number threshold and a second tag number threshold according to the embedded model rated tag number, wherein the first tag number threshold is less than the embedded model rated tag number, and the second tag number threshold is greater than the embedded model rated tag number;

[0286] The first content block merging unit may be configured to merge the content block 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 less than a first mark number threshold;

[0287] The content block merging determination unit may be used to determine that the content block does not need to be processed for content block merging if the number of content block tags corresponding to the content block is greater than or equal to the rated number of tags of the embedding model;

[0288] The to-be-judged content block generating unit may be configured to merge the content block with the next content block corresponding to the content block to obtain a merged to-be-judged content block if the content block tag number corresponding to the content block is greater than or equal to the first tag number threshold and less than the embedding model rated tag number;

[0289] The content block merging cancellation unit may be used to cancel the content block merging process with the next content block if the content block mark number corresponding to the content block to be determined is greater than a second mark number threshold;

[0290] The second content block merging unit may be configured to use the content block to be determined as a merged content block if the content block mark number corresponding to the content block to be determined is less than or equal to a second mark number threshold.

[0291] In some exemplary embodiments of the present disclosure, the content block segmentation unit may further include a second mark number threshold determination unit, a parent text segment generation unit, and a content block segmentation continuation unit.

[0292] The second tag number threshold judgment unit may be used to judge whether the document tag number corresponding to the private knowledge document is less than the second tag number threshold;

[0293] The parent text segment generating unit may be used to directly use the private knowledge document as a parent text segment if the number of document tags corresponding to the private knowledge document is less than a second tag number threshold;

[0294] The content block segmentation continuing unit may be used to continue executing subsequent steps to perform content block segmentation processing on the private knowledge document if the number of document tags corresponding to the private knowledge document is greater than or equal to a second tag number threshold.

[0295] In some exemplary embodiments of the present disclosure, the sub-segment segmentation unit may include a sub-segment rated mark number determination unit and a sub-segment segmentation quantity determination unit.

[0296] The sub-segment rated mark number determining unit may be configured to determine the sub-segment rated mark number according to a first mark number threshold;

[0297] The sub-segment segmentation number determination unit may be configured to determine the sub-segment segmentation number corresponding to the parent text segment according to the number of parent text tags corresponding to the parent text segment and the rated number of sub-segment tags.

[0298] In some exemplary embodiments of the present disclosure, the sub-segment segmentation unit may further include a theoretical segmentation point determination unit and a real segmentation point determination unit.

[0299] The theoretical segmentation point determination unit may be used to determine the theoretical segmentation point in the parent text segment according to the number of characters in the parent text segment and the number of sub-segment segments corresponding to the parent text segment;

[0300] The real segmentation point determination unit can be used to take the line break closest to each theoretical segmentation point as the real segmentation point in the parent text segment, and perform sub-segment segmentation processing on the parent text segment according to the real segmentation point to obtain multiple sub-text segments contained in the parent text segment.

[0301] In some exemplary embodiments of the present disclosure, the vector database generation unit may include a text segment vector conversion unit, which may be used to convert each parent text segment and each child text segment into a corresponding parent segment vector and child segment vector respectively through an embedding model.

[0302] In some exemplary embodiments of the present disclosure, the vector database generation module may further include a knowledge document denoising unit, which may be used to denoise the private knowledge document to be processed and delete irrelevant characters in the private knowledge document.

[0303] In some exemplary embodiments of the present disclosure, the question text acquisition module 1410 may include a question text vector conversion unit, which may be used to convert the input question text into a corresponding input question vector through an embedding model.

[0304] In some exemplary embodiments of the present disclosure, the candidate text matching module 1420 may include a similarity calculation unit, a similarity sorting unit, and a candidate text screening unit. Among them:

[0305] The similarity calculation unit can be used 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 ranking unit may be used to rank the text segment vectors according to the similarity between the input question vector and the text segment vectors;

[0307] The candidate text screening unit may 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 exemplary embodiments of the present disclosure, the target text determination module 1430 may include a parent text segment screening unit, a parent-child relationship judgment unit, a child text segment deletion unit, a child segment expansion unit, and a text segment list update unit. Among them:

[0309] The parent text segment screening unit may be used to put the parent text segment in the candidate text segment into a highly relevant text segment list if the parent text segment exists in the candidate text segment;

[0310] The parent-child relationship judgment unit may be used to judge whether there is a child text segment having a parent-child relationship with the parent text segment in the candidate text segment according to the parent-child relationship data between the candidate text segments;

[0311] The sub-text segment deletion unit may be used to delete the sub-text segments in the candidate text segment that have a parent-child relationship with the parent text segment, if any, and put the remaining sub-text segments in the candidate text segment into a highly relevant text segment list;

[0312] The sub-segment expansion unit may be used to perform sub-segment expansion processing on the sub-text segments in the highly relevant text segment list according to the parent-child relationship data related to the sub-text segments;

[0313] The text segment list updating unit can be used to update the highly relevant text segment list according to the sub-text segments after sub-segment expansion processing until there are no sub-text segments to be expanded in the highly relevant text segment list, and obtain the target text segment according to the updated highly relevant text segment list.

[0314] In some exemplary embodiments of the present disclosure, the sub-segment expansion unit may include an expansion processing order determination unit, a sub-text segment to be expanded determination unit, an adjacent sub-text segment acquisition unit, an expanded sub-text segment generation unit, an expansion stop condition judgment unit, an all sub-segment expansion stop unit, a current sub-segment expansion stop unit, a mergeable sub-text segment determination unit, and a text segment merging unit. Among them:

[0315] The expansion processing order determination unit may be used to determine the expansion processing order of each sub-text segment according to the similarity between each sub-text segment in the highly relevant text segment list and the input question vector;

[0316] The sub-text segment to be expanded determining unit may be used to select one sub-text segment from the sub-text segments in the highly relevant text segment list as the sub-text segment to be expanded according to the expansion processing order of each sub-text segment;

[0317] The adjacent sub-text segment acquisition unit may be used to acquire a previous sub-text segment and a next sub-text segment adjacent to the sub-text segment to be expanded from the parent text segment where the sub-text segment to be expanded is located;

[0318] The extended subtext segment generating unit may be used to extend the subtext segment to be extended according to the previous subtext segment and the next subtext segment to obtain the extended subtext segment;

[0319] The extension stop condition judgment unit may be used to judge whether all sub-segment extension stop conditions and the current sub-segment extension stop condition are satisfied according to the extended sub-text segment;

[0320] The all sub-segment extension stopping unit can be used to stop the sub-segment extension processing of all sub-text segments in the highly relevant text segment list if the all sub-segment extension stopping condition is met, and use the sub-segment extension processing result of the previous round as the final sub-segment extension processing result;

[0321] The current sub-segment extension stop unit may be used to select the next sub-text segment from the sub-text segments in the highly relevant text segment list as the sub-text segment to be extended according to the extension processing order of each sub-text segment if all sub-segment extension stop conditions are not satisfied but the current sub-segment extension stop condition is satisfied;

[0322] The mergeable sub-text segment determination unit may be used to determine whether there is a mergeable sub-text segment adjacent to the extended sub-text segment and belonging to the same parent text segment as the extended sub-text segment in the highly relevant text segment list if the all sub-segment extension stop condition is not satisfied and the all sub-segment extension stop condition is not satisfied;

[0323] The text segment merging unit may be used to merge the extended sub-text segment with the mergeable sub-text segment if there is a mergeable sub-text segment, and update the highly relevant text segment list according to the merged sub-text segment.

[0324] In some exemplary embodiments of the present disclosure, the extension stop condition determination unit may include a text tag number sum determination unit and a total sub-segment extension stop condition determination unit.

[0325] The text token number sum determination unit may be used to obtain the current text token number sum according to the question text token number corresponding to the input question text, the text segment token number corresponding to the expanded sub-text segment, and the text segment token number corresponding to all other text segments in the highly relevant text segment list;

[0326] The all sub-segment extension stop condition judgment unit can be used to obtain the language model rated token number corresponding to the language model. If the total number of current text tokens is greater than the language model rated token number, it is determined that the all sub-segment extension stop condition is met.

[0327] In some exemplary embodiments of the present disclosure, the expansion stop condition judgment unit may also include a current sub-segment expansion stop condition judgment unit, which can be used to determine that the current sub-segment expansion stop condition is met if the expanded sub-text segment is exactly the same as the parent text segment where the expanded sub-text segment is located.

[0328] The specific details of each module / unit in the above-mentioned model prompt generation device have been described in detail in the corresponding method embodiment part, and will not be repeated here.

[0329] Fig.15 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present disclosure is shown.

[0330] It should be noted that Fig.15 The computer system 1500 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0331] like Fig.15 As shown, the computer system 1500 includes a central processing unit (CPU) 1501, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1502 or the program loaded from the storage part 1508 to the 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 section 1506 including a keyboard, a mouse, etc.; an output section 1507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1508 including a hard disk, etc.; and a communication section 1509 including a network interface card such as a LAN card, a modem, etc. The communication section 1509 performs communication processing via a network such as the Internet. A drive 1510 is also connected to the I / O interface 1505 as needed. A removable medium 1511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1510 as needed, so that a computer program read therefrom is installed into the storage section 1508 as needed.

[0333] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part 1509, and / or installed from a removable medium 1511. When the computer program is executed by a central processing unit (CPU) 1501, various functions defined in the system of the present disclosure are executed.

[0334] It should be noted that the computer-readable medium shown in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0335] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0336] As another aspect, the present disclosure further provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by an electronic device, the electronic device implements the method described in the above embodiment.

[0337] It should be noted that, although several modules of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules described above can be concretized in one module. Conversely, the features and functions of one module described above can be further divided into multiple modules to be concretized.

[0338] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure.

[0339] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A method for generating a model prompt, characterized in that: include: Obtaining an 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 the vector database, and determining a plurality of candidate text segment vectors from the text segment vectors according to the matching results; wherein the text segment vectors in the vector database include a plurality of parent segment vectors obtained from private knowledge documents, and child segment vectors respectively contained in each of the parent segment vectors; Convert the candidate text segment vectors into corresponding candidate text segments respectively, and screen 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; A target text prompt is obtained according to all the target text segments, and a language model prompt for input into a language model is obtained according to the input question text and the target text prompt.

2. The method for generating model prompts according to claim 1, characterized in that: The method further includes a method for generating the vector database, and the method for generating the vector database includes: Acquire a private knowledge document to be processed, and based on the document type of the private knowledge document, perform content block segmentation processing on the private knowledge document to obtain a plurality of parent text segments in the private knowledge document; Obtaining the number of sub-segment segments corresponding to the parent text segment, and performing sub-segment segmentation processing on the parent text segment according to the number of sub-segment segments, to obtain a plurality of sub-text segments respectively contained in each of the parent text segments; Each of the parent text segments and each of the child text segments are converted into a corresponding parent segment vector and a child segment vector, and the parent segment vector and the child segment vector are put into the vector database.

3. The method for generating model prompts according to claim 2, characterized in that: The method further comprises: When the parent text segment is segmented into child segments, parent-child relationship data between the parent text segment and the child text segment is established, and the parent-child relationship data is put into a parent-child relationship database.

4. The method for generating model prompts according to claim 2, characterized in that: The step of dividing the private knowledge document into content blocks based on the document type of the private knowledge document includes: If the document type of the private knowledge document is a text document including a document title, the private knowledge document is segmented into content blocks according to the document title; If the document type of the private knowledge document is a text document that does not include a document title, the private knowledge document is segmented into content blocks according to line breaks in the private knowledge document; If the document type of the private knowledge document is a spreadsheet document, the private knowledge spreadsheet document is divided into content blocks based on each worksheet in the private knowledge spreadsheet document.

5. The method for generating model prompts according to claim 4, characterized in that: The process of dividing the private knowledge electronic spreadsheet document into content blocks by taking each worksheet in the private knowledge electronic spreadsheet document as a unit includes: Taking each worksheet in the private knowledge electronic spreadsheet document as a unit, the private knowledge electronic spreadsheet document is segmented into content blocks, and the data in each worksheet is converted into text data.

6. The method for generating model prompts according to claim 5, characterized in that: The step of converting the data in each worksheet into text data comprises: All cells except empty cells in the worksheet are read in sequence according to a preset reading order; For each cell data read from the cell, an indentation character corresponding to the number of columns is added before each cell data, and a line break character is added after each cell data; All the cell data read in the worksheet are combined into worksheet text data corresponding to the worksheet according to the preset reading order.

7. The method for generating model prompts according to claim 2, characterized in that: After the private knowledge document is segmented into content blocks, the method further includes: According to the content block mark numbers corresponding to the respective content blocks obtained after the private knowledge document is segmented into content blocks, it is determined whether the content block needs to be merged with other content blocks, and content block merging processing is performed on the content blocks that need to be merged.

8. The method for generating model prompts according to claim 7, characterized in that: The determining whether the content block needs to be merged with other content blocks according to the number of content block tags corresponding to each content block obtained after the content block segmentation processing is performed on the private knowledge document, and performing content block merging processing on the content block that needs to be merged, includes: Obtaining an embedded model rated number of tags corresponding to an embedded model used for vector conversion, and determining a first tag number threshold and a second tag number threshold according to the embedded model rated number of tags, wherein the first tag number threshold is less than the embedded model rated number of tags, and the second tag number threshold is greater than the embedded model rated number of tags; If the content block mark number corresponding to the content block is less than the first mark number threshold, merging the content block 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 rated mark number, it is determined that the content block does not need to be subjected to content block merging processing; If the content block tag number corresponding to the content block is greater than or equal to the first tag number threshold and less than the embedding model rated tag number, merging the content block with the next content block corresponding to the content block to obtain a merged content block to be judged; If the content block mark number corresponding to the to-be-determined content block is greater than the second mark number threshold, canceling the content block merging process with the next content block; If the content block mark number corresponding to the to-be-determined content block is less than or equal to the second mark number threshold, the to-be-determined content block is used as the merged content block.

9. The method for generating model prompts according to claim 8, characterized in that: Before dividing the private knowledge document into content blocks, the method further includes: Determining whether the number of document tags corresponding to the private knowledge document is less than the second tag number threshold; If the number of document tags corresponding to the private knowledge document is less than the second tag number threshold, the private knowledge document is directly used as a parent text segment; If the number of document tags corresponding to the private knowledge document is greater than or equal to the second tag number threshold, then continue to execute subsequent steps to perform content block segmentation processing on the private knowledge document.

10. The method for generating model prompts according to claim 8, characterized in that: The obtaining the number of child segmentations corresponding to the parent text segment includes: Determining a sub-segment rated number of marks according to the first mark number threshold; The number of sub-segment segments corresponding to the parent text segment is determined according to the number of parent text tags corresponding to the parent text segment and the rated number of sub-segment tags.

11. The method for generating model prompts according to claim 2, characterized in that: The sub-segment segmentation process is performed 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, including: Determining theoretical segmentation points in the parent text segment according to the number of characters in the parent text segment and the number of sub-segment segments corresponding to the parent text segment; The line break nearest to each of the theoretical segmentation points is used as a real segmentation point in the parent text segment, and the parent text segment is segmented into sub-segments according to the real segmentation point to obtain multiple sub-text segments contained in the parent text segment.

12. The method for generating model prompts according to claim 2, characterized in that: The converting each of the parent text segments and each of the child text segments into a corresponding parent segment vector and child segment vector, respectively, includes: Each of the parent text segments and each of the child text segments are converted into a corresponding parent segment vector and child segment vector respectively through an embedding model.

13. The method for generating model prompts according to claim 2, characterized in that: After obtaining the private knowledge document to be processed, the method further includes: The private knowledge document to be processed is denoised, and irrelevant characters in the private knowledge document are deleted.

14. The method for generating model prompts according to claim 1, characterized in that: The step of obtaining a corresponding input question vector according to the input question text includes: The input question text is converted into a corresponding input question vector through an embedding model.

15. The method for generating model prompts according to claim 1, characterized in that: The step of matching the input question vector with each text segment vector in the vector database and determining a plurality of candidate text segment vectors from the text segment vectors according to the matching results includes: 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 the text segment vectors according to the similarity between the input question vector and each of the text segment vectors; According to the sorting result of the text segment vectors and a preset number of candidate segments, a plurality of candidate text segment vectors are determined from the text segment vectors.

16. The method for generating model prompts according to claim 15, characterized in that: The step of screening and processing 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 segment, the parent text segment in the candidate text segment is put into a highly relevant text segment list; According to the parent-child relationship data between the candidate text segments, determining whether there is a child text segment in the candidate text segment that has a parent-child relationship with the parent text segment; If so, the child text segments in the candidate text segments that have a parent-child relationship with the parent text segment are deleted, and the remaining child text segments in the candidate text segments are put into the highly relevant text segment list; performing sub-segment expansion processing on the sub-text segments in the highly relevant text segment list according to parent-child relationship data related to the sub-text segments; The highly relevant text segment list is updated according to the sub-text segment after the sub-segment expansion processing until there is no sub-text segment to be expanded in the highly relevant text segment list, and the target text segment is obtained according to the updated highly relevant text segment list.

17. The method for generating model prompts according to claim 16, characterized in that: The step of performing sub-segment expansion processing on the sub-text segments in the highly relevant text segment list according to the parent-child relationship data related to the sub-text segments includes: Determining the expansion processing order of each of the sub-text segments according to the similarity between each of the sub-text segments in the highly relevant text segment list and the input question vector; According to the expansion processing order of each of the sub-text segments, sequentially selecting a sub-text segment from the sub-text segments in the highly relevant text segment list as the sub-text segment to be expanded; Acquire, from the parent text segment where the sub-text segment to be expanded is located, a previous sub-text segment and a next sub-text segment adjacent to the sub-text segment to be expanded; Expanding the subtext segment to be expanded according to the previous subtext segment and the next subtext segment to obtain an expanded subtext segment; Determining whether all sub-segment extension stop conditions and the current sub-segment extension stop conditions are satisfied according to the extended sub-text segment; If the all sub-segment expansion stop condition is met, the sub-segment expansion processing of all the sub-text segments in the highly relevant text segment list is stopped, and the sub-segment expansion processing result of the previous round is used as the final sub-segment expansion processing result; If the extension stop condition for all sub-segments is not satisfied, but the extension stop condition for the current sub-segment is satisfied, then, according to the extension processing order of each sub-text segment, the next sub-text segment is selected from the sub-text segments in the highly relevant text segment list as the sub-text segment to be extended; If the condition for stopping the extension of all sub-segments is not met, and the condition for stopping the extension of all sub-segments is not met, determining whether there is a mergeable sub-text segment in the highly relevant text segment list that is adjacent to the extended sub-text segment and belongs to the same parent text segment as the extended sub-text segment; If the mergeable sub-text segment exists, the extended sub-text segment is merged with the mergeable sub-text segment, and the highly relevant text segment list is updated according to the merged sub-text segment.

18. The method for generating model prompts according to claim 17, characterized in that: Determine whether all sub-segment extension stop conditions are met, including: Obtaining a total number of current text tags according to the number of question text tags corresponding to the input question text, the number of text segment tags corresponding to the expanded sub-text segment, and the number of text segment tags corresponding to all other text segments in the highly relevant text segment list; The language model rated token number corresponding to the language model is obtained, and if the total number of current text tokens is greater than the language model rated token number, it is determined that the stop condition for all sub-segment expansion is satisfied.

19. The method for generating model prompts according to claim 17, characterized in that: Determine whether the current sub-segment extension stop condition is met, including: If the extended sub-text segment is completely identical to the parent text segment in which the extended sub-text segment is located, it is determined that the current sub-segment extension stop condition is met.

20. A device for generating model prompts, characterized in that: include: A question text acquisition module, used to acquire an input question text and obtain a corresponding input question vector according to the input question text; A candidate text matching module, 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 results; wherein the text segment vectors in the vector database include a plurality of parent segment vectors obtained from private knowledge documents, and child segment vectors respectively contained in each of the parent segment vectors; A target text determination module, used to convert the candidate text segment vectors into corresponding candidate text segments respectively, and screen 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 model prompt generation module is used to obtain target text prompts according to all the target text segments, and to obtain language model prompts for input into the language model according to the input question text and the target text prompts.

21. An electronic device, characterized in that: include: processor; as well as A memory for storing one or more programs, which, when executed by the processor, enables the processor to implement the method for generating model prompts according to any one of claims 1 to 19.

22. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for generating a model prompt according to any one of claims 1 to 19 is implemented.

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

  • Intelligent question and answer method and device, storage medium and equipment

    CN116401345A

  • Question and answer method and device, terminal equipment and readable storage medium

    CN116483962A

  • Method and apparatus for configuring chat robot, computer device and storage medium

    WO2021012382A1