Text generation method and device based on structured semantic association retrieval

By introducing structural semantic association retrieval methods in RAG technology, the text paragraphs of the texture of vector coding and associated relationships are used to solve the problem of poor retrieval accuracy in existing technologies, and more efficient information retrieval and answer generation.

CN119357326APending Publication Date: 2025-01-24CHINA RAILWAY CONSTR HEAVY IND
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411386127.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-30
Publication Date
2025-01-24

AI Technical Summary

Technical Problem

In the process of data retrieval and ranking, existing RAG technology relies on vector similarity matching to lead to poor retrieval accuracy, and there is a problem that irrelevant redundant noise affects the generation accuracy.

Method used

Using a text -generating method based on a structured semantic association, coding user problems through a vector coding model, finding the target node coding vector in the vector database, determining the parent node and screening paragraphs based on the association relationship, and finally the fusion of the prompt engineering project. Generate answers.

Benefits of technology

It improves retrieval accuracy, reduces the impact of irrelevant information, and improves the accuracy of generated answers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357326A_ABST
    Figure CN119357326A_ABST
Patent Text Reader

Abstract

The invention relates to a text generation method and device based on structured semantic association retrieval, and the method comprises the steps: carrying out the vector coding of a question text through a vector coding model after the question text inputted by a user is received, and obtaining a user question coding vector corresponding to the question text; searching a plurality of target sub-node coding vectors corresponding to the user question coding vector from a vector database; determining a father node corresponding to each target child node coding vector in the plurality of target child node coding vectors based on the association relationship to obtain a plurality of father nodes, and screening the text paragraphs corresponding to each father node in the plurality of father nodes to obtain the screened text paragraphs; and fusing the question text and the paragraph corresponding to the screened text paragraph based on the cue word project to obtain an input vector of the large language model, and inputting the input vector into the large language model to obtain a question answer, so that the retrieval accuracy can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of large language model knowledge retrieval question and answer applications, and in particular to a text generation method and device based on structured semantic association retrieval. Background Art

[0002] Since OpenAI released the ChatGPT large model at the end of 2022, the Large Language Model (LLM) as the core of AI products has received more and more attention from relevant industry personnel. OpenAI, Google, Meta, Baidu, Alibaba Cloud and other major domestic and foreign Internet and artificial intelligence related manufacturers have also launched AI product application technology frameworks based on their own large models. Among them, the Retrieval-augmented Generation (RAG) technology framework still has limitations in terms of training cost, interpretability, and capability status of large models. Through query processing, data retrieval, document optimization, enhanced generation, semantic understanding, document structuring and self-enhancement, it has achieved a deep understanding of user questions and accurate answers based on database queries. It has become an important solution for various manufacturers to quickly implement large model technology.

[0003] The existing RAG solution mainly includes the following aspects: 1. Query processing, vector encoding the question information entered by the user for subsequent vector similarity matching; 2. Data retrieval and ranking, the system retrieves (Retrieval) relevant data from various data sources (such as relational databases, graph databases, vector databases, etc.) through indicators such as vector similarity, and ranks the results according to relevance (Ranking); 3. Retrieval enhancement and generation, using prompt engineering and other technologies to splice the retrieved information with the preset prompt words, and use the complete prompt words as the input of the downstream large language model to generate the answer content required by the user.

[0004] The above RAG technology framework has the advantages of low hallucination of generated answers, good interpretability, suitable for private deployment, good scalability, etc. in enterprise-oriented product applications. It can also assist enterprises in achieving unified file management. However, traditional RAG technology still has some defects. For example, in the process of data retrieval and ranking, relying solely on vector similarity matching may cause irrelevant redundant noise data to affect the generation accuracy, so it at least has the problem of poor retrieval accuracy. Summary of the invention

[0005] 1. Technical issues to be resolved

[0006] In view of the above-mentioned shortcomings and deficiencies of the prior art, the present invention provides a text generation method and device based on structured semantic association retrieval, which solves the technical problem of poor retrieval accuracy existing in the prior art.

[0007] (II) Technical solution

[0008] In order to achieve the above object, the main technical solutions adopted by the present invention include:

[0009] In a first aspect, an embodiment of the present invention provides a text generation method based on structured semantic association retrieval, comprising: after receiving a question text input by a user, using a vector encoding model to vector encode the question text to obtain a user question encoding vector corresponding to the question text; wherein the vector encoding model is the same as the vector encoding model used in the parsing and storage process of the text document uploaded by the user; searching a plurality of target child node encoding vectors corresponding to the user question encoding vector from a vector database; wherein the vector database records a plurality of child node encoding vectors and related information thereof, and the related information of each child node encoding vector in the plurality of child node encoding vectors includes an association relationship between the child node encoding vector and its corresponding parent node, and the target child node encoding vector is a child node encoding vector whose vector similarity with the user question encoding vector is greater than or equal to a vector similarity threshold; determining a parent node corresponding to each target child node encoding vector in the plurality of target child node encoding vectors based on the association relationship to obtain a plurality of parent nodes, and filtering a text paragraph corresponding to each parent node in the plurality of parent nodes to obtain a filtered text paragraph; fusing the question text and the paragraph corresponding to the filtered text paragraph based on a prompt word project to obtain an input vector of a large language model, and inputting the input vector into the large language model to obtain an answer to the question.

