Multi-Word document question and answer method and system based on knowledge graph and RAG
By constructing a title structure tree for dual-granularity block segmentation and combining knowledge graphs with multi-level filtering retrieval using RAG, the problems of semantic fragmentation at block boundaries and insufficient evidence coverage in multi-Word document question answering are solved, resulting in more accurate, coherent, and traceable question answering results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGZHOU TIANYUE ELECTRONICS TECH
- Filing Date
- 2026-01-15
- Publication Date
- 2026-05-01
AI Technical Summary
Existing multi-Word document question answering technologies are insufficient in parsing the native hierarchical structure and non-text paragraphs of Word documents during the segmentation stage, resulting in semantic fragmentation at segmentation boundaries. When relying on fixed thresholds or similarity networks during the retrieval stage, redundant blocks are prone to clustering, insufficient coverage, or missed recall of key evidence. Furthermore, when generating answers, the evidence coverage is limited, the reference positioning is not accurate enough, and it is difficult to complete cross-document associations.
By constructing a title structure tree based on knowledge graphs and RAG, a structure-aware dual-granularity block segmentation is performed. Multi-level filtering and retrieval are combined with vector databases and graph databases to achieve dynamic retrieval constraints and evidence merging, thereby improving evidence coverage and the accuracy and traceability of answers.
While maintaining the semantic boundaries of chapters, we can improve retrieval efficiency and evidence location, reduce the risk of semantic breakage of fragmented evidence, enhance the stability and traceability of answers, and ensure the integrity and verifiability of key content.
Smart Images

