Document retrieval generation method and device and electronic equipment
By dynamically adjusting the size of the file index block in combination with the file semantic structure and the correlation of query information, and using vector matching, keyword matching and file style analysis during search, the problem of low matching and comprehensiveness of search information in the existing technology is solved, and more accurate and comprehensive search results are achieved.
Patent Information
- Application Number
- CN202411804985.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-03-25
AI Technical Summary
The existing search enhancement generation technology has defects in search matching methods, file block division methods and special format processing methods, resulting in low matching and comprehensiveness between the search information and user query information, and missing related information, resulting in low accuracy of the search results.
By dynamically adjusting the size of the file index blocks by combining file semantic structure and query information relevance, avoiding information omissions, and using vector matching, keyword matching and file style analysis during search, more comprehensive and accurate target file search information is obtained.
The accuracy of the search results output based on the searched target file search information and user query information is improved, and the comprehensiveness and accuracy of the search results are ensured.
Smart Images

Figure CN119690915A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of natural language processing, and in particular to a document retrieval generation method, device and electronic device. Background Art
[0002] Retrieval-Augmented Generation (RAG) is a natural language processing technology that combines retrieval and generation capabilities. By using the above technology to refer to external knowledge bases, the breadth and accuracy of the model's answers to user query information can be improved.
[0003] When performing data retrieval through RAG, in the relevant technology, due to the retrieval matching method (generally keyword matching), the block division method for files, and the special format processing method for files, the matching degree and comprehensiveness of the retrieved file retrieval information and the user output query information are low, and retrieval information that is more relevant to the query information is omitted 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 the present application is to provide a document retrieval generation method, device and electronic device, which dynamically adjusts the size of the file index block by combining the file semantic structure and the query relevance of the query information to avoid missing information in the file index block, and when retrieving based on the query information, 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 target file retrieval information obtained based on the retrieval and the retrieval results output by the user query information.
[0005] In a first aspect, an embodiment of the present application provides a document retrieval generation method, the document retrieval generation method comprising:
[0006] Parsing and dividing the pre-uploaded multiple files into multiple file index blocks; wherein each of the file index blocks 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;
[0007] According to the query information input by the user, at least one target file retrieval information matching the query information is determined from the multiple file index blocks; wherein the at least one target file retrieval information is determined by performing vectorized matching and / or keyword matching on the query information and the file content in the file index block and / or performing file style analysis on the file content in the file index block;
[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 context information of the at least one target file retrieval information and outputs a query result for the query information.
[0009] In a possible implementation, parsing and dividing the pre-uploaded multiple files into multiple file index blocks includes:
[0010] For each file, based on the semantic structure of the file, multiple file semantic structure types contained in the file are determined, and file contents belonging to the same file semantic structure type in the file are divided into the same file index block; and / or,
[0011] Parsing the query information input by the user, determining the same target query object contained in the query information, and dividing the file contents of the multiple files belonging 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 chapter, document paragraph, document sentence boundaries.
[0014] In a possible implementation manner, the file index block includes file style information and file style relationship information; and the document retrieval generation method further includes:
[0015] For each file, detecting whether the file belongs to a target file type; wherein the file belonging to the target file type is a structured file;
[0016] For each file belonging to the target file type, directly parse the file to determine a plurality of file style information contained in the file and file style relationship information between the plurality of file style information;
[0017] For each file that does not belong to the target file type, multiple text box ranges and corresponding coordinates in the file obtained 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, multiple file style information contained in the file and file style relationship information between the multiple file style information are associated with the file content in the file index block corresponding to the file and stored, so that each file index block contains corresponding file style information.
[0019] In a possible implementation, for each file, the file style information of the file is stored through the following steps:
[0020] For each file, determine the multiple file styles contained in the file and the hierarchical relationship between the multiple file styles;
[0021] For each file, based on multiple file styles contained in the file and the hierarchical relationship between the multiple file styles, a file tree is constructed to store the file styles and corresponding file contents;
[0022] The file styles in the superior relationship in the file tree are nodes of the file tree, and the child nodes under each node are subordinate file styles of the file style in the superior relationship corresponding to the node and corresponding file contents.
[0023] In a possible implementation, the document retrieval generation method further includes:
[0024] For each file, determine whether there is a table in the file based on the file style information parsed from the file;
[0025] For each file containing a table, the coordinate information of the location of each table contained in the file and a screenshot of the table are input into a pre-trained table structure recognition model, and the cell information and header information corresponding to the cell location information in the table of each table in the file are output;
[0026] The cell information and header information corresponding to the cell position information in each table corresponding to each file are stored, so as to obtain the query result according to the query information input by the user in combination with the cell information and header information corresponding to the cell position information in the table.
[0027] In a possible implementation manner, determining at least one target file retrieval information matching the query information from the plurality of file index blocks according to the query information input by the user includes:
[0028] 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 matching the query vector from a pre-built vector database;
[0029] Determine a plurality of target keywords included in the query information input by the user and the text content in the file index block, and determine at least one keyword matching result matching each target keyword;
[0030] Determining at least one target vector search result and at least one keyword matching result and inputting them into a pre-trained language representation model, so that the language representation model sorts the at least one target vector search result and the at least one keyword matching result, and outputs a target output result that is sorted before a preset position;
[0031] The target output result is determined as the target file retrieval information.
[0032] In a possible implementation manner, when the query information includes file style query information, the target file retrieval information is determined by the following steps:
[0033] Determine at least one file query pattern included in the file pattern query information;
[0034] For each file query pattern, query the file tree for 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 based on the file query pattern;
[0035] The node file content and the sub-node file content are determined as the target file retrieval information.
[0036] In a possible implementation, the document retrieval generation method further includes:
[0037] The query information input by the user is recursively decomposed into a plurality of related query information, so as to determine the at least one target file retrieval information from the plurality of file index blocks according to the plurality of related query information.
[0038] In a second aspect, an embodiment of the present application further provides a document retrieval generation device, the document retrieval generation device comprising:
[0039] An index block partitioning module is used to parse and partition a plurality of pre-uploaded files into a plurality of file index blocks; wherein each of the file index blocks 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] A search information determination module, configured to determine, based on the query information input by the user, at least one target file search information matching the query information from the multiple file index blocks; wherein the at least one target file search information is determined by performing vectorized matching and / or keyword matching on the query information and the file content in the file index block and / or performing file style analysis on the file content in the file index block;
[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 a query result for the query information.
[0042] In a third aspect, an embodiment of the present disclosure further provides an electronic device, comprising: 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 execute the document retrieval generation method as described in any one of the first aspects.
[0043] In a fourth aspect, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the document retrieval generation method as described in any one of the first aspects is executed.
[0044] The document retrieval generation method, device and electronic device provided by the embodiment of the present application 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; at least one target file retrieval information matching the query information is determined from the multiple file index blocks according to the query information input by the user; wherein at least one target file retrieval information is determined by vector matching of the query information and the file content in the file index block, and / or keyword matching and / or file style analysis of the file content in the file index block; the query information and at least one target file retrieval information are input into a pre-trained language processing model so that the language processing model combines the context information of at least one target file retrieval information and outputs a query result for the query information. In this way, the size of the file index block is dynamically adjusted by combining the semantic structure of the file and the query relevance of the query information to avoid missing information in the file index block, and when searching according to the query information, vector matching and / or keyword matching and considering the file style are combined to obtain more comprehensive and accurate target file retrieval information, which helps to improve the accuracy of the retrieval results output according to the target file retrieval information obtained by the retrieval and the user query information.
[0045] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0047] Figure 1 A flowchart of a document retrieval generation method provided in an embodiment of the present application;
[0048] Figure 2 One of the structural schematic diagrams of a document retrieval generation device provided in an embodiment of the present application;
[0049] Figure 3 A second structural diagram of a document retrieval generation device provided in an embodiment of the present application;
[0050] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application usually described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, each other embodiment obtained by those skilled in the art without making creative work belongs to the scope of protection of the present application.
[0052] Retrieval-Augmented Generation (RAG) is a natural language processing technology that combines retrieval and generation capabilities. By using the above technology to refer to external knowledge bases, the breadth and accuracy of the model's answers to user query information can be improved.
[0053] When performing data retrieval through RAG, in the relevant technology, due to the retrieval matching method (generally keyword matching), the block division method for files, and the special format processing method for files, the matching degree and comprehensiveness of the retrieved file retrieval information and the user output query information are low, and retrieval information that is more relevant to the query information is omitted during the retrieval process, resulting in low accuracy of the query results obtained based on the retrieval information analysis.
[0054] Based on this, an embodiment of the present application provides a document retrieval generation method to improve the accuracy of the retrieval results output based on the target file retrieval information obtained by the retrieval and the user query information.
[0055] See also Figure 1 , Figure 1 A flowchart of a document retrieval generation method provided in an embodiment of the present application. Figure 1 As shown in , the document retrieval generation method provided in the embodiment of the present application includes:
[0056] S101. Parse and divide a plurality of pre-uploaded files into a plurality of file index blocks; wherein each of the file index blocks is dynamically determined based on the semantic structure of the files and the relevance of the query object in the context of the query information input by the user.
[0057] S102. According to the query information input by the user, determine at least one target file retrieval information matching the query information from the multiple file index blocks; wherein the at least one target file retrieval information is determined by performing vectorized matching and / or keyword matching on the query information and the file content in the file index block and / or performing file style analysis on the file content in the file index block.
[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 and outputs a query result for the query information.
[0059] A document retrieval generation method provided by an embodiment of the present disclosure dynamically adjusts the size of a file index block by combining the file semantic structure and the query relevance of query information to avoid missing information in the file index block, and when retrieving based on query information, 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 target file retrieval information obtained based on the retrieval and the retrieval results outputted from the user query information.
[0060] The following is a description of the exemplary steps of the embodiment of the present disclosure:
[0061] S101. Parse and divide a plurality of pre-uploaded files into a plurality of file index blocks; wherein each of the file index blocks is dynamically determined based on the semantic structure of the files and the relevance of the query object in the context of the query information input by the user.
[0062] In an embodiment of the present application, Retrieval-Augmented Generation (RAG) is a natural language processing technology that combines retrieval and generation capabilities. By adopting the above technology to refer to an external knowledge base, the breadth and accuracy of the model's answers to user query information can be improved.
[0063] In a possible implementation, for RAG technology, an external knowledge database needs to be connected, so users are required to upload all knowledge-related files, and then the files uploaded by users are segmented to obtain multiple file blocks. Furthermore, the segmented file blocks are placed in the corresponding database to obtain file index blocks.
[0064] Here, although the large language model in the related technology can process relatively long texts, the processing capacity of the large language model is obviously insufficient when faced with the vast amount of archived files with thousands of pages. For a file, the file content related to the query information entered by the user may only be one or several parts in the file. Therefore, it is necessary to parse the file and divide it into multiple file index blocks. When performing a query, the file information in one or more file index blocks that are most relevant to the user's query information can be found, thereby improving the efficiency of file query.
[0065] In one possible implementation, when files are segmented, in order to facilitate user queries and file storage, the size of each file index block is generally fixed, but the specific size of each file block can generally be customized by the user. However, because the block size is fixed, if the size of each file index block is set too large, useful information may be submerged in useless information. If it is large to a certain extent, it will exceed the processing capacity of the language model. If the size of each file index block is set too small, in addition to possibly causing the information in the mentioned file to be lost accidentally, it may also cause insufficient context information, leading to ambiguity and other problems, thereby affecting the accuracy of the final query result.
[0066] Based on this, in an embodiment of the present 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, thereby avoiding excessive or missing information in each file index block and improving the accuracy of the final query results.
[0067] Specifically, the parsing and segmenting of the pre-uploaded multiple files into multiple file index blocks includes:
[0068] a1: for each file, based on the semantic structure of the file, determining multiple file semantic structure types contained in the file, and dividing the file contents belonging to the same file semantic structure type in the file into the same file index block; and / or,
[0069] a2: parsing the query information input by the user, determining the same target query object contained in the query information, and grouping the file contents of the multiple files belonging to the same target query object into the same file index block.
[0070] In a possible implementation, when parsing and splitting each file, the file semantic structure of each file can be analyzed first to determine multiple file semantic structure types contained in each file, and then the file contents belonging to the same file 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 chapter, document paragraph, document sentence boundaries.
[0073] Exemplarily, for the same file, by analyzing the file content of the file, multiple chapters and multiple paragraphs contained in the file are determined; the information of multiple chapters (such as chapter titles, file content ranges corresponding to chapters) is divided into a chapter index module; and the information of multiple paragraphs (the number of paragraphs in the file, the document content range corresponding to each paragraph, and other information) is divided into a 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, it is also possible to divide the file contents belonging to the same target query object into the same file index block based on the target query object included in the user's query information, and then determine the size of each file index block based on the content contained in each file index block.
[0075] Exemplarily, after analyzing the user's query information, it is determined that the target query objects mentioned in the user's query information include time, place, and target person. Therefore, the file content related to time in the file can be divided into the same file index block, the file content related to location in the file can be divided into the same file index block, and the file content related to person in the file 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 in the file and the user's query information through the above method, while ensuring the integrity of the file content in each file index block, and at the same time, the accuracy of the retrieval results obtained based on the query information retrieval can be improved.
[0077] Furthermore, when searching for file index blocks, information such as file chapters may be retrieved, but each chapter may contain multiple subsections. When the query information input by the user includes a chapter title, a matching query based on the chapter title or information such as the chapter title can often only retrieve file index blocks near the chapter, and related file text content farther away from the title may be ignored, resulting in a low accuracy rate in the target file retrieval information obtained by querying based on the user's query information.
[0078] Based on this, when storing chapter information in a file, the embodiment of the present application considers storing it according to the association relationship between chapters to ensure that each file index block carries title information. When querying according to the chapter query information input by the user, all relevant chapters and the corresponding file text content can be indexed based on the chapter title information, thereby improving the accuracy of the target file retrieval information obtained by querying according to the user's query information.
[0079] Specifically, the document retrieval generation method further includes:
[0080] b1: for each file, detecting whether the file belongs to a target file type; wherein a file belonging to the target file type is a structured file.
[0081] b2: for each file belonging to the target file type, directly parse the file to determine a plurality of file style information contained in the file and file style relationship information between the plurality of file style information.
[0082] b3: For each file that does not belong to the target file type, multiple text box ranges and corresponding coordinates in the file 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.
[0083] b4: For each file, multiple file style information contained in the file and file style relationship information between the multiple file style information are associated with the file content in the file index block corresponding to the file and stored, so that each of the file index blocks contains corresponding file style information.
[0084] The file style information may include the font, font size, whether it is a title, text, table, picture, header, footer, reference, and other information in the file.
[0085] In a possible implementation, when determining the file style information of a file, it is first necessary to determine the file type of the file. If the file belongs to a target file type of a structured file, the style information of the file can be directly parsed using open source tools.
[0086] Exemplarily, the target file type may be a word file. docx itself is a semi-structured file. The word type file can be directly parsed through open source tools to obtain file style information such as the title in the file. At the same time, the font style in the file can be determined (for example, font, font size, whether it is a title, etc.).
[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 unstructured file of image type, although PDF can also be processed by a parsing tool, since PDF is a document format optimized for printing scenarios, the text therein only retains basic font, location coordinates and other information, but the title format cannot be determined.
[0088] Based on this, in an embodiment of the present application, optical character recognition is performed on the file to determine the range and coordinates of each text box in the file, and then the file style information contained in the file is analyzed through the service parsing model.
[0089] Among them, Optical Character Recognition (OCR) refers to the process in which an electronic device (such as a scanner or digital camera) examines characters printed on paper, determines their shapes by detecting dark and light patterns, and then translates the shapes into computer text using character recognition methods; that is, for printed characters, an optical method is used to convert the text in a paper document into a black and white dot matrix image file, and recognition software is used to convert the text in the image into a text format for further editing and processing by word processing software.
[0090] Furthermore, OCR can be used to identify text boxes in a file and the coordinates of specific text in the document, and then the identified multiple text box ranges and corresponding coordinates are input into a pre-trained layout parsing model, and the text style information contained in the file is output by the layout parsing model.
[0091] Here, the layout parsing model outputs the file style information such as the file title, text, table, picture, header, footer, reference, etc., and then the multiple file style information contained in the file and the file style relationship information between the multiple file style information can be determined, and the file style information of the file is stored according to the file style relationship information.
[0092] Here, the file style relationship information includes the association and subordination between different file styles. For example, for the file style of chapter, the chapter can contain multiple titles and multiple subtitles associated with each title. This association and subordination is the file style relationship. According to the file style relationship, multiple file styles in the file can be associated. When searching, 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, and then accurate and comprehensive target file retrieval information can be retrieved.
[0093] In a possible implementation, for each file, the file style information of the file is stored through the following steps:
[0094] c1: For each file, determine the multiple file styles contained in the file and the hierarchical relationships between the multiple file styles.
[0095] c2: For each file, based on multiple file styles contained in the file and the hierarchical relationship between the multiple file styles, a file tree is constructed to store the file styles and corresponding file contents.
[0096] In an embodiment of the present 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 of the file tree, an association relationship between the file styles contained in the file is constructed, and all file information related to the file style can be obtained during query.
[0097] Specifically, the file styles in the superior relationship in the file tree are nodes of the file tree, and the child nodes under each node are subordinate file styles of the file style in the superior relationship corresponding to the node and corresponding file contents.
[0098] Exemplarily, taking the file style as chapter title as an example, each level of title corresponds to a node, and the subtitle and body of the title are the child nodes of the node, thereby constructing a file tree.
[0099] For example, when searching, if the user's query information includes title A, then when searching for related information of title A, subtitle A1 and subtitle A2 related to title A can be found from the pre-built file tree, as well as the corresponding file text content. When the query results are returned, title A, subtitle A1, subtitle A2 and file text content are all query results obtained by the query, ensuring the comprehensiveness and accuracy of the query results.
[0100] In a possible implementation, in the related art, when processing a file, if the file contains table content (the table content here does not refer to pure table formats such as excel, csv, etc., but includes a table inserted in word, pdf), since the format of the table inserted in the file is inconsistent and there are merged cells, the corresponding column name in the table will also be changed, making it difficult to identify; at the same time, a part of the table inserted in the document is placed in the document in the form of a picture, and the current OCR intelligently recognizes text information and cannot recognize the table structure. Furthermore, when searching for a table in a file, it is difficult to search, because the entire table has complete semantic information, it is difficult to segment and index. If it is not segmented, the support for large tables is quite poor. Based on the above problems, the recognition and retrieval accuracy of tables in the related art is relatively low.
[0101] Based on this, in an embodiment of the present application, a table structure recognition model is used to identify the cell information and header information corresponding to the cell position information of the table existing in the file, and an accurate recognition result is output, which can improve the accuracy of table recognition queries in the file.
[0102] Specifically, the document retrieval generation method further includes:
[0103] d1: For each file, based on the file style information parsed from the file, determine whether there is a table in the file.
[0104] d2: For each file containing a table, the coordinate information of the location of each table contained in the file and a screenshot of the table are input into a pre-trained table structure recognition model, and the cell information and header information corresponding to the cell position information in the table of each table in the file are output.
[0105] d3: storing the cell information and header information corresponding to the cell position information in each table corresponding to each file, so as to obtain the query result according to the query information input by the user combined with the cell information and header information corresponding to the cell position information in the table.
[0106] In an embodiment of the present application, after the file is identified by the layout recognition model, if it is determined that there is a table in the current file, the coordinate information of the location of the table in the file identified by OCR and a screenshot of the table need to be input into a pre-trained table structure recognition model, and then the cell information and header information corresponding to the cell position information of the table are output by the table structure recognition model.
[0107] Here, the table structure recognition model, namely Table Structure Recognition (TSR), can be used to identify the row and column structure of the table and determine the position of each cell. Commonly used methods include clustering method and projection histogram analysis. When the coordinate information of the location of the table in the file and the table screenshot obtained by taking a screenshot of the table in the file are input into the table structure recognition model, the table structure in the file is analyzed and recognized by the table structure recognition model, and then the specific information of the table is obtained.
[0108] Exemplarily, Table 1 is a table to be identified in a table format to be determined. For Table 1, TSR can output a result in a similar json format after processing.
[0109] Table 1 Table to be identified
[0110]
[0111]
[0112]
[0113]
[0114] Furthermore, after determining and identifying the cell information and header information corresponding to the cell position information in each table corresponding to each file, a relational database can be established for the table information to save it. After the user subsequently inputs query information, the query information is spliced with the target table information in the relational database, and the spliced information is input into the model to obtain the query results.
[0115] Furthermore, after the file is parsed and split into file index blocks, after the user inputs query information, the file index blocks can be indexed according to the query information to obtain target file retrieval information.
[0116] S102. According to the query information input by the user, determine at least one target file retrieval information matching the query information from the multiple file index blocks; wherein the at least one target file retrieval information is determined by performing vectorized matching and / or keyword matching on the query information and the file content in the file index block and / or performing file style analysis on the file content in the file index block.
[0117] In the related art, when indexing uploaded files, strings are generally saved directly for indexing. After the user enters query information, the relevant target file retrieval information is determined by matching the query information with keywords. For example, the retrieval algorithm may be an inverted index, bm25 or other derivative algorithms. However, the above query algorithm matches by keywords and cannot query text outside the matching query information, resulting in low query matching accuracy.
[0118] For example, if the query information input by the user is "What fruit did you eat today", the content stored in the pre-stored file is "I bought a banana and an apple in Central Park today. In the afternoon, I bought half a watermelon... I ate all the fruit I bought before when I got home at night", and the results returned for the query information input by the user should be bananas, apples and watermelons. However, when parsing the file, the "bought bananas, apples and watermelons" and "ate the fruit I bought before" in the parsed file index block will not belong to the same file index block. When searching based on the keywords of the query information, the matching is prioritized based on "fruit", and the matching result is "ate the fruit I bought before". Obviously, the key information of what fruit was eaten will be ignored by the retrieval algorithm, resulting in the query results output by the subsequent language model based on the retrieval results being relatively low in accuracy.
[0119] Based on this, in an embodiment of the present application, when searching for files through query information input by the user to determine at least one target file retrieval information, not only can the corresponding information be matched by keywords, but similar files can also be retrieved through the distance between vectors, thereby obtaining more accurate and comprehensive retrieval results, so as to improve the accuracy of query results obtained by subsequent language models based on the retrieval results.
[0120] Specifically, the step of "determining at least one target file retrieval information matching the query information from the plurality of file index blocks according to 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 matching the query vector from a pre-built vector database.
[0122] e2: Determine multiple target keywords included in the query information input by the user and the text content in the file index block, and determine at least one keyword matching result that matches each target keyword.
[0123] e3: Determine at least one target vector retrieval result and at least one keyword matching result and input them 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 a target output result that is sorted before a preset position.
[0124] e4: Determine the target output result as the target file retrieval information.
[0125] In an embodiment of the present application, when searching through query information input by the user 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 to ensure the comprehensiveness and accuracy of the target file retrieval information obtained by the query and avoid omissions.
[0126] In a possible implementation, the query statement in the query information can be converted into a query vector through vectorization processing, and a vector database (for example, milvus database, etc.) 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 vector in the vector database to obtain a matching target vector retrieval result.
[0127] Here, the query vector may be matched with the vectors in the vector database by using a distance algorithm, and a target vector retrieval result matching the query vector may be determined according to the distance between the query vector and each vector data in the vector database.
[0128] In a possible implementation, the distance between the query vector and each vector data in the vector database may be calculated by the following formula:
[0129]
[0130] Where d is the distance (cosine distance) between the query vector and the vector data in the vector database; is the query vector; It is the vector data in the vector database.
[0131] Furthermore, after determining at least one target vector retrieval result that is close to the query vector based on vector calculation, it is also necessary to match the keywords in the query information with the file contents in each file index block to obtain a keyword matching result, and then input the at least one target vector retrieval result and at least one keyword matching result obtained into a pre-trained language representation model, sort the retrieval results and determine the target output result at the front as the target file retrieval information that matches the query information.
[0132] In a possible implementation, the language representation model may be a BERT model, and the BERT model is used to score and rank the target vector retrieval results and keyword matching results. The ranking order may be to sort the retrieval results in descending order according to the score corresponding to each retrieval result. The higher the score, the higher the match between the retrieval result and the query information. The query results ranked in the top few positions are then determined as the target output results, and participate in the determination and output of subsequent query results.
[0133] Exemplarily, after vector query, target vector retrieval result X1, target vector retrieval result X2 and target vector retrieval result X3 are obtained; after keyword query, keyword matching result Y1, keyword matching result Y2 and keyword matching result Y3 are obtained, and the above results are input into the BERT model, and the sorting order obtained after scoring and sorting each matching result is: 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, and the target vector retrieval result X1 which is ranked highest and closest to the query information is selected as the target file retrieval information.
[0134] In a possible implementation, if the query information includes file style query information, when performing query indexing based on the query information, a comprehensive search needs to be performed based on a pre-stored file tree to ensure the accuracy and comprehensiveness of the search results.
[0135] Specifically, when the query information includes file style query information, the target file retrieval information is determined by the following steps:
[0136] f1: Determine at least one file query pattern included in the file pattern query information.
[0137] f2: for each file query pattern, query the file tree for 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 based on the file query pattern.
[0138] f3: Determine the node file content and the sub-node file content as the target file retrieval information.
[0139] In an embodiment of the present application, when the query information includes file style query information, at least one file query style that the user currently 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.), and then a deep 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 sub-node file content corresponding to the sub-node associated with the file query style, and then all the queried content is returned to obtain the target file retrieval information, thereby ensuring the comprehensiveness and accuracy of the target file retrieval information.
[0140] Exemplarily, 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 the title W is associated with subtitle W1, subtitle W and main content B. Then the target file retrieval information returned by the query includes title W, subtitle W1, subtitle W and main content B.
[0141] In a possible implementation, when performing a query based on the query information input by the user, in order to obtain as many query targets in the query information as possible and ensure the accuracy of the query retrieval, the query statement may be recursively analyzed multiple times to determine the accurate query target.
[0142] Specifically, the document retrieval generation method further includes:
[0143] g1: recursively decompose the query information input by the user into a plurality of related query information, so as to determine the at least one target file retrieval information from the plurality of file index blocks according to the plurality of related query information.
[0144] In an embodiment of the present application, after receiving the query information input by the user, the query information can be decomposed into multiple related query information, and multiple recursive queries can be performed on each query information. Then, based on multiple query analyses, the user's true query intention can be determined, and the target retrieval information that matches the query information can be determined based on the determined true query intention.
[0145] For example, the query information input by the user is "What fruit did you eat today?" Through decomposition analysis, the relevant query information that can be decomposed includes "Today's date" -> "Type of fruit" -> "Eat fruit". By gradually decomposing and analyzing the query information, the target search information can be accurately retrieved.
[0146] Furthermore, after obtaining target file retrieval information by matching the query information with the file index block, the query result for the query information can be obtained by combining the obtained target file retrieval information with the query information input by the user through processing by the language processing model.
[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 and outputs a query result for the query information.
[0148] In an embodiment of the present application, after the user inputs query information, target file retrieval information can be retrieved based on the query information, and then the query information and at least one target file retrieval information obtained are input into a pre-trained language processing model. In the language processing model, context information of at least one target file retrieval information can be referenced to output accurate query results for the query information.
[0149] In a possible implementation, the language processing model may be a large language processing model, an NL2SQL model, or the like.
[0150] The document retrieval generation method provided by the embodiment of the present application parses and divides the pre-uploaded multiple 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; according to the query information input by the user, at least one target file retrieval information matching the query information is determined from the multiple file index blocks; wherein the at least one target file retrieval information is determined by vector matching of the query information and the file content in the file index block, and / or keyword matching and / or file style analysis of the file content in the file index block; the query information and at least one target file retrieval information are input into a pre-trained language processing model so that the language processing model combines the context information of at least one target file retrieval information and outputs the query result for the query information. In this way, the size of the file index block is dynamically adjusted by combining the semantic structure of the file and the query relevance of the query information to avoid missing information in the file index block, and when searching according to the query information, vector matching and / or keyword matching and considering the file style are combined to obtain more comprehensive and accurate target file retrieval information, which helps to improve the accuracy of the retrieval results output according to the target file retrieval information obtained by the retrieval and the user query information.
[0151] Based on the same inventive concept, a document retrieval generation device corresponding to the document retrieval generation method is also provided in the embodiment of the present application. Since the principle of solving the problem by the device in the embodiment of the present application is similar to the above-mentioned document retrieval generation method in the embodiment of the present application, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0152] See also Figure 2 , Figure 3 , Figure 2 This is one of the structural diagrams of a document retrieval generation device provided in an embodiment of the present application. Figure 3 This is a second structural diagram of a document retrieval generation device provided in an embodiment of the present application. Figure 2 As shown in , the document retrieval generation device 200 includes:
[0153] The index block partitioning module 210 is used to parse and partition the pre-uploaded multiple files into multiple file index blocks; wherein each of the file index blocks 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] A search information determination module 220 is used to determine at least one target file search information matching the query information from the multiple file index blocks according to the query information input by the user; wherein the at least one target file search information is determined by performing vectorized matching and / or keyword matching on the query information and the file content in the file index block and / or performing file style analysis on the file content in the file index block;
[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 a query result for the query information.
[0156] In a possible implementation, when the index block division module 210 is used to parse and divide the pre-uploaded multiple files into multiple file index blocks, the index block division module 210 is used to:
[0157] For each file, based on the semantic structure of the file, multiple file semantic structure types contained in the file are determined, and file contents belonging to the same file semantic structure type in the file are divided into the same file index block; and / or,
[0158] Parsing the query information input by the user, determining the same target query object contained in the query information, and dividing the file contents of the multiple files belonging 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 chapter, document paragraph, document sentence boundaries.
[0161] In a possible implementation manner, the file index block includes file style information and file style relationship information; Figure 3 As shown, the document retrieval generation device 200 further includes a file style association module 240, and the file style association module 240 is used to:
[0162] For each file, detecting whether the file belongs to a target file type; wherein the file belonging to the target file type is a structured file;
[0163] For each file belonging to the target file type, directly parse the file to determine a plurality of file style information contained in the file and file style relationship information between the plurality of file style information;
[0164] For each file that does not belong to the target file type, multiple text box ranges and corresponding coordinates in the file obtained 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, multiple file style information contained in the file and file style relationship information between the multiple file style information are associated with the file content in the file index block corresponding to the file and stored, so that each file index block contains corresponding file style information.
[0166] In a possible implementation, for each file, the file style association module 240 is used to store the file style information of the file through the following steps:
[0167] For each file, determine the multiple file styles contained in the file and the hierarchical relationship between the multiple file styles;
[0168] For each file, based on multiple file styles contained in the file and the hierarchical relationship between the multiple file styles, a file tree is constructed to store the file styles and corresponding file contents;
[0169] The file styles in the superior relationship in the file tree are nodes of the file tree, and the child nodes under each node are subordinate file styles of the file style in the superior relationship corresponding to the node and corresponding file contents.
[0170] In a possible implementation, Figure 3 As shown, the document retrieval generation device 200 further includes a table query module 250, and the table query module 250 is used to:
[0171] For each file, determine whether there is a table in the file based on the file style information parsed from the file;
[0172] For each file containing a table, the coordinate information of the location of each table contained in the file and a screenshot of the table are input into a pre-trained table structure recognition model, and the cell information and header information corresponding to the cell location information in the table of each table in the file are output;
[0173] The cell information and header information corresponding to the cell position information in each table corresponding to each file are stored, so as to obtain the query result according to the query information input by the user in combination with the cell information and header information corresponding to the cell position information in the table.
[0174] In a possible implementation manner, when the search information determination module 220 is used to determine at least one target file search information matching the query information from the multiple file index blocks according to the query information input by the user, the search information determination module 220 is used to:
[0175] 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 matching the query vector from a pre-built vector database;
[0176] Determine a plurality of target keywords included in the query information input by the user and the text content in the file index block, and determine at least one keyword matching result matching each target keyword;
[0177] Determining at least one target vector search result and at least one keyword matching result and inputting them into a pre-trained language representation model, so that the language representation model sorts the at least one target vector search result and the at least one keyword matching result, and outputs a target output result that is sorted before a preset position;
[0178] The target output result is determined as the target file retrieval information.
[0179] In a possible implementation manner, when the query information includes file style query information, the search information determination module 220 is used to determine the target file search information through the following steps:
[0180] Determine at least one file query pattern included in the file pattern query information;
[0181] For each file query pattern, query the file tree for 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 based on the file query pattern;
[0182] The node file content and the sub-node file content are determined as the target file retrieval information.
[0183] In a possible implementation, Figure 3 As shown, the document retrieval generation device 200 further includes a query information disassembly module 260, and the query information disassembly module 260 is used to:
[0184] The query information input by the user is recursively decomposed into a plurality of related query information, so as to determine the at least one target file retrieval information from the plurality of file index blocks according to the plurality of related query information.
[0185] The document retrieval generation device provided by the embodiment of the present application parses and divides the pre-uploaded multiple 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; according to the query information input by the user, at least one target file retrieval information matching the query information is determined from the multiple file index blocks; wherein the at least one target file retrieval information is determined by vector matching of the query information and the file content in the file index block, and / or keyword matching and / or file style analysis of the file content in the file index block; the query information and at least one target file retrieval information are input into a pre-trained language processing model, so that the language processing model combines the context information of at least one target file retrieval information and outputs the query result for the query information. In this way, the size of the file index block is dynamically adjusted 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, and when searching according to the query information, vector matching and / or keyword matching are combined and the file style is considered to obtain more comprehensive and accurate target file retrieval information, which helps to improve the accuracy of the target file retrieval information obtained according to the retrieval and the retrieval results output by the user query information.
[0186] See also Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 4 As shown in , 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, the above-mentioned Figure 1 The steps of the document retrieval generation method in the illustrated method embodiment and the specific implementation thereof can be found in the method embodiment, which will not be described in detail here.
[0188] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the computer program can execute the above-mentioned Figure 1 The steps of the document retrieval generation method in the illustrated method embodiment and the specific implementation thereof can be found in the method embodiment, which will not be described in detail here.
[0189] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0190] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0191] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0192] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0193] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application can essentially or in other words, the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0194] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A document retrieval generation method, characterized in that: The document retrieval generation method comprises: Parsing and dividing the pre-uploaded multiple files into multiple file index blocks; wherein each of the file index blocks 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; According to the query information input by the user, at least one target file retrieval information matching the query information is determined from the multiple file index blocks; wherein the at least one target file retrieval information is determined by performing vectorized matching and / or keyword matching on the query information and the file content in the file index block and / or performing file style analysis on the file content in the file index block; 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 context information of the at least one target file retrieval information and outputs a query result for the query information.
2. The document retrieval generation method according to claim 1, characterized in that: The step of parsing and dividing the pre-uploaded multiple files into multiple file index blocks includes: For each file, based on the semantic structure of the file, multiple file semantic structure types contained in the file are determined, and file contents belonging to the same file semantic structure type in the file are divided into the same file index block; and / or, Parsing the query information input by the user, determining the same target query object contained in the query information, and dividing the file contents of the multiple files belonging 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 chapter, document paragraph, document sentence boundaries.
3. The document retrieval 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 generation method also includes: For each file, detecting whether the file belongs to a target file type; wherein the file belonging to the target file type is a structured file; For each file belonging to the target file type, directly parse the file to determine a plurality of file style information contained in the file and file style relationship information between the plurality of file style information; For each file that does not belong to the target file type, multiple text box ranges and corresponding coordinates in the file obtained 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, multiple file style information contained in the file and file style relationship information between the multiple file style information are associated with the file content in the file index block corresponding to the file and stored, so that each file index block contains corresponding file style information.
4. The document retrieval generation method according to claim 3, characterized in that: For each file, the file style information of the file is stored through the following steps: For each file, determine the multiple file styles contained in the file and the hierarchical relationship between the multiple file styles; For each file, based on multiple file styles contained in the file and the hierarchical relationship between the multiple file styles, a file tree is constructed to store the file styles and corresponding file contents; The file styles in the superior relationship in the file tree are nodes of the file tree, and the child nodes under each node are subordinate file styles of the file style in the superior relationship corresponding to the node and corresponding file contents.
5. The document retrieval generation method according to claim 3, characterized in that: The document retrieval generation method also includes: For each file, determine whether there is a table in the file based on the file style information parsed from the file; For each file containing a table, the coordinate information of the location of each table contained in the file and a screenshot of the table are input into a pre-trained table structure recognition model, and the cell information and header information corresponding to the cell location information in the table of each table in the file are output; The cell information and header information corresponding to the cell position information in each table corresponding to each file are stored, so as to obtain the query result according to the query information input by the user in combination with the cell information and header information corresponding to the cell position information in the table.
6. The document retrieval 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 according to the query information input by the user comprises: 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 matching the query vector from a pre-built vector database; Determine a plurality of target keywords included in the query information input by the user and the text content in the file index block, and determine at least one keyword matching result matching each target keyword; Determining at least one target vector search result and at least one keyword matching result and inputting them into a pre-trained language representation model, so that the language representation model sorts the at least one target vector search result and the at least one keyword matching result, and outputs a target output result that is sorted before a preset position; The target output result is determined as the target file retrieval information.
7. The document retrieval 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 by the following steps: Determine at least one file query pattern included in the file pattern query information; For each file query pattern, query the file tree for 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 based on the file query pattern; The node file content and the sub-node file content are determined as the target file retrieval information.
8. The document retrieval generation method according to claim 1, characterized in that: The document retrieval generation method also includes: The query information input by the user is recursively decomposed into a plurality of related query information, so as to determine the at least one target file retrieval information from the plurality of file index blocks according to the plurality of related query information.
9. A document retrieval generation device, characterized in that: The document retrieval generation device comprises: An index block partitioning module is used to parse and partition a plurality of pre-uploaded files into a plurality of file index blocks; wherein each of the file index blocks 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; A search information determination module, configured to determine, based on the query information input by the user, at least one target file search information matching the query information from the multiple file index blocks; wherein the at least one target file search information is determined by performing vectorized matching and / or keyword matching on the query information and the file content in the file index block and / or performing file style analysis on the file content in the file index block; 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 a query result for the query information.
10. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, 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 generation method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Retrieval methodology base on layout information
CN101246475A
Chinese search engine mixed speech-oriented query error corrosion method and system
CN102867040A
Encryption search method and device based on text semantics
CN116737750A
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
Cited By
Formula generation method
CN121306341A