Document structuring and retrieving method, electronic equipment and storage medium
By analyzing document layout and generating document nodes based on the relationships between structural elements, the problem of difficult retrieval caused by unclear document hierarchy is solved, enabling fast and accurate document retrieval.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SF TECH CO LTD
- Filing Date
- 2024-10-16
- Publication Date
- 2026-04-17
AI Technical Summary
In existing technologies, the document hierarchy is unclear during the knowledge text segmentation and transformation process, leading to retrieval difficulties.
By analyzing the layout of the document to be processed, document nodes are generated, and knowledge documents are built based on the relationships between structural elements, thus forming a structured knowledge document.
It has created a well-structured knowledge document with clear hierarchy, which facilitates fast and accurate retrieval.
Smart Images

Figure CN121880481A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data retrieval technology, specifically to a document structuring and retrieval method, electronic device, and storage medium. Background Technology
[0002] Retrieval-augmented generation (RAG) technology refers to the process of extracting information from multi-source data in a local knowledge base, such as CSV, HTML, PPTX, and DOCX files, to construct a vector database. In response to user queries, this vector database is retrieved and the results are returned to the user.
[0003] In existing technologies, vector database construction and querying typically follow these steps: document layout analysis, knowledge text segmentation, vector library generation, and query retrieval. Document layout analysis involves, for example, using libraries like python-docx to analyze the layout of docx files, python-PyMuPDF to analyze the layout of pdf files, and python-BeautifulSoup to analyze the layout of html files. Knowledge text segmentation involves splitting and storing text data, adding summaries to tabular data or storing it row-by-row, and converting image data from visual signals to text and storing it. Finally, a vector library is generated based on the obtained data, and retrieval is performed based on the user's input question.
[0004] However, during the process of knowledge text segmentation and transformation, there may be problems with unclear document hierarchy, leading to difficulties in retrieval. Summary of the Invention
[0005] Based on the defects and shortcomings of the existing technology, this application proposes a document structuring and retrieval method, electronic device and storage medium, which can generate document nodes and construct knowledge documents based on the structural elements and the correspondence between structural elements obtained from the analysis of the document layout, thereby obtaining a structured knowledge document and solving the problem of retrieval difficulties caused by unclear document hierarchy during knowledge text block conversion.
[0006] According to a first aspect of the embodiments of this application, a document structuring method is provided, including:
[0007] A layout analysis is performed on the document to be processed to obtain the layout analysis result of the document to be processed. The layout analysis result includes each structural element in the document to be processed and the relationship between each structural element.
[0008] Based on the layout analysis results, multiple document nodes are generated. There is a corresponding relationship between the document nodes and the structural elements. The document nodes store the structural elements corresponding to them, as well as the association relationships between the corresponding structural elements and other structural elements.
[0009] Based on the relationships between the various structural elements, the multiple document nodes are assembled into a knowledge document according to the target architecture, forming a structured knowledge document.
[0010] According to a second aspect of the embodiments of this application, a document structuring apparatus is provided, comprising:
[0011] The analysis module is used to perform layout analysis on the document to be processed and obtain the layout analysis results of the document to be processed. The layout analysis results include each structural element in the document to be processed and the relationship between each structural element.
[0012] The generation module is used to generate multiple document nodes based on the layout analysis results. There is a correspondence between the document nodes and the structural elements. The document nodes store the corresponding structural elements and the association relationships between the corresponding structural elements and other structural elements.
[0013] The module is used to build knowledge documents by assembling the multiple document nodes according to the target architecture based on the relationships between the various structural elements, thereby forming structured knowledge documents.
[0014] According to a third aspect of the embodiments of this application, a retrieval method is provided, characterized in that the method includes:
[0015] Receive search request;
[0016] Based on the search request, a search is performed in the knowledge base according to the target architecture to obtain search results. The knowledge base stores structured knowledge documents as described in the first aspect.
[0017] Output the search results.
[0018] According to a fourth aspect of the embodiments of this application, a retrieval device is provided, characterized in that the device comprises:
[0019] The receiving module is used to receive search requests;
[0020] The retrieval module is used to perform a retrieval in the knowledge base according to the target architecture based on the retrieval request, and obtain the retrieval results;
[0021] Output the search results.
[0022] According to a fifth aspect of the embodiments of this application, an electronic device is provided, including a memory and a processor;
[0023] The memory is connected to the processor and is used to store programs;
[0024] The processor is used to implement the document structuring method as described in the first aspect, or the retrieval method as described in the third aspect, by running a program in the memory.
[0025] According to a sixth aspect of the embodiments of this application, a storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the document structuring method as described in the first aspect, or the retrieval method as described in the third aspect.
[0026] In the aforementioned document structuring and retrieval methods, electronic devices, and storage media, based on the layout analysis results obtained from the layout analysis of the document to be processed, including the various structural elements in the document to be processed and the relationships between the structural elements, multiple document nodes corresponding to the structural elements can be generated. Each document node stores its corresponding structural element and the relationships between its corresponding structural element and other structural elements. Based on the relationships between the structural elements, the multiple document nodes are constructed into a knowledge document according to the target architecture to form a structured knowledge document, thereby realizing the structured transformation of the document to be processed and obtaining a well-structured knowledge document with clear hierarchy, which facilitates fast and accurate retrieval based on the structured knowledge document. Attached Figure Description
[0027] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0028] Figure 1 This is a flowchart illustrating a document structuring method as provided in an embodiment of this application;
[0029] Figure 2 This is a schematic diagram illustrating a node attribute as provided in an embodiment of this application;
[0030] Figure 3 This is a schematic diagram illustrating a document structuring process as provided in an embodiment of this application;
[0031] Figure 4 This is a flowchart illustrating a retrieval method proposed in an embodiment of this application;
[0032] Figure 5 This is a schematic diagram of a document structuring device proposed in an embodiment of this application;
[0033] Figure 6 This is a schematic diagram of the structure of a retrieval device proposed in an embodiment of this application;
[0034] Figure 7 This is a schematic diagram of the structure of an electronic device proposed in an embodiment of this application. Detailed Implementation
[0035] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0036] Overview
[0037] As described in the background section, existing RAG technologies typically involve retrieving and querying vector databases following steps such as document layout analysis, knowledge text segmentation, vector library generation, and query retrieval. However, the knowledge text segmentation and conversion process may result in unclear document hierarchy, leading to retrieval difficulties.
[0038] Building upon this foundation, the inventors further discovered that, based on the layout analysis results obtained from analyzing the document to be processed, including the various structural elements in the document and the relationships between these structural elements, multiple document nodes corresponding to the structural elements are generated. Each document node stores its corresponding structural element and the relationships between its corresponding structural element and other structural elements. Based on the relationships between the various structural elements, the multiple document nodes are constructed into a knowledge document according to the target architecture, forming a structured knowledge document. This achieves the structured transformation of the document to be processed, resulting in a clearly hierarchical structured knowledge document, which facilitates fast and accurate retrieval.
[0039] Based on the above concept, this specification provides a document structuring and retrieval method, which will be described exemplarily below with reference to the accompanying drawings.
[0040] Exemplary methods
[0041] Please see Figure 1 In one exemplary embodiment, a document structuring method is provided, applicable to any electronic device, such as a server. Figure 1 As shown, the document structuring method includes steps S101-S103:
[0042] S101: Perform layout analysis on the document to be processed to obtain the layout analysis results of the document to be processed.
[0043] The layout analysis results include the structural elements in the document to be processed and the relationships between these structural elements.
[0044] The document to be processed can be in formats such as html, pptx, docx, etc., and its structural elements include text, headings, tables, and images.
[0045] The relationships between structural elements refer to their positional and logical relationships. For example, consider structural elements 1 and 2. Consider their order in the document, and the fact that both structural elements 1 and 2 are headings, with structural element 2 being a subheading of the heading structural element 1.
[0046] The parser performs layout analysis on the document to be processed, obtaining the layout analysis results, namely, the text portions, headings, tables, and images of the document, and the relationships between these portions. The parser can be one of the parsers mentioned in existing technologies, such as python-docx, python-PyMuPDF, and python-BeautifulSoup. The specific parser used may vary depending on the format of the document. For a detailed introduction to layout analysis, please refer to existing technologies.
[0047] S102: Generate multiple document nodes based on the layout analysis results.
[0048] There is a correspondence between document nodes and structural elements. Document nodes store their corresponding structural elements, as well as the associations between their corresponding structural elements and other structural elements.
[0049] Based on each structural element in the document to be processed, document nodes are generated to obtain multiple document nodes, and these multiple document nodes have a corresponding relationship with the structural elements.
[0050] For example, taking a document to be processed as having structural elements 1 and 2 as examples, document node 1 is generated based on structural element 1. Document node 1 stores the content of structural element 1 and the association between structural element 1 and other structural elements, that is, the association between structural element 1 and structural element 2. Based on structural element 2, document node 2 is generated. Document node 2 stores the content of structural element 2 and the association between structural element 2 and other structural elements, that is, the association between structural element 2 and structural element 1.
[0051] In this context, document nodes store the relationships between various structural elements in the form of attribute items.
[0052] S103: Based on the relationships between various structural elements, multiple document nodes are assembled into a knowledge document according to the target architecture to form a structured knowledge document.
[0053] The structured knowledge document stores all the content of the document to be processed.
[0054] Based on the relationships between various structural elements, multiple document nodes corresponding to each structural element are used to build knowledge documents according to the target architecture, forming structured knowledge documents.
[0055] Based on the relationships between various structural elements, each structural element is constructed according to the target architecture. Then, based on the correspondence between structural elements and document nodes, structural elements located in different positions in the target architecture are replaced with their corresponding document nodes to obtain structured knowledge documents.
[0056] In this embodiment, based on the layout analysis results obtained from the layout analysis of the document to be processed, including the various structural elements in the document and the relationships between the structural elements, multiple document nodes corresponding to the structural elements are generated. Each document node stores its corresponding structural element and the relationships between its corresponding structural element and other structural elements. Based on the relationships between the structural elements, the multiple document nodes are constructed into a knowledge document according to the target architecture to form a structured knowledge document, thereby realizing the structured transformation of the document to be processed and obtaining a well-structured knowledge document with clear hierarchy, which facilitates fast and accurate retrieval based on the structured knowledge document.
[0057] In some embodiments, when generating multiple document nodes based on layout analysis results, for each structural element, a document node corresponding to that structural element is generated by combining the relationships between that structural element and other structural elements. This document node stores the structural element and the relationships between that structural element and other structural elements.
[0058] Since document nodes can store the relationships between various structural elements in the form of attribute items, when generating a document node for each structural element and combining the relationships between that structural element and other structural elements, you can first generate an empty node for each structural element, and then set the values of the attribute items of the empty nodes corresponding to each structural element based on the structural elements and the relationships between them, thus obtaining multiple document nodes.
[0059] In this case, the values of each attribute item in an empty node are empty.
[0060] In other words, an empty node is a node whose attributes are empty and that does not store any content.
[0061] Specifically, when generating the corresponding empty node for each structural element, a custom node is set for each structural element, attribute items are configured for the custom node, and the values of each attribute item are initialized to empty, thus obtaining the empty node corresponding to each structural element.
[0062] For example, taking a structural element consisting of structural element s1 and structural element s2 as an example, for structural element s1, a custom node z1 is set, and attribute items a1 and b1 are configured for the custom node z1. The values of attribute items a1 and b1 are initialized to none, resulting in an empty node j1 corresponding to structural element s1; for structural element s2, a custom node z2 is set, and attribute items a2 and b2 are configured for the custom node z2. The values of attribute items a2 and b2 are initialized to none, resulting in an empty node j2 corresponding to structural element s2.
[0063] Specifically, based on each structural element and the relationships between them, the values of the attribute items of the empty nodes corresponding to each structural element are set. When multiple document nodes are obtained, for each empty node, based on the structural element corresponding to the empty node and the relationships between the structural element corresponding to the empty node and other structural elements, the values of the attribute items of the empty node are set to obtain the corresponding document node.
[0064] Alternatively, for each structural element, based on that structural element and its relationships with other structural elements, the values of each attribute item of the corresponding empty node are set to obtain the document node corresponding to that structural element.
[0065] In this embodiment, firstly, empty nodes with empty attribute values are generated for each structural element. Then, based on each structural element and the relationships between them, the values of each attribute value of the empty node corresponding to each structural element are set, resulting in multiple document nodes. This stores the relationships between each structural element in the document nodes, so that each document node stores the smallest granularity of information in the document to be processed, that is, the structural elements in the document to be processed that cannot be further subdivided. Furthermore, based on the values of each attribute value of each document node, when searching structured knowledge documents, fast and accurate retrieval of each document node can be achieved.
[0066] In some embodiments, the attribute items include element content, child nodes, and parent nodes.
[0067] Based on each structural element and the relationships between them, the values of the attribute items of the empty nodes corresponding to each structural element are set. When multiple document nodes are obtained, the values of the element content of each empty node are set based on each structural element, and the values of the child nodes and parent nodes of each empty node are set based on the relationships between them.
[0068] Understandably, once the values of each attribute item for each empty node are set, the required document nodes can be obtained.
[0069] Specifically, when setting the value of the element content of an empty node, each structural element is set to the value of the element content of its corresponding empty node. That is, for each structural element, the structural element is set to the value of the element content of its corresponding empty node, until the value of the element content of each empty node is set.
[0070] Specifically, when setting the values of the parent and child nodes of an empty node, first determine the upper and / or lower nodes of the empty nodes corresponding to each structural element based on the relationship between the structural elements. Then, based on the upper and / or lower nodes, set the values of the parent and child nodes of the empty nodes corresponding to each structural element.
[0071] That is, for each structural element, based on the relationship between the structural element and other structural elements, the upper-level node and / or lower-level node of the empty node corresponding to the structural element are determined.
[0072] It is understandable that the root node has no parent node, and the lowest-level node has no child nodes. Therefore, some empty nodes corresponding to certain structural elements have no parent nodes, and some empty nodes corresponding to certain structural elements have no child nodes. For each structural element, based on the relationship between this structural element and other structural elements, we can determine the parent node of the empty node corresponding to this structural element, or determine the child node of the empty node corresponding to this structural element, or determine both the parent and child nodes of the empty node corresponding to this structural element.
[0073] More specifically, for each structural element, its parent structural element is determined based on its relationships with other structural elements. Then, based on its parent structural element, the empty node corresponding to that parent structural element is determined as the parent node of the empty node corresponding to that structural element.
[0074] For each structural element, based on the relationship between the structural element and other structural elements, the lower-level structural elements of the structural element are determined. Then, based on the lower-level structural elements of the structural element, the empty nodes corresponding to the lower-level structural elements are determined as the lower-level nodes of the empty nodes corresponding to the structural element.
[0075] For example, assuming structural elements include level 1 headings, level 2 headings, and level 3 headings, for level 1 headings, considering the relationships between level 1 headings and level 2 and level 3 headings, it is determined that empty nodes corresponding to level 1 headings have no parent nodes, and the parent nodes of empty nodes corresponding to level 1 headings are the empty nodes corresponding to level 2 headings; for level 2 headings, considering the relationships between level 2 headings and level 1 and level 3 headings, it is determined that the parent nodes of empty nodes corresponding to level 2 headings are the empty nodes corresponding to level 1 headings, and the parent nodes of empty nodes corresponding to level 2 headings are the empty nodes corresponding to level 3 headings; for level 3 headings, considering the relationships between level 3 headings and level 1 and level 2 headings, it is determined that the parent nodes of empty nodes corresponding to level 3 headings are the empty nodes corresponding to level 2 headings, and the parent nodes of empty nodes corresponding to level 3 headings are the empty nodes corresponding to level 3 headings.
[0076] More specifically, for each structural element, if the parent node of the empty node corresponding to the structural element is determined, and the empty node has no child node, then the information of the parent node is set to the value of the parent node of the empty node corresponding to the structural element, and the value of the child node of the empty node corresponding to the structural element is set to empty; if the child node of the empty node corresponding to the structural element is determined, and the empty node has no parent node, then the value of the parent node of the empty node corresponding to the structural element is set to empty, and the information of the child node is set to the value of the child node of the empty node corresponding to the structural element; if both the child node and the parent node of the empty node corresponding to the structural element are determined, then the information of the parent node is set to the value of the parent node of the empty node corresponding to the structural element, and the information of the child node is set to the value of the child node of the empty node corresponding to the structural element.
[0077] The information of the upper-level node and the information of the lower-level node can refer to the node's identifier.
[0078] In this embodiment, when the attribute items include element content, parent node, and child node, each structural element is set to the element content of its corresponding empty node. Based on the relationships between the structural elements, the parent and / or child nodes of the empty nodes corresponding to each structural element are first determined. Then, based on the information of the parent and / or child nodes, the values of the parent and child nodes of the empty nodes corresponding to each structural element are set. In this way, based on the various attribute items of the document node, upward and downward indexing of the node can be realized. Combined with the element content of the node, the required data can be retrieved quickly and accurately, improving retrieval efficiency.
[0079] In some embodiments, the attribute item also includes route content.
[0080] When setting the value of the attribute item of the empty node corresponding to each structural element based on each structural element and the relationship between each structural element, the value of the route content of the empty node corresponding to each structural element is also set based on each structural element and the relationship between each structural element.
[0081] Specifically, when setting the value of the route content of an empty node, based on the relationship between each structural element, all structural elements from the top-level structural element to the top-level structural elements of each structural element are determined, and all such structural elements are set as the value of the route content of each structural element.
[0082] That is, for each structural element, based on the structural element and the relationships between structural elements, determine all structural elements from the top-level structural element to the top-level structural element of the structural element, and set all of these structural elements to the value of the routing content of the structural element.
[0083] In other words, for each empty node, based on the relationship between various structural elements, that is, the hierarchical relationship between various empty nodes, the routing node of the empty node is determined, and the structural element corresponding to the routing node is set to the value of the routing content of the empty node.
[0084] The routing nodes for an empty node include all nodes from the root node to the parent node of that empty node.
[0085] For example, taking a structural element that includes a first-level heading, a second-level heading, and a third-level heading as an example, for the empty node corresponding to the third-level heading, based on the association relationship between the first-level, second-level, and third-level headings, that is, the hierarchical relationship between the empty nodes corresponding to the first-level, second-level, and third-level headings, the nodes corresponding to the first-level and second-level headings are determined as the routing nodes of the empty node, and the structural elements corresponding to the routing nodes, namely the first-level and second-level headings, are set as the routing content of the empty node.
[0086] Alternatively, after determining the routing node for an empty node, set the summary of the structure element corresponding to the routing node to the value of the routing content of the empty node.
[0087] Generally, routing content can be determined in a top-down manner, that is, from the top-level node to the bottom-level node, the routing content of each node is determined level by level, which facilitates the implementation of top-down indexing function based on the routing content and the performance of top-down retrieval.
[0088] In this embodiment, by setting the values of each attribute item of each empty node, each document node is obtained. The attribute items also contain routing content. Then, for each empty node corresponding to a structural element, based on the relationships between structural elements, the routing node corresponding to each empty node is determined, including all nodes from the root node to the parent node of the empty node. The structural element corresponding to the routing node is set to the value of the routing content of that empty node, or the summary of the structural element corresponding to the routing node is set to the value of the routing content of the empty node. In this way, since the document node stores the content of all structural elements from the root node to that document node, the question the user is searching for might be a subheading of a document, and the answer to the question is located in the content under that subheading. During retrieval, based on the routing content stored in the document node, the answer to the question can be found quickly and accurately, achieving fast and accurate retrieval and improving retrieval efficiency.
[0089] In some embodiments, the attribute item also includes a summary.
[0090] When setting the attribute values of empty nodes corresponding to each structural element based on each structural element and the relationships between them, the summary values of the empty nodes corresponding to each structural element are also set based on each structural element and the relationships between them.
[0091] Specifically, when setting the value of the summary of each empty node, the value of the summary of each empty node is set based on the structure element corresponding to each empty node.
[0092] That is, for each empty node, the value of the summary of the empty node is set based on the structure element corresponding to the empty node.
[0093] Specifically, for each empty node, a summary is extracted from the corresponding structuring element, and the extracted summary is set as the value of the summary of the empty node.
[0094] More specifically, based on a multimodal model, a summary can be extracted from the content of the structural element corresponding to an empty node to obtain a summary of that structural element.
[0095] Generally, the abstract can be determined in a bottom-up manner, that is, from the lowest level node to the highest level node, the abstract of each node is determined level by level.
[0096] In this embodiment, the attribute item also includes a summary. For each empty node, a summary is extracted from the corresponding structural element based on a multimodal model, and the extracted summary is set as the summary of the empty node. This effectively improves the understanding of structured data such as tables during document structuring, thereby enabling quick and accurate retrieval of the required answers when searching structured knowledge documents obtained from document structuring. Furthermore, summary extraction using a multimodal model allows for automatic summary extraction, effectively saving labor costs.
[0097] In some embodiments, the summary of each empty node can be set first, and then the routing content of each empty node can be set based on the summary of each empty node and the routing node of each empty node.
[0098] In some embodiments, the attribute item also includes the element type, i.e., the data type of the structure element.
[0099] When setting the value of the attribute item of the empty node corresponding to each structural element based on each structural element and the relationship between each structural element, the value of the element type of the empty node corresponding to each structural element is also set based on the data type of each structural element.
[0100] Specifically, the data type of each structure element is set to the value of the element type of the corresponding empty node.
[0101] That is, for each structural element, the data type of the structural element is set to the value of the element type of the corresponding empty node.
[0102] In other words, the element type of an empty node is used to record the data type of the data / structure elements stored in that empty node.
[0103] For example, the data type of a structural element can be, for instance, text paragraphs, images, tables, and headings, which can be further subdivided into first-level headings, second-level headings, and so on.
[0104] In this embodiment, the attribute item also includes element type, setting the data type of each structural element to the value of the element type of the corresponding empty node. This allows for appropriate data processing when setting attributes such as summary for document nodes, resulting in accurate attribute values. Furthermore, when searching the knowledge base formed from structured knowledge documents, accurate and fast retrieval is achieved based on element type.
[0105] In some embodiments, when determining the summary of the empty node corresponding to each structural element, a summary can be extracted from each structural element based on the data type of each structural element, and the extracted summary can be used as the summary of the empty node.
[0106] In some embodiments, when each structural element is set as the element content of its corresponding empty node, the text and other content in the structural element can be stored in the form of different attribute items, including text element and sent to text element.
[0107] Other content refers to the content in the structural elements other than text, such as images.
[0108] For example, the structure element includes the text "The system structure is as follows". Figure 1 As shown: "and taking image a as an example, it can be determined that image a is the "mentioned in the text" Figure 1 The system structure is as follows: (The text within this structure element is missing from the original text.) Figure 1 As shown: "", set to the value of the text element of the empty node corresponding to this struct element, and set the image 'a' in this struct element to the value of the non-text element of the empty node corresponding to this struct element.
[0109] In this embodiment, text and non-text elements in the structure element are stored separately using different attribute items to obtain document nodes. This allows for rapid retrieval of document content based on the text and non-text elements within these document nodes, achieving fast and accurate retrieval and improving retrieval efficiency.
[0110] For example, such as Figure 2As shown, the document node attributes designed in this embodiment include parent, children, type, text, others, summary, and context. Here, parent represents the parent node, children represent child nodes, type represents the element type, text represents text elements, others represent non-text elements, summary represents a summary, and context represents the route content. The functions of each attribute are as follows: parent points to the parent node, children points to child nodes, type records the node's storage type, text stores text information, others stores non-text information, summary provides a node summary, and context records the content of the route node.
[0111] The node storage type can be p, img, table, h, etc., where p represents paragraph type, img represents image type, table represents table type, and h represents heading. Specifically, h can be divided into h1, h2, etc., where h1 represents first-level heading and h2 represents second-level heading.
[0112] The text information stored in `text` can be, for example, the text content of the first-level heading represented by `h1`, while the non-text information stored in `others` can be, for example, images.
[0113] Additionally, among these, parent, children, ype, text, summary, and context are required attributes, while tothers is optional. Of course, the specific requirements for each attribute may vary depending on the actual needs.
[0114] In some embodiments, based on the relationships between various structural elements, multiple document nodes are assembled into a knowledge document according to the target architecture to form a structured knowledge document.
[0115] There can be multiple target structures. Based on the relationships between the various structural elements, multiple document nodes are used to build knowledge documents according to different target architectures, resulting in different structured knowledge documents.
[0116] Specifically, the target structure includes a first target structure and a second target structure. Then, based on the relationships between the various structural elements, and according to the first and second target architectures, knowledge documents are constructed from multiple document nodes to form a first structured knowledge document and a second structured knowledge document.
[0117] The first structured knowledge document is a structured document formed by building knowledge documents from multiple document nodes according to the first target architecture, and the second structured knowledge document is a structured document formed by building knowledge documents from multiple document nodes according to the second target architecture.
[0118] For example, the first target architecture is a flat architecture, and the second target structure is a tree architecture.
[0119] When building a knowledge document from multiple document nodes according to the first target architecture, namely the flat architecture, the root node of these multiple document nodes is determined based on the parent and child nodes in the attribute items of the multiple document nodes. All other nodes are regarded as the lower-level nodes of the root node. The knowledge document is built from these multiple document nodes according to the flat architecture to obtain the first structured knowledge document.
[0120] When constructing knowledge documents for multiple document nodes according to the second target architecture, namely the tree architecture, the knowledge documents are constructed based on the parent and child nodes in the attribute items of multiple document nodes, and the second structured knowledge document is obtained.
[0121] In this embodiment, based on the relationships between various structural elements, knowledge documents are constructed from multiple document nodes according to a first target architecture and a second target architecture, forming a first structured knowledge document and a second structured knowledge document. The first target architecture is a flat structure, while the second target architecture is a tree structure. By constructing knowledge documents based on multiple different architectures, multiple structured knowledge documents with different architectures can be obtained. This facilitates the selection of a more suitable structured knowledge document based on business needs during retrieval, allowing for the retrieval of the content stored in that structured knowledge document, thereby quickly and accurately meeting retrieval requirements and improving retrieval efficiency.
[0122] Since the large amount of content stored in a document node may reduce retrieval efficiency, increase retrieval time, and reduce the accuracy of retrieval results, in order to ensure retrieval efficiency, reduce retrieval time, and improve retrieval accuracy, in some embodiments, based on the relationship between various structural elements, before building a knowledge document by multiple document nodes according to the target structure, it can be determined whether to split the document node based on whether the data length of the structural elements corresponding to each document node exceeds the preset length, that is, whether the data length of the structural elements stored in each document node exceeds the preset length.
[0123] Specifically, for each document node, it is determined whether the data length of the structure element corresponding to the document node exceeds the preset length, and based on whether the data length of the structure element corresponding to the document node exceeds the preset length, it is determined whether to split the document node.
[0124] If the data length of the structural element corresponding to the document node exceeds the preset length, then the document node is split and at least two new document nodes are generated.
[0125] Correspondingly, if not, that is, if the data length of the structural element corresponding to the document node does not exceed the preset length, then the document node will not be split.
[0126] More specifically, when splitting a document node and regenerating at least two document nodes, the structural element corresponding to the document node is split into at least two child elements, and at least two document nodes are regenerated based on these at least two child elements.
[0127] Among them, at least two document nodes and at least two child elements respectively store at least two child elements.
[0128] For example, if a document node stores a large amount of table content, such as 3000 rows, which exceeds the preset number of 100 rows, the document node is split according to the preset number of 100 rows. The table stored in the document node is split into 30 child elements according to the preset number of rows, and 30 new document nodes are generated based on these 30 child elements.
[0129] Understandably, the various attribute items of these 30 regenerated document nodes, such as summaries and route content, can be regenerated based on their stored child elements.
[0130] In this embodiment, for each document node, it is determined whether the data length of the structure element corresponding to the document node exceeds a preset length. If it exceeds the preset length, the structure element corresponding to the document node is split into at least two sub-elements, and at least two document nodes corresponding to these at least two sub-elements are regenerated. In this way, after generating a structured knowledge document based on the final document nodes, fast retrieval can be performed based on the content of the elements stored in each document node, avoiding data loss and ensuring the accuracy of the retrieval.
[0131] In some embodiments, at least two document nodes with limited storage content can be merged to generate a new document node.
[0132] For each document node, determine whether the data length of the structure element corresponding to the document node does not exceed the minimum length, and determine whether to merge the document nodes based on whether the data length of the structure element corresponding to the document node exceeds the minimum length, as well as the parent node and other attribute items of the document node.
[0133] If the document node is adjacent to other document nodes whose data length does not exceed the minimum length, then the document node is merged with other document nodes whose data length does not exceed the minimum length to obtain a new document node.
[0134] In this way, merging document nodes under the same parent node that store less data can reduce the number of document nodes and achieve fast and accurate document retrieval.
[0135] For example, a document structuring process can be as follows: Figure 3 As shown, a suitable parser (python-docx, PyMuPDF, BeautifulSoup, etc.) is first used to parse various documents such as .html, .pdf, .csv, and .docx (i.e., HTML documents, PDF documents, CSV documents, docx documents, etc.). The document layout is analyzed into text parts, heading parts, table parts, and image parts (i.e., the above structural elements). Each part of the document is stored using a node, which is a custom node that must contain attributes such as parent and children to enable upward and downward indexing. The node also needs to contain a type attribute, etc. See details. Figure 2The context and summary attributes can be populated in the node semantic enhancement section. Then, each node is constructed using both flat and hierarchical tree architectures, building them from top to bottom and bottom to top, forming a node tree with both flat (html_flat_tree, ..., pdf_flat_tree, etc.) and hierarchical (html_hlerarchical_tree, ..., pdf_hlerarchical_tree, etc.) structures. Next, node semantic enhancement is performed on each node, extracting the route content from the root node to the current node (context_from_top) and the summary of the corresponding part of each node (summary_from_bottom), and populating the context and summary attributes. Information is used, for example, for image nodes, a multimodal large model is used for image understanding, converting image information into text information, which is then filled into the summary attribute. The context attribute stores information about the text of all nodes traversed from the root node to the current node. This information helps RAG achieve more accurate top-down retrieval. Finally, chunks are generated. Each node is traversed again. If there are nodes with a lot of content, a splitting operation is performed to obtain table chunks (i.e., table_text_chunk) and image chunks (i.e., img_text_chunk). For example, if a table has a lot of content, it can be split into several sub-tables according to certain rules and stored in several nodes. If there are nodes with less content, a merging operation is performed, merging adjacent nodes with less content and the same parent node. During this process, the summary and context can be regenerated as needed. Finally, a node tree, i.e., a structured knowledge document, is generated, thereby clearly and concisely managing the massive knowledge base for better retrieval and querying.
[0136] Please see Figure 4 In one exemplary embodiment, a retrieval method is provided, applied to any electronic device capable of communicating with an electronic device performing the document structuring method described above. For example... Figure 4 As shown, the retrieval method includes steps S401-S403.
[0137] S401: Receive retrieval request.
[0138] In response to the question entered by the user, a search request is generated.
[0139] The search request includes a question entered by the user, which is used to request a search of the knowledge base to obtain the answer to the question.
[0140] S402: Based on the search request, perform a search in the knowledge base according to the target architecture to obtain the search results.
[0141] The knowledge base stores structured knowledge documents obtained by structuring the documents to be processed through the above embodiments.
[0142] Based on the search request, the structured knowledge documents in the knowledge base are searched according to the target architecture to obtain the search results.
[0143] The target architecture refers to the architecture followed when building the structured knowledge documents in the knowledge base, including the first target architecture and / or the second target architecture. Correspondingly, the structured knowledge documents include the first structured knowledge document and / or the second structured knowledge document.
[0144] Based on the retrieval request, the first structured knowledge document and / or the second structured knowledge document in the knowledge base are retrieved according to the first target architecture and / or the second target architecture to obtain the retrieval results.
[0145] Specifically, based on the search request, the first structured knowledge document or the second structured knowledge document in the knowledge base is searched according to the first target architecture or the second target architecture to obtain search results. Alternatively, based on the search request, the first structured knowledge document and the second structured knowledge document in the knowledge base are searched according to the first target architecture and the second target architecture respectively to obtain first search results and second search results. The first search results and the second search results are then deduplicated and merged to obtain the final search results required.
[0146] Alternatively, based on the search request and in conjunction with actual business needs, the structured knowledge documents in the knowledge base can be searched according to the first target architecture and / or the second target architecture to obtain the search results.
[0147] The first target architecture is, for example, a flat architecture, and the second target architecture is, for example, a tree architecture.
[0148] If the document structure involved in a certain business is relatively simple and flat, then based on the search request and combined with the actual business needs of the business, the first structured knowledge document in the knowledge base can be searched according to the first target architecture, namely the flat architecture, to obtain the search results.
[0149] If the document structure involved in a certain business is relatively complex and has multiple levels, then based on the search request and combined with the actual business needs of the business, the second structured knowledge documents in the knowledge base can be searched according to the first target architecture, namely the tree architecture, to obtain the search results.
[0150] If a business involves documents that include both simple, flat documents and complex, multi-level documents, then based on the search request and the actual business requirements, the first and second structured knowledge documents in the knowledge base can be searched according to the first and second target architectures, respectively, to obtain the first and second search results. The first and second search results are then deduplicated and merged to obtain the final required search results.
[0151] Of course, depending on the actual needs, a variety of different target architectures can be selected for retrieval.
[0152] In addition, the search results are the answers to the questions entered by the user, retrieved from the knowledge base.
[0153] S403: Output search results.
[0154] Optionally, the search results can be output and displayed so that users can quickly understand the answer to their query.
[0155] Exemplary device
[0156] like Figure 5 As shown in the figure, this application embodiment also provides a document structuring device, including an analysis module 501, a generation module 502, and a building module 503.
[0157] in,
[0158] Analysis module 501 is used to perform layout analysis on the document to be processed and obtain the layout analysis result of the document to be processed. The layout analysis result includes each structural element in the document to be processed and the relationship between each structural element.
[0159] The generation module 502 is used to generate multiple document nodes based on the layout analysis results. There is a correspondence between the document nodes and the structural elements. The document nodes store the structural elements corresponding to them, as well as the association relationships between the corresponding structural elements and other structural elements.
[0160] The module 503 is used to build a knowledge document by assembling the multiple document nodes according to the target architecture based on the relationship between the various structural elements, thereby forming a structured knowledge document.
[0161] The document structuring apparatus provided in this embodiment belongs to the same concept as the document structuring method provided in the above embodiments of this application. It can execute the method provided in any of the above embodiments of this application and has the corresponding functional modules and beneficial effects of the method. Technical details not described in detail in this embodiment can be found in the specific processing content of the document structuring method provided in the above embodiments of this application, and will not be repeated here.
[0162] The functions implemented by the analysis module 501, generation module 502 and construction module 503 can be implemented by the same or different processors calling software, and this application embodiment does not limit this.
[0163] like Figure 6 As shown in the figure, this application embodiment also provides a retrieval device, including a receiving module 601, a retrieval module 602, and an output module 603.
[0164] in,
[0165] Receiver module 601 is used to receive retrieval requests;
[0166] The retrieval module 602 is used to perform a retrieval in the knowledge base according to the target architecture based on the retrieval request, and obtain the retrieval results. The knowledge base stores the structured knowledge documents mentioned above.
[0167] Output module 603 is used to output the search results.
[0168] The retrieval device provided in this embodiment belongs to the same application concept as the document structuring method and retrieval method provided in the above embodiments of this application. It can execute the methods provided in any of the above embodiments of this application and has the corresponding functional modules and beneficial effects of the method execution. Technical details not described in detail in this embodiment can be found in the specific processing content of the retrieval method provided in the above embodiments of this application, and will not be repeated here.
[0169] The functions implemented by the receiving module 601, the retrieval module 602, and the output module 603 described above can be implemented by the same or different processors calling software, and this application embodiment does not limit this.
[0170] Exemplary electronic devices
[0171] Another embodiment of this application also provides an electronic device, see [link to relevant documentation] Figure 7 As shown, the electronic device includes a memory 700 and a processor 710.
[0172] The memory 700 is connected to the processor 710 and is used to store programs;
[0173] The processor 710 is configured to implement the document structuring and retrieval method disclosed in any of the above embodiments by running the program stored in the memory 700.
[0174] Specifically, the electronic device may also include: a bus, a communication interface 720, an input device 730, and an output device 740.
[0175] The processor 710, memory 700, communication interface 720, input device 730, and output device 740 are interconnected via a bus. Among them:
[0176] A bus can include a pathway for transmitting information between various components of a computer system.
[0177] The processor 710 can be a general-purpose processor, such as a general-purpose central processing unit (CPU), a microprocessor, etc., or an application-specific integrated circuit (ASIC), or one or more integrated circuits used to control the execution of the program of the present application. It can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0178] The processor 710 may include a main processor, as well as a baseband chip, modem, etc.
[0179] The memory 700 stores a program that executes the technical solution of this application, and may also store an operating system and other key business functions. Specifically, the program may include program code, which includes computer operation instructions. More specifically, the memory 700 may include read-only memory (ROM), other types of static storage devices that can store static information and instructions, random access memory (RAM), other types of dynamic storage devices that can store information and instructions, disk storage, flash memory, etc.
[0180] Input device 730 may include a device for receiving data and information input by a user, such as a keyboard, mouse, camera, scanner, light pen, voice input device, touch screen, pedometer, or gravity sensor.
[0181] Output device 740 may include devices that allow information to be output to a user, such as a display screen, printer, speaker, etc.
[0182] The communication interface 720 may include a device that uses any transceiver to communicate with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc.
[0183] The processor 710 executes the program stored in the memory 700 and calls other devices, which can be used to implement the various steps of any of the document structuring and retrieval methods provided in the above embodiments of this application.
[0184] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the electronic device to which the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.
[0185] This application also proposes a chip including a processor and a data interface. The processor reads and runs a program stored in a memory through the data interface to execute the document structuring and retrieval method described in any of the above embodiments. For details of the processing and its beneficial effects, please refer to the embodiments of the document structuring and retrieval method described above.
[0186] In addition to the methods and apparatus described above, embodiments of this application provide a computer program product comprising computer program instructions that, when executed by a processor, cause the processor to perform the steps of the document structuring and retrieval methods according to various embodiments of this application as described in the "Exemplary Methods" section of this specification.
[0187] The computer program product can be written in any combination of one or more programming languages to perform the operations of the embodiments of this application. The programming languages include object-oriented programming languages such as Java and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0188] Furthermore, embodiments of this application also propose a storage medium storing a computer program, which is executed by a processor in the document structuring and retrieval methods according to various embodiments of this application described in the "Exemplary Methods" section above.
[0189] The basic principles of the present invention have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in the present invention are merely examples and not limitations, and should not be considered as essential features of each embodiment of the present invention. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the present invention to the necessity of employing the aforementioned specific details.
[0190] The block diagrams of devices, apparatuses, devices, and systems involved in this invention are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As those skilled in the art will recognize, these devices, apparatuses, devices, and systems can be connected, arranged, and configured in any manner. Words such as “comprising,” “including,” “having,” etc., are open-ended terms meaning “including but not limited to,” and are used interchangeably with them. The terms “or” and “and” as used herein refer to the terms “and / or,” and are used interchangeably with them unless the context clearly indicates otherwise. The term “such as” as used herein refers to the phrase “such as but not limited to,” and is used interchangeably with it.
[0191] It should also be noted that in the apparatus, device, and method of the present invention, the components or steps can be disassembled and / or recombined. These disassemblies and / or recombinations should be considered as equivalent solutions of the present invention.
[0192] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the invention. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein can be applied to other aspects without departing from the scope of the invention. Therefore, the invention is not intended to be limited to the aspects shown herein, but rather to be carried out within the widest scope consistent with the principles and novel features disclosed herein.
[0193] It should be understood that the qualifying terms "first", "second", "third", "fourth", "fifth" and "sixth" used in the description of the embodiments of the present invention are only used to more clearly illustrate the technical solutions and are not intended to limit the scope of protection of the present invention.
[0194] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of the invention to the forms disclosed herein. Although numerous exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations therein.
Claims
1. A document structuring method, characterized in that, The method includes: A layout analysis is performed on the document to be processed to obtain the layout analysis result of the document to be processed. The layout analysis result includes each structural element in the document to be processed and the relationship between each structural element. Based on the layout analysis results, multiple document nodes are generated. There is a corresponding relationship between the document nodes and the structural elements. The document nodes store the structural elements corresponding to them, as well as the association relationships between the corresponding structural elements and other structural elements. Based on the relationships between the various structural elements, the multiple document nodes are assembled into a knowledge document according to the target architecture, forming a structured knowledge document.
2. The document structuring method according to claim 1, characterized in that, Based on the layout analysis results, multiple document nodes are generated, including: For each structural element, a corresponding empty node is generated, and the values of each attribute item of the empty node are empty; Based on the various structural elements and the relationships between them, the values of the attribute items of the empty nodes corresponding to the various structural elements are set to obtain the multiple document nodes.
3. The document structuring method according to claim 2, characterized in that, The attribute items include element content, child nodes, and parent nodes; Based on the various structural elements and the relationships between them, the values of the attribute items of the empty nodes corresponding to each structural element are set to obtain the multiple document nodes, including: Each of the structural elements is set to the element content of the corresponding empty node; Based on the relationships between the various structural elements, the upper-level nodes and / or lower-level nodes of the empty nodes corresponding to each structural element are determined. Based on the information of the upper-level nodes and / or the lower-level nodes, the values of the parent node and the child node of the empty nodes corresponding to each structural element are set.
4. The document structuring method according to claim 3, characterized in that, The attribute items also include route content. The step of setting the value of the attribute item corresponding to the empty node of each structural element based on the structural elements and the relationships between them to obtain the multiple document nodes also includes: For each empty node, Based on the relationships between the various structural elements, the routing nodes of the empty node are determined, and the routing nodes include all nodes from the root node to the parent node of the empty node; Set the structure element corresponding to the routing node to the routing content of the empty node, or set the summary of the structure element corresponding to the routing node to the routing content of the empty node.
5. The document structuring method according to claim 3, characterized in that, The attribute items also include a summary. The step of setting the value of the attribute item corresponding to the empty node of each structural element based on the structural elements and the relationships between them to obtain the multiple document nodes further includes: For each empty node, based on a multimodal model, a summary is extracted from the structuring element corresponding to the empty node, and the extracted summary is set as the summary of the empty node.
6. The document structuring method according to claim 3, characterized in that, The attribute items also include element type. The process of setting the value of the attribute item corresponding to the empty node of each structural element based on the structural elements and the relationships between them, to obtain the multiple document nodes, includes: Set the data type of each structure element to the element type of the empty node corresponding to each structure element.
7. The document structuring method according to claim 1, characterized in that, Based on the relationships between the various structural elements, the multiple document nodes are constructed into a structured knowledge document according to the target architecture, including: Based on the relationships between the various structural elements, knowledge documents are constructed for the multiple document nodes according to the first target architecture and the second target architecture, forming a first structured knowledge document and a second structured knowledge document. The first target architecture is a flat architecture, and the second target structure is a tree architecture.
8. The document structuring method according to any one of claims 1-7, characterized in that, Before constructing the knowledge document from the multiple document nodes according to the target architecture based on the relationships between the various structural elements, the method further includes: For each document node, Determine whether the data length of the structural element corresponding to the document node exceeds a preset length; If so, the structural element corresponding to the document node is split into at least two sub-elements, and at least two document nodes are regenerated based on the at least two sub-elements.
9. A retrieval method, characterized in that, The method includes: Receive search request; Based on the search request, a search is performed in the knowledge base according to the target architecture to obtain search results. The knowledge base stores structured knowledge documents as described in any one of claims 1-8. Output the search results.
10. An electronic device, characterized in that, Including memory and processor; The memory is connected to the processor and is used to store programs; The processor is configured to implement the document structuring method as described in any one of claims 1 to 8, or the retrieval method as described in claim 9, by running a program in the memory.
11. A storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the document structuring method as described in any one of claims 1 to 8, or the retrieval method as described in claim 9.