[0010] In one possible embodiment, searching a vector database for multiple target sub-node encoding vectors corresponding to the user question encoding vector includes: calculating the vector similarity between the user question encoding vector and each sub-node encoding vector in the vector database to obtain multiple vector similarities; sorting the multiple vector similarities in descending order of vector similarity to obtain a vector similarity sorting result; and selecting multiple target vector similarities whose vector similarities are greater than a vector similarity threshold from the vector similarity sorting result.

[0011] In a possible embodiment, the text paragraph corresponding to each parent node among multiple parent nodes is screened to obtain the screened text paragraph, including: deduplicating multiple parent nodes to obtain multiple deduplicated parent nodes; screening the text paragraph corresponding to each parent node among the multiple deduplicated parent nodes to obtain the screened text paragraph.

[0012] In a possible embodiment, the text paragraphs corresponding to each parent node in the multiple parent nodes after deduplication are screened to obtain the screened text paragraphs, including: searching for the text paragraphs corresponding to each parent node in the multiple parent nodes after deduplication, and splitting each text paragraph according to sentences to obtain a sentence set corresponding to each text paragraph; performing vector encoding on the sentence set corresponding to each text paragraph using a vector encoding model to obtain a vector set; calculating the semantic relevance score of each vector in the vector set and the user question encoding vector using a semantic relevance model, and taking the largest semantic relevance score among the semantic relevance scores corresponding to all sentences in each text paragraph as the semantic relevance score of the corresponding text; selecting text paragraphs with a semantic relevance threshold value or greater from all text paragraphs to obtain the screened text paragraphs.

[0013] In a possible embodiment, the parsing and storage process of the text document uploaded by the user includes: splitting the text document uploaded by the user into text paragraphs according to paragraph delimiters, and splitting the text paragraphs with a paragraph character number greater than a preset maximum paragraph character number into text paragraphs with a character number less than the preset maximum paragraph character number, to obtain the text paragraphs corresponding to the parent node; splitting the text paragraph of the parent node into sub-text paragraphs corresponding to the child nodes with a character number less than or equal to the preset number of characters based on the sentence end delimiter, and recording the association relationship between the parent node and its corresponding child node; using the vector coding model to vector encode the sub-text paragraphs corresponding to the child node to obtain the child node coding vector, and storing the child node coding vector and related information in the vector database.

[0014] In a second aspect, an embodiment of the present invention provides a text generation device based on structured semantic association retrieval, comprising: a vector encoding module, which is used to perform vector encoding on the question text using a vector encoding model after receiving the question text input by the user, so as to obtain a user question encoding vector corresponding to the question text; wherein the vector encoding model is the same as the vector encoding model used in the process of parsing and storing the text document uploaded by the user; a search module is used to search for multiple target sub-node encoding vectors corresponding to the user question encoding vector from a vector database; wherein the vector database records multiple sub-node encoding vectors and related information thereof, and each of the multiple sub-node encoding vectors has a target sub-node encoding vector corresponding to the user question encoding vector. The relevant information includes the association relationship between the target child node and its corresponding parent node, the target child node encoding vector is a child node encoding vector whose vector similarity with the user question encoding vector is greater than or equal to the vector similarity threshold; a determination and screening module is used to determine the parent node corresponding to each target child node encoding vector in multiple target child node encoding vectors based on the association relationship, obtain multiple parent nodes, and screen the text paragraphs corresponding to each parent node in the multiple parent nodes to obtain the screened text paragraphs; a fusion input module is used to fuse the paragraphs corresponding to the question text and the screened text paragraphs based on the prompt word project to obtain the input vector of the large language model, and input the input vector into the large language model to obtain the answer to the question.

[0015] In one possible embodiment, the search module is specifically used to: calculate the vector similarity between the user question encoding vector and the encoding vector of each child node in the vector database to obtain multiple vector similarities; sort the multiple vector similarities in order from large to small in vector similarity to obtain a vector similarity sorting result; select multiple target vector similarities whose vector similarity is greater than a vector similarity threshold from the vector similarity sorting result.

[0016] In one possible embodiment, a filtering module is determined, which is specifically used to: perform deduplication processing on multiple parent nodes to obtain multiple deduplicated parent nodes; and filter the text paragraphs corresponding to each parent node in the multiple deduplicated parent nodes to obtain filtered text paragraphs.

