Knowledge retrieval method, system and equipment based on document structure context enhancement and medium
By performing structural analysis and formatting of multi-source heterogeneous structured documents, building a document directory tree and dividing knowledge blocks to form enhanced knowledge blocks, and using the embedding model for vectorization, the problem of document context information loss in the existing technology is solved, and efficient and accurate multi-document question-and-answer retrieval is achieved.
Patent Information
- Application Number
- CN202411857575.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-04-11
AI Technical Summary
When existing search enhancement generation technologies deal with large amounts of documents with similar content or complex content, they are prone to destroy the context, resulting in the retrieved information blocking lacking sufficient background information and unable to effectively utilize the structured information of the document.
By performing unified structural analysis and formatting of multi-source heterogeneous structured documents, extracting metadata and hierarchical structure information, building document directory trees and chapter associations, dividing chapter paragraphs into knowledge blocks, and adding document titles and previous titles as prefixes in front of the knowledge blocks to form enhanced knowledge blocks. The embedding model is used to vectorize the enhanced knowledge blocks and perform multi-layer searches in the knowledge base.
It realizes the low-cost and efficient use of document structured information, improves the retrieval efficiency and accuracy of multi-document Q&A and complex documents, and avoids the loss of context information.
Smart Images

Figure CN119807359A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of retrieval enhancement technology, and in particular to a knowledge retrieval method, system, device and medium based on document structure context enhancement. Background Art
[0002] In scenarios such as knowledge base question answering, Retrieval Enhanced Generation (RAG) has become one of the most popular LLM application paradigms. Providing LLM with complete and accurate context information is the direction of many RAG technologies. Traditional RAG solutions represent documents as unstructured text blocks, but when processing large amounts of documents with similar or complex content, the context will be destroyed, resulting in the lack of sufficient background information in the retrieved information blocks, and the context is often lost, which makes the system unable to retrieve relevant information from the knowledge base. How to better retain context information and use the internal structure information of the document to improve the accuracy and efficiency of retrieval is a key issue.
[0003] There are already some solutions, such as the RAPTOR method, which uses embedding, clustering and summary text modules to build a tree structure with different summary layers from bottom to top. This method allows the model to retrieve information from this tree during reasoning and achieve integration across different abstract layers of text. Contextual RAG adds an explanatory contextual fragment to each fragment in the document to give each document fragment a richer context. However, these methods usually need to first input the entire document into the LLM to generate a document summary text, which requires a high context processing length of the LLM. Using public LLM services is very costly. Privately deployed LLMs usually do not have such a long context processing capability. HiQA proposes a hierarchical context-enhanced RAG framework for multi-document question answering to solve the retrieval accuracy problem in multi-document question answering. Its feature is that it uses a cascaded document structure to perform text enhancement during data processing, extracts hierarchical metadata from the document, and cascades it to each chapter to form an enhanced document fragment. However, when this method processes documents with a deeper structural level, the effective information of the document fragment will become less, mainly because the text length that the currently used embedding model can process is limited.
[0004] Therefore, how to utilize the structured information of documents more efficiently and at a lower cost to solve multi-document question and answer problems and process documents with complex hierarchical structures requires comprehensive consideration of the overall process of RAG for redesign and implementation. Summary of the invention
[0005] The purpose of the present invention is to overcome the defects of the above-mentioned prior art and to provide a knowledge retrieval method, system, device and medium based on document structure context enhancement.
[0006] The purpose of the present invention can be achieved by the following technical solutions:
[0007] According to a first aspect of the present invention, a knowledge retrieval method based on document structure context enhancement is provided, the method comprising the following steps:
[0008] Document parsing: Obtain multi-source heterogeneous structured documents and perform unified structural parsing and formatting, extracting metadata and hierarchical information of the documents;
[0009] Knowledge extraction: Based on the extracted document metadata and hierarchical information, the document directory tree and chapter association are constructed, and the chapter paragraphs are divided into knowledge blocks;
[0010] Knowledge enhancement: Perform hierarchical context enhancement on knowledge blocks according to the document directory tree to form enhanced knowledge blocks;
[0011] Knowledge storage: Use the embedding model to vectorize the enhanced knowledge blocks, and store the enhanced knowledge blocks and their vectorization results in the knowledge base;
[0012] Knowledge retrieval: Perform multi-channel and multi-layer retrieval in the knowledge base based on the user query text to recall relevant knowledge blocks;
[0013] Knowledge filtering: Sort the recalled knowledge blocks, extract the most relevant knowledge blocks, and obtain the retrieval results.
[0014] As a preferred technical solution, the document parsing is specifically: parsing different types of multi-source heterogeneous structured documents with a table of contents, and generating formatted parsing results in Markdown form through one or more of layout detection, formula detection, formula recognition, and optical character recognition models.
[0015] As a preferred technical solution, the knowledge extraction is specifically as follows: detecting the document parsing results, extracting the document title and chapter titles, and forming a document directory tree; segmenting the non-title paragraphs into blocks, and dividing the non-title paragraphs into multiple knowledge blocks by using fixed-size segmentation, segmentation based on sentences, or segmentation based on semantic similarity.
[0016] As a preferred technical solution, the knowledge enhancement is specifically as follows: adding the document title text and the previous title text corresponding to the knowledge block in sequence as prefixes before the original knowledge block to form an enhanced knowledge block.
[0017] As a preferred technical solution, the knowledge storage is specifically as follows: using a pre-trained embedding model to process the enhanced knowledge block to generate a corresponding vectorized representation, and using ElasticSearch to store the enhanced knowledge block and its vectorized representation together in the knowledge base.
[0018] As a preferred technical solution, the knowledge retrieval is specifically as follows: based on the user query text, keyword retrieval and vector retrieval are used to recall the first retrieval result set and the second retrieval result set respectively from the knowledge base, and for each knowledge block text in the first retrieval result set and the second retrieval result set, the most relevant multiple knowledge blocks are recalled through vector retrieval to form a third retrieval result set.
[0019] As a preferred technical solution, the knowledge filtering is specifically as follows: for the first, second and third search result sets of multi-way and multi-layer retrieval recall, a recursive ranking fusion algorithm is used to merge the search results and perform rough sorting; the results of the rough sorting are filtered out with the most relevant knowledge blocks through a pre-trained re-ranking model as the final search results.
[0020] According to a second aspect of the present invention, there is provided a knowledge retrieval system based on document structure context enhancement, comprising:
[0021] Document parsing module: obtains multi-source heterogeneous structured documents and performs unified structural parsing and formatting, extracting metadata and hierarchical structure information of the documents;
[0022] Knowledge extraction module: constructs the document directory tree and chapter associations based on the extracted document metadata and hierarchical structure information, and divides the chapter paragraphs into knowledge blocks;
[0023] Knowledge enhancement module: performs hierarchical context enhancement on knowledge blocks according to the document directory tree to form enhanced knowledge blocks;
[0024] Knowledge storage module: Use the embedding model to vectorize the enhanced knowledge blocks, and store the enhanced knowledge blocks and their vectorization results in the knowledge base;
[0025] Knowledge retrieval module: performs multi-channel and multi-layer retrieval in the knowledge base based on the user query text to recall relevant knowledge blocks;
[0026] Knowledge filtering module: sort the recalled knowledge blocks, extract the most relevant knowledge blocks, and obtain the retrieval results.
[0027] According to a third aspect of the present invention, there is provided an electronic device, comprising a memory and a processor, wherein a computer program is stored in the memory, and the method described above is implemented when the processor executes the program.
[0028] According to a fourth aspect of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, wherein the program implements the method described when executed by a processor.
[0029] Compared with the prior art, the present invention has the following beneficial effects:
[0030] The present invention realizes low-cost and efficient use of document structured information by collaboratively designing hierarchical context enhancement and multi-path and multi-layer retrieval in the retrieval enhancement generation process, thereby improving the retrieval efficiency and accuracy of multi-document question and answer and complex documents. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 is a flow chart of the method of the present invention;
[0032] Figure 2 It is a schematic diagram of hierarchical context enhancement of the present invention;
[0033] Figure 3 It is a schematic diagram of the multi-path and multi-layer retrieval of the present invention. DETAILED DESCRIPTION
[0034] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0035] Unless otherwise defined, the technical terms or scientific terms involved in this application should be understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the" and the like involved in this application do not indicate a quantitative limitation, and may represent the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects before and after are in an "or" relationship. The terms "first", "second", "third", etc. involved in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0036] This embodiment first provides a knowledge retrieval method based on document structure context enhancement, which includes two processes: knowledge base construction and knowledge retrieval. The knowledge base construction process is the process of converting documents into knowledge and storing them in the knowledge base (including the following steps S1-S4), and the knowledge retrieval process is the process of retrieving relevant knowledge from the knowledge base based on user queries (including the following steps S5-S6). Figure 1 As shown, the method comprises the following steps:
[0037] S1, document parsing: obtain multi-source heterogeneous structured documents and perform unified structural parsing and formatting, and extract the metadata and hierarchical information of the documents.
[0038] Parse different types of multi-source heterogeneous structured documents with catalogs (such as internal corporate reports, legal documents, scientific research papers, etc.). The main format of the document is word or pdf. Generate formatted parsing results in Markdown format through one or more of layout detection, formula detection, formula recognition, and optical character recognition models.
[0039] S2, knowledge extraction: Based on the extracted document metadata and hierarchical information, the document directory tree and chapter associations are constructed, and the chapter paragraphs are divided into knowledge blocks.
[0040] The document parsing results are tested to extract the document title and chapter titles to form a document directory tree; non-title paragraphs are divided into blocks and segmented into multiple knowledge blocks using fixed-size segmentation, sentence segmentation, or semantic similarity segmentation.
[0041] S3, knowledge enhancement: hierarchical context enhancement of knowledge blocks is performed according to the document directory tree to form enhanced knowledge blocks.
[0042] In this embodiment, Figure 2 As shown, the document title text and the previous title text corresponding to the knowledge block are added as prefixes in sequence before the original knowledge block to form an enhanced knowledge block. For example, for knowledge block 1, its previous title is title 2.2.1, so the enhanced knowledge block 1 corresponding to knowledge block 1 is expressed as: document title-title 2.2.1-knowledge block 1; for knowledge block 2, its previous title is title k.2, so the enhanced knowledge block 2 corresponding to knowledge block 2 is expressed as: document title-title k.2-knowledge block 2.
[0043] S4, knowledge storage: Use the embedding model to vectorize the enhanced knowledge blocks, and store the enhanced knowledge blocks and their vectorization results in the knowledge base.
[0044] A pre-trained embedding model, such as bge-large-zh-v1.5, is used to process the enhanced knowledge block to generate the corresponding vectorized representation, and ElasticSearch is used to store the enhanced knowledge block and its vectorized representation in the knowledge base.
[0045] S5, knowledge retrieval: perform multi-way and multi-layer retrieval in the knowledge base based on the user query text to recall relevant knowledge blocks.
[0046] According to the user query text, keyword retrieval and vector retrieval are used to recall the retrieval result set T and retrieval result set S respectively from the knowledge base. For each knowledge block text in the retrieval result set T and the retrieval result set S, the most relevant q knowledge blocks are recalled through vector retrieval to form the retrieval result set ST.
[0047] S6, knowledge filtering: sort the recalled knowledge blocks, extract the most relevant knowledge blocks, and obtain the retrieval results.
[0048] like Figure 3 As shown in the figure, for the retrieval result sets S, T and ST of multi-way and multi-layer retrieval recall, the recursive ranking fusion (RRF) algorithm is used to merge the search results and perform rough sorting; the rough sorting results are passed through a special pre-trained reranking model, such as bge-reranker-v2-m3, to filter out the most relevant knowledge blocks as the final retrieval results.
[0049] After a two-step sorting and filtering process, it is ensured that the information knowledge blocks most relevant to the user's query text are retrieved.
[0050] The above is an introduction to the method embodiment. The following is a further explanation of the solution of the present invention through a system embodiment.
[0051] This embodiment also provides a knowledge retrieval system based on document structure context enhancement, including:
[0052] Document parsing module: obtains multi-source heterogeneous structured documents and performs unified structural parsing and formatting, extracting metadata and hierarchical structure information of the documents;
[0053] Knowledge extraction module: constructs the document directory tree and chapter associations based on the extracted document metadata and hierarchical structure information, and divides the chapter paragraphs into knowledge blocks;
[0054] Knowledge enhancement module: performs hierarchical context enhancement on knowledge blocks according to the document directory tree to form enhanced knowledge blocks;
[0055] Knowledge storage module: Use the embedding model to vectorize the enhanced knowledge blocks, and store the enhanced knowledge blocks and their vectorization results in the knowledge base;
[0056] Knowledge retrieval module: performs multi-channel and multi-layer retrieval in the knowledge base based on the user query text to recall relevant knowledge blocks;
[0057] Knowledge filtering module: sort the recalled knowledge blocks, extract the most relevant knowledge blocks, and obtain the retrieval results.
[0058] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the described module can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0059] The electronic device of the present invention includes a central processing unit (CPU), which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) or loaded from a storage unit into a random access memory (RAM). In the RAM, various programs and data required for device operation can also be stored. The CPU, ROM and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0060] Multiple components in the device are connected to the I / O interface, including: input units, such as keyboards, mice, etc.; output units, such as various types of displays, speakers, etc.; storage units, such as disks, optical disks, etc.; and communication units, such as network cards, modems, wireless communication transceivers, etc. The communication unit allows the device to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunication networks.
[0061] The processing unit performs the various methods and processes described above, such as methods S1 to S6. For example, in some embodiments, methods S1 to S6 may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit. In some embodiments, part or all of the computer program may be loaded and / or installed on the device via a ROM and / or a communication unit. When the computer program is loaded into the RAM and executed by the CPU, one or more steps of methods S1 to S6 described above may be performed. Alternatively, in other embodiments, the CPU may be configured to execute methods S1 to S6 in any other appropriate manner (e.g., by means of firmware).
[0062] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0063] The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or server.
[0064] In the context of the present invention, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0065] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A knowledge retrieval method based on document structure context enhancement, characterized in that: The method comprises the following steps: Document parsing: Obtain multi-source heterogeneous structured documents and perform unified structural parsing and formatting, extracting metadata and hierarchical information of the documents; Knowledge extraction: Based on the extracted document metadata and hierarchical information, the document directory tree and chapter association are constructed, and the chapter paragraphs are divided into knowledge blocks; Knowledge enhancement: Perform hierarchical context enhancement on knowledge blocks according to the document directory tree to form enhanced knowledge blocks; Knowledge storage: Use the embedding model to vectorize the enhanced knowledge blocks, and store the enhanced knowledge blocks and their vectorization results in the knowledge base; Knowledge retrieval: Perform multi-channel and multi-layer retrieval in the knowledge base based on the user query text to recall relevant knowledge blocks; Knowledge filtering: Sort the recalled knowledge blocks, extract the most relevant knowledge blocks, and obtain the retrieval results.
2. A knowledge retrieval method based on document structure context enhancement according to claim 1, characterized in that: The document parsing is specifically: parsing different types of multi-source heterogeneous structured documents with a table of contents, and generating a formatted parsing result in Markdown form through one or more of layout detection, formula detection, formula recognition, and optical character recognition models.
3. The knowledge retrieval method based on document structure context enhancement according to claim 1 is characterized in that: The knowledge extraction is specifically as follows: detecting the document parsing results, extracting the document title and chapter titles, and forming a document directory tree; segmenting the non-title paragraphs into blocks, and dividing the non-title paragraphs into multiple knowledge blocks by using fixed-size segmentation, segmentation based on sentences, or segmentation based on semantic similarity.
4. The knowledge retrieval method based on document structure context enhancement according to claim 1, characterized in that: The knowledge enhancement is specifically as follows: adding the document title text and the previous title text corresponding to the knowledge block in sequence as prefixes before the original knowledge block to form an enhanced knowledge block.
5. The knowledge retrieval method based on document structure context enhancement according to claim 1 is characterized in that: The knowledge storage is specifically as follows: using a pre-trained embedding model to process the enhanced knowledge block to generate a corresponding vectorized representation, and using ElasticSearch to store the enhanced knowledge block and its vectorized representation together in the knowledge base.
6. The knowledge retrieval method based on document structure context enhancement according to claim 1 is characterized in that: The knowledge retrieval is specifically as follows: according to the user query text, keyword retrieval and vector retrieval are used to respectively recall the first retrieval result set and the second retrieval result set from the knowledge base, and for each knowledge block text in the first retrieval result set and the second retrieval result set, the most relevant multiple knowledge blocks are recalled through vector retrieval to form a third retrieval result set.
7. A knowledge retrieval method based on document structure context enhancement according to claim 6, characterized in that: The knowledge filtering is specifically as follows: for the first, second and third search result sets of multi-channel and multi-layer search recalls, a recursive ranking fusion algorithm is used to merge the search results and perform rough sorting; the results of the rough sorting are filtered out with a pre-trained re-ranking model to obtain the most relevant knowledge blocks as the final search results.
8. A knowledge retrieval system based on document structure context enhancement, characterized in that: include: Document parsing module: obtains multi-source heterogeneous structured documents and performs unified structural parsing and formatting, extracting metadata and hierarchical structure information of the documents; Knowledge extraction module: constructs the document directory tree and chapter associations based on the extracted document metadata and hierarchical structure information, and divides the chapter paragraphs into knowledge blocks; Knowledge enhancement module: performs hierarchical context enhancement on knowledge blocks according to the document directory tree to form enhanced knowledge blocks; Knowledge storage module: Use the embedding model to vectorize the enhanced knowledge blocks, and store the enhanced knowledge blocks and their vectorization results in the knowledge base; Knowledge retrieval module: performs multi-channel and multi-layer retrieval in the knowledge base based on the user query text to recall relevant knowledge blocks; Knowledge filtering module: sort the recalled knowledge blocks, extract the most relevant knowledge blocks, and obtain the retrieval results.
9. An electronic device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the processor executes the program, the method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Knowledge base construction method and device, equipment and medium
CN120297399A
Information retrieval system and method based on multi-path recall, terminal, medium and product
CN120407870A
Enterprise knowledge retrieval method, system and equipment based on knowledge base
CN120849587A
Engineering knowledge base construction and deep retrieval method
CN120893548A
A Method for Engineering Knowledge Base Construction and Deep Retrieval
CN120893548B