Figure CN121958631A_ABST
Abstract
Description
A Multi-Word Document Question Answering Method and System Based on Knowledge Graph and RAG Technical Field
[0001] This invention relates to the field of natural language processing technology, specifically to a multi-Word document question-answering method and system based on knowledge graphs and RAG. Background Technology
[0002] RAG (Retrieval-Augmented Generation) is a question-answering method that allows a large model to retrieve evidence from an external knowledge base / document before generating an answer. The system first segments the document into searchable fragments and builds vector or keyword indexes. When a user asks a question, it first performs semantic / keyword retrieval to recall the most relevant fragments. The question is then combined with the evidence fragments and input into the large model. Under the constraints of evidence, the large model completes extraction, induction, and generative expression, while outputting the corresponding citation sources. This reduces the risk of fabrication without referring to the document and makes the answer traceable and verifiable.
[0003] Existing multi-Word document question-answering solutions typically involve the system first accessing and parsing multiple Word documents, extracting heading levels, paragraph text, and table text, then cleaning and segmenting the data. Each text segment is then bound to metadata such as document source and chapter position, and a keyword inverted index and semantic vector index are constructed simultaneously. When a user asks a question, the system extracts keywords and performs semantic vectorization on the question, performs a hybrid search in the multi-document index to retrieve several relevant segments, and can rearrange them according to relevance and complete the context. Subsequently, the user's question and the retrieved segments are used as input to a large model, which extracts, summarizes, and generates a generative answer within the given segment range, and includes citation information (such as document name, chapter or paragraph position) in the output to support traceability verification, thereby achieving traceable question-answering for multiple Word documents.
[0004] For example, Chinese invention patent application CN120353892A discloses a coarse-to-fine multi-document question answering method based on a search head, which includes the following steps: S1, coarse-grained filtering: quickly remove a large number of background documents and retain the candidate document set; S2, fine-grained guidance: further suppress interfering documents from the candidate set and enhance attention to the golden evidence documents.
[0005] For example, Chinese invention patent CN119903190B discloses a multi-document question-answering retrieval method that combines a generative language model and a semantic document graph. The method employs a BERT-based model to construct the graph and a KGP3 algorithm to optimize the retrieval traversal. During graph traversal, a sub-question involving the next required node is generated by combining the main question and the obtained nodes. The most suitable document node is precisely selected from neighboring nodes, and its relevance to the initial question is determined. If the node is irrelevant, it is not included in the subsequent search list.
[0006] Most existing multi-Word document question answering technologies are based on fixed or semi-fixed rules to divide the document content into text blocks, and then rely on keyword matching or vector similarity calculation to retrieve candidate text blocks, or guide the model to generate answers through attention reordering and bias injection mechanisms in long text contexts. However, in actual multi-document question answering, documents often contain multiple structural units such as heading levels, clause numbers, tables and images. Moreover, evidence for the same question is often scattered across multiple files in different chapters, different documents, or even folder directories. Usually, it is necessary to complete cross-block splicing and association completion while maintaining the structural boundaries as much as possible in order to form a relatively complete and verifiable chain of evidence.
[0007] Therefore, if existing technologies lack sufficient unified parsing capabilities or boundary constraints for Word's native hierarchical structure and non-text paragraphs during the segmentation stage, semantic fragmentation may occur at segmentation boundaries, or the correspondence between table / image information and the main text may weaken, thereby reducing the probability of text blocks and tables / images being stably hit during the retrieval stage. Furthermore, if the retrieval stage mainly relies on fixed thresholds or similarity networks for recall, redundant block aggregation, insufficient coverage, or missed recall of key evidence may easily occur when there are significant differences in expression across different domains and a large number of repetitive template paragraphs. At the same time, when there is a certain bias in the candidate set, subsequent reordering, attention bias, or multi-hop traversal may amplify the impact of early misselection, making the retrieval results more fragmented and structurally difficult to automatically merge into a coherent context. Ultimately, although large language models can generate corresponding answers, they still face common defects such as limited coverage of answer evidence, insufficient accuracy in citation positioning, and inadequate cross-document association completion, which affects the completeness, stability, and verifiability of question-and-answer output. In business scenarios that require rigorous traceability, this increases verification costs, leads to misunderstandings, and may even affect subsequent decisions. Summary of the Invention
[0008] To address the shortcomings of existing technologies, this invention provides a multi-Word document question-answering method and system based on knowledge graphs and RAG, which can effectively solve the problems mentioned in the background technology.
[0009] To achieve the above objectives, the present invention provides the following technical solution: The first aspect of the present invention provides a multi-Word document question-answering method based on knowledge graphs and RAG, comprising: receiving a batch of Word documents through a knowledge processing component; constructing a title structure tree for each Word document based on a title stack; performing structure-aware dual-granularity block processing on the Word documents through the title structure tree; inputting the block results of each Word document into a vector database for embedding; integrating hierarchical metadata for each Word document to form a hierarchical structure of the Word document; constructing a multi-Word document knowledge graph in a graph database based on each hierarchical structure; receiving user questions and generating dynamic retrieval constraints through a question-answering processing component; performing a first-stage retrieval based on the vector database to obtain a candidate knowledge fragment set; rearranging and merging the candidate knowledge fragment set; performing a second-stage retrieval based on the graph database to obtain the final evidence set for the question and answer; and outputting the question-answering result based on the final evidence set for the question and answer, thus completing the multi-Word document question-answering process.
[0010] The second aspect of this invention provides a multi-Word document question-answering system based on knowledge graphs and RAG, comprising: a dual-granularity segmentation module, used to receive batches of Word documents through a knowledge processing component, construct a title structure tree for each Word document based on a title stack, perform structure-aware dual-granularity segmentation processing on the Word documents through the title structure tree, and input the segmentation results of each Word document into a vector database for embedding; a knowledge graph construction module, used to integrate hierarchical metadata for each Word document to form a hierarchical structure of the Word documents, and construct a knowledge graph of multiple Word documents in a graph database based on each hierarchical structure; a multi-level filtering and retrieval module, used to receive user questions through a question-answering processing component to generate dynamic retrieval constraints, perform a first-stage retrieval based on the vector database to obtain a set of candidate knowledge fragments, rearrange and merge the set of candidate knowledge fragments, and perform a second-stage retrieval based on the graph database to obtain the final evidence set for the question and answer; and a question-answering result output module, used by the question-answering processing component to output the question-answering result based on the final evidence set for the question and answer, thus completing the question-answering process for multiple Word documents.
[0011] Compared with the prior art, the embodiments of the present invention have at least the following advantages or beneficial effects: (1) The present invention provides a multi-Word document question answering method and system based on knowledge graph and RAG. The knowledge processing component receives a batch of Word documents, constructs a title structure tree based on the title stack, and performs structure-aware dual-granularity segmentation on each document accordingly. The segmentation results are used to generate embedded vectors and write them into a vector database, thereby improving the hit efficiency and evidence locatability of subsequent searches while maintaining the semantic boundaries of chapters. At the same time, the knowledge processing component integrates hierarchical metadata for each Word document and forms a standard hierarchical structure. It constructs a multi-document knowledge graph containing folder directory, document, and content elements in the graph database, thereby facilitating cross-document association expansion. The expansion and scope constraints provide structured support; after receiving user questions, the question-answering processing component generates dynamic retrieval constraints, performs a first-stage retrieval in the vector database to obtain a set of candidate knowledge fragments, and reorders and intelligently merges the candidate fragments to form more coherent initial evidence, thereby reducing semantic breaks caused by fragmented evidence; subsequently, it queries related nodes based on the graph database and triggers a second-stage association completion retrieval to obtain the final evidence set for question answering, thereby supplementing the contextual evidence that was not hit in the first round and improving evidence coverage; finally, the question-answering processing component generates answers for the context-driven large model based on the final evidence set and outputs the question-answering results, thereby improving the accuracy and traceability of the answers under controlled evidence constraints and completing the multi-Word document question-answering process.
[0012] (2) This invention proposes a document structure-aware dual-granularity hierarchical block segmentation method, which generates small-granularity retrieval blocks and large-granularity context blocks with the title structure tree as the boundary. This makes the small blocks more suitable for vector retrieval while the large blocks provide complete contextual wrapping, thus balancing retrieval accuracy and the completeness of the context during generation. At the same time, the placeholder protection and backfilling mechanism prevents tables and images from being split or misaligned at the block boundaries, ensuring that structured evidence is aligned with the semantics of the main text and improving the usability and verifiability of key content such as table parameters and illustrations.
[0013] (3) The multi-level filtering retrieval and intelligent merging method proposed in this invention combines dynamic range constraints, first-stage vector recall, reordering and continuous merging within the same chapter, so that candidate evidence is upgraded from similar fragments to readable continuous evidence blocks, reducing the risk of noise recall and misinterpretation; further, by combining the associated nodes of the graph database to trigger the second-stage completion retrieval, the contextual evidence missed in the first round can be supplemented within the scope of associated documents, improving the completeness of evidence coverage and cross-document consistency, thereby enhancing the stability and persuasiveness of the final answer.
[0014] (4) Compared with the common process that relies solely on single vector retrieval, simple filtering, and direct generation, this method incorporates document structure tree segmentation, vector evidence recall, and graph association completion into the same closed loop: on the one hand, structure-aware segmentation improves evidence granularity and contextual integrity, and on the other hand, graph association and two-stage retrieval enhance cross-document completion capabilities, thereby better balancing recall accuracy, evidence coherence, and result traceability in multi-Word scenarios, and reducing answer bias caused by fragmentation, missed recall, or insufficient context. Attached Figure Description
[0015] The present invention will be further described with reference to the accompanying drawings, but the embodiments in the drawings do not constitute any limitation on the present invention. For those skilled in the art, other drawings can be obtained based on the following drawings without creative effort.
[0016] Figure 1 is a schematic diagram of the method steps of the present invention.
[0017] Figure 2 is a schematic diagram of the system module connection of the present invention.
[0018] Figure 3 is a schematic diagram of the judgment logic of the dual-granularity structure perception block.
[0019] Figure 4 is a logical diagram of two-stage retrieval-enhanced question answering. Detailed Implementation
[0020] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0021] To make the technical problems, technical solutions and advantages of the present invention clearer, a detailed description will be given below in conjunction with the accompanying drawings and specific embodiments.
[0022] Example 1:
[0023] Referring to Figure 1, the first aspect of the present invention provides a multi-Word document question answering method based on knowledge graph and RAG, comprising: receiving a batch of Word documents through a knowledge processing component, constructing a title structure tree for each Word document based on a title stack, performing structure-aware dual-granularity block processing on the Word documents through the title structure tree, and inputting the block results of each Word document into a vector database for embedding.
[0024] In this embodiment, both the knowledge processing component and the question-answering processing component are responsible for the data processing functions of the large language model.
[0025] The knowledge processing component is used to structure and organize external knowledge in a searchable manner before question-answer generation. This component accesses and standardizes batches of Word documents and their folder directory levels, parses the internal heading levels and content elements such as tables and images, performs structure-aware segmentation and vectorized representation generation, and writes the segmentation results along with document hierarchy metadata into a vector library. At the same time, it constructs a fused knowledge graph in a graph database, which focuses on recording the relationships between multiple documents. The graph nodes include folder directory level nodes, document nodes, and table nodes, thus forming a knowledge base that can be used for permission constraints, scope filtering, cross-document association expansion, and evidence tracing, enabling large language models to obtain high-quality, localizable external evidence input within a controlled scope.
[0026] The question-answering processing component is used to understand, retrieve, schedule, and organize evidence when a user asks a question, and drive the retrieval enhancement to generate output. This component verifies the user's query and access permissions, parses the scope constraints and structural clues in the query and constructs dynamic access filtering conditions, performs multi-stage semantic retrieval and reordering in the vector library, performs structural merging and redundancy removal on the retrieved knowledge fragments, and performs cross-document completion retrieval by combining the folder directory hierarchy and association identifiers provided by the knowledge graph. Finally, it forms an evidence set covering the key points of the question and inputs it into the generative language model to generate an answer. At the same time, it binds the corresponding source location information to key conclusions to support traceable verification, thereby completing the controlled question-answering output of the large language model in the external knowledge scenario.
[0027] For each Word document, a title structure tree is constructed based on the title stack. The specific construction process is as follows: The knowledge processing component extracts all levels of titles (e.g., first-level title, second-level title, third-level title) for each received Word document and arranges them in order to form a title sequence. The adjacent subheadings in the title sequence are used as interval boundaries. The paragraphs in each interval are traversed and parsed one by one: First, it is determined whether the content type of the paragraph is body text, table, image or mixed element; for text segments, plain text is directly collected and counted in the token count of the paragraph (the token count refers to the number of words after the text segment is split according to the counting unit of the large language model, which can be approximately understood as the word count of the text segment processed by the model).
[0028] The process involves using a visual language model to generate image descriptions for image segments (a visual language model is a model that can understand image content and output text descriptions), storing the original image in an object storage server to obtain a URL (Uniform Resource Locator), constructing the image content in Markdown format (Markdown is a text markup style where the description represents a link that displays descriptive text and can be clicked to jump to that address), and inserting unique placeholders into the text stream (a unique placeholder is a short mark that will not be confused with the main text to replace the actual content of the image / table, which will be replaced with the corresponding image link or table content later when needed; the text stream is a continuous string of content concatenated in the original text order); and converting table segments into Markdown tables and embedding them into the text stream using unique placeholders as well.
[0029] Finally, a title tree structure is constructed using the intervals defined by adjacent subheadings as units. First, corresponding interval structured nodes are created, and the parsing results of each paragraph within the interval are sequentially linked into an ordered sequence of child nodes according to their appearance order in the original text. At the same time, during the aggregation process, interval-level attribute information (including interval title chains, paragraph boundary order, key term sets, anchor point sets such as clause / step / table / figure numbers, and table field or image description summaries, etc.) are summarized and generated, forming a continuously splicable interval content representation and paragraph boundary positioning information, thus obtaining interval-level structured node objects that can be used for subsequent segmentation, indexing, and graph modeling.
[0030] The knowledge processing component maintains a title stack to represent the current title level path. The structured node object of the interval is pushed onto the title stack. What is pushed onto the stack is not the title string itself, but the structured node object corresponding to the title (which can also be understood as a reference to the title node / chapter node object).
[0031] The titles are processed sequentially according to their appearance order in the document: When a new title is encountered, the processing component first writes the title text, title level, and position identifier in the document to the structured node object of the new title. If the level of the structured node object is deeper than the level of the top structured node object, it is attached as a child node of the top structured node object and pushed onto the title node stack.
[0032] If the level of the structured node object is not deeper than the level of the top structured node object in the stack, the title node stack is continuously popped until the level of the top structured node object is lower than the level of the structured node object, thus determining its parent structured node object. Then, the structured node object is attached as a child node of the parent structured node object and pushed onto the title node stack. After traversing all titles, the processing component creates a super-root structured node object and attaches the structured node objects corresponding to each first-level title in the document to the super-root structured node object to form a unified entry point for the title structure tree for subsequent interval parsing, block division and indexing processing.
[0033] The Word document is processed using a title tree structure for structure-aware, two-granularity segmentation. The specific processing logic is shown in Figure 3. Figure 3 is a schematic diagram of the judgment logic for two-granularity structure-aware segmentation. Starting from the root node of the input tree, the processing component first determines whether the current node is a leaf node. If it is a leaf node, the text content corresponding to the node is directly segmented. If it is not a leaf node, it further determines whether the "text length of the current subtree aggregated" exceeds the preset large block threshold. If it does not exceed the threshold, the entire subtree is segmented as a unit. If it exceeds the threshold, only the content of the current node itself is segmented, and it is determined whether it has child nodes. When child nodes exist, the child nodes are recursively traversed and the above judgment and segmentation process is repeated until there are no child nodes. Then, the recursion is exited and the segmentation ends. This achieves coarse-to-fine segmentation processing while ensuring the chapter hierarchy boundaries.
[0034] The specific chunking process is as follows: In the preprocessing stage before chunking based on the title structure tree, the processing component traverses the title structure tree from top to bottom. For each title node, it first extracts the content that the node can cover and calculates its content length index as the judgment criterion. The content length index can be determined by at least one of the following: the number of characters, the number of words, or the number of large language model counting units in the aggregated text of the node. When the content length index does not exceed the preset threshold, the entire subtree consisting of the title node and all its child nodes is regarded as a unit to be sliced and its aggregated content is output. No further splitting is carried out at the child node level. When the content length index exceeds the preset threshold, the processing component only outputs the direct content of the node as the unit to be sliced and recursively repeats the above length calculation and strategy selection for each of its child nodes. This achieves coarse-to-fine structure-aware chunking preparation while maintaining the title hierarchy boundaries.
[0035] The main text content corresponding to each child node of the title structure tree of each Word document is used as the object to be segmented. The main text to be segmented is continuously truncated into first-granularity text blocks using a sliding window method according to the preset first-granularity length. During the truncation process, when the window boundary is adjacent to an image placeholder or table placeholder, the knowledge processing component makes a fine adjustment to the boundary position according to the placeholder protection rules to avoid splitting the same placeholder into different text blocks. At the same time, a preset length of overlapping fragments is retained between adjacent first-granularity text blocks to reduce the risk of semantic breakage at the boundary.
[0036] It should be explained that the above placeholder protection rule treats images or tables as an indivisible whole in the text, prohibiting them from being cut off inside the placeholder. To meet this protection rule, the "forward and backward adjustment" means that when the window boundary is about to cut into the placeholder, the boundary is moved forward before the placeholder or backward after the placeholder, so that the entire placeholder falls completely into a certain text block without being split.
[0037] After obtaining each first-granularity text block, the knowledge processing component further expands a preset range forward and backward with the first-granularity text block as the center in the context of the original Word document to construct a second-granularity text block for context completion, so that the first-granularity text block is wrapped by a more complete context.
[0038] Subsequently, the knowledge processing component outputs each first-granularity text block and its corresponding second-granularity text block as a dual-granularity block result. In the output stage, the image and table placeholders retained in the first-granularity text block (and / or the second-granularity text block) are replaced with their corresponding Markdown image representations or Markdown table representations, thereby obtaining a dual-granularity block processing result for each Word document that is suitable for vector retrieval and can provide complete contextual support.
[0039] In this embodiment, by outputting small-granularity retrieval blocks and large-granularity context blocks in pairs, the processing component maintains the semantic focus of small-granularity text blocks and the hit rate of vector retrieval, while ensuring that each hit small-granularity text block naturally carries its corresponding large-granularity context range. This allows for more complete contextual support when generating answers, reducing misinterpretation and inference bias caused by missing context. At the same time, a placeholder protection and backfilling mechanism is used during the block segmentation process, ensuring that images and tables are preserved as an indivisible whole at the slice boundaries and restored to their corresponding Markdown representations in the output stage. This avoids the cutting, loss, or misalignment of multimodal content with the main text, ensuring the consistency and readability of semantic alignment between text blocks and images / tables.
[0040] Based on the above mechanism, small-granularity blocks are responsible for accurate recall, large-granularity blocks are responsible for contextual completion, and placeholder protection and backfilling are responsible for structural and multimodal integrity. The collaboration of the three can improve the continuity of evidence coverage and the coherence of answer expression in multi-Word document question answering, and improve the verifiability of key evidence such as table parameters and image descriptions, thereby reducing the risk of unfounded generation and improving the accuracy and stability of question answering results.
[0041] After the knowledge processing component completes the two-granularity block processing of each Word document, it uses the first-granularity text block as the basic index unit for vector retrieval. The embedding model is called block by block to generate the corresponding embedding vector representation for each first-granularity text block, and the content of the first-granularity text block and its embedding vector are written into the vector database to form a vector index that can be searched from nearest neighbors. At the same time, the processing component synchronously stores the metadata fields bound to each first-granularity text block. The metadata includes at least the document name, the normalized folder directory path, the chapter title chain, the position range in the document (page number range and / or paragraph number range), and whether it contains structural markers such as tables or images. This enables range filtering, access control, and result tracing and location based on vector similarity recall in the subsequent retrieval stage.
[0042] Each Word document undergoes hierarchical metadata integration to form a hierarchical structure. Based on this hierarchical structure, a knowledge graph of multiple Word documents is constructed in a graph database.
[0043] The hierarchical structure of a Word document is specifically defined by expanding the original folder directory structure of each Word document into a standard hierarchical path, where the standard hierarchical path is used to represent the hierarchical structure of the Word document.
[0044] In this embodiment, the processing component receives a batch of Word documents and parses the directory information of their source carriers. For documents from folders, it reads the hierarchical directory names of the folders they belong to; for documents from compressed packages, it reads the hierarchical directory names within the compressed packages. Then, it concatenates the directory names at each level according to a unified delimiter rule and combines them with the document file names to generate the corresponding standard hierarchical path. The standard hierarchical path serves as the hierarchical structure identifier for the Word document, representing the document's hierarchical position in the overall folder directory tree, and providing a consistent path basis for subsequent path-based determination of parent-child inclusion relationships, range filtering, and source tracing.
[0045] The knowledge graph for multiple Word documents is constructed as follows: When the knowledge processing component performs batch writing of the knowledge graph on a batch of Word documents, it first creates a corresponding document node in the graph database for each Word document. The document node is used as the end node in the folder directory hierarchy to represent the Word document entity, and writes necessary attributes such as document name, file external identifier, standard hierarchical path, and an initially empty relation identifier field (relation_node_id). At the same time, the node type is marked as document.
[0046] Subsequently, the knowledge processing component decomposes the folder directories contained in the standard hierarchical path of the Word document level by level. For each level of directory, a corresponding folder directory node is created and its standard hierarchical path is recorded to support node deduplication and subsequent relationship completion. The directory node type from the source is a compressed file and the directory node type from the source is a folder. This forms a hierarchical node set organized level by level by folder directory nodes and with document nodes as leaf nodes, providing a unified graph node foundation for subsequent parent-child containment relationship construction and cross-document association processing.
[0047] When constructing the hierarchical relationship of the knowledge graph, the knowledge processing component uses the standard hierarchical path of each folder directory node and document leaf node as the basis for determining parent and child relationships. First, it pairs nodes with the same path prefix to determine their superior and subordinate nodes. The superior node is the node corresponding to the standard hierarchical path of the subordinate node after removing the last-level directory name or file name. Then, it generates parent-child relationships of superior node-inclusion relationship-subordinate node in batches to form a hierarchical inclusion structure from folder directory to folder directory and from folder directory to document.
[0048] For existing parent-child relationship pairs, a merged writing method is used to avoid duplication, and only missing inclusion relationships are filled in, thus keeping the graph relationship edges free of redundancy. After the hierarchical inclusion structure is established, the knowledge processing component further updates the association attribute field of each document leaf node. Other leaf sibling nodes in the same parent folder directory as the leaf node, as well as the leaf descendant document nodes contained in the non-leaf sibling folder directory nodes in the same parent folder directory, are identified as the set of associated nodes of the leaf node in the knowledge graph and written into the association attribute field to support subsequent cross-document association expansion and retrieval scope completion.
[0049] After completing the document-level hierarchical tree composed of folder directory nodes and document leaf nodes, the knowledge processing component further creates a corresponding table node in the knowledge graph based on the table parsing results output by the dual-granularity block module. The table node maintains at least the Markdown representation of the table, the corresponding document external identifier, and the related attribute field (relation_node_id).
[0050] Subsequently, the processing component establishes a document-containment-table parent-child relationship between a document node and its parent table node by matching the document external identifier of the table node with the file external identifier of the document node in the graph, thus forming a subordinate structure of "document-[:CONTAINS]->table". After establishing the subordinate relationship, the knowledge processing component updates the relation_node_id field of the table node, identifying the leaf sibling document nodes in the same parent folder directory as the table node's parent document, as well as the leaf descendant document nodes contained in the non-leaf sibling folder directory nodes at the same level, as the set of associated nodes of the table node and writing them into the relation_node_id field. This supports subsequent cross-document association expansion and retrieval scope completion for table-based evidence.
[0051] The question-and-answer processing component receives user questions and generates dynamic retrieval constraints. The first stage of retrieval is performed based on a vector database to obtain a set of candidate knowledge fragments. The set of candidate knowledge fragments is rearranged and merged, and the second stage of retrieval is performed based on a graph database to obtain the final evidence set for the question and answer.
[0052] The multi-level filtering retrieval logic for multiple Word documents is shown in Figure 4. Figure 4 is a schematic diagram of the logic of the two-stage retrieval enhanced question answering. When the user inputs the text Q to be queried, the processing component first verifies and performs semantic analysis on the query content and generates dynamic filtering conditions. At the same time, the question Q is represented semantically as a vector. Under the constraints of the filtering conditions, the first-stage vector retrieval is performed to obtain candidate blocks. The candidate blocks are reordered and semantic blocks are merged. Then, based on the merging results, the filtering conditions of related documents are generated, triggering the second-stage deep association retrieval to supplement contextual evidence. After obtaining the second-stage results, the system merges and aligns the structured and unstructured results, and reorders the finally merged large block content. Finally, the sorted evidence is used as context input to the Large Language Model (LLM) to generate and output the answer.
[0053] The first stage of retrieval is based on a vector database. The specific retrieval process is as follows: After receiving the retrieval question and answer request initiated by the user, the question and answer processing component first performs initial text validation on the query text entered by the user. This is done by checking whether the query text is empty or too short, whether it contains parsable natural language expressions, and whether there are obvious meaningless character stacks or garbled characters. At the same time, the access token carried by the user with the request is validated for legality, and the scope of access permissions is determined accordingly.
[0054] After the initial text validation passes, the question-answering processing component further identifies limiting information from the query text. This limiting information consists of explicit or implicit clues provided by the user in the question regarding the scope of the search, such as specific project names, folder directory paths, document sets, time ranges, business domains, or data categories. These information is used to limit the data set that the search should cover. Subsequently, the question-answering processing component inputs the limiting information into a large language model and combines it with a pre-set knowledge engine rule base for parsing and mapping, generating dynamic data access filtering conditions that are consistent with the current user's permission scope.
[0055] Dynamic data access filtering conditions are scope restriction rules that can be directly executed by the search engine. They are used to recall data only within a subset of data that meets the scope and permission requirements of the project / folder directory / document during subsequent retrieval processes, thereby realizing a controlled retrieval question-and-answer process of verification, identification, and filtering.
[0056] When the initial text validation fails, the question-and-answer processing component will perform corresponding processing based on the reason for the failure: if the query text is empty, semantically unparseable, or suspected meaningless input, a prompt message will be returned to guide the user to supplement or restate the question; if the access token is invalid, expired, or the scope of permissions is insufficient to access the target data, the retrieval will be refused and a permission restriction prompt will be returned. If necessary, audit information will be recorded to support subsequent security tracking, thereby avoiding triggering subsequent vector retrieval and content generation under invalid input or unauthorized conditions.
[0057] After constructing the dynamic data access filtering conditions, the question-answering processing component calls a preset vector model to encode the user's query text, converting the natural language query from readable text into a set of computable numerical representations. This makes semantically similar queries closer in numerical space, thus obtaining a semantic vector representation that can characterize the semantic features of the query. Subsequently, the question-answering processing component connects to the vector database and uses the semantic vector as the input retrieval vector. Under the premise of satisfying the dynamic data access filtering conditions and content availability constraints, it performs a first-stage approximate nearest neighbor retrieval based on vector similarity. The content availability constraints allow the retrieval engine to recall only knowledge fragments that have been parsed, segmented, and entered into the database, and that have not been removed, deleted, or marked as unretrievalable, in order to avoid returning content that has not yet been entered into the database or should not participate in the retrieval.
[0058] The processing component recalls and retrieves knowledge fragments with similar vector semantics from the vector database as initial results, and filters the recall results for effectiveness based on a preset vector similarity threshold. Knowledge fragments with vector similarity not lower than the threshold are retained as a set of candidate knowledge fragments, thereby obtaining the first-stage candidate evidence input for subsequent reordering and generation within the scope of data with controlled permissions and valid content.
[0059] The candidate knowledge fragment set is rearranged and merged. The specific analysis process is as follows: In this embodiment, after obtaining the candidate knowledge fragment set returned by the first stage retrieval, the question-answering processing component calls the semantic reordering model to perform fine-grained relevance evaluation and reordering of the candidate knowledge fragments. Specifically, the processing component inputs the user question text and the main text content of each candidate piece into the semantic reordering model (the semantic reordering model can be implemented using a cross-encoder or a generative re-scoring machine), and outputs a relevance score that represents the degree of fine-grained semantic matching between the two. At the same time, the chapter title chain to which the candidate piece belongs is concatenated into a title text in hierarchical order, and the keywords extracted from the user question are matched with the title text to output a title chain hit score, which is used to represent the degree of fit between the candidate piece and the user question at the document structure and topic level. Subsequently, the system merges the relevance score and the title chain hit score of each candidate piece into a comprehensive score according to a preset combination strategy, and reorders the candidate knowledge fragment set according to the comprehensive score, so that the candidate pieces that are semantically relevant and more matched in terms of chapter topic are output first as high-confidence inputs for subsequent evidence merging and answer generation.
[0060] After obtaining the reordered candidate knowledge fragment results, the question-answering processing component uses the preset metadata fields in each knowledge fragment to perform intelligent merging processing on the results in the order of reordering. The preset fields include at least the document identifier, the chapter title chain, and the position range in the document, which are used to determine the affiliation and adjacency relationships between knowledge fragments.
[0061] Specifically, the processing component prioritizes grouping knowledge fragments from the same document and belonging to the same chapter. Within each group, it determines the merging feasibility based on the overlap of text content or the continuity of positional range of each knowledge fragment. For candidate fragments with overlapping or consecutive segments, they are sequentially spliced together and deduplicated to form a larger piece of evidence with more complete content. At the same time, the component simultaneously aggregates the associated field information carried by the knowledge fragments, including but not limited to source, author, update time, and permission tags, to form a more compact and semantically coherent merged result. Finally, the processing component records the merged candidate knowledge fragment set obtained through the above intelligent merging as the initial evidence fragment set, which is used for subsequent association completion retrieval and answer generation.
[0062] The second stage of retrieval is based on the graph database. The specific retrieval process is as follows: After obtaining the initial set of evidence fragments, the question answering component selects several of the top-ranked evidence fragments as seeds for association expansion based on the document identifiers and chapter metadata of the initial evidence fragments. It then queries the set of associated node identifiers corresponding to the seeds in the knowledge graph to obtain the range of first-order associated documents that are associated with the seeds in terms of folder directory level, associated domain identifiers, or structural reference relationships.
[0063] Subsequently, the processing component constructs a second-stage association completion retrieval constraint based on the set of associated node identifiers. This constraint includes at least the set of allowed associated document identifiers and / or the range of associated folder directory paths, the range of optional chapter title chains, and node filtering conditions that match the associated domain identifiers. This constraint, together with the dynamic data access filtering conditions, serves as the retrieval restriction input vector database. A second-stage deep association retrieval is performed within the scope of associated documents to recall context-related supplementary evidence fragments that were not hit in the first round, forming a supplementary evidence fragment set. After obtaining the supplementary evidence fragments, the system performs a secondary fusion and field alignment between the supplementary evidence fragment set and the initial evidence fragment set, integrating structured attribute fields (such as source, author, update time, permission tags, and location range) with the corresponding unstructured text evidence to obtain the final evidence set containing semantic context and structured attributes.
[0064] The final set of evidence includes the initial set of evidence fragments and the supplementary set of evidence fragments.
[0065] The question-and-answer processing component outputs the question-and-answer results based on the final evidence set of the questions and answers, completing the question-and-answer process for multiple Word documents.
[0066] After completing multi-level semantic retrieval, dynamic data access filtering control, evidence fragment reordering and intelligent merging, and associative completion retrieval, the question-answering processing component obtains the final evidence set used to answer user questions. Subsequently, the processing component uses the evidence content in the final evidence set as context input to the generative language model and constructs question-answering prompts in conjunction with the user's original question, enabling the generative language model to generate answer content consistent with the question semantics under the constraints of the evidence context. During the generation process, the question-answering processing component can associate source document identifiers, chapter title chains, and location ranges corresponding to the final evidence set with the answer content for output, so as to locate and verify key conclusions. Thus, the question-answering processing component outputs the question-answering results and completes the enhanced question-answering process for multi-Word document retrieval.
[0067] Example 2:
[0068] Based on the unchanged conditions in Example 1, the first-stage retrieval based on the vector database described above can be further performed as follows: After receiving the user's query text, the question-answering processing component first performs structured parsing on the query text to extract the main semantic points of the question, possible types of evidence requirements, and clue information related to the document structure. Based on this, a query vector representation set for retrieval is generated. The query vector representation set includes at least the main query vector representing the main semantics of the question and the structured query vector related to the expression of chapter titles or field descriptions.
[0069] Subsequently, the question-answering processing component connects to the vector database. Under the premise of meeting the dynamic data access filtering conditions, it first performs nearest neighbor retrieval on the vector index objects at the document level and / or chapter level based on the query vector representation set to determine the candidate document domain and / or candidate chapter domain corresponding to each Word document. The candidate document domain and / or candidate chapter domain are recorded as the candidate semantic domain of the Word document. After obtaining the candidate semantic domain, the question-answering processing component further performs nearest neighbor recall on the knowledge fragment vectors within the scope defined by the candidate semantic domain to obtain a first-stage candidate knowledge fragment set that is similar to the semantics of the user query. This set is used for subsequent reordering, merging, and association completion retrieval processing.
[0070] In a specific embodiment, the multi-Word document question-answering process can be as follows: Scenario: The large model has been connected to multiple Word documents in the Project A / Running and Maintenance folder directory, and has completed standard hierarchical path expansion, dual-granularity block division and vector input. At the same time, the inclusion relationship and association identifier of folder directory-document-table are established in the knowledge graph.
[0071] User question: "In Project A, what vibration threshold will trigger an orange alarm? Please provide the relevant section or table." Step 1: Structured analysis and dynamic range.
[0072] The question-and-answer processing component verifies the question text and access permissions. Once verified, it identifies the restriction information "Project A / Operation and Maintenance" and parses the evidence requirement as "threshold value + alarm level definition", thereby generating dynamic search range constraints.
[0073] Step 2: Generate the query vector representation set.
[0074] Generate multi-way query vectors (such as main semantic vector, chapter title vector, and table field vector) based on the parsing results.
[0075] Step 3: Candidate semantic domain determination and intra-domain recall.
[0076] First, candidate semantic domains (e.g., “Equipment Maintenance Specifications.docx / Inspection Threshold”, “Alarm Classification Description.docx / Orange Definition”) are determined in the document-level / chapter-level index of the vector library. Then, nearest neighbor recall is performed on the knowledge fragment vectors within the candidate semantic domains to obtain the first-stage candidate knowledge fragment set.
[0077] Step 4: Reordering and Smart Merging.
[0078] Fine-grained semantic relevance scores are calculated for candidate fragments, and combined with the hit rate of chapter title chains to form a comprehensive score for re-ranking; then, they are merged into an initial set of evidence fragments according to the rule of "same document, same chapter and continuous / overlapping content" (for example, merging "threshold table block" and "orange definition block").
[0079] Step 5: Related completion and final output.
[0080] In the knowledge graph, based on the document to which the initial evidence belongs, query the set of associated node identifiers to construct the second-stage association completion retrieval constraints, recall supplementary evidence fragments in the vector library and merge them with the initial evidence to form the final evidence set; input the final evidence set into the large model to generate the answer, and return the answer to the user with "table / chapter" as the basis.
[0081] Referring to Figure 2, a second aspect of the present invention provides a multi-Word document question-answering system based on knowledge graphs and RAG, comprising: a dual-granularity block segmentation module, a knowledge graph construction module, a multi-layer filtering retrieval module, and a question-answering result output module. The multi-layer filtering retrieval module includes a vector database and a graph database.
[0082] The dual-granularity segmentation module is connected to the knowledge graph construction module, which in turn is connected to the multi-layer filtering and retrieval module. The multi-layer filtering and retrieval module is also connected to the question-answering result output module. Furthermore, the multi-layer filtering and retrieval module is connected to both a vector database and a graph database.
[0083] The dual-granularity segmentation module is used to receive batches of Word documents through the knowledge processing component, construct a title structure tree for each Word document based on the title stack, perform structure-aware dual-granularity segmentation processing on the Word document through the title structure tree, and input the segmentation results of each Word document into the vector database for embedding.
[0084] The knowledge graph construction module is used to integrate hierarchical metadata of each Word document to form a hierarchical structure of the Word document, and to build a knowledge graph of multiple Word documents in a graph database based on each hierarchical structure.
[0085] The multi-layer filtering retrieval module is used to receive user questions through the question-answering processing component to generate dynamic retrieval constraints, perform a first-stage retrieval based on a vector database to obtain a set of candidate knowledge fragments, rearrange and merge the set of candidate knowledge fragments, and perform a second-stage retrieval based on a graph database to obtain the final evidence set of the question and answer.
[0086] The question-and-answer result output module is used by the question-and-answer processing component to output the question-and-answer results based on the final evidence set of the questions and answers, thus completing the question-and-answer process for multiple Word documents.
[0087] The above description is merely an example and illustration of the structure of the present invention. Those skilled in the art can make various modifications or additions to the specific embodiments described, or use similar methods to replace them, as long as they do not deviate from the structure of the invention or exceed the scope defined by the present invention, they should all fall within the protection scope of the present invention.
Claims
1. A multi-Word document question-answering method based on knowledge graphs and RAG, characterized in that, include: The knowledge processing component receives batches of Word documents. For each Word document, a title structure tree is constructed based on a title stack. The title structure tree is then used to perform structure-aware, two-granularity block segmentation on the Word documents. The resulting block segmentation is then input into a vector database for embedding. Hierarchical metadata is integrated for each Word document to form a hierarchical structure. Based on these hierarchical structures, a knowledge graph of multiple Word documents is constructed in a graph database. The question-answering component receives user questions and generates dynamic retrieval constraints. A first-stage retrieval is performed based on the vector database to obtain a set of candidate knowledge fragments. This set of candidate knowledge fragments is then rearranged and merged. A second-stage retrieval is performed based on the graph database to obtain the final evidence set for the question and answer. The question-answering component outputs the question-answering results based on the final evidence set, completing the question-answering process for multiple Word documents.
2. The multi-Word document question answering method based on knowledge graph and RAG according to claim 1, characterized in that, Includes the following steps: The specific process of constructing a title structure tree for each Word document based on a title stack is as follows: The knowledge processing component extracts all levels of titles for each received Word document to form a title sequence. Using adjacent subheadings in the title sequence as interval boundaries, it traverses the paragraphs within each interval and parses them one by one to generate a structured node object for that interval. The structured node object of that interval is pushed onto the title stack. The structured node objects pushed onto the title stack are updated sequentially by traversing all title intervals to construct the title structure tree for each Word document. At the same time, a global unified tree for multiple Word documents is formed based on the root nodes of several title structure trees.
3. The multi-Word document question-answering method based on knowledge graph and RAG according to claim 2, characterized in that, Includes the following steps: The structure-aware dual-granularity block processing of Word documents through the title structure tree is specifically performed as follows: each child node of the title structure tree of each Word document is truncated using a set sliding window to generate each first-granularity text block, and placeholder protection and semantic boundary alignment are performed at the block boundaries; each first-granularity text block is expanded forward and backward in the original Word document context to construct the second-granularity text block to which the first-granularity text block belongs; the knowledge processing component performs block output based on the dual-granularity text blocks to obtain the dual-granularity block processing result of each Word document.
4. The multi-Word document question answering method based on knowledge graph and RAG according to claim 3, characterized in that, Includes the following steps: When the knowledge processing component performs block output based on dual-granularity text blocks, the placeholder of each first-granularity text block is replaced with the corresponding image / table text representation to obtain the dual-granularity block processing result.
5. The multi-Word document question answering method based on knowledge graph and RAG according to claim 1, characterized in that, Includes the following steps: The hierarchical structure of the Word documents specifically involves expanding the original folder directory structure of each Word document into a standard hierarchical path, which represents the hierarchical structure of the Word documents. The construction of the knowledge graph for multiple Word documents involves the following steps: During the batch writing phase of the knowledge processing component, leaf nodes for each Word document are created on the knowledge graph. Simultaneously, each level of folder directory is decomposed based on the standard hierarchical path of each Word document, and nodes are created separately, denoted as the folder directory nodes for each Word document on the knowledge graph. Parent-child relationships are generated on the knowledge graph by pairing folder directory nodes and / or leaf nodes with the same path prefix using the standard hierarchical paths of each folder directory node. Update the association attribute field of each leaf node, and regard the sibling nodes of the same leaf node or the leaf descendants of non-leaf sibling nodes as the related nodes of the same leaf node in the knowledge graph.
6. The multi-Word document question answering method based on knowledge graph and RAG according to claim 1, characterized in that, Includes the following steps: The first-stage retrieval based on the vector database is specifically performed as follows: the question-answering processing component receives the retrieval questions and answers initiated by the user, performs initial text validation on the query text input by the user, identifies the limiting information of the query text after the validation passes, and constructs the user's dynamic data access filtering conditions based on the limiting information; the query text is converted into a semantic vector representation using a vector model, and connected to the vector database, under the premise of satisfying the dynamic data access filtering conditions, the first-stage approximate nearest neighbor retrieval based on vector similarity is performed on the semantic vectors, and the knowledge fragments in the vector database corresponding to the semantic vectors with a vector similarity greater than the similarity threshold are returned as a set of candidate knowledge fragments.
7. The multi-Word document question answering method based on knowledge graph and RAG according to claim 6, characterized in that, Includes the following steps: The specific analysis process for rearranging and merging the candidate knowledge fragment set is as follows: the fine-grained semantic relevance between the query text and the candidate knowledge fragment set is reordered; the reordered results are then intelligently merged sequentially using preset fields in the knowledge fragments, and the merged candidate knowledge fragment set is denoted as the initial evidence fragment set.
8. The multi-Word document question answering method based on knowledge graph and RAG according to claim 1, characterized in that, Includes the following steps: The first-stage retrieval based on the vector database is specifically performed as follows: the question-answering processing component performs structured parsing of the query text and generates a query vector representation set based on the parsing results; the candidate document domain and / or candidate chapter domain of each Word document are determined in the vector database and denoted as the candidate semantic domain of the Word document; nearest neighbor recall is performed on knowledge fragments within the candidate semantic domain to obtain the first-stage candidate knowledge fragment set.
9. The multi-Word document question answering method based on knowledge graph and RAG according to claim 1, characterized in that, Includes the following steps: The second-stage retrieval based on the graph database is specifically performed as follows: based on the document to which the initial evidence fragment set belongs, the knowledge graph queries its associated node identifier set to construct the second-stage association completion retrieval constraint; and performs deep association retrieval in the vector database to obtain supplementary evidence fragments of the document to which the associated nodes belong, forming a supplementary evidence fragment set; the final evidence set includes the initial evidence fragment set and the supplementary evidence fragment set.
10. A multi-Word document question-answering system based on knowledge graphs and RAG, characterized in that: include: The dual-granularity segmentation module is used by the knowledge processing component to receive batches of Word documents, construct a title structure tree for each Word document based on the title stack, and perform structure-aware dual-granularity segmentation processing on the Word documents through the title structure tree. The segmentation results of each Word document are then input into the vector database for embedding. The knowledge graph construction module is used to integrate hierarchical metadata for each Word document to form a hierarchical structure of the Word documents. Based on each hierarchical structure, a knowledge graph of multiple Word documents is constructed in the graph database. The multi-layer filtering retrieval module is used by the question-answering processing component to receive user questions and generate dynamic retrieval constraints. It performs a first-stage retrieval based on a vector database to obtain a set of candidate knowledge fragments, rearranges and merges the candidate knowledge fragment set, and performs a second-stage retrieval based on a graph database to obtain the final evidence set for the question and answer. The question-and-answer result output module is used to output the question-and-answer results based on the final evidence set of the question and answer, completing the question-and-answer process for multiple Word documents.
Citation Information
Patent Citations
A Multi-Document Question Answering Retrieval Method Combining Generative Language Model and Semantic Document Graph
CN119903190B
Coarse-to-fine multi-document question and answer method based on search head
CN120353892A