[0017] In one possible embodiment, a screening module is determined, which is specifically used to: find the text paragraph corresponding to each parent node in the multiple parent nodes after deduplication, and split each text paragraph according to sentences to obtain a sentence set corresponding to each text paragraph; use a vector encoding model to vector encode the sentence set corresponding to each text paragraph to obtain a vector set; use a semantic relevance model to calculate the semantic relevance score of each vector in the vector set and the user question encoding vector, and use the largest semantic relevance score among the semantic relevance scores corresponding to all sentences in each text paragraph as the semantic relevance score of the corresponding text; select text paragraphs with a semantic relevance threshold greater than or equal to the threshold from all text paragraphs to obtain screened text paragraphs.

[0018] In one possible embodiment, the text generation device includes a parsing and storage module, which is used for: splitting a text document uploaded by a user into text paragraphs according to paragraph delimiters, and splitting a text paragraph with a number of paragraph characters greater than a preset maximum number of paragraph characters into text paragraphs with a number of characters less than the preset maximum number of paragraph characters, to obtain a text paragraph corresponding to a parent node; splitting the text paragraph of a parent node into sub-text paragraphs corresponding to child nodes with a number of characters less than or equal to a preset number of characters based on a sentence end delimiter, and recording the association relationship between the parent node and its corresponding child node; performing vector encoding on the sub-text paragraph corresponding to the child node using a vector encoding model to obtain a child node encoding vector, and storing the child node encoding vector and related information in a vector database.

[0019] (III) Beneficial effects

[0020] The beneficial effects of the present invention are:

[0021] The embodiment of the present invention proposes a text generation method and device based on structured semantic association retrieval. After receiving a question text input by a user, the question text is vector-encoded by using a vector encoding model to obtain a user question encoding vector corresponding to the question text, and then multiple target child node encoding vectors corresponding to the user question encoding vector are searched from a vector database, and then the parent node corresponding to each target child node encoding vector in the multiple target child node encoding vectors is determined based on the association relationship to obtain multiple parent nodes, and the text paragraphs corresponding to each parent node in the multiple parent nodes are screened to obtain the screened text paragraphs, and finally the paragraphs corresponding to the question text and the screened text paragraphs are fused based on the prompt word engineering to obtain the input vector of the large language model, and the input vector is input into the large language model to obtain the answer to the question. Compared with the existing scheme, it can improve the retrieval accuracy.

[0022] In order to make the above-mentioned objectives, features and advantages to be achieved by the embodiments of the present application more obvious and understandable, the following specifically cites preferred embodiments and describes them in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0024] Figure 1 A flowchart of a text generation method based on structured semantic association retrieval provided in an embodiment of the present application is shown;

[0025] Figure 2 A schematic diagram showing the association of a three-layer architecture model provided in an embodiment of the present application is shown;

[0026] Figure 3 A structural block diagram of a text generation device based on structured semantic association retrieval provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0027] In order to better explain the present invention and facilitate understanding, the present invention is described in detail below through specific implementation modes in conjunction with the accompanying drawings.

[0028] Retrieval-enhanced generation technology is a key technology for the current application of large language models. Its core indicators lie in retrieval accuracy (retrieving valid information while minimizing the recall of irrelevant information) and generation reliability (the sentences are reasonable and fluent, contain valid information, and avoid the generation of other hallucinatory information as much as possible).

[0029] In order to achieve accurate information retrieval, it is necessary to condense the encoded information as much as possible, but this will cause the retrieved information to be too trivial and difficult to contain the complete information required by the user; conversely, in order to ensure the integrity and richness of the information, it is necessary to increase the information fragment window as much as possible, but this will reduce the semantic similarity of the retrieved information, resulting in the inability to match key information.

[0030] In addition, although the retrieval and sorting methods that only rely on the distance between vectors for matching have the advantages of fast calculation speed and can quickly find the top K closest vectors, neither the Euclidean distance nor the cosine similarity calculation methods can fully guarantee that the user's questions and retrieval results must have a high correlation at the semantic level, which may lead to low-relevance information being input into the natural language large model, thereby affecting the quality of generated content.

[0031] In addition, traditional RAG technology still has other defects. For example, it is difficult to design the size of text document block divisions. Too small divisions may lead to missing contextual information, while too large divisions may reduce retrieval accuracy.

