A document retrieval generation method, device and electronic equipment
Patent Information
- Application Number
- CN202411804985.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2044-12-09
AI Technical Summary
[0003]在通过RAG进行数据检索时相关技术中因为检索匹配方式(一般为关键词匹配)、对于文件的块划分的方式以及对于文件中特殊格式处理方式,导致检索得到的文件检索信息与用户输出查询信息匹配的匹配度以及全面性均较低,会在检索过程中遗漏与查询信息更为相关的检索信息,导致基于检索信息分析得到的查询结果的准确性较低
[0044]本申请实施例提供的文档检索生成方法、装置及电子设备,将预先上传的多个文件解析切分为多个文件索引块;其中,每个文件索引块是基于文件的语义结构以及用户输入的查询信息的上下文中查询对象相关性动态确定的;根据用户输入的查询信息,从多个文件索引块中确定出与查询信息匹配的至少一个目标文件检索信息;其中,至少一个目标文件检索信息是通过对查询信息与文件索引块中的文件内容进行向量化匹配、和/或关键词匹配和/或对文件索引块中的文件内容进行文件样式分析确定的;将查询信息以及至少一个目标文件检索信息输入至预先训练好的语言处理模型,以使语言处理模型结合至少一个目标文件检索信息的上下文信息,输出针对于查询信息的查询结果。这样,通过结合文件语义结构以及查询信息的查询相关性动态调整文件索引块的大小,避免文件索引块遗漏信息,并且在根据查询信息检索时,结合向量匹配和/或关键词匹配并考虑文件样式,得到更为全面以及准确的目标文件检索信息,有助于提升根据检索得到的目标文件检索信息以及用户查询信息输出的检索结果的准确性。
Smart Images

