Enhanced document generation and retrieval method based on knowledge graph
By applying dynamic segmentation and Graph-RAG models to heterogeneous documents, the knowledge graph is constructed and updated, and the existing document generation and search system is solved in the problems of insufficient semantic understanding, low knowledge correlation and poor generation quality, and high-quality document generation and precise retrieval.
Patent Information
- Application Number
- CN202411702394.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2044-11-26
AI Technical Summary
The existing document generation and search systems have shortcomings in insufficient semantic understanding, low knowledge relevance and poor generation quality, resulting in low relevance of search results and improved quality and coherence of generated content.
By dynamic segmentation processing of heterogeneous documents, combining the Graph-RAG model to build and update the knowledge graph, establish the mapping relationship between document segmentation and knowledge graph entity, and realize accurate retrieval based on semantic understanding and high-quality document generation.
The semantic understanding ability and retrieval accuracy of document generation are improved, so that the generated design documents not only have good structured characteristics, but also realize knowledge correlation across documents, ensuring the quality and coherence of generated content.
Smart Images

Figure CN119646178A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of knowledge graph technology, and in particular to an enhanced document generation and retrieval method based on a knowledge graph. Background Art
[0002] With the rapid development of artificial intelligence technology, document generation and retrieval systems based on knowledge graphs have been widely used in the fields of intelligent question answering, search engines, and decision support. Such systems organize and manage massive amounts of document information by building knowledge graphs, and use natural language processing technology to achieve intelligent retrieval and automatic generation of documents. At present, mainstream document generation and retrieval systems mainly use a retrieval method based on keyword matching, and use preset templates to assist in document generation.
[0003] Existing document generation and retrieval methods usually treat knowledge graph construction and document processing as independent steps. In terms of knowledge graph construction, the system extracts structured knowledge from documents through technologies such as entity recognition and relationship extraction; in terms of document processing, a fixed segmentation strategy is used to segment documents, and a retrieval index is established based on word frequency statistics or simple semantic similarity calculations. At the same time, the document generation process mainly relies on predefined templates and rules, and lacks in-depth use of the retrieval content.
[0004] However, this fragmented processing method has obvious shortcomings: first, the fixed document segmentation strategy is difficult to ensure the semantic integrity of the segmented content, affecting the accuracy of knowledge extraction; second, the simple retrieval method cannot fully utilize the semantic association information in the knowledge graph, resulting in low relevance of the retrieval results; finally, the document generation method based on fixed templates lacks flexibility and is difficult to adapt to the personalized needs of different scenarios, and the quality and coherence of the generated content need to be improved. These problems seriously restrict the actual application effect of document generation and retrieval systems. Summary of the invention
[0005] In view of this, the present invention proposes an enhanced document generation and retrieval method based on knowledge graph, which dynamically segments heterogeneous documents, combines the Graph-RAG model to build and update the knowledge graph, and establishes a mapping relationship between document segments and knowledge graph entities, thereby achieving precise retrieval and high-quality document generation based on semantic understanding, thereby solving technical problems existing in traditional document processing methods such as insufficient semantic understanding, low knowledge relevance, and poor generation quality.
[0006] The technical solution of the present invention is implemented as follows: The present invention provides an enhanced document generation and retrieval method based on knowledge graph, comprising:
[0007] S1, receiving heterogeneous document input, and dynamically segmenting the heterogeneous documents to obtain document segments with semantic integrity;
[0008] S2. Build the Graph-RAG model, including the knowledge graph-document index extraction module and the design document generation module;
[0009] S3, construct and update the knowledge graph based on document segmentation through the knowledge graph-document index extraction module, and organize entities and relationships into triples;
[0010] S4. Extract feature vectors of document segments using feature extraction models, establish mapping relationships between document segments and entities in knowledge graphs through matching strategies, and build retrieval indexes based on the mapping relationships between document segments and entities in knowledge graphs;
[0011] S5. Receive the user's query sequence, and in the design document generation module, retrieve relevant entities and document segments through the retrieval index, and generate the target design document in combination with the preset template.
[0012] Preferably, step S1 comprises:
[0013] S11. Receive heterogeneous documents, convert the heterogeneous documents into a unified XML or JSON intermediate format, and obtain a standardized document structure; based on the standardized document structure, parse the document hierarchical structure, extract structured features, and obtain document content with structural annotations; process the document content with structural annotations, identify and standardize special tags, and obtain a structured document with key tags retained; perform unified coding and normalization on the structured document with key tags retained, remove redundant characters, and obtain a pre-processed standard document;
[0014] S12. Use a bidirectional long short-term memory network LSTM to extract text features. Based on the preprocessed standard document, set the sliding window size n and the step size k to obtain a series of overlapping text fragments; for each text fragment, encode it through the LSTM network to obtain a feature vector sequence with a dimension of d; based on the feature vector sequence, calculate the cosine similarity between adjacent windows to obtain the semantic relevance score between the text fragments;
[0015] S13, using the semantic relevance scores between text segments, marking potential segmentation points based on the first threshold θ1, and obtaining a preliminary segmentation boundary set; combining the structured features of the standard document and the second threshold θ2, verifying and confirming the segmentation points, and obtaining structure-aware segmentation boundaries; calculating the information entropy H(w) of the current window text, and adjusting the window size when it exceeds the third threshold θ3, to obtain an adaptive segmentation granularity;
[0016] S14. Based on the adaptive segmentation granularity, optimization is performed according to similarity and segment length, adjacent segments with highly semantic correlation are merged, and segments with too large semantic span are split to obtain the optimized final document segmentation.
[0017] Preferably, step S14 includes:
[0018] S141, extract the topic vector T of each segment for the adaptive segmentation granularity i , get the segmented semantic representation;
[0019] S142, calculate the length distribution characteristics of all segments, including the average length μ and standard deviation σ; identify segments whose length exceeds μ+1.5σ and mark them as the set to be split P; identify segments whose length is less than the minimum threshold L min The segments are marked as the set to be merged Q;
[0020] S143. For the segments in the split set P, recursively perform the following operations:
[0021] Execute steps S12-S13 for each segment to re-segment, re-execute S142 for length analysis of the newly generated segments, update the set to be split P and the set to be merged Q, and when the set to be split P is an empty set, the recursion ends and the set to be merged Q after the recursion is output;
[0022] S144. For the segments in the recursive set Q to be merged, define the adjacent segments of each segment as the segments before and after it:
[0023] Calculate the cosine similarity SIM(T) between each segment and its adjacent segment’s topic vector i ,T i+1 ), judging whether the merging condition is met based on the fourth threshold θ4, if only one adjacent segment meets the condition, adding the segment pair to the set to be merged M; if both adjacent segments meet the condition, selecting the segment pair with the highest cosine similarity to be added to the set to be merged M; outputting the final set M of segment pairs to be merged;
[0024] S145 . Perform a segment merging operation on the segment pairs to be merged in the final set M of segment pairs to be merged to obtain optimized final document segments.
[0025] Preferably, if the length of the first or last segment of the document is less than the minimum threshold L min , then determine the cosine similarity between it and the topic vector of the only adjacent segment. If the cosine similarity satisfies the fourth threshold θ4, the first segment of the document or the last segment of the document and its corresponding adjacent segment are added to the set M as a segment pair to be merged; if not, keep it as it is.
[0026] Preferably, the step of constructing a knowledge graph based on document segmentation includes:
[0027] Use the Transformer encoder to represent the segmented text; identify the entity set E in the text based on the feature representation; analyze the semantic dependency between entities and obtain the relationship set R;
[0028] Align the identified entities with the external knowledge base; use the word embedding model to calculate the semantic similarity between entities; perform entity disambiguation and synonym normalization based on semantic similarity;
[0029] The entity pair (e i ,e j ) and its relationship ij Organized into triplets (e i ,r ij ,e j ); verify the semantic rationality of the triple; complete the missing entity attributes based on external knowledge;
[0030] Integrate the normalized triple set into the knowledge graph g(h); establish the index structure of entities and relations; save the semantic vector representation of entities and relations;
[0031] The formula expression of the knowledge graph g(h) is as follows:
[0032] g(h)={(e i ,r ij ,e j )|e i ,e j ∈E,r ij ∈R}
[0033] In the formula, g(h) is the knowledge graph generated by the Transformer model; E is the entity set; R is the relationship set; (e i ,r ij ,e j ) represents entity e i and e j Through the relationship ij The composed triplet.
[0034] Preferably, the update strategy of the knowledge graph is:
[0035] Perform multi-dimensional credibility evaluation on the knowledge units extracted from the newly added document segments. By calculating the TF-IDF weight, the semantic consistency score based on the pre-trained word embedding model, and the source reliability score, calculate the comprehensive credibility score Score1 for each attribute value and relationship triple.
[0036] Calculate the entity name similarity S using the character-level edit distance algorithm c , Calculate semantic similarity S based on pre-trained word embedding model s , Calculate the structural similarity S by the overlap of attribute sets and the overlap of relationship triples r , the similarities of these three dimensions are combined according to the weights to obtain the comprehensive matching score Score2,
[0037] Based on the comprehensive matching score Score2, two thresholds τ1 and τ2 are set, τ1>τ2, and the following judgment strategy is used for processing:
[0038] When Score2 is greater than τ1, it is considered a complete match, and the Score1 scores of each attribute value and relationship triple are compared respectively; the attribute values and relationship triples with higher Score1 scores are retained, and the replaced knowledge is saved as a historical version;
[0039] When Score2 is between τ1 and τ2, it is considered a partial match. The alignable attribute values and relationship triples are compared one by one, and the attribute values and relationship triples with higher Score1 are retained. For newly added attribute values and relationship triples, they are allowed to be added when their Score1 exceeds the preset matching threshold.
[0040] When Score2 is less than or equal to τ2, it is determined to be a new entity. The comprehensive credibility score Score1 of the new entity is checked. It is allowed to be added to the knowledge graph only when Score1 exceeds the preset new threshold. The initial credibility benchmark of the new entity is recorded.
[0041] At the same time, the timestamp, operation type, change content, and related Score1 and Score2 scores are recorded for all update operations.
[0042] Preferably, step S4 comprises:
[0043] S41, record the document segments of the input heterogeneous documents as a segment set {s1, s2, ..., s n}, and assign a unique index identifier z = {1,2,...,n} to each segment; use the BERT model to extract feature vectors for each document segment, and obtain a feature vector set d(z) = {d1,d2,...,d n}, where d i ∈R d represents the feature vector of segment i;
[0044] S42. At the same time, the BERT model is used to vectorize the entities in the knowledge graph to obtain the entity vector e k ∈P d ;
[0045] S43. Calculate the semantic association between the entity and the document segment through maximum inner product search:
[0046] Sim(e k ,d i )=e k T ·d i
[0047] In the formula, e k Represents the entity vector in the knowledge graph, d i Feature vectors representing document segments;
[0048] S44. For each entity e k , based on the semantic relevance calculation results, determine the most relevant document segment index:
[0049]
[0050] In the formula, Z k * Represents entity e k The most relevant document segment index;
[0051] S45. Construct a mapping set of entity-document segments:
[0052] A={(e k ,z k * )|e k ∈g(h),z k * ∈d(z)}
[0053] Where A represents the set of mapping relationships between entities and document segment indexes.
[0054] Preferably, the design document generation module includes a retriever and a generator, wherein:
[0055] The retriever includes a query encoding unit, an index retrieval unit, and a sorting output unit. The retrieval process is expressed as follows:
[0056] q(h,z|x)=P(h,z|x)=TopK[sim(q(x),I(A))]
[0057] Where q(h,z|x) represents the retriever, P(h,z|x) represents the conditional probability distribution of the retrieved entity h and document segment z according to the input query x, x represents the query sequence, q(x) is the query vector, A represents the set of mapping relationships between entities and document segment indexes, I(A) represents the retrieval index constructed based on the mapping relationship between entities and document segment indexes, sim represents the similarity calculation function, and TopK represents the function that returns the top K results with the highest similarity.
[0058] The generator includes a context encoding unit, an autoregressive decoding unit, and a document organization unit. Its generation process is expressed as:
[0059] p(y i |h,z,t,y {i-1})=P(y i |x,h,z,t,y {i-1} ;φ)=Decoder(c(h,z,t),y {i-1} )
[0060] In the formula, p(y i |h,z,t,y {i-1} ) represents the generator, P(y i |x,h,z,t,y {i-1} ; φ) means generating the next tag y under given conditions i , φ is the parameter of the generator, h is the retrieved entity, z is the document segment related to entity h, t is the preset document generation template, y i is the target tag to be generated at the current time step, y {i-1} is the generated target sequence {y1,y2,...,y i-1}, represents all target tags that have been generated before the current time step i, c(h,z,t) represents the context vector obtained by encoding the entity h, document segment z and the preset document generation template t, and Decoder represents the decoder function, which is used to convert the context vector and the generated sequence into the probability distribution of the next tag.
[0061] Preferably, step S5 comprises:
[0062] S51, receiving a query sequence x input by a user, encoding the query sequence into a query vector through a Transformer model, and normalizing the query vector;
[0063] S52, using the retriever to search in the pre-built search index I(A), calculating the similarity between the query vector and the entity-segment pairs in the index, and returning the Top-K most relevant entity-segment pairs (h, z) as the search results;
[0064] S53, combining the retrieved entity h, document segment z and the preset document generation template t into context information; initializing the generated target sequence y to be an empty sequence; and generating the target sequence token by token in an autoregressive manner:
[0065] At each time step i, based on the current context and the generated sequence y {i-1} Predict the next token y i ; Add the predicted tokens to the generated target sequence; Repeat the process until the complete document is generated or the termination condition is reached;
[0066] S54, organizing the generated content according to the structural constraints of the preset document generation template t to form a final target design document that meets the specifications.
[0067] Preferably, the retriever and the generator include a pre-training process, and the objective function during the pre-training is:
[0068]
[0069] In the formula, represents the expectation on the training dataset D; ψ, φ are the parameters of the retriever and generator respectively; P(y|x) is the joint probability representation of the retriever and generator; x is the input query sequence; y is the target generated sequence; q(h,z|x) is the conditional probability of the retriever output; Π represents multiplication; n is the length of the generated sequence.
[0070] Compared with the prior art, the present invention has the following beneficial effects:
[0071] (1) The present invention constructs a Graph-RAG model to organically combine the knowledge graph with the document index extraction module, thereby realizing intelligent processing and knowledge association of heterogeneous documents. The model uses the Transformer encoder to represent the features of the document, establishes the triple form of entities and relationships, and uses the BERT model to extract document segment feature vectors, thereby realizing deep semantic understanding of the document content. This dual feature extraction mechanism improves the semantic understanding ability and retrieval accuracy of document generation, so that the generated design documents not only have good structural features, but also realize knowledge association across documents;
[0072] (2) The present invention adopts a dynamic segmentation technology based on bidirectional LSTM, and adaptively adjusts the segmentation granularity by setting the sliding window and step size parameters, combined with the semantic relevance score and information entropy threshold. The system marks potential segmentation points based on the first threshold θ1, verifies the rationality of the segmentation boundary through the second threshold θ2, and dynamically adjusts the window size using the third threshold θ3. On this basis, the segments are merged and split through a recursive optimization algorithm, and the length distribution characteristics of the segments are calculated, including the average length μ and the standard deviation σ, and the overlong and overshort segments are optimized. This multi-level segmentation optimization mechanism ensures the semantic integrity and rationality of document segmentation, and effectively solves the semantic fragmentation problem caused by the traditional fixed window segmentation method;
[0073] (3) The present invention updates the knowledge graph through a multi-dimensional credibility evaluation strategy, comprehensively considers the TF-IDF weight, the semantic consistency score based on the pre-trained word embedding model, and the source reliability score, and calculates the comprehensive credibility score Score1. At the same time, the entity name similarity S is calculated by the character-level edit distance algorithm. c , Calculate semantic similarity S based on pre-trained word embedding model s , Calculate the structural similarity S by the overlap of attribute sets and the overlap of relationship triples r, and the comprehensive matching score Score2 is obtained by synthesis. Based on these two scoring indicators, a dual threshold judgment mechanism of τ1 and τ2 is established to achieve accurate update and version management of the knowledge graph. This update strategy based on multi-dimensional evaluation ensures the accuracy and timeliness of the knowledge base, while retaining the historical record of knowledge evolution through the version management mechanism;
[0074] (4) The document generation module of the present invention adopts the collaborative working mode of the retriever and the generator, wherein the retriever realizes accurate retrieval through three functional units of query encoding, index retrieval and sorting output, and the generator includes three processing units of context encoding, autoregressive decoding and document organization. The system calculates the semantic association between entities and document segments through the maximum inner product search technology, establishes the mapping relationship between entity-document segment, and performs autoregressive decoding generation in combination with the structural constraints of the preset template. This generation method based on the collaboration of two modules not only improves the standardization and reliability of the generated documents, but also ensures the integrity and consistency of the generated content through template constraints, so that the generated documents not only maintain the accuracy of the original knowledge, but also meet the standardized structural requirements. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0076] Figure 1 is a flow chart of a method according to an embodiment of the present invention;
[0077] Figure 2 It is a technical implementation diagram of an embodiment of the present invention;
[0078] Figure 3 Schematic diagram of dynamic segmentation according to an embodiment of the present invention. DETAILED DESCRIPTION
[0079] The following will be combined with the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0080] like Figure 1 and Figure 2 As shown, the present invention provides an enhanced document generation and retrieval method based on knowledge graph, comprising:
[0081] S1, receiving heterogeneous document input, and dynamically segmenting the heterogeneous documents to obtain document segments with semantic integrity;
[0082] S2. Build the Graph-RAG model, including the knowledge graph-document index extraction module and the design document generation module;
[0083] S3, construct and update the knowledge graph based on document segmentation through the knowledge graph-document index extraction module, and organize entities and relationships into triples;
[0084] S4. Extract feature vectors of document segments using feature extraction models, establish mapping relationships between document segments and entities in knowledge graphs through matching strategies, and build retrieval indexes based on the mapping relationships between document segments and entities in knowledge graphs;
[0085] S5. Receive the user's query sequence, and in the design document generation module, retrieve relevant entities and document segments through the retrieval index, and generate the target design document in combination with the preset template.
[0086] Specifically, Figure 3 As shown, in one embodiment of the present invention, step S1 includes:
[0087] S11. Receive heterogeneous documents and convert them into a unified XML or JSON intermediate format to obtain a standardized document structure; based on the standardized document structure, parse the document hierarchical structure, extract structured features, and obtain document content with structural annotations; process the document content with structural annotations, identify and standardize special tags, and obtain structured documents that retain key tags; uniformly encode and normalize the structured documents that retain key tags, remove redundant characters, and obtain pre-processed standard documents.
[0088] Specifically, heterogeneous documents may be technical documents, product documents, research reports, professional literature, etc. These documents can be manually uploaded by the administrator, and the update frequency can be set to automatically capture the latest documents and perform subsequent processing on them to ensure that the knowledge base can be updated in a timely manner.
[0089] In this embodiment, the XML conversion uses a DOM parser to build a document object model, builds an XML tree structure through a depth-first traversal method, retains the hierarchical relationship and attribute information of the document, and outputs a standardized XML document structure; the JSON conversion uses a recursive parser to build a three-layer basic structure: metadata, content, and references. The hierarchical relationship of the document is maintained through recursive parsing, and attribute mapping is established to ensure data integrity, and a standardized JSON format output is generated.
[0090] The format conversion rule set is as follows: Word document conversion: extract structured elements such as paragraphs, tables, and pictures, and retain style attributes; PDF document conversion: extract text blocks based on layout analysis, and identify title and body structure; HTML document conversion: parse the DOM tree structure and extract semantic tag content; plain text conversion: identify document structure based on delimiters and indentation relationships.
[0091] Structural feature extraction includes: title level recognition: analyzing font size, style features, numbering system; paragraph relationship analysis: identifying indentation relationships, paragraph spacing, and marking symbols; list structure recognition: processing ordered lists, unordered lists, and definition lists; table structure analysis: identifying table boundaries, merged cells, and header information. The feature extraction method can be to use a feature vector space model to extract the hierarchical relationship features of the document, analyze the semantic coherence of the text, and construct a structured feature matrix.
[0092] Feature tag processing: Formula tagging: Identify mathematical formulas in LaTeX and MathML formats, and unify the formula representation format; Reference tagging: Process literature citation and cross-reference information, and standardize the reference tag style; Chart tagging: Extract image captions and table titles, and standardize the chart description format; Code block: Identify program code and pseudocode paragraphs, and unify the code block representation method.
[0093] S12. Use a bidirectional long short-term memory network LSTM to extract text features. Based on the preprocessed standard document, set the sliding window size n and step size k to obtain a series of overlapping text fragments. For each text fragment, encode it through the LSTM network to obtain a feature vector sequence with a dimension of d. Based on the feature vector sequence, calculate the cosine similarity between adjacent windows to obtain the semantic relevance score between text fragments.
[0094] In this embodiment, the bidirectional LSTM adopts a two-layer structure, and the hidden layer dimension is 256. The input layer uses pre-trained Word2Vec with a dimension of 300. Each LSTM unit contains a forget gate, an input gate, and an output gate, and a residual connection is added to alleviate the gradient disappearance problem.
[0095] Text feature extraction is represented as: h t =BiLSTM(x t ,h {t-1} );feature vector =concat([forward ht ,backward ht ]). The forward and backward LSTM output vectors are concatenated to obtain the final feature vector.
[0096] The sliding window size n is initially set to 50 tokens, and the step size k is set to 1 / 4 of the window size. Adjacent windows are ensured to have 75% overlap, and a padding strategy is adopted for the beginning and end of the document.
[0097] S13. Using the semantic relevance scores between text fragments, potential segmentation points are marked based on the first threshold θ1 to obtain a preliminary set of segmentation boundaries; combining the structured features of the standard document and the second threshold θ2, the segmentation points are verified and confirmed to obtain structure-aware segmentation boundaries; the information entropy H(w) of the current window text is calculated, and when it exceeds the third threshold θ3, the window size is adjusted to obtain an adaptive segmentation granularity.
[0098] In this embodiment, a preliminary segmentation point set is first established based on the first threshold value θ1, and the position and score of each potential segmentation point is recorded. Then, the hierarchical structure information of the document is combined to analyze paragraph tags and format identifiers, identify chapter titles and list structures, and extract the logical organization features of the document. The segmentation boundaries are confirmed based on the second threshold value θ2, and the boundaries that do not meet the conditions are adjusted to generate a structure-aware segmentation boundary set.
[0099] Statistical word frequency distribution in the window, calculate the standardized information entropy H(w), establish an entropy value evaluation benchmark, identify abnormal information density areas, adjust the window based on the third threshold θ3, when H(w)>θ3, reduce the window size, when H(w)<θ3, increase the window size, set the upper and lower limits of the window size, and achieve smooth window transition. The adjustment formula is: new =min(max(n current +a t ,n min ),n max ), where n current Indicates the current window size, n min Indicates the lower limit, n max Indicates the upper limit value, a t Specifically, the adjustment step size can be set to k / 2.
[0100] S14. Based on the adaptive segmentation granularity, optimization is performed according to similarity and segment length, adjacent segments with highly semantic correlation are merged, and segments with too large semantic span are split to obtain the optimized final document segmentation.
[0101] Step S14 includes:
[0102] S141, extract the topic vector T of each segment for the adaptive segmentation granularity i , get the segmented semantic representation;
[0103] S142, calculate the length distribution characteristics of all segments, including the average length μ and standard deviation σ; identify segments whose length exceeds μ+1.5σ and mark them as the set to be split P; identify segments whose length is less than the minimum threshold L min The segments are marked as the set to be merged Q;
[0104] S143. For the segments in the split set P, recursively perform the following operations:
[0105] Execute steps S12-S13 for each segment to re-segment, re-execute S142 for length analysis of the newly generated segments, update the set to be split P and the set to be merged Q, and when the set to be split P is an empty set, the recursion ends and the set to be merged Q after the recursion is output;
[0106] S144. For the segments in the recursive set Q to be merged, define the adjacent segments of each segment as the segments before and after it:
[0107] Calculate the cosine similarity SIM(T) between each segment and its adjacent segment’s topic vector i ,T i+1 ), judging whether the merging condition is met based on the fourth threshold θ4, if only one adjacent segment meets the condition, adding the segment pair to the set to be merged M; if both adjacent segments meet the condition, selecting the segment pair with the highest cosine similarity to be added to the set to be merged M; outputting the final set M of segment pairs to be merged;
[0108] S145 . Perform a segment merging operation on the segment pairs to be merged in the final set M of segment pairs to be merged to obtain optimized final document segments.
[0109] If the length of the first or last segment of the document is less than the minimum threshold L min , then determine the cosine similarity between it and the topic vector of the only adjacent segment. If the cosine similarity satisfies the fourth threshold θ4, the first segment of the document or the last segment of the document and its corresponding adjacent segment are added to the set M as a segment pair to be merged; if not, keep it as it is.
[0110] In this embodiment, the LDA model can be used to extract topic vectors. When the length distribution parameters are set, the average length μ and the standard deviation σ are determined based on the statistical analysis of the domain documents. min Can be set to μ / 3.
[0111] Specifically, this embodiment can achieve adaptive optimization of segmentation through the steps of topic vector extraction, length distribution feature analysis, recursive splitting processing, merging condition judgment, and final merging optimization, which not only ensures the semantic integrity of the segmentation, but also ensures the rationality of the segmentation length. This method can effectively reduce overly long or short segments, improve the balance and readability of the document structure, and maintain semantic coherence.
[0112] Specifically, in one embodiment of the present invention, the Graph-RAG model mainly includes two parts: a knowledge graph-document index extraction module and a design document generation module. The knowledge graph-document index extraction module is used to construct and update the knowledge graph and establish a retrieval index. The design document generation module performs retrieval based on the user's query sequence input, and then generates a target design document based on the retrieval results.
[0113] Specifically, the steps of constructing a knowledge graph based on document segmentation include:
[0114] Use the Transformer encoder to represent the segmented text; identify the entity set E in the text based on the feature representation; analyze the semantic dependency between entities and obtain the relationship set R;
[0115] Align the identified entities with the external knowledge base; use the word embedding model to calculate the semantic similarity between entities; perform entity disambiguation and synonym normalization based on semantic similarity;
[0116] The entity pair (e i ,e j ) and its relationship ij Organized into triplets (e i ,r ij ,e j ); verify the semantic rationality of the triple; complete the missing entity attributes based on external knowledge;
[0117] Integrate the normalized triple set into the knowledge graph g(h); establish the index structure of entities and relations; save the semantic vector representation of entities and relations;
[0118] The formula expression of the knowledge graph g(h) is as follows:
[0119] g(h)={(e i ,r ij ,e j )|e i ,e j ∈E,r ij ∈R}
[0120] In the formula, g(h) is the knowledge graph generated by the Transformer model; E is the entity set; R is the relationship set; (e i ,r ij ,e j ) represents entity e i and e j Through the relationship ij The composed triplet.
[0121] In this embodiment, the Transformer model adopts a BERT-base or RoBERTa-base pre-trained model, including 12 layers of standard Transformer layers, and its feature extraction process is: 1. Use the WordPiece algorithm to perform subword segmentation, add special tags [CLS] and [SEP], and generate position encoding; 2. Capture contextual relationships through a multi-head self-attention mechanism, use a feedforward neural network to process features, and apply residual connections and layer normalization; 3. Merge feature representations of different layers, weightedly fuse the outputs of multiple attention heads, and generate the final text representation.
[0122] The knowledge graph construction process of this embodiment is as follows:
[0123] 1. Use pre-trained models to identify professional terms, extract key concepts and proper nouns, identify numerical entities and time expressions; analyze the descriptive text of entities, extract the key features of entities, and identify the limiting conditions of entities.
[0124] 2. Construct a syntactic dependency tree, analyze the semantic relationship between words, and extract the subject-predicate-object ternary relationship; identify the hierarchical relationship between entities, extract causal relationships, analyze temporal relationships, and identify attribute relationships.
[0125] 3. Perform entity matching with external knowledge bases, calculate semantic similarity between entities, and establish entity mapping relationships; perform entity disambiguation based on context, use entity attributes to distinguish, and apply rule constraints to eliminate ambiguity.
[0126] 4. Organize entity pairs and relationships, build (e i ,r ij ,e j ) in the form of a triple, add attribute information; check semantic rationality, verify the validity of the relationship, and supplement missing attributes.
[0127] After constructing the knowledge graph, you can also build a knowledge graph index to quickly locate related entities in the knowledge graph. The specific process is as follows:
[0128] 1. Design the index structure, including entity index and relationship index. Entity index: establish a mapping from entity ID to entity information, build entity attribute index, and create entity alias index; relationship index: establish relationship type index, build relationship direction index, and create relationship attribute index.
[0129] 2. Store vector representations, including entity vectors and relationship vectors. Entity vectors: store the semantic vector representation of entities, save the contextual features of entities, and maintain the evolution history of entities; relationship vectors: store the semantic vector representation of relationships, save the direction information of relationships, and maintain the confidence of relationships.
[0130] Specifically, in one embodiment of the present invention, the update strategy of the knowledge graph is:
[0131] Perform multi-dimensional credibility evaluation on the knowledge units extracted from the newly added document segments. By calculating the TF-IDF weight, the semantic consistency score based on the pre-trained word embedding model, and the source reliability score, calculate the comprehensive credibility score Score1 for each attribute value and relationship triple.
[0132] Calculate the entity name similarity S using the character-level edit distance algorithm c , Calculate semantic similarity S based on pre-trained word embedding model s , Calculate the structural similarity S by the overlap of attribute sets and the overlap of relationship triples r , the similarities of these three dimensions are combined according to the weights to obtain the comprehensive matching score Score2,
[0133] Based on the comprehensive matching score Score2, two thresholds τ1 and τ2 are set, τ1>τ2, and the following judgment strategy is used for processing:
[0134] When Score2 is greater than τ1, it is considered a complete match, and the Score1 scores of each attribute value and relationship triple are compared respectively; the attribute values and relationship triples with higher Score1 scores are retained, and the replaced knowledge is saved as a historical version;
[0135] When Score2 is between τ1 and τ2, it is considered a partial match. The alignable attribute values and relationship triples are compared one by one, and the attribute values and relationship triples with higher Score1 are retained. For newly added attribute values and relationship triples, they are allowed to be added when their Score1 exceeds the preset matching threshold.
[0136] When Score2 is less than or equal to τ2, it is determined to be a new entity. The comprehensive credibility score Score1 of the new entity is checked. It is allowed to be added to the knowledge graph only when Score1 exceeds the preset new threshold. The initial credibility benchmark of the new entity is recorded.
[0137] At the same time, the timestamp, operation type, change content, and related Score1 and Score2 scores are recorded for all update operations.
[0138] The dynamic update of knowledge graph is a key link to maintain the timeliness and accuracy of knowledge. Traditional update methods often have problems such as untimely updates, improper conflict handling, and loss of historical versions. This embodiment achieves high-quality dynamic update of knowledge graph through multi-dimensional evaluation and hierarchical update strategy.
[0139] In this embodiment, the calculation process of score Score1 is as follows:
[0140] TF-IDF weight calculation: TF(t,d) = number of occurrences of word t in document d / total number of words in document d; IDF(t) = log(total number of documents / (number of documents containing word t + 1)); TF-IDF(t,d) = TF(t,d) × IDF(t).
[0141] Semantic consistency score calculation: Use the pre-trained word embedding model to generate a vector representation Vec know =Embedding(knowledge unit ); Vec context =Embedding(context); Calculate cosine similarity Semantic Score =sim(Vec know ,Vecc ontext ).
[0142] Source reliability score calculation: Source Score =w1*DocType+w2*Author+w3*Time+w4*Citation.
[0143] Score1 comprehensive calculation: Score1 = α*TF-IDF+β*Semantic Score +γ*Source Score .
[0144] Then, the multi-dimensional similarity between the newly added document segment and the existing knowledge graph is calculated, including entity name similarity, semantic similarity, and structural similarity. The entity name similarity is calculated using the character-level edit distance algorithm. c =1-(Edit Dis / max(len(e1),len(e2))); semantic similarity first uses the pre-trained word embedding model to generate vectors, and then calculates the cosine similarity, S s =cosine similarity (Vec1, Vec2); structural similarity is calculated based on the attribute set overlap A = |A1∩A2| / |A1∪A2| and the relationship triple overlap R = |R1∩R2| / |R1∪R2|, S r =(A+R) / 2; finally, the entity name similarity, semantic similarity, and structural similarity are weighted and summed to obtain the comprehensive matching score Score2.
[0145] Specifically, in one embodiment of the present invention, step S4 includes:
[0146] S41, record the document segments of the input heterogeneous documents as a segment set {s1, s2, ..., s n}, and assign a unique index identifier z = {1,2,...,n} to each segment; use the BERT model to extract feature vectors for each document segment, and obtain a feature vector set d(z) = {d1,d2,...,d n}, where d i ∈R d represents the feature vector of segment i;
[0147] S42. At the same time, the BERT model is used to vectorize the entities in the knowledge graph to obtain the entity vector e k ∈R d ;
[0148] S43. Calculate the semantic association between the entity and the document segment through maximum inner product search:
[0149] Sim(e k ,d i )=e k T ·d i
[0150] In the formula, e k Represents the entity vector in the knowledge graph, d i Feature vectors representing document segments;
[0151] S44. For each entity e k , based on the semantic relevance calculation results, determine the most relevant document segment index:
[0152]
[0153] In the formula, z k * Represents entity e k The most relevant document segment index;
[0154] S45. Construct a mapping set of entity-document segments:
[0155] A={(e k ,z k * )|e k ∈g(h),z k * ∈d(z)}
[0156] Where A represents the set of mapping relationships between entities and document segment indexes.
[0157] Specifically, in this embodiment, the BERT-base pre-trained model can still be used to extract features for each segment. The model uses a 12-layer Transformer structure with a 768-dimensional hidden layer. At the input end, the segmented text is segmented by WordPiece, [CLS] and [SEP] tags are added, and the sequence length is uniformly padded to 512. The output of the [CLS] position is extracted as the feature vector d of the segment. i , and normalize them by L2 norm to ensure the comparability of vectors. At the same time, a unique digital index z is assigned to each segment, and a mapping relationship between segment ID and feature vector is established. The feature vector set d(z) = {d1, d2, ..., d n}, in this case, d(z) represents the set of all eigenvectors corresponding to the index set z, and also implies the index z to the eigenvector d i The mapping relationship.
[0158] Next, the same BERT model is used to vectorize the entities in the knowledge graph. To enhance the semantic representation of the entity, the entity name is combined with its attribute description and relationship information to construct the input sequence. The different features are weighted and fused through the attention mechanism to generate an entity vector e with the same dimension as the segment vector. k This ensures that the entity vector and the segment vector can be similarly calculated in the same feature space.
[0159] Then, the maximum inner product search is used to calculate the semantic relevance between the entity and the document segment. The inner product of the entity vector and the segment vector is calculated by batch matrix multiplication, i.e., Sim(e k ,d i )=e k T ·d i To improve computational efficiency, the N entity vectors are constructed as a matrix E∈R N×768 , n segment vectors are constructed as a matrix D∈R n×768 , through E.D. T The N×n similarity matrix is obtained at one time. The temperature coefficient τ (default 0.07) is introduced to adjust the similarity distribution, and the Softmax function is used for normalization.
[0160] For each entity e k , find the segment index z with the highest score in the similarity matrix through the argmax function k * , the most relevant document segment, To handle the one-to-many mapping situation, a similarity threshold θ is set (recommended value 0.7), and the top-3 candidate segments with similarity exceeding the threshold are retained. For the case where multiple entities are mapped to the same segment, priority is sorted based on similarity scores and entity importance to ensure the rationality of the mapping.
[0161] Finally, a mapping set A of entity-document segments is constructed. An inverted index structure is used, and the index item is the entity ID. The index value contains the mapped segment ID, similarity score, timestamp and other information. The Skip List data structure is used to implement the index, which supports O(logn) query efficiency. The real-time nature of the index is maintained through an asynchronous update mechanism, and mapping relationships with similarities below the threshold or expired are regularly cleaned up. A balance is struck between memory and performance, hot data is cached in memory, and cold data is stored on disk. To support incremental updates, when a new document segment is added, it is only necessary to calculate the similarity between the new segment and the existing entity and update the affected index items.
[0162] Specifically, in one embodiment of the present invention, the retriever is composed of three core functional units: a query encoding unit, an index retrieval unit, and a sorting output unit. The query encoding unit adopts a Transformer encoder structure, which includes a multi-layer self-attention mechanism and a feedforward neural network. The input query sequence x is first converted into a vector representation through a word embedding layer, and then the contextual relationship within the query is captured through a multi-head self-attention layer, and finally the query vector q(x) is obtained through a feedforward neural network. The mathematical expression of the retrieval process is:
[0163] q(h,z|x)=P(h,z|x)=topK[sim(q(x),I(A))]
[0164] In the formula, q(h,z|x) represents the retriever, P(h,z|x) represents the conditional probability distribution of the retrieved entity h and document segment z according to the input query x, x represents the query sequence, q(x) is the query vector, A represents the set of mapping relationships between entities and document segment indexes, I(A) represents the retrieval index built based on the mapping relationship between entities and document segment indexes, sim represents the similarity calculation function, and TopK represents the function that returns the top K results with the highest similarity. The index retrieval unit uses an inverted index structure to support efficient vector similarity retrieval.
[0165] The generator adopts an encoder-decoder architecture, which includes a context encoding unit, an autoregressive decoding unit, and a document organization unit. The context encoding unit uses a Transformer encoder to encode the retrieved entity h, document segment z, and preset template t into a context vector c(h, z, t). The autoregressive decoding unit uses a Transformer decoder with a masked attention mechanism to generate a context vector c(h, z, t) at each time step i based on the context vector and the generated sequence y. {i-1} Predict the next token y i The mathematical expression of the generation process is:
[0166] p(y i |h,z,t,y {i-1} )=P(y i |x,h,z,t,y {i-1} ;φ)=Decoder(c(h,z,t),y {i-1} )
[0167] In the formula, p(y i |h,z,t,y {i-1} ) represents the generator, P(y i |x,h,z,t,y {i-1} ; φ) means generating the next tag y under given conditions i , φ is the parameter of the generator, h is the retrieved entity, z is the document segment related to entity h, t is the preset document generation template, y i is the target tag to be generated at the current time step, y {i-1} is the generated target sequence {y1,y2,...,y i-1}, represents all target tags that have been generated before the current time step i, c(h,z,t) represents the context vector obtained by encoding the entity h, document segment z and the preset document generation template t, and Decoder represents the decoder function, which is used to convert the context vector and the generated sequence into the probability distribution of the next tag.
[0168] The training of the retriever and generator adopts an end-to-end joint optimization method, and the training objective function is:
[0169]
[0170] The calculation formula of the joint probability P(y|x) is:
[0171]
[0172] In the formula, represents the expectation on the training dataset D; ψ, φ are the parameters of the retriever and generator respectively; P(y|x) is the joint probability representation of the retriever and generator; x is the input query sequence; y is the target generated sequence; q(h,z|x) is the conditional probability of the retriever output; ∏ represents multiplication; n is the length of the generated sequence.
[0173] The specific training process is as follows:
[0174] 1. Data preprocessing: Construct a training set D, where each sample contains a query sequence x and a target generated sequence y.
[0175] 2. Parameter initialization: Randomly initialize the retriever parameters ψ and generator parameters φ.
[0176] 3. Forward propagation:
[0177] The retriever calculates q(h,z|x) to obtain the probability distribution of entity-segment pairs;
[0178] The generator generates target sequences token by token based on the retrieval results.
[0179] 4. Back Propagation:
[0180] Calculate the joint probability P(y|x);
[0181] Calculate the log-likelihood loss -logP(y|x; ψ,φ);
[0182] Update the parameters ψ, φ by gradient descent.
[0183] 5. Iterative optimization: Repeat steps 3-4 until convergence.
[0184] The teacherforcing strategy is adopted during training, that is, the real pre-order label sequence y is used during training. {i-1} Rather than the sequence generated by the model. At the same time, gradient clipping is used to prevent gradient explosion, and techniques such as dropout and layer normalization are used to improve the generalization ability of the model.
[0185] Specifically, in one embodiment of the present invention, step S5 includes:
[0186] S51, receiving a query sequence x input by a user, encoding the query sequence into a query vector through a Transformer model, and normalizing the query vector;
[0187] S52, using the retriever to search in the pre-built search index I(A), calculating the similarity between the query vector and the entity-segment pairs in the index, and returning the Top-K most relevant entity-segment pairs (h, z) as the search results;
[0188] S53, combining the retrieved entity h, document segment z and the preset document generation template t into context information; initializing the generated target sequence y to be an empty sequence; and generating the target sequence token by token in an autoregressive manner:
[0189] At each time step i, based on the current context and the generated sequence y {i-1} Predict the next token y i ; Add the predicted tokens to the generated target sequence; Repeat the process until the complete document is generated or the termination condition is reached;
[0190] S54, organizing the generated content according to the structural constraints of the preset document generation template t to form a final target design document that meets the specifications.
[0191] In a specific example, the implementation process of step S5 is as follows:
[0192] First, the query sequence x input by the user is received and processed using a 12-layer Transformer encoder. The encoder uses a multi-head self-attention mechanism (12 attention heads) and the hidden layer dimension is 768. The input sequence is word-segmented by WordPiece, special tags [CLS] and [SEP] are added, and the sequence length is uniformly padded to 512. The output at the [CLS] position is extracted as the query vector q(x), and normalized by the L2 norm to ensure comparability with the vector in the index.
[0193] Perform a maximum inner product search in the pre-built retrieval index I(A). Specifically, calculate the cosine similarity between the normalized query vector q(x) and all entity-segment pair vectors in the index:
[0194] σ(q(x),I(A))=q(x) T I(A);
[0195] The temperature coefficient τ (default 0.07) is introduced to adjust the similarity distribution and normalized by the Softmax function. The Top-K candidate set is maintained using the heap sort algorithm, and the K entity-segment pairs (h, z) with the highest similarity are returned. For each search result, its similarity score and the corresponding entity and segment information are obtained at the same time.
[0196] The retrieved entity h, document segment z and preset template t are combined to construct the input sequence. The Transformer encoder-decoder architecture is used. The encoder processes the input sequence to obtain the context vector c(h,z,t). The decoder uses a masked multi-head attention mechanism to ensure that only generated tokens can be accessed during the generation process.
[0197] At each time step i:
[0198] 1. The generated sequence y {i-1} Enter the decoder.
[0199] 2. Fuse the context vector c(h,z,t) through the cross attention mechanism.
[0200] 3. Get the next tag y through the fully connected layer and the Softmax layer i The probability distribution of .
[0201] 4. Use beam search (beam width b=4) to maintain multiple candidate sequences.
[0202] 5. Determine whether to terminate generation based on the stop mark or maximum length limit.
[0203] The probability of the generation process is calculated as:
[0204] P(y i |h,z,t,y {i-1} )=Softmax(W·h i + b);
[0205] where h i is the hidden state of the corresponding position in the last layer of the decoder, and W and b are learnable parameters.
[0206] Organize the generated content based on the structural constraints of the preset template t: parse the placeholders and format requirements in template t, map the generated content to the corresponding positions according to the template structure, process special tags and formatting characters, verify the integrity and consistency of the document structure, apply post-processing rules (such as paragraph indentation, line breaks, etc.), and output the final design document that meets the specifications.
[0207] Throughout the generation process, the quality of generated content is ensured through attention weight visualization and decoding probability threshold control. At the same time, an alignment relationship between generated content and retrieved content is established to support traceability and interpretation.
[0208] In summary, the present invention first dynamically segments heterogeneous documents through a bidirectional LSTM network and a multi-threshold adaptive strategy to ensure the semantic integrity of the segmentation; then uses a Transformer encoder to extract entities and relationships from the segmentation, constructs a standardized knowledge graph, and realizes the dynamic update of the knowledge graph through multi-dimensional credibility evaluation and similarity-based matching strategy; then uses the BERT model to vectorize the document segmentation and knowledge graph entities, and establishes entity-segment mapping relationships and retrieval indexes through maximum inner product search; finally, a document generation module based on a retriever-generator architecture is designed, in which the retriever retrieves relevant content through similarity matching between the query vector and the index, and the generator uses an encoder-decoder structure and combines preset templates for autoregressive generation. This solution improves the accuracy and semantic relevance of document generation through knowledge graph enhancement, while supporting efficient retrieval and dynamic updating of documents, and realizing intelligent processing and knowledge reuse of heterogeneous documents.
[0209] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. An enhanced document generation and retrieval method based on knowledge graph, characterized in that: include: S1, receiving heterogeneous document input, and dynamically segmenting the heterogeneous documents to obtain document segments with semantic integrity; S2. Build the Graph-RAG model, including the knowledge graph-document index extraction module and the design document generation module; S3, construct and update the knowledge graph based on document segmentation through the knowledge graph-document index extraction module, and organize entities and relationships into triples; S4. Extract feature vectors of document segments using feature extraction models, establish mapping relationships between document segments and entities in knowledge graphs through matching strategies, and build retrieval indexes based on the mapping relationships between document segments and entities in knowledge graphs; S5. Receive the user's query sequence, and in the design document generation module, retrieve relevant entities and document segments through the retrieval index, and generate the target design document in combination with the preset template.
2. The enhanced document generation and retrieval method based on knowledge graph according to claim 1, characterized in that: Step S1 includes: S11. Receive heterogeneous documents, convert the heterogeneous documents into a unified XML or JSON intermediate format, and obtain a standardized document structure; based on the standardized document structure, parse the document hierarchical structure, extract structured features, and obtain document content with structural annotations; process the document content with structural annotations, identify and standardize special tags, and obtain a structured document with key tags retained; perform unified coding and normalization on the structured document with key tags retained, remove redundant characters, and obtain a pre-processed standard document; S12. Use a bidirectional long short-term memory network LSTM to extract text features. Based on the preprocessed standard document, set the sliding window size n and the step size k to obtain a series of overlapping text fragments; for each text fragment, encode it through the LSTM network to obtain a feature vector sequence with a dimension of d; based on the feature vector sequence, calculate the cosine similarity between adjacent windows to obtain the semantic relevance score between the text fragments; S13, using the semantic relevance scores between text segments, marking potential segmentation points based on the first threshold θ1, and obtaining a preliminary segmentation boundary set; combining the structured features of the standard document and the second threshold θ2, verifying and confirming the segmentation points, and obtaining structure-aware segmentation boundaries; calculating the information entropy H(w) of the current window text, and adjusting the window size when it exceeds the third threshold θ3, to obtain an adaptive segmentation granularity; S14. Based on the adaptive segmentation granularity, optimization is performed according to similarity and segment length, adjacent segments with highly semantic correlation are merged, and segments with too large semantic span are split to obtain the optimized final document segmentation.
3. The enhanced document generation and retrieval method based on knowledge graph according to claim 2, characterized in that: Step S14 includes: S141, extract the topic vector T of each segment for the adaptive segmentation granularity i , get the segmented semantic representation; S142, calculate the length distribution characteristics of all segments, including the average length μ and standard deviation σ; identify segments whose length exceeds μ+1.5σ and mark them as the set to be split P; identify segments whose length is less than the minimum threshold L min The segments are marked as the set to be merged Q; S143. For the segments in the split set P, recursively perform the following operations: Execute steps S12-S13 for each segment to re-segment, re-execute S142 for length analysis of the newly generated segments, update the set to be split P and the set to be merged Q, and when the set to be split P is an empty set, the recursion ends and the set to be merged Q after the recursion is output; S144. For the segments in the recursive set Q to be merged, define the adjacent segments of each segment as the segments before and after it: Calculate the cosine similarity SIM(T) between each segment and its adjacent segment’s topic vector i ,T i+1 ), judging whether the merging condition is met based on the fourth threshold θ4, if only one adjacent segment meets the condition, adding the segment pair to the set to be merged M; if both adjacent segments meet the condition, selecting the segment pair with the highest cosine similarity to be added to the set to be merged M; outputting the final set M of segment pairs to be merged; S145 . Perform a segment merging operation on the segment pairs to be merged in the final set M of segment pairs to be merged to obtain optimized final document segments.
4. The enhanced document generation and retrieval method based on knowledge graph according to claim 3, characterized in that: If the length of the first or last segment of the document is less than the minimum threshold L min , then determine the cosine similarity between it and the topic vector of the only adjacent segment. If the cosine similarity satisfies the fourth threshold θ4, the first segment of the document or the last segment of the document and its corresponding adjacent segment are added to the set M as a segment pair to be merged; if not, keep it as it is.
5. The enhanced document generation and retrieval method based on knowledge graph according to claim 1, characterized in that: The steps to build a knowledge graph based on document segmentation include: Use the Transformer encoder to represent the segmented text; identify the entity set E in the text based on the feature representation; analyze the semantic dependency between entities and obtain the relationship set R; Align the identified entities with the external knowledge base; use the word embedding model to calculate the semantic similarity between entities; perform entity disambiguation and synonym normalization based on semantic similarity; The entity pair (e i ,e j ) and its relationship ij Organized into triplets (e i ,r ij ,e j ); verify the semantic rationality of the triple; complete the missing entity attributes based on external knowledge; Integrate the normalized triple set into the knowledge graph g(h); establish the index structure of entities and relations; save the semantic vector representation of entities and relations; The formula expression of the knowledge graph g(h) is as follows: g(h)={(e i ,r ij ,e j )|e i ,e j ∈E,r ij ∈R} In the formula, g(h) is the knowledge graph generated by the Transformer model; E is the entity set; R is the relationship set; (e i ,r ij ,e j ) represents entity e i and e j Through the relationship ij The composed triplet.
6. The enhanced document generation and retrieval method based on knowledge graph according to claim 1, characterized in that: The update strategy of the knowledge graph is: Perform multi-dimensional credibility evaluation on the knowledge units extracted from the newly added document segments. By calculating the TF-IDF weight, the semantic consistency score based on the pre-trained word embedding model, and the source reliability score, calculate the comprehensive credibility score Score1 for each attribute value and relationship triple. Calculate the entity name similarity S using the character-level edit distance algorithm c , Calculate semantic similarity S based on pre-trained word embedding model s , Calculate the structural similarity S by the overlap of attribute sets and the overlap of relationship triples r , the similarities of these three dimensions are combined according to the weights to obtain the comprehensive matching score Score2, Based on the comprehensive matching score Score2, two thresholds τ1 and τ2 are set, τ1>τ2, and the following judgment strategy is used for processing: When Score2 is greater than τ1, it is considered a complete match, and the Score1 scores of each attribute value and relationship triple are compared respectively; the attribute values and relationship triples with higher Score1 scores are retained, and the replaced knowledge is saved as a historical version; When Score2 is between τ1 and τ2, it is considered a partial match. The alignable attribute values and relationship triples are compared one by one, and the attribute values and relationship triples with higher Score1 are retained. For newly added attribute values and relationship triples, they are allowed to be added when their Score1 exceeds the preset matching threshold. When Score2 is less than or equal to τ2, it is determined to be a new entity. The comprehensive credibility score Score1 of the new entity is checked. It is allowed to be added to the knowledge graph only when Score1 exceeds the preset new threshold. The initial credibility benchmark of the new entity is recorded. At the same time, the timestamp, operation type, change content, and related Score1 and Score2 scores are recorded for all update operations.
7. The enhanced document generation and retrieval method based on knowledge graph according to claim 5, characterized in that: Step S4 comprises: S41, record the document segments of the input heterogeneous documents as a segment set {s1, s2, ..., s n }, and assign a unique index identifier z = {1,2,...,n} to each segment; use the BERT model to extract feature vectors for each document segment, and obtain a feature vector set d(z) = {d1,d2,...,d n }, where d i ∈R d represents the feature vector of segment i; S42. At the same time, the BERT model is used to vectorize the entities in the knowledge graph to obtain the entity vector e k ∈R d ; S43. Calculate the semantic association between the entity and the document segment through maximum inner product search: Yes(and k ,d i )=and k T ·d i In the formula, e k Represents the entity vector in the knowledge graph, d i Feature vectors representing document segments; S44. For each entity e k , based on the semantic relevance calculation results, determine the most relevant document segment index: In the formula, z k * Represents entity e k The most relevant document segment index; S45. Construct a mapping set of entity-document segments: A={(e k ,with k * )|e k ∈g(h),z k * ∈d(z)} Where A represents the set of mapping relationships between entities and document segment indexes.
8. The enhanced document generation and retrieval method based on knowledge graph according to claim 1, characterized in that: The design document generation module includes a retriever and a generator, where: The retriever includes a query encoding unit, an index retrieval unit, and a sorting output unit. The retrieval process is expressed as follows: q(h,z|x)=P(h|,z|x)=TopK[sim(q(x),I(A))] Where q(h,z|x) represents the retriever, P(h,z|x) represents the conditional probability distribution of the retrieved entity h and document segment z according to the input query x, x represents the query sequence, q(x) is the query vector, A represents the set of mapping relationships between entities and document segment indexes, I(A) represents the retrieval index constructed based on the mapping relationship between entities and document segment indexes, sim represents the similarity calculation function, and TopK represents the function that returns the top K results with the highest similarity. The generator includes a context encoding unit, an autoregressive decoding unit, and a document organization unit. Its generation process is expressed as: p(y i |h,z,t,y {i-1} )=P(y i |x,h,z,t,y {i-1} ;φ)=Decoder(c(h,z,t),y {i-1} ) In the formula, p(y i |h,z,t,y {i-1} ) represents the generator, P(y i |x,h,z,t,y {i-1} ; φ) means generating the next tag y under given conditions i , φ is the parameter of the generator, h is the retrieved entity, z is the document segment related to entity h, t is the preset document generation template, y i is the target tag to be generated at the current time step, y {i-1} is the generated target sequence {y1,y2,...,y i-1 }, represents all target tags that have been generated before the current time step i, c(h,z,t) represents the context vector obtained by encoding the entity h, document segment z and the preset document generation template t, and Decoder represents the decoder function, which is used to convert the context vector and the generated sequence into the probability distribution of the next tag.
9. The enhanced document generation and retrieval method based on knowledge graph according to claim 8, characterized in that: Step S5 includes: S51, receiving a query sequence x input by a user, encoding the query sequence into a query vector through a Transformer model, and normalizing the query vector; S52, using the retriever to search in the pre-built search index I(A), calculating the similarity between the query vector and the entity-segment pairs in the index, and returning the Top-K most relevant entity-segment pairs (h, z) as the search results; S53, combining the retrieved entity h, document segment z and the preset document generation template t into context information; initializing the generated target sequence y to be an empty sequence; and generating the target sequence token by token in an autoregressive manner: At each time step i, based on the current context and the generated sequence y {i-1} Predict the next token y i ; Add the predicted tokens to the generated target sequence; Repeat the process until the complete document is generated or the termination condition is reached; S54, organizing the generated content according to the structural constraints of the preset document generation template t to form a final target design document that meets the specifications.
10. The enhanced document generation and retrieval method based on knowledge graph according to claim 8, characterized in that: The retriever and generator include a pre-training process, and the objective function during pre-training is: In the formula, represents the expectation on the training dataset D; ψ, φ are the parameters of the retriever and generator respectively; P(y|x) is the joint probability representation of the retriever and generator; x is the input query sequence; y is the target generated sequence; q(h,z|x) is the conditional probability of the retriever output; Π represents multiplication; n is the length of the generated sequence.
Citation Information
Patent Citations
Construction method of RAG system based on Graph
CN118503407A
Retrieval enhancement method based on semantic comprehension and semantic generation model
CN118733715A
Apparatus and method for automatic object segmentation for background composition
KR1020130075636A
Entity resolution from documents
US20150205803A1
Cited By
Conference memory enhancement method and equipment for conference tablet and medium
CN119988591A
Global context analysis method and system for complex document
CN120012759A
Document generation method and electronic equipment
CN120146022A
Vector matching-based abnormal luggage processing method and system
CN120234407A
Abnormal baggage processing method and system based on vector matching
CN120234407B