[0032] Based on this, an embodiment of the present invention proposes a text generation method and device based on structured semantic association retrieval. After receiving the question text input by the user, the question text is vector-encoded by using a vector encoding model to obtain a user question encoding vector corresponding to the question text, and then multiple target child node encoding vectors corresponding to the user question encoding vector are searched from a vector database, and then the parent node corresponding to each target child node encoding vector in the multiple target child node encoding vectors is determined based on the association relationship to obtain multiple parent nodes, and the text paragraphs corresponding to each parent node in the multiple parent nodes are screened to obtain the screened text paragraphs, and finally the paragraphs corresponding to the question text and the screened text paragraphs are fused based on the prompt word engineering to obtain the input vector of the large language model, and the input vector is input into the large language model to obtain the answer to the question. Compared with the existing scheme, it can improve the retrieval accuracy.

[0033] In order to better understand the above technical solution, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to enable a clearer and more thorough understanding of the present invention and to fully convey the scope of the present invention to those skilled in the art.

[0034] First embodiment

[0035] See also Figure 1 , Figure 1 A flowchart of a text generation method based on structured semantic association retrieval provided by an embodiment of the present application is shown. It should be understood that the text generation method can be executed by a text generation device, and the specific device of the text generation device can be set according to actual needs, and the embodiment of the present application is not limited thereto. For example, the text generation device can be a computer, or a server, etc. Specifically, the text generation method includes:

[0036] Step S110, after receiving the question text input by the user, the question text is vector-encoded using a vector coding model to obtain a user question coding vector corresponding to the question text. The vector coding model is the same as the vector coding model used in the parsing and storage process of the text document uploaded by the user.

[0037] Specifically, after receiving the question text input by the user, the question text input by the user is vector-encoded using the same vector encoding model as that used in the parsing and storage process of the text document uploaded by the user to generate a user question encoding vector q.

[0038] It should be understood that the specific process of parsing and storing the text document uploaded by the user can be set according to actual needs, and the embodiments of the present application are not limited to this.

[0039] Optionally, the parsing and storage process of the text document uploaded by the user includes: splitting the text document uploaded by the user into text paragraphs according to paragraph delimiters, and splitting the text paragraphs with a paragraph character number greater than a preset maximum paragraph character number into text paragraphs with a character number less than the preset maximum paragraph character number, to obtain the text paragraphs corresponding to the parent node; splitting the text paragraph of the parent node into sub-text paragraphs corresponding to the child nodes with a character number less than or equal to a preset number of characters based on the end-of-sentence delimiter, and recording the association relationship between the parent node and its corresponding child node; using a vector coding model to perform vector coding on the sub-text paragraphs corresponding to the child node to obtain a child node coding vector, and storing the child node coding vector and related information in a vector database.

[0040] Specifically, the text document uploaded by the user is split into large paragraphs according to the paragraph separator, and a preset maximum number of paragraph characters K is set. max , when the number of characters in a paragraph exceeds the preset maximum number of characters K max In the case of , the paragraph is split into m parts with less than K characters according to various sentence end separators (such as ".", ";" and "?", etc.). max The maximum number of characters above does not exceed K max The paragraph will be marked as the parent node. The maximum number of characters in a paragraph is K. max The specific value of can be set according to actual needs; m is a positive integer greater than or equal to 2.

[0041] And, for each parent node paragraph, continue to divide the parent node paragraph into n characters not exceeding the preset character number M according to the various sentence end separators. max The sub-paragraph is marked as a child node; n is a positive integer greater than or equal to 2; the preset number of characters M max The specific value of can also be set according to actual needs, as long as K max Greater than or equal to M max That's it.

[0042] In addition, the sub-node paragraphs can be further divided into sub-sub-node paragraphs with fewer characters according to the sentence end separator, and the sub-node paragraphs can also be regarded as the parent nodes of the sub-sub-node paragraphs, thus forming a three-layer or even multi-layer document splitting structure, and the preset number of characters used for each split is less than the preset number of characters used last time. For example, see Figure 2 , Figure 2 FIG. 1 shows a schematic diagram of a three-layer architecture model provided by an embodiment of the present application. Figure 2As shown, it includes a three-layer architecture, and the number of characters in each parent node is less than or equal to K (i.e., K max ), and the number of characters that can be used for each sub-node is less than or equal to M (i.e. M max ), and the number of characters in each secondary child node is less than or equal to N (that is, N max ), and K>M>N. And, the vector coding model can be used to perform vector coding on the sub-paragraph corresponding to the sub-node and the sub-sub-paragraph corresponding to the sub-sub-node.

[0043] In addition, by setting a unique ID for each node and marking the parent node ID on the child node, a structured association between the parent node and the child node is achieved. The association relationship between the parent node and the child node can be found in Figure 2 .

[0044] And, after completing the text paragraph splitting using the above method, the natural language vector encoding model is used to map the text into vectors and store them together with related information in the vector database.

[0045] Step S120, searching for multiple target child node encoding vectors corresponding to the user question encoding vector from the vector database. The vector database records multiple child node encoding vectors and related information thereof, and the related information of each child node encoding vector in the multiple child node encoding vectors includes the association relationship between the child node encoding vector and its corresponding parent node, and the target child node encoding vector is a child node encoding vector whose vector similarity with the user question encoding vector is greater than or equal to the vector similarity threshold.

[0046] It should be understood that the specific process of searching the vector database for multiple target sub-node encoding vectors corresponding to the user question encoding vector can be set according to actual needs, and the embodiments of the present application are not limited to this.

[0047] Optionally, the vector similarity between the user question encoding vector and each child node encoding vector in the vector database is calculated to obtain multiple vector similarities; the multiple vector similarities are sorted in order from large to small to obtain a vector similarity sorting result; and multiple target vector similarities whose vector similarities are greater than a vector similarity threshold are selected from the vector similarity sorting result.

[0048] For example, search the vector database for all sub-node encoding vectors E = {e1, e2, ..., e i}, i is a positive integer, and the vector similarity between the user question encoding vector q and each vector in the sub-node encoding vector set E is calculated, and the specific calculation method of the vector similarity may include Euclidean distance, cosine similarity, etc. And, according to the vector similarity calculation result, each vector in the sub-node encoding vector set E is sorted in descending order of vector similarity, and the first n sub-node encoding vectors with the highest similarity are selected to obtain the sub-vector set E top_n ={e 1_select ,e 2_select ,...,e n_select}. Where n is a positive integer.

[0049] Step S130, determining the parent node corresponding to each target child node encoding vector in the multiple target child node encoding vectors based on the association relationship, obtaining multiple parent nodes, and filtering the text paragraphs corresponding to each parent node in the multiple parent nodes to obtain filtered text paragraphs.

[0050] It should be understood that the specific process of filtering the text paragraphs corresponding to each parent node among multiple parent nodes to obtain the filtered text paragraphs can be set according to actual needs, and the embodiments of the present application are not limited to this.

[0051] Optionally, multiple parent nodes are deduplicated to obtain multiple deduplicated parent nodes, and then the text paragraphs corresponding to each parent node in the multiple deduplicated parent nodes are filtered to obtain filtered text paragraphs.

[0052] It should also be understood that the specific process of filtering the text paragraphs corresponding to each parent node in the multiple parent nodes after deduplication and obtaining the filtered text paragraphs can also be set according to actual needs, and the embodiments of the present application are not limited to this.

[0053] Optionally, find the text paragraph corresponding to each parent node in the multiple parent nodes after deduplication, and split each text paragraph according to sentences to obtain a sentence set corresponding to each text paragraph; use a vector encoding model to vector encode the sentence set corresponding to each text paragraph to obtain a vector set; use a semantic relevance model to calculate the semantic relevance score of each vector in the vector set and the user question encoding vector, and use the largest semantic relevance score among the semantic relevance scores corresponding to all sentences in each text paragraph as the semantic relevance score of the corresponding text; select text paragraphs with a semantic relevance threshold greater than or equal to the threshold from all text paragraphs to obtain filtered text paragraphs.

[0054] To facilitate understanding of step S130, a specific embodiment is used to describe it below.

[0055] Specifically, since the relevant information of the child node encoding vector in the vector database includes the association relationship between it and its corresponding parent node, the child vector set E can be found top_n Each subvector e in i_select The only corresponding parent node paragraph, and get the corresponding parent node set Father_Node = {f1,f2,...,f n}. Where n is a positive integer.

[0056] In addition, since there may be multiple child node vectors corresponding to the same parent node, it is necessary to deduplicate the parent node set and obtain the deduplicated parent node set Father_Node unique ={f1,f2,...,f m}. Wherein, m is a positive integer less than or equal to n.

[0057] Furthermore, for three-layer and above architecture modes, the child node levels used for retrieval and the parent node levels associated with the return can be flexibly selected and combined to meet the processing requirements of different target documents or task types.

[0058] Furthermore, since the above method is only calculated based on semantic similarity, it does not fully represent the semantic relevance. Therefore, for each parent node f finally found i , it is necessary to further evaluate their semantic relevance and perform post-processing such as screening and sorting. The specific steps are as follows:

[0059] Find the parent of each node f i The corresponding text paragraph txt i , and split each text paragraph according to the sentence, and get the sentence set corresponding to each paragraph txti sentence={s1,s2,...,s k}. Where k is a positive integer;

[0060] And, using the same vector encoding model as in the text parsing storage process, the sentence set is converted into a vector set Vector = {v1, v2, ..., v k};

[0061] And, using the semantic relevance model smi Calculate the semantic relevance score between each vector in the vector set Vector and the user question encoding vector q, score j =model smi (q,v j ), j is a positive integer less than k, and the semantic relevance score with the largest score is selected, that is, the most relevant sentence score j_max , take it as the corresponding parent node paragraph txt i's relevance score;