Figure CN119690915B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing technology, and in particular to a document retrieval and generation method, apparatus and electronic device. Background Technology
[0002] Retrieval-Augmented Generation (RAG) is a natural language processing technique that combines retrieval and generation capabilities. By employing this technique and referencing external knowledge bases, the breadth and accuracy of the model's responses to user queries can be improved.
[0003] When using RAG for data retrieval, the matching methods (usually keyword matching), file block division methods, and special format processing methods in related technologies result in low matching degree and comprehensiveness between the retrieved file information and the user's output query information. This can lead to the omission of more relevant search information during the retrieval process, resulting in low accuracy of the query results obtained based on the retrieval information analysis. Summary of the Invention
[0004] In view of this, the purpose of this application is to provide a document retrieval generation method, apparatus and electronic device, which dynamically adjusts the size of the file index block by combining the semantic structure of the file and the query relevance of the query information, so as to avoid missing information in the file index block. Furthermore, when retrieving based on the query information, it combines vector matching and / or keyword matching and considers the file style to obtain more comprehensive and accurate target file retrieval information, which helps to improve the accuracy of the retrieval results output based on the target file retrieval information and user query information.
[0005] In a first aspect, embodiments of this application provide a document retrieval and generation method, the document retrieval and generation method comprising:
[0006] Multiple pre-uploaded files are parsed and divided into multiple file index blocks; wherein each file index block is dynamically determined based on the semantic structure of the file and the relevance of the query object in the context of the user's input query information;
[0007] Based on the query information input by the user, at least one target file retrieval information matching the query information is determined from the plurality of file index blocks; wherein, the at least one target file retrieval information is determined by performing vectorized matching and / or keyword matching and / or file style analysis on the file content in the file index blocks;
[0008] The query information and the at least one target file retrieval information are input into a pre-trained language processing model, so that the language processing model combines the contextual information of the at least one target file retrieval information to output query results for the query information.
[0009] In one possible implementation, the step of parsing and dividing the pre-uploaded multiple files into multiple file index blocks includes:
[0010] For each file, based on its semantic structure, determine the multiple file semantic structure types contained within the file, and group the file content belonging to the same file semantic structure type into the same file index block; and / or,
[0011] Parse the query information entered by the user, determine the same target query object contained in the query information, and divide the file content of the multiple files that belongs to the same target query object into the same file index block;
[0012] The file semantic structure type includes at least one of the following:
[0013] Document chapters, document paragraphs, document sentence boundaries.
[0014] In one possible implementation, the file index block includes file style information and file style relationship information; the document retrieval and generation method further includes:
[0015] For each file, determine whether it belongs to the target file type; where files belonging to the target file type are structured files.
[0016] For each file belonging to the target file type, the file is directly parsed to determine the multiple file style information contained in the file and the file style relationship information between the multiple file style information;
[0017] For each file that does not belong to the target file type, the range of multiple text boxes in the file and their corresponding coordinates, which are identified by optical character recognition, are input into a pre-trained layout parsing model to obtain multiple file style information contained in the file and file style relationship information between the multiple file style information.
[0018] For each file, the multiple file style information contained in the file and the file style relationship information between the multiple file style information are associated and stored with the file content in the file index block corresponding to the file, so that each file index block contains the corresponding file style information.
[0019] In one possible implementation, for each file, the file style information of that file is stored through the following steps:
[0020] For each file, determine the multiple file styles contained in that file and the hierarchical relationships between the multiple file styles;
[0021] For each file, a file tree is constructed based on the multiple file styles contained in the file and the hierarchical relationship between the multiple file styles to store the file styles and their corresponding file content;
[0022] In this context, the file style that is in a superior relationship in the file tree is a node of the file tree, and the child nodes under each node are the subordinate file styles of the file style in the superior relationship of that node and the corresponding file content.
[0023] In one possible implementation, the document retrieval and generation method further includes:
[0024] For each file, based on the file style information parsed from that file, determine whether a table exists in that file;
[0025] For each file containing tables, the coordinate information of the location of each table in the file and a screenshot of the table are input into a pre-trained table structure recognition model, and the cell information and table header information corresponding to the cell position information of each table in the file are output.
[0026] The system stores the cell information and header information corresponding to the cell position information in each table for each file, so as to obtain the query result based on the query information input by the user and the cell information and header information corresponding to the cell position information in the table.
[0027] In one possible implementation, determining at least one target file retrieval information matching the query information from the plurality of file index blocks based on the query information input by the user includes:
[0028] The query information input by the user is converted into a query vector, and based on the query vector, at least one target vector retrieval result matching the query vector is searched from a pre-built vector database.
[0029] Determine multiple target keywords included in the query information input by the user, as well as the text content in the file index block, and determine at least one keyword matching result that matches each target keyword;
[0030] The system inputs at least one target vector retrieval result and at least one keyword matching result into a pre-trained language representation model, so that the language representation model sorts the at least one target vector retrieval result and at least one keyword matching result, and outputs the target output result that is ranked at a preset position.
[0031] The target output result is determined as the target file retrieval information.
[0032] In one possible implementation, when the query information includes file style query information, the target file retrieval information is determined through the following steps:
[0033] Determine at least one file query style contained in the file style query information;
[0034] For each file query pattern, the file content of the node corresponding to the file query pattern and the file content of the child node corresponding to the child node associated with the file query pattern are retrieved from the file tree.
[0035] The content of the node file and the content of the child node file are determined as the target file retrieval information.
[0036] In one possible implementation, the document retrieval and generation method further includes:
[0037] The user-input query information is recursively broken down into multiple related query information, so as to determine the at least one target file retrieval information from the multiple file index blocks based on the multiple related query information.
[0038] Secondly, embodiments of this application also provide a document retrieval and generation apparatus, the document retrieval and generation apparatus comprising:
[0039] The index block partitioning module is used to parse and divide multiple pre-uploaded files into multiple file index blocks; wherein, each file index block is dynamically determined based on the semantic structure of the file and the relevance of the query object in the context of the query information input by the user;
[0040] The retrieval information determination module is used to determine at least one target file retrieval information that matches the query information from the plurality of file index blocks based on the query information input by the user; wherein the at least one target file retrieval information is determined by performing vectorized matching and / or keyword matching and / or file style analysis on the file content in the file index blocks;
[0041] The query result output module is used to input the query information and the at least one target file retrieval information into a pre-trained language processing model, so that the language processing model combines the context information of the at least one target file retrieval information to output query results for the query information.
[0042] Thirdly, embodiments of this disclosure also provide an electronic device, including: a processor, a storage medium, and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the document retrieval and generation method as described in any of the first aspects.
[0043] Fourthly, embodiments of this disclosure also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the document retrieval and generation method as described in any of the first aspects.
[0044] The document retrieval generation method, apparatus, and electronic device provided in this application divide multiple pre-uploaded files into multiple file index blocks. Each file index block is dynamically determined based on the semantic structure of the file and the relevance of the query object in the context of the user-input query information. Based on the user-input query information, at least one target file retrieval information matching the query information is determined from the multiple file index blocks. This at least one target file retrieval information is determined by vectorized matching and / or keyword matching and / or file style analysis of the file content in the file index blocks. The query information and the at least one target file retrieval information are input into a pre-trained language processing model, which combines the contextual information of the at least one target file retrieval information to output query results specific to the query information. By dynamically adjusting the size of the file index blocks based on the file semantic structure and the query relevance of the query information, information omissions are avoided. Furthermore, by combining vector matching and / or keyword matching and considering file style during retrieval based on the query information, more comprehensive and accurate target file retrieval information is obtained, which helps improve the accuracy of the retrieval results output based on the retrieved target file retrieval information and the user query information.
[0045] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0046] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1 A flowchart illustrating a document retrieval and generation method provided in this application embodiment;
[0048] Figure 2 This is one of the structural schematic diagrams of a document retrieval and generation device provided in an embodiment of this application;
[0049] Figure 3 This is a second schematic diagram of the structure of a document retrieval and generation device provided in an embodiment of this application;
[0050] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0051] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, 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. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. Based on the embodiments of this application, every other embodiment obtained by those skilled in the art without inventive effort falls within the scope of protection of this application.
[0052] Retrieval-Augmented Generation (RAG) is a natural language processing technique that combines retrieval and generation capabilities. By employing this technique and referencing external knowledge bases, the breadth and accuracy of the model's responses to user queries can be improved.
[0053] When using RAG for data retrieval, the matching methods (usually keyword matching), file block division methods, and special format processing methods in related technologies result in low matching degree and comprehensiveness between the retrieved file information and the user's output query information. This can lead to the omission of more relevant search information during the retrieval process, resulting in low accuracy of the query results obtained based on the retrieval information analysis.
[0054] Based on this, embodiments of this application provide a document retrieval generation method to improve the accuracy of retrieval results output based on the target file retrieval information and user query information obtained from the retrieval.
[0055] Please see Figure 1 , Figure 1 This is a flowchart illustrating a document retrieval and generation method provided in an embodiment of this application. Figure 1 As shown in the embodiments of this application, the document retrieval and generation method includes:
[0056] S101. Parse and divide the pre-uploaded files into multiple file index blocks; wherein each file index block is dynamically determined based on the semantic structure of the file and the relevance of the query object in the context of the user-input query information.
[0057] S102. Based on the query information input by the user, determine at least one target file retrieval information that matches the query information from the plurality of file index blocks; wherein, the at least one target file retrieval information is determined by performing vectorized matching and / or keyword matching and / or file style analysis on the file content in the file index blocks.
[0058] S103. Input the query information and the at least one target file retrieval information into a pre-trained language processing model, so that the language processing model combines the context information of the at least one target file retrieval information to output query results for the query information.
[0059] The document retrieval and generation method provided in this disclosure dynamically adjusts the size of the file index block by combining the semantic structure of the file and the query relevance of the query information, so as to avoid missing information in the file index block. Furthermore, when retrieving based on the query information, it combines vector matching and / or keyword matching and considers the file style to obtain more comprehensive and accurate target file retrieval information, which helps to improve the accuracy of the retrieval results output based on the retrieved target file retrieval information and the user query information.
[0060] The exemplary steps of the embodiments of this disclosure are described below:
[0061] S101. Parse and divide the pre-uploaded files into multiple file index blocks; wherein each file index block is dynamically determined based on the semantic structure of the file and the relevance of the query object in the context of the user-input query information.
[0062] In this application embodiment, Retrieval-Augmented Generation (RAG) is a natural language processing technique that combines retrieval and generation capabilities. By employing the above technique and referencing external knowledge bases, the breadth and accuracy of the model's responses to user queries can be improved.
[0063] In one possible implementation, RAG technology requires an external knowledge database. Therefore, users need to upload all knowledge-related files, and then the uploaded files are split into multiple file blocks. Furthermore, the split file blocks are placed into the corresponding database to obtain file index blocks.
[0064] While large language models can handle relatively long texts, their processing power is clearly insufficient when faced with massive archives of tens of thousands of pages. Furthermore, for a single file, the content relevant to the user's query may only be one or a few parts of the file. Therefore, it is necessary to parse and divide the file into multiple file index blocks. During a query, the file information in one or more file index blocks that are most relevant to the user's query can be found, thereby improving the efficiency of file retrieval.
[0065] In one possible implementation, when splitting a file, the size of each file index block is generally fixed to facilitate user queries and file storage. However, the specific size of each file block can generally be customized by the user. But if the size of each file index block is set too large because the block size is fixed, useful information may be buried among useless information. If it becomes too large, it will exceed the processing capacity of the language model. On the other hand, if the size of each file index block is set too small, in addition to the possibility of losing information in the file, it may also cause insufficient contextual information, leading to ambiguity and other problems, thus affecting the accuracy of the final query results.
[0066] Based on this, in the embodiments of this application, the content contained in each index file block and the size of the file index block are dynamically determined based on the semantic structure of the file and the relevance of the query object in the context of the query information input by the user, so as to avoid too much information or missing information in each file index block and improve the accuracy of the final query results.
[0067] Specifically, the step of parsing and dividing the pre-uploaded files into multiple file index blocks includes:
[0068] a1: For each file, based on its semantic structure, determine the multiple file semantic structure types contained within the file, and group the file content belonging to the same file semantic structure type into the same file index block; and / or,
[0069] a2: Parse the query information input by the user, determine the same target query object contained in the query information, and divide the file content of the multiple files that belongs to the same target query object into the same file index block.
[0070] In one possible implementation, when parsing and splitting each file, the semantic structure of each file can be analyzed first to determine the multiple semantic structure types contained in each file, and then the file content belonging to the same semantic structure type can be divided into the same file index block.
[0071] The file semantic structure type includes at least one of the following:
[0072] Document chapters, document paragraphs, document sentence boundaries.
[0073] For example, for the same file, by analyzing the file content, multiple chapters and multiple paragraphs contained in the file are determined; the information of multiple chapters (such as chapter titles, the file content range corresponding to the chapters) is divided into the chapter index module; the information of multiple paragraphs (the number of paragraphs in the file, the document content range corresponding to each paragraph, etc.) is divided into the paragraph index module.
[0074] In another possible implementation, in order to better match the user's query information and more accurately find the file index block that matches the user's query information, the file content that belongs to the same target query object can be divided into the same file index block according to the target query object included in the user's query information. Then, the size of each file index block is determined according to the content contained in each file index block.
[0075] For example, after analyzing the user's query information, it is determined that the target query objects mentioned in the user's query information include time, location, and target person. Therefore, the file content related to time can be divided into the same file index block, the file content related to location can be divided into the same file index block, and the file content related to person can be divided into the same file index block.
[0076] In this way, the size and number of file index blocks can be dynamically adjusted according to the semantic structure type of the file and the user's query information. This ensures the integrity of the file content in each file index block while improving the accuracy of the search results obtained based on the query information.
[0077] Furthermore, when searching file index blocks, information such as the chapters of the file may be retrieved. However, each chapter may contain multiple subsections. When the user's query information includes the chapter title, matching the query based on the chapter title or other information often only retrieves the file index blocks near the chapter. The relevant file text content further away from the title may be ignored, resulting in a low accuracy rate of the target file retrieval information obtained based on the user's query information.
[0078] Based on this, when storing chapter information and other information in a file, this application embodiment considers storing them according to the relationship between chapters to ensure that each file index block carries title information. When querying according to the chapter query information entered by the user, all relevant chapters and corresponding file text content can be indexed based on the chapter title information, thereby improving the accuracy of the target file retrieval information obtained based on the user's query information.
[0079] Specifically, the document retrieval and generation method further includes:
[0080] b1: For each file, check whether the file belongs to the target file type; where files belonging to the target file type are structured files.
[0081] b2: For each file belonging to the target file type, directly parse the file to determine the multiple file style information contained in the file and the file style relationship information between the multiple file style information.
[0082] b3: For each file that does not belong to the target file type, the range of multiple text boxes in the file and their corresponding coordinates, which are identified by optical character recognition, are input into the pre-trained layout parsing model to obtain multiple file style information contained in the file and the file style relationship information between the multiple file style information.
[0083] b4: For each file, the multiple file style information contained in the file and the file style relationship information between the multiple file style information are associated and stored with the file content in the file index block corresponding to the file, so that each file index block contains the corresponding file style information.
[0084] The document style information may include the font, font size, whether it is a title, body text, table, image, header, footer, citation, etc.
[0085] In one possible implementation, when determining the file style information of a file, it is first necessary to determine the file type. If the file belongs to the target file type of a structured file, the style information of the file can be directly parsed using open source tools.
[0086] For example, the target file type can be a Word file. docx itself is a semi-structured file, and Word files can be directly parsed using open-source tools to obtain file style information such as titles, and at the same time, the font style (e.g., font, font size, whether it is a title, etc.) can be determined.
[0087] In another possible implementation, if the file does not belong to the target file type, that is, the file is an unstructured file, for example, if the file is a PDF or an image type of unstructured file, although the PDF can also be processed by the parsing tool, since the PDF is a document format optimized for printing scenarios, the text in it only retains basic information such as font and position coordinates, but the title format cannot be determined.
[0088] Based on this, in this embodiment of the application, the range and coordinates of each text box in the document are determined by optical character recognition, and then the document style information contained in the document is analyzed by the document parsing model.
[0089] Optical Character Recognition (OCR) refers to the process by which electronic devices (such as scanners or digital cameras) examine characters printed on paper, determine their shapes by detecting dark and light patterns, and then translate the shapes into computer text using character recognition methods. In other words, for printed characters, optical methods are used to convert the text in paper documents into black and white dot matrix image files, and recognition software is used to convert the text in the image into text format for further editing and processing by word processing software.
[0090] Furthermore, OCR can identify text boxes and the coordinates of specific text within a document. The identified text box ranges and their corresponding coordinates are then input into a pre-trained layout parsing model, which outputs the text style information contained in the document.
[0091] Here, the layout parsing model outputs file style information such as title, body, tables, images, headers, footers, and references. This allows the determination of multiple file style information contained in the file and the file style relationship information between these multiple file style information. The file style information is then stored based on the file style relationship information.
[0092] Here, the file style relationship information includes the association and subordinate relationships between different file styles. For example, for the file style of chapter, a chapter can contain multiple headings and multiple subheadings associated with each heading. This association and subordinate relationship is the file style relationship. Based on the file style relationship, multiple file styles in a file can be associated. When performing a search, a depth-first traversal search can be performed on the file style information included in the query information to obtain all file index blocks associated with the file style information included in the query information, thereby retrieving accurate and comprehensive target file search information.
[0093] In one possible implementation, for each file, the file style information of that file is stored through the following steps:
[0094] c1: For each file, determine the multiple file styles contained in that file and the hierarchical relationships between the multiple file styles.
[0095] c2: For each file, based on the multiple file styles contained in the file and the hierarchical relationship between the multiple file styles, construct a file tree to store the file styles and their corresponding file content.
[0096] In this embodiment of the application, after determining the file style information of the file and each file style information, a file tree can be constructed based on the determined multiple file styles and the hierarchical relationship between the multiple file styles. Based on the relationship between different nodes in the file tree, the association relationship between the file styles contained in the file can be constructed, so that all file information related to the file style can be obtained when querying.
[0097] Specifically, the file styles that are in a superior relationship in the file tree are nodes of the file tree, and the child nodes under each node are the subordinate file styles of the file styles in the superior relationship of that node and the corresponding file content.
[0098] For example, taking the document style as the chapter title, each level of title corresponds to a node, and the subheadings and body text of the title are the child nodes of that node, thus constructing a document tree.
[0099] For example, when querying, if the user's query information includes title A, then when querying the relevant information of title A, the subtitles A1 and A2 related to title A can be found from the pre-built file tree, as well as the corresponding file text content. When returning the query results, title A, subtitles A1, subtitles A2 and the file text content are all the query results, ensuring the comprehensiveness and accuracy of the query results.
[0100] In one possible implementation, in related technologies, when processing documents, if the document contains tables (not referring to pure Excel or CSV tables, but tables inserted into Word or PDF documents), the inconsistent formatting of the inserted tables and the presence of merged cells will alter the column names, making them difficult to recognize. Furthermore, if some tables are inserted as images, current OCR technology, which only recognizes text, cannot identify the table structure. Further, searching for tables within a document is challenging because the entire table, possessing complete semantic information, is difficult to segment and index. Without segmentation, large tables are poorly supported. Due to these issues, the accuracy of table recognition and retrieval in related technologies is generally low.
[0101] Based on this, in this embodiment of the application, a table structure recognition model is used to identify the cell information and table header information corresponding to the cell position information of the table in the file, and output accurate recognition results, which can improve the accuracy of table recognition and query in the file.
[0102] Specifically, the document retrieval and generation method further includes:
[0103] d1: For each file, determine whether a table exists in the file based on the file style information parsed from the file.
[0104] d2: For each file containing tables, input the coordinates of each table's location and a screenshot of the table into a pre-trained table structure recognition model, and output the cell information and header information corresponding to the cell location information of each table in the file.
[0105] d3: Stores the cell information and header information corresponding to the cell position information in each table for each file, so as to obtain the query result based on the query information input by the user and the cell information and header information corresponding to the cell position information in the table.
[0106] In this embodiment of the application, after the document is identified by the layout recognition model, if it is determined that there is a table in the current document, the coordinate information of the table in the document identified by OCR and the screenshot of the table are input into the pre-trained table structure recognition model, and then the table structure recognition model outputs the cell information and header information corresponding to the cell position information of the table.
[0107] Here, the table structure recognition model, or Table Structure Recognition (TSR), is used to identify the row and column structure of a table and determine the position of each cell. Common methods include clustering and projected histogram analysis. When the coordinates of the table's location in a file and a screenshot of the table are input into the table structure recognition model, the model parses and identifies the table structure in the file, thereby obtaining the table's specific information.
[0108] For example, Table 1 is a table to be identified with a format to be determined. After processing Table 1, TSR can output a result in a similar JSON format.
[0109] Table 1 Table of objects to be identified
[0110]
[0111]
[0112]
[0113]
[0114] Furthermore, after identifying the cell location information and header information of each table in each file, a relational database can be created to store the table information. When the user inputs query information later, the query information is concatenated with the target table information in the relational database, and the concatenated information is input into the model to obtain the query results.
[0115] Furthermore, after parsing and splitting the file into file index blocks, the file index blocks can be indexed based on the user's query information to obtain the target file retrieval information.
[0116] S102. Based on the query information input by the user, determine at least one target file retrieval information that matches the query information from the plurality of file index blocks; wherein, the at least one target file retrieval information is determined by performing vectorized matching and / or keyword matching and / or file style analysis on the file content in the file index blocks.
[0117] In related technologies, when indexing uploaded files, the index is typically created by directly saving the string. After the user enters query information, the relevant target file retrieval information is determined by matching keywords with the query information. For example, the retrieval algorithm could be an inverted index, bm25, or other derived algorithms. However, the above query algorithms match based on keywords and cannot search for and match text outside the query information, resulting in low accuracy in query matching.
[0118] For example, if a user inputs the query "What fruit did I eat today?", the pre-stored file might contain the information "I bought a banana and an apple at Central Park today. In the afternoon, I bought half a watermelon... I ate all the fruit I bought when I got home in the evening." The returned result for this query would be banana, apple, and watermelon. However, during file parsing, the phrases "bought banana, apple, and watermelon" and "ate the fruit I bought" will not belong to the same file index block. When searching based on the query keywords, the algorithm prioritizes matching "fruit," resulting in the match "ate the fruit I bought." Clearly, the crucial information about what fruit was eaten is ignored by the retrieval algorithm, leading to low accuracy in the subsequent query results output by the language model.
[0119] Based on this, in this embodiment of the application, when querying a file using the query information input by the user and determining at least one target file retrieval information, not only is the corresponding information matched by keywords, but also similar files can be retrieved by the distance between vectors, thereby obtaining more accurate and comprehensive retrieval results, so as to improve the accuracy of the subsequent language model obtaining query results based on the retrieval results.
[0120] Specifically, the step "determining at least one target file retrieval information matching the query information from the plurality of file index blocks based on the query information input by the user" includes:
[0121] e1: Convert the query information input by the user into a query vector, and based on the query vector, search for at least one target vector retrieval result that matches the query vector from a pre-built vector database.
[0122] e2: Determine the multiple target keywords included in the query information input by the user, as well as the text content in the file index block, and determine at least one keyword matching result that matches each target keyword.
[0123] e3: Input at least one target vector retrieval result and at least one keyword matching result into a pre-trained language representation model, so that the language representation model sorts the at least one target vector retrieval result and the at least one keyword matching result, and outputs the target output result that is sorted at a preset position.
[0124] e4: The target output result is determined as the target file retrieval information.
[0125] In this embodiment of the application, when querying based on user-input query information and matching it with the content in the file index block, in addition to keyword matching, vector matching can also be used to find query results similar to the query information, so as to ensure the comprehensiveness and accuracy of the target file retrieval information obtained and avoid omissions.
[0126] In one possible implementation, the query statement in the query information can be converted into a query vector through vectorization processing, and a vector database (e.g., a Milvus database) can be introduced before the query. Multiple different vectors are stored in the vector database. When performing a retrieval query, the query vector can be matched with the vectors in the vector database to obtain the matching target vector retrieval result.
[0127] Here, a distance algorithm can be used to match the query vector with vectors in the vector database. Based on the distance between the query vector and each vector in the vector database, the target vector retrieval result that matches the query vector can be determined.
[0128] In one possible implementation, the distance between the query vector and each vector in the vector database can be calculated using the following formula:
[0129]
[0130] Where d is the distance (cosine distance) between the query vector and the vector data in the vector database; For query vector; This refers to vector data in a vector database.
[0131] Furthermore, after determining at least one target vector retrieval result that is similar to the query vector based on vector calculation, it is also necessary to match the keywords in the query information with the file content in each file index block to obtain keyword matching results. Then, the obtained at least one target vector retrieval result and at least one keyword matching result are input into the pre-trained language representation model, and the various retrieval results are sorted. The target output result that is at the top is determined as the target file retrieval information that matches the query information.
[0132] In one possible implementation, the language representation model can be the BERT model. The BERT model scores and sorts the retrieved target vectors and keyword matching results. The sorting order can be based on the score of each retrieval result from high to low. The higher the score, the higher the matching degree between the retrieval result and the query information. The query results ranked at the top are then determined as the target output results and participate in the determination and output of subsequent query results.
[0133] For example, after vector query, target vector retrieval results X1, X2, and X3 are obtained; after keyword query, keyword matching results Y1, Y2, and Y3 are obtained. The above results are input into the BERT model, and the sorting order of each matching result after scoring and sorting is as follows: target vector retrieval result X1, keyword matching result Y1, keyword matching result Y3, target vector retrieval result X2, keyword matching result Y2, and target vector retrieval result X3. The target vector retrieval result X1, which is the first in the sorted list and closest to the query information, is selected as the target file retrieval information.
[0134] In one possible implementation, if the query information includes file style query information, when performing a query index based on the query information, a comprehensive search based on the pre-stored file tree is required to ensure the accuracy and comprehensiveness of the obtained search results.
[0135] Specifically, when the query information includes file style query information, the target file retrieval information is determined through the following steps:
[0136] f1: Determine at least one file query style contained in the file style query information.
[0137] f2: For each file query pattern, based on the file query pattern, query the node file content corresponding to the file query pattern and the child node file content corresponding to the child node associated with the file query pattern from the file tree.
[0138] f3: Determine the content of the node file and the content of the child node file as the target file retrieval information.
[0139] In this embodiment, when the query information includes file style query information, at least one file query style that the user needs to query is determined based on the file style query information. For example, the category of the query style (chapter or paragraph, etc.) and the name of the query style (chapter name, title name, etc.) are used. Then, a depth-first traversal search is performed on the pre-stored file tree based on the file query style to determine the node file content corresponding to the file query style and the child node file content corresponding to the child node associated with the file query style. Finally, all the queried content is returned to obtain the target file retrieval information, ensuring the comprehensiveness and accuracy of the target file retrieval information.
[0140] For example, by analyzing the query information input by the user, it is determined that the user currently needs to query the relevant information of title W. After indexing through the file tree, it is determined that title W is associated with subtitle W1, self-title W, and body content B. Then the target file retrieval information returned by the query includes title W, subtitle W1, self-title W, and body content B.
[0141] In one possible implementation, when performing a query based on user-input query information, in order to ensure that as many query targets as possible are obtained from the query information and to ensure the accuracy of the query retrieval, the query statement can be recursively analyzed multiple times to determine the accurate query targets.
[0142] Specifically, the document retrieval and generation method further includes:
[0143] g1: Recursively decompose the user-input query information into multiple related query information, so as to determine the at least one target file retrieval information from the multiple file index blocks based on the multiple related query information.
[0144] In this embodiment of the application, after receiving the query information input by the user, the query information can be broken down into multiple related query information, and multiple recursive queries can be performed for each query information. Then, based on the analysis of multiple queries, the user's true query intent can be determined, and the target retrieval information matching the query information can be determined based on the determined true query intent.
[0145] For example, if a user inputs the query "What fruit did you eat today?", by breaking it down and analyzing it, the relevant query information can be broken down into "Today's date" -> "Types of fruit" -> "Eating fruit". By breaking down the query information step by step and analyzing it step by step, the target search information can be accurately obtained.
[0146] Furthermore, after matching the query information with the file index block to obtain the target file retrieval information, the obtained target file retrieval information can be combined with the user-input query information and processed by the language processing model to obtain the query results for the query information.
[0147] S103. Input the query information and the at least one target file retrieval information into a pre-trained language processing model, so that the language processing model combines the context information of the at least one target file retrieval information to output query results for the query information.
[0148] In this embodiment, after the user inputs query information, target file retrieval information can be obtained based on the query information. Then, the query information and the obtained target file retrieval information are input into a pre-trained language processing model. The language processing model can refer to the context information of the target file retrieval information to output accurate query results for the query information.
[0149] In one possible implementation, the language processing model can be a large language processing model, an NL2SQL model, etc.
[0150] The document retrieval and generation method provided in this application divides multiple pre-uploaded files into multiple file index blocks. Each file index block is dynamically determined based on the semantic structure of the file and the relevance of the query object in the context of the user-input query information. Based on the user-input query information, at least one target file retrieval information matching the query information is determined from the multiple file index blocks. This at least one target file retrieval information is determined by vectorized matching and / or keyword matching and / or file style analysis of the file content in the file index blocks. The query information and the at least one target file retrieval information are input into a pre-trained language processing model, which combines the contextual information of the at least one target file retrieval information to output query results specific to the query information. By dynamically adjusting the size of the file index blocks based on the file semantic structure and the query relevance of the query information, information omissions are avoided. Furthermore, by combining vector matching and / or keyword matching and considering file style during retrieval based on the query information, more comprehensive and accurate target file retrieval information is obtained, which helps improve the accuracy of the retrieval results output based on the retrieved target file retrieval information and the user query information.
[0151] Based on the same inventive concept, this application also provides a document retrieval and generation device corresponding to the document retrieval and generation method. Since the principle of the device in this application is similar to that of the document retrieval and generation method described above, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0152] Please see Figure 2 , Figure 3 , Figure 2 This is one of the structural schematic diagrams of a document retrieval and generation device provided in an embodiment of this application. Figure 3 This is a second schematic diagram of a document retrieval and generation device provided in an embodiment of this application. Figure 2 As shown, the document retrieval and generation device 200 includes:
[0153] The index block partitioning module 210 is used to parse and divide multiple pre-uploaded files into multiple file index blocks; wherein, each file index block is dynamically determined based on the semantic structure of the file and the relevance of the query object in the context of the query information input by the user;
[0154] The retrieval information determination module 220 is used to determine at least one target file retrieval information that matches the query information from the plurality of file index blocks based on the query information input by the user; wherein the at least one target file retrieval information is determined by performing vectorized matching and / or keyword matching and / or file style analysis on the file content in the file index blocks;
[0155] The query result output module 230 is used to input the query information and the at least one target file retrieval information into a pre-trained language processing model, so that the language processing model combines the context information of the at least one target file retrieval information to output query results for the query information.
[0156] In one possible implementation, when the index block partitioning module 210 is used to parse and split multiple pre-uploaded files into multiple file index blocks, the index block partitioning module 210 is used to:
[0157] For each file, based on its semantic structure, determine the multiple file semantic structure types contained within the file, and group the file content belonging to the same file semantic structure type into the same file index block; and / or,
[0158] Parse the query information entered by the user, determine the same target query object contained in the query information, and divide the file content of the multiple files that belongs to the same target query object into the same file index block;
[0159] The file semantic structure type includes at least one of the following:
[0160] Document chapters, document paragraphs, document sentence boundaries.
[0161] In one possible implementation, the file index block includes file style information and file style relationship information; such as Figure 3 As shown, the document retrieval and generation device 200 further includes a document style association module 240, which is used for:
[0162] For each file, determine whether it belongs to the target file type; where files belonging to the target file type are structured files.
[0163] For each file belonging to the target file type, the file is directly parsed to determine the multiple file style information contained in the file and the file style relationship information between the multiple file style information;
[0164] For each file that does not belong to the target file type, the range of multiple text boxes in the file and their corresponding coordinates, which are identified by optical character recognition, are input into a pre-trained layout parsing model to obtain multiple file style information contained in the file and file style relationship information between the multiple file style information.
[0165] For each file, the multiple file style information contained in the file and the file style relationship information between the multiple file style information are associated and stored with the file content in the file index block corresponding to the file, so that each file index block contains the corresponding file style information.
[0166] In one possible implementation, for each file, the file style association module 240 stores the file style information of that file through the following steps:
[0167] For each file, determine the multiple file styles contained in that file and the hierarchical relationships between the multiple file styles;
[0168] For each file, a file tree is constructed based on the multiple file styles contained in the file and the hierarchical relationship between the multiple file styles to store the file styles and their corresponding file content;
[0169] In this context, the file style that is in a superior relationship in the file tree is a node of the file tree, and the child nodes under each node are the subordinate file styles of the file style in the superior relationship of that node and the corresponding file content.
[0170] In one possible implementation, such as Figure 3 As shown, the document retrieval and generation device 200 further includes a table query module 250, which is used for:
[0171] For each file, based on the file style information parsed from that file, determine whether a table exists in that file;
[0172] For each file containing tables, the coordinate information of the location of each table in the file and a screenshot of the table are input into a pre-trained table structure recognition model, and the cell information and table header information corresponding to the cell position information of each table in the file are output.
[0173] The system stores the cell information and header information corresponding to the cell position information in each table for each file, so as to obtain the query result based on the query information input by the user and the cell information and header information corresponding to the cell position information in the table.
[0174] In one possible implementation, when the retrieval information determining module 220 determines at least one target file retrieval information matching the query information from the plurality of file index blocks based on the query information input by the user, the retrieval information determining module 220 is configured to:
[0175] The query information input by the user is converted into a query vector, and based on the query vector, at least one target vector retrieval result matching the query vector is searched from a pre-built vector database.
[0176] Determine multiple target keywords included in the query information input by the user, as well as the text content in the file index block, and determine at least one keyword matching result that matches each target keyword;
[0177] The system inputs at least one target vector retrieval result and at least one keyword matching result into a pre-trained language representation model, so that the language representation model sorts the at least one target vector retrieval result and at least one keyword matching result, and outputs the target output result that is ranked at a preset position.
[0178] The target output result is determined as the target file retrieval information.
[0179] In one possible implementation, when the query information includes file style query information, the retrieval information determination module 220 is used to determine the target file retrieval information through the following steps:
[0180] Determine at least one file query style contained in the file style query information;
[0181] For each file query pattern, the file content of the node corresponding to the file query pattern and the file content of the child node corresponding to the child node associated with the file query pattern are retrieved from the file tree.
[0182] The content of the node file and the content of the child node file are determined as the target file retrieval information.
[0183] In one possible implementation, such as Figure 3 As shown, the document retrieval and generation device 200 further includes a query information decomposition module 260, which is used for:
[0184] The user-input query information is recursively broken down into multiple related query information, so as to determine the at least one target file retrieval information from the multiple file index blocks based on the multiple related query information.
[0185] The document retrieval and generation apparatus provided in this application provides a method for parsing and dividing multiple pre-uploaded files into multiple file index blocks. Each file index block is dynamically determined based on the semantic structure of the file and the relevance of the query object in the context of the user-input query information. Based on the user-input query information, at least one target file retrieval information matching the query information is determined from the multiple file index blocks. This at least one target file retrieval information is determined by vectorized matching and / or keyword matching and / or file style analysis of the file content in the file index blocks. The query information and the at least one target file retrieval information are input into a pre-trained language processing model, which combines the contextual information of the at least one target file retrieval information to output query results specific to the query information. By dynamically adjusting the size of the file index blocks based on the file semantic structure and the query relevance of the query information, information omissions are avoided. Furthermore, by combining vector matching and / or keyword matching and considering file style during retrieval based on the query information, more comprehensive and accurate target file retrieval information is obtained, which helps improve the accuracy of the retrieval results output based on the retrieved target file retrieval information and the user query information.
[0186] Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 4 As shown, the electronic device 400 includes a processor 410, a memory 420, and a bus 430.
[0187] The memory 420 stores machine-readable instructions executable by the processor 410. When the electronic device 400 is running, the processor 410 communicates with the memory 420 via the bus 430. When the machine-readable instructions are executed by the processor 410, they can perform the operations described above. Figure 1 The steps of the document retrieval and generation method in the method embodiment shown are described in detail in the method embodiment, and will not be repeated here.
[0188] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can perform the above-described actions. Figure 1 The steps of the document retrieval and generation method in the method embodiment shown are described in detail in the method embodiment, and will not be repeated here.
[0189] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0190] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the shown or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.
[0191] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0192] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0193] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0194] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The scope of protection of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this application. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A document retrieval and generation method, characterized in that, The document retrieval and generation method includes: Multiple pre-uploaded files are parsed and divided into multiple file index blocks; wherein, the content contained in each file index block and the size of the file index block are dynamically determined based on the semantic structure of the file, dividing the file content belonging to the same file semantic structure type into the same file index block, and based on the query object in the context of the user input query information, dividing the file content belonging to the same query object into the same file index block. Based on the query information input by the user, at least one target file retrieval information matching the query information is determined from the plurality of file index blocks; wherein, the at least one target file retrieval information is determined by performing vectorized matching and / or keyword matching and / or file style analysis on the file content in the file index blocks; The query information and the at least one target file retrieval information are input into a pre-trained language processing model, so that the language processing model combines the contextual information of the at least one target file retrieval information to output query results for the query information.
2. The document retrieval and generation method according to claim 1, characterized in that, The process of parsing and dividing multiple pre-uploaded files into multiple file index blocks includes: For each file, based on its semantic structure, determine the multiple file semantic structure types contained within the file, and group the file content belonging to the same file semantic structure type into the same file index block; and / or, Parse the query information entered by the user, determine the same target query object contained in the query information, and divide the file content of the multiple files that belongs to the same target query object into the same file index block; The file semantic structure type includes at least one of the following: Document chapters, document paragraphs, document sentence boundaries.
3. The document retrieval and generation method according to claim 1, characterized in that, The file index block includes file style information and file style relationship information; the document retrieval and generation method further includes: For each file, determine whether it belongs to the target file type; where files belonging to the target file type are structured files. For each file belonging to the target file type, the file is directly parsed to determine the multiple file style information contained in the file and the file style relationship information between the multiple file style information; For each file that does not belong to the target file type, the range of multiple text boxes in the file and their corresponding coordinates, which are identified by optical character recognition, are input into a pre-trained layout parsing model to obtain multiple file style information contained in the file and file style relationship information between the multiple file style information. For each file, the multiple file style information contained in the file and the file style relationship information between the multiple file style information are associated and stored with the file content in the file index block corresponding to the file, so that each file index block contains the corresponding file style information.
4. The document retrieval and generation method according to claim 3, characterized in that, For each file, the file style information is stored through the following steps: For each file, determine the multiple file styles contained in that file and the hierarchical relationships between the multiple file styles; For each file, a file tree is constructed based on the multiple file styles contained in the file and the hierarchical relationship between the multiple file styles to store the file styles and their corresponding file content; In the file tree, the file style that is in the parent-child relationship is a node of the file tree, and the child nodes under each node are the child file styles of the corresponding parent-child file styles and the corresponding file content.
5. The document retrieval and generation method according to claim 3, characterized in that, The document retrieval and generation method also includes: For each file, based on the file style information parsed from that file, determine whether a table exists in that file; For each file containing tables, the coordinate information of the location of each table in the file and a screenshot of the table are input into a pre-trained table structure recognition model, and the cell information and table header information corresponding to the cell position information of each table in the file are output. The system stores the cell information and header information corresponding to the cell position information in each table for each file, so as to obtain the query result based on the query information input by the user and the cell information and header information corresponding to the cell position information in the table.
6. The document retrieval and generation method according to claim 1, characterized in that, The step of determining at least one target file retrieval information matching the query information from the plurality of file index blocks based on the query information input by the user includes: The query information input by the user is converted into a query vector, and based on the query vector, at least one target vector matching the query vector is retrieved from a pre-built vector database. Determine multiple target keywords included in the query information input by the user, as well as the text content in the file index block, and determine at least one keyword matching result that matches each target keyword; The system inputs at least one target vector retrieval result and at least one keyword matching result into a pre-trained language representation model, so that the language representation model sorts the at least one target vector retrieval result and at least one keyword matching result, and outputs the target output result that is ranked at a preset position. The target output result is determined as the target file retrieval information.
7. The document retrieval and generation method according to claim 4, characterized in that, When the query information includes file style query information, the target file retrieval information is determined through the following steps: Determine at least one file query style contained in the file style query information; For each file query pattern, the file content of the node corresponding to the file query pattern and the file content of the child node corresponding to the child node associated with the file query pattern are retrieved from the file tree. The content of the node file and the content of the child node file are determined as the target file retrieval information.
8. The document retrieval and generation method according to claim 1, characterized in that, The document retrieval and generation method also includes: The user-input query information is recursively broken down into multiple related query information, so as to determine the at least one target file retrieval information from the multiple file index blocks based on the multiple related query information.
9. A document retrieval and generation device, characterized in that, The document retrieval and generation device includes: The index block partitioning module is used to parse and divide multiple pre-uploaded files into multiple file index blocks. The content and size of each file index block are dynamically determined based on the semantic structure of the file, dividing file content belonging to the same semantic structure type into the same file index block, and based on the query object in the context of the user's input query information, dividing file content belonging to the same query object into the same file index block. The retrieval information determination module is used to determine at least one target file retrieval information that matches the query information from the plurality of file index blocks based on the query information input by the user; wherein the at least one target file retrieval information is determined by performing vectorized matching and / or keyword matching and / or file style analysis on the file content in the file index blocks; The query result output module is used to input the query information and the at least one target file retrieval information into a pre-trained language processing model, so that the language processing model combines the context information of the at least one target file retrieval information to output query results for the query information.
10. An electronic device, characterized in that, include: The device includes a processor, a memory, and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is in operation, the processor communicates with the memory via the bus, and the processor executes the machine-readable instructions to perform the steps of the document retrieval and generation method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Retrieval methodology base on layout information
CN101246475A
Multimodal data partitioning method and system based on enterprise information semantic retrieval
CN118132794A
Text processing method and device for improving information retrieval and generation quality and computer system
CN118535710A