[0062] According to the preset relevance threshold, the parent node paragraphs below the relevance threshold are deleted, and all the node paragraphs above the relevance threshold are sorted from large to small to form the final retrieval data set (i.e. the screened text paragraphs).

[0063] Step S140: Based on the prompt word engineering, the question text and the paragraphs corresponding to the filtered text paragraphs are merged to obtain an input vector of the large language model, and the input vector is input into the large language model to obtain the answer to the question.

[0064] Specifically, the prompt word engineering is used to integrate the question text, the filtered text paragraphs and other prompt word template contents to form input variables that can be input into the large language model, and the large language model generates answers based on the input content.

[0065] In addition, the generated answers can be returned to the customer from the front-end interface, along with relevant material information found during the search process and relevant file traceability information.

[0066] Therefore, with the help of the above-mentioned technical scheme, the present application realizes an effective combination of different text division scales through pyramid multi-level node structured association technology and corresponding retrieval methods, which can not only improve the document information concentration in the semantic encoding process, thereby improving the accuracy of retrieval matching, but also increase the returned relevant context information, thereby improving the information completeness and richness of the retrieval results.

[0067] In addition, the present application combines the pyramid multi-level node structured association technology and the post-processing method of semantic relevance matching to achieve accurate analysis, filtering and reordering of relevant information, effectively ensure the relevance of data information input into the downstream large language model and user questions, reduce information redundancy, and thereby alleviate model hallucinations and improve generation efficiency.

[0068] In addition, the present application is an advanced retrieval enhancement generation technology based on the above-mentioned technical solution, which can effectively improve the application efficiency of the retrieval enhancement generation application system for text materials and the quality of generated content, and further enhance the application effect of the retrieval enhancement generation technology in information query, document writing, data learning and other fields.

[0069] It should be understood that the above-mentioned text generation method based on structured semantic association retrieval is only exemplary, and those skilled in the art may make various modifications based on the above-mentioned method, and the modified schemes also fall within the protection scope of this application.

[0070] Second embodiment

[0071] See also Figure 3 , Figure 3The structural block diagram of a text generation device 300 based on structured semantic association retrieval provided in an embodiment of the present application is shown. It should be understood that the text generation device 300 can execute each step in the above method embodiment. The specific functions of the text generation device 300 can be found in the description above. To avoid repetition, the detailed description is appropriately omitted here. The text generation device 300 includes at least one software function module that can be stored in a memory in the form of software or firmware or solidified in the operating system (OS) of the text generation device 300. Specifically, the text generation device 300 includes:

[0072] The vector encoding module 310 is used to, after receiving the question text input by the user, use the vector encoding model to vector encode the question text to obtain the user question encoding vector corresponding to the question text; wherein the vector encoding model is the same as the vector encoding model used in the process of parsing and storing the text document uploaded by the user;

[0073] A search module 320 is used to search for multiple target child node coding vectors corresponding to the user question coding vector from a vector database; wherein the vector database records multiple child node coding vectors and related information thereof, and the related information of each child node coding vector in the multiple child node coding vectors includes the association relationship between the child node coding vector and its corresponding parent node, and the target child node coding vector is a child node coding vector whose vector similarity with the user question coding vector is greater than or equal to a vector similarity threshold;

[0074] A determination and screening module 330 is used to determine a parent node corresponding to each target child node encoding vector in a plurality of target child node encoding vectors based on the association relationship, obtain a plurality of parent nodes, and screen the text paragraphs corresponding to each parent node in the plurality of parent nodes to obtain screened text paragraphs;

[0075] The fusion input module 340 is used to fuse the question text and the paragraphs corresponding to the filtered text paragraphs based on the prompt word engineering to obtain the input vector of the large language model, and input the input vector into the large language model to obtain the answer to the question.

[0076] In a possible embodiment, the search module 320 is specifically used to: calculate the vector similarity between the user question encoding vector and each child node encoding vector in the vector database to obtain multiple vector similarities; sort the multiple vector similarities in order from large to small in vector similarity to obtain a vector similarity sorting result; select multiple target vector similarities whose vector similarity is greater than a vector similarity threshold from the vector similarity sorting result.

[0077] In a possible embodiment, a filtering module 330 is determined, which is specifically used to: perform deduplication processing on multiple parent nodes to obtain multiple deduplicated parent nodes; and filter the text paragraphs corresponding to each parent node in the multiple deduplicated parent nodes to obtain filtered text paragraphs.

[0078] In one possible embodiment, a screening module 330 is determined, which is specifically used to: search for the text paragraph corresponding to each parent node in the multiple parent nodes after deduplication, and split each text paragraph according to sentences to obtain a sentence set corresponding to each text paragraph; use a vector encoding model to vector encode the sentence set corresponding to each text paragraph to obtain a vector set; use a semantic relevance model to calculate the semantic relevance score of each vector in the vector set and the user question encoding vector, and use the largest semantic relevance score among the semantic relevance scores corresponding to all sentences in each text paragraph as the semantic relevance score of the corresponding text; select text paragraphs with a semantic relevance threshold greater than or equal to the threshold from all text paragraphs to obtain screened text paragraphs.

[0079] In one possible embodiment, the text generation device includes a parsing and storage module (not shown), which is used for: splitting the text document uploaded by the user into text paragraphs according to paragraph separators, and splitting the text paragraphs with a number of paragraph characters greater than a preset maximum number of paragraph characters into text paragraphs with a number of characters less than the preset maximum number of paragraph characters, to obtain the text paragraphs corresponding to the parent node; splitting the text paragraph of the parent node into sub-text paragraphs corresponding to the child nodes with a number of characters less than or equal to the preset number of characters based on the end-of-sentence separator, and recording the association relationship between the parent node and its corresponding child node; using the vector coding model to vector encode the sub-text paragraphs corresponding to the child node to obtain the child node coding vector, and storing the child node coding vector and related information in the vector database.

[0080] Since the device described in the above embodiment of the present invention is a device used to implement the method of the above embodiment of the present invention, based on the method described in the above embodiment of the present invention, a person skilled in the art can understand the specific structure and deformation of the device, so it is not described here. All devices used in the method of the above embodiment of the present invention belong to the scope of protection of the present invention.

[0081] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0082] The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present invention. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions.

[0083] It should be noted that in the claims, any reference numerals placed between brackets shall not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claims. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The invention may be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In the claims enumerating several means, several of these means may be embodied by the same hardware. The use of the words first, second, third, etc., is for convenience of expression only and does not indicate any order. These words may be understood as part of the component name.

[0084] In addition, it should be noted that, in the description of this specification, the description of the terms "one embodiment", "some embodiments", "embodiment", "example", "specific example" or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.

[0085] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments after knowing the basic creative concept. Therefore, the claims should be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present invention.

[0086] Obviously, those skilled in the art can make various modifications and variations to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention should also include these modifications and variations.

Claims

1. A text generation method based on structured semantic association retrieval, characterized in that: include: After receiving the question text input by the user, the question text is vector-encoded using a vector coding model to obtain a user question coding vector corresponding to the question text; wherein the vector coding model is the same as the vector coding model used in the process of parsing and storing the text document uploaded by the user; Searching for multiple target child node encoding vectors corresponding to the user question encoding vector from a vector database; wherein the vector database records multiple child node encoding vectors and related information thereof, and the related information of each child node encoding vector in the multiple child node encoding vectors includes an association relationship between the child node encoding vector and its corresponding parent node, and the target child node encoding vector is a child node encoding vector whose vector similarity with the user question encoding vector is greater than or equal to a vector similarity threshold; Determine a parent node corresponding to each target child node encoding vector in the multiple target child node encoding vectors based on the association relationship to obtain multiple parent nodes, and filter the text paragraphs corresponding to each parent node in the multiple parent nodes to obtain filtered text paragraphs; Based on the prompt word engineering, the question text and the paragraphs corresponding to the filtered text paragraphs are fused to obtain an input vector of a large language model, and the input vector is input into the large language model to obtain an answer to the question.

2. The text generation method according to claim 1, characterized in that: The step of searching a vector database for a plurality of target sub-node encoding vectors corresponding to the user question encoding vector comprises: Calculating the vector similarity between the user question encoding vector and each child node encoding vector in the vector database to obtain multiple vector similarities; Sorting the plurality of vector similarities in descending order of vector similarity to obtain a vector similarity sorting result; A plurality of target vector similarities whose vector similarities are greater than the vector similarity threshold are selected from the vector similarity sorting results.

3. The text generation method according to claim 1, characterized in that: The step of screening the text paragraphs corresponding to each parent node of the plurality of parent nodes to obtain the screened text paragraphs includes: Deduplication processing is performed on the multiple parent nodes to obtain multiple deduplication-free parent nodes; The text paragraph corresponding to each parent node in the plurality of parent nodes after deduplication is screened to obtain the screened text paragraph.

4. The text generation method according to claim 3, characterized in that: The step of screening the text paragraphs corresponding to each parent node in the plurality of parent nodes after deduplication to obtain the screened text paragraphs includes: Find the text paragraph corresponding to each parent node in the multiple parent nodes after deduplication, and split each text paragraph according to sentences to obtain a sentence set corresponding to each text paragraph; Using the vector coding model, vector coding is performed on the sentence set corresponding to each of the text paragraphs to obtain a vector set; Calculating the semantic relevance score between each vector in the vector set and the user question encoding vector using a semantic relevance model, and taking the largest semantic relevance score among the semantic relevance scores corresponding to all sentences in each of the text paragraphs as the semantic relevance score of the corresponding text; Text paragraphs having a semantic relevance greater than or equal to a threshold are selected from all the text paragraphs to obtain the screened text paragraphs.

5. The text generation method according to claim 1, characterized in that: The parsing and storage process of the text document uploaded by the user includes: Splitting the text document uploaded by the user into text paragraphs according to paragraph delimiters, and splitting a text paragraph whose number of paragraph characters is greater than a preset maximum number of paragraph characters into text paragraphs whose number of characters is less than the preset maximum number of paragraph characters, to obtain text paragraphs corresponding to the parent node; Splitting the text paragraph of the parent node into sub-text paragraphs corresponding to the child nodes whose number of characters is less than or equal to the preset number of characters based on the sentence end separator, and recording the association relationship between the parent node and its corresponding child nodes; The sub-text paragraph corresponding to the sub-node is vector-encoded using the vector coding model to obtain a sub-node coding vector, and the sub-node coding vector and related information are stored in the vector database.

6. A text generation device based on structured semantic association retrieval, characterized in that: include: A vector encoding module is used to, after receiving the question text input by the user, perform vector encoding on the question text using a vector encoding model to obtain a user question encoding vector corresponding to the question text; wherein the vector encoding model is the same as the vector encoding model used in the process of parsing and storing the text document uploaded by the user; A search module, used to search for multiple target child node code vectors corresponding to the user question code vector from a vector database; wherein the vector database records multiple child node code vectors and related information thereof, and the related information of each child node code vector in the multiple child node code vectors includes an association relationship between the child node and its corresponding parent node, and the target child node code vector is a child node code vector whose vector similarity with the user question code vector is greater than or equal to a vector similarity threshold; A determination and screening module is used to determine the parent node corresponding to each target child node encoding vector in the multiple target child node encoding vectors based on the association relationship, obtain multiple parent nodes, and screen the text paragraphs corresponding to each parent node in the multiple parent nodes to obtain screened text paragraphs; A fusion input module is used to fuse the question text and the paragraphs corresponding to the filtered text paragraphs based on the prompt word engineering to obtain an input vector of the large language model, and input the input vector into the large language model to obtain an answer to the question.

7. The text generation device according to claim 6, characterized in that: The search module is specifically used to: calculate the vector similarity between the user question encoding vector and each child node encoding vector in the vector database to obtain multiple vector similarities; sort the multiple vector similarities in descending order of vector similarity to obtain a vector similarity sorting result; A plurality of target vector similarities whose vector similarities are greater than the vector similarity threshold are selected from the vector similarity sorting results.

8. The text generation device according to claim 6, characterized in that: The determination and screening module is specifically used to: perform deduplication processing on the multiple parent nodes to obtain multiple deduplicated parent nodes; and screen the text paragraphs corresponding to each parent node in the multiple deduplicated parent nodes to obtain screened text paragraphs.

9. The text generation device according to claim 8, characterized in that: The determination and screening module is specifically used to: search for the text paragraph corresponding to each parent node in the multiple parent nodes after deduplication, and split each text paragraph according to sentences to obtain a sentence set corresponding to each text paragraph; use the vector encoding model to vector encode the sentence set corresponding to each text paragraph to obtain a vector set; use the semantic relevance model to calculate the semantic relevance score of each vector in the vector set and the user question encoding vector, and use the largest semantic relevance score among the semantic relevance scores corresponding to all sentences in each text paragraph as the semantic relevance score of the corresponding text; select text paragraphs with a semantic relevance threshold greater than or equal to the text paragraph from all the text paragraphs to obtain the screened text paragraphs.

10. The text generation device according to claim 1, characterized in that: The text generation device includes a parsing and storage module, which is used to: split the text document uploaded by the user into text paragraphs according to paragraph delimiters, and split the text paragraphs with a number of paragraph characters greater than a preset maximum number of paragraph characters into text paragraphs with a number of characters less than the preset maximum number of paragraph characters to obtain text paragraphs corresponding to the parent node; split the text paragraph of the parent node into sub-text paragraphs corresponding to the child nodes with a number of characters less than or equal to a preset number of characters based on the end-of-sentence delimiter, and record the association relationship between the parent node and its corresponding child node; use the vector coding model to vector encode the sub-text paragraphs corresponding to the child node to obtain the child node coding vector, and store the child node coding vector and related information in the vector database.

Citation Information

Cited By

  • Contract retrieval enhancement optimization method, equipment and medium

    CN120596647A

  • A contract search enhancement optimization method, device, and medium

    CN120596647B

  • Document processing method and device

    CN120763314A