Question and answer method based on file analysis technology, medium and equipment

By differentiating and binding file types and user questions with engine processing, the accuracy and consistency issues of large language models in processing ultra-large files are solved, achieving efficient and accurate question-answering results.

CN121833907APending Publication Date: 2026-04-10HANGZHOU YUNSHEN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HANGZHOU YUNSHEN TECH CO LTD
Filing Date
2026-01-26
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

When large language models process extremely large files that exceed the preset context window, they face a decline in information capture capabilities, resulting in reduced accuracy and coherence of answers, and they also struggle to effectively handle structured tables and long document data.

Method used

By analyzing the file type and the task attributes of the user's question, the target file is parsed and transformed to generate an intermediate representation that matches the task attributes. The file is then processed using a question-and-answer processing engine corresponding to the file type, which combines a code execution engine and a large language model engine to ensure that the processing is carried out within the effective working range of the large language model.

Benefits of technology

It improves the accuracy and relevance of question-and-answer results, solves the problem of exceeding file limits, avoids information redundancy and calculation errors, and ensures that the answers are highly relevant to user needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121833907A_ABST
    Figure CN121833907A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of question answering, in particular to a question answering method based on a file analysis technology, a medium and equipment, and the method comprises the steps: converting an original file into an intermediate representation which is controllable in length and is matched with a task by analyzing the structural features of a target file, exceeding a context window of a large language model, of the file and the task demand of a user question; the problem of file overrun is solved, and input information is highly related to user requirements; through binding of the file type and the question and answer processing engine, executable codes of a structured table can be directly operated by a code execution engine, deep semantic analysis is not needed, format misunderstanding and calculation errors when a large language model processes the table are avoided, and simplified text fragments of an unstructured document are processed by the large language model, so that the processing efficiency of the unstructured document is improved. Redundant information filtering is not needed, the answers are made to better fit the intention of the user question, it is ensured that the questions are always performed in the effective working interval of the large language model, and the accuracy and pertinence of the question and answer result are remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

field

[0001] This invention relates to the field of question-and-answer technology, and in particular to a question-and-answer method, medium, and device based on document analysis technology. Background Technology

[0002] Large language models have demonstrated powerful capabilities in natural language processing and question answering tasks. When handling file-based question answering, a full input mode is typically used, where the file content and user question are directly concatenated and input into the model, relying on the model's contextual understanding to generate the answer. However, large language models face significant technical bottlenecks when processing extremely large files that exceed a preset context window. Specifically: When the length of the input context approaches or exceeds the theoretical upper limit of the model, the model's ability to capture information from the middle of the text drops sharply, resulting in information loss and a significant decrease in the factual accuracy and coherence of the generated answers. Existing methods typically crudely concatenate the entire file with the question before inputting it into the model, ignoring the model's effective working range, leading to uncontrollable performance when processing large files.

[0003] Furthermore, most existing solutions rely on a single generative model path. For highly structured tabular data, the model needs to understand the entire structure and content of the table before generating the answer. This not only consumes a lot of computational resources but is also prone to factual errors and cannot perform accurate data queries and statistics. For long document data, existing technologies, whether using simple truncation methods or indiscriminate vector retrieval, struggle to capture a balanced overview of the entire document for global issues or accurately locate key details for local issues within a limited context window. This results in incomplete or irrelevant contextual information obtained by the model.

[0004] Therefore, how to provide an intelligent file question answering method that can adapt to file type and question intent and effectively overcome the contextual limitations of large models has become an urgent problem to be solved. Summary of the Invention

[0005] To address the aforementioned technical problems, the present invention provides a question-and-answer method based on document analysis technology, which includes the following steps: S1. If the total number of characters in the target file is greater than the first preset length threshold, then the target file is parsed and converted according to the file type of the target file and the task attributes of the target user's question for the file type, and an intermediate representation with a character count less than the first preset length threshold and matching the task attributes is obtained. The file type includes structured tables and unstructured documents.

[0006] S2, through the question-answering processing engine corresponding to the file type, executes the preset operation corresponding to the type of the intermediate representation to obtain the target answer. The question-answering processing engine includes a code execution engine and a large language model engine. If the file type is a structured table, the preset operation is executed by the code execution engine. If the file type is an unstructured document, the preset operation is executed by the large language model engine.

[0007] The present invention also provides a non-transitory computer-readable storage medium storing at least one instruction or at least one program, wherein the at least one instruction or at least one program is loaded and executed by a processor to implement the above-described question-and-answer method based on document analysis technology.

[0008] The present invention also provides an electronic device, including a processor and the aforementioned non-transitory computer-readable storage medium.

[0009] This invention has at least the following beneficial effects: For extremely large files exceeding the context window of a large language model, by analyzing the structural features of the file and the task requirements of the user's question, the original file is converted into an intermediate representation with a controllable length that matches the task. This solves the problem of file exceeding the limit and ensures that the input information is highly relevant to the user's needs. By binding the file type with the question-answering processing engine, structured tables can be directly executed by the code execution engine without deep semantic analysis, avoiding format misunderstandings and calculation errors when the large language model processes tables. Unstructured documents can be processed by the large language model to obtain their simplified text fragments without redundant information filtering, making the answer more consistent with the user's intent. At the same time, it ensures that the process always occurs within the effective working range of the large language model, significantly improving the accuracy and relevance of the question-answering results. Attached Figure Description

[0010] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0011] Figure 1 This is a flowchart of a question-and-answer method based on document analysis technology provided in Embodiment 1 of the present invention. Detailed Implementation

[0012] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0013] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It is understood that, where appropriate, the terms used to distinguish similar objects can be interchanged so that the invention can also be implemented in other embodiments besides the illustrated or described embodiments. Furthermore, the terms "including," "having," and any variations are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices.

[0014] Example 1 This first embodiment provides a question-and-answer method based on document analysis technology, such as Figure 1 As shown, this question-answering method based on document analysis technology includes the following steps: S1. If the total number of characters in the target file is greater than the first preset length threshold, then the target file is parsed and converted according to the file type of the target file and the task attributes of the target user's question for the file type, so as to obtain an intermediate representation with a character count less than the first preset length threshold and matching the task attributes.

[0015] The file types include structured tables and unstructured documents. In structured tables, data is organized in rows and columns and has clear headers and structured fields (such as Excel and CSV files). In unstructured documents, data exists in the form of natural language paragraphs and has no fixed structure (such as PDF reports and Word documents).

[0016] Those skilled in the art will recognize that any method for determining file type in the prior art falls within the protection scope of this invention. For example, structured tables and unstructured documents can be distinguished by file format (e.g., .xlsx / .csv are structured tables, .pdf / .doc are unstructured documents) combined with table structure detection, text paragraph recognition, and other content parsing methods. Further details will not be elaborated here.

[0017] Task attributes represent the specific needs of users regarding a particular document. They are used to refine the transformation goals, ensuring that the intermediate representation accurately matches the problem requirements and avoiding information redundancy or omissions. Specifically, for structured tables, task attributes include simple query statistics (such as "query sales revenue in 2023") and complex query statistics (such as "first group sales revenue by region, then calculate the year-on-year growth rate"). For unstructured documents, task attributes include global questions (such as "summarize the core viewpoints of the entire text") and local questions (such as "what is the principle behind a certain technology mentioned in the text?").

[0018] Those skilled in the art will know that any method for determining file type in the prior art falls within the protection scope of this invention. For example, a pre-trained intent recognition model (such as Bidirectional EncoderRepresentations from Transformers) can be used to determine the specific needs of the target user for the current file type, which will not be elaborated here.

[0019] The first preset length threshold is a critical length determined based on the performance degradation curve of the large language model, such as 80,000 characters. When the file length exceeds the first preset length threshold, the question-answering accuracy of the large language model decreases significantly. Therefore, the first preset length threshold is used as the standard for judging whether the target file needs to be converted, ensuring that subsequent processing is always carried out within the effective working range of the model.

[0020] For extremely large files that exceed the context window of a large language model, a differentiated transformation strategy is adopted by parsing the structured features of the target file and the task requirements of the target user's question. The original target file is converted into an intermediate representation with a controllable length that matches the task. This ensures that the number of characters in the intermediate representation is less than the first preset length threshold and matches the task attributes. This solves the problem of file exceeding the limit and ensures that the input information is highly relevant to the user's needs, laying the foundation for subsequent question answering processing.

[0021] It should be noted that if the total number of characters in the target file is less than or equal to the first preset length threshold, the target file and the target user's question can be directly input into the large language model to obtain the corresponding target answer.

[0022] As described above, by using file type-based differential conversion, structured tables can leverage their data format advantages through code-based conversion, while unstructured documents can leverage their text understanding advantages through semantic compression and retrieval. This ensures that files with different structural features can be optimally processed, avoiding the poor adaptability problem caused by a one-size-fits-all approach. By controlling the length of intermediate representations and task attribute orientation, the intermediate representations retain only the key information needed to answer questions, reducing interference from irrelevant information and ensuring that subsequent question-answering processing always stays within the effective working range of the model. This avoids intermediate loss caused by exceeding file length limits, thereby ensuring the model's ability to capture input information and solving the problem of decreased answer accuracy and coherence caused by exceeding length limits in existing technologies.

[0023] In one specific implementation, the first preset length threshold is obtained through the following steps: On the large language model engine, performance tests were conducted using test datasets containing different context lengths to obtain performance test results. The test datasets included several question-answer pairs with known standard answers, and each question-answer pair was associated with a test file. The context length was changed by gradually increasing the number of characters in the test file.

[0024] Based on the performance test results, a performance degradation curve corresponding to the large language model engine is constructed with context length as the horizontal axis and question-answering performance evaluation indicators as the vertical axis.

[0025] Based on the performance degradation curve, the context length corresponding to the value of the performance evaluation index decreasing from the peak to the preset degradation ratio is determined as the first preset length threshold.

[0026] The Large Language Model (LLM) is a deep learning-based artificial intelligence model that can be trained and fine-tuned using large-scale text data to understand and generate human language, completing complex natural language processing tasks. In this embodiment, the LLM can analyze the input document content and question content and provide corresponding answers. It also supports continuous multi-turn dialogue and can generate responses by combining historical dialogue context, simulating human dialogue logic. Those skilled in the art will understand that any existing LLM and its fine-tuning methods fall within the protection scope of this invention, and will not be elaborated further here.

[0027] The test dataset selects test files covering different fields and types (such as tables and documents). For each test file, several question-answer pairs with standard answers are matched (such as query questions for tables and summary questions for documents) to form a test dataset, providing standardized input and evaluation benchmarks for performance testing to ensure the objectivity and reproducibility of test results.

[0028] The context length is the total number of characters in the input large language model text. Since the question length is relatively fixed and extremely small relative to the total number of characters in the text, in this embodiment, the context length is specifically referred to as the number of characters in the test file.

[0029] For each test file, the initial number of characters is gradually increased and adjusted. After each adjustment, the test file and corresponding question are concatenated and input into the large language model engine to generate answers. By comparing the model's generated answers with the standard answers, performance evaluation metrics for each input set are calculated, such as accuracy, BLEU score (an indicator for evaluating the quality of machine translation and natural language generation), and semantic consistency score. This transforms the model performance from a qualitative perception into quantifiable data, providing a vertical axis for the performance degradation curve. The increment step of the character count can be set by the implementer according to the actual situation, for example, 5,000 characters or 10,000 characters. Those skilled in the art will recognize that the calculation methods for accuracy, BLEU score, and semantic consistency score in the prior art fall within the protection scope of this invention, and will not be elaborated upon here.

[0030] Using context length as the horizontal axis and question-answering performance metrics (such as accuracy) as the vertical axis, the test results are fitted to a performance decay curve, visually reflecting the trend of model performance as input length increases. In the performance decay curve, performance stabilizes near the peak when the length is short; however, once the length exceeds a certain value, performance declines significantly, forming a "decay segment." Therefore, an acceptable preset decay ratio is set, and the context length corresponding to the decay at the preset ratio is found on the performance decay curve, which is determined as the first preset length threshold. The specific value of the preset decay ratio can be set by the implementer based on actual conditions, for example, 30%.

[0031] The above-mentioned quantitative testing of the question-answering performance of the large language model under different context lengths identifies the critical node where the model performance deteriorates from high efficiency and stability to significant degradation. The context length corresponding to the critical node is used as the first preset length threshold to ensure that subsequent file processing is always carried out within the effective working range of the model, avoiding performance degradation caused by exceeding the length limit.

[0032] S2, through the question-answering processing engine corresponding to the file type, executes the preset operation corresponding to the type of the intermediate representation to obtain the target answer. The question-answering processing engine includes a code execution engine and a large language model engine. If the file type is a structured table, the preset operation is executed by the code execution engine. If the file type is an unstructured document, the preset operation is executed by the large language model engine.

[0033] The code execution engine is an environment for running structured query code, supporting operations such as reading, calculating, and filtering tabular data, such as an executor integrating the pandas library. The large language model engine is a model with natural language understanding and generation capabilities, used for semantic reasoning of text-based information, such as the GPT series and LLaMA models. The code engine excels in precise calculations, while the large language model excels in semantic understanding, providing dedicated processing capabilities based on file type to avoid the limitations of a single engine.

[0034] The intermediate representation type is a transitional information form corresponding to file type and task attributes, used to determine the specific content of the preset operation (running code / semantic reasoning), making the engine operation more targeted. Among them, the intermediate representation corresponding to structured tables is code class, such as executable code or code collection; the intermediate representation corresponding to unstructured documents is text class, such as summary documents or related text fragments.

[0035] Preset operations are standardized processing flows for question-answering engines based on specific intermediate representation types. These processes ensure the standardization and efficiency of the engine's operations and reduce redundant operations. Specifically, the preset operations for the code execution engine are loading tabular data, running code, and outputting calculation results. The preset operations for the large language model engine are receiving text fragments and questions, performing semantic reasoning, and generating natural language answers.

[0036] As described above, by binding file types with the question-answering processing engine, structured tables are directly manipulated by the code execution engine, avoiding format misunderstandings and calculation errors when the large language model processes tables. Unstructured documents are processed by the large language model to handle text semantics, leveraging its contextual understanding advantage to ensure adaptability to different file structures and solve the problem of poor adaptability of a single engine. Through the correspondence between intermediate representation types and preset operations, the code execution engine only needs to run preset code without deep semantic analysis, and the large language model only needs to process concise text fragments without redundant information filtering. Both types of question-answering processing engines focus on core tasks, improving processing efficiency and reducing computational resource consumption. Through the split-engine processing mechanism, the code execution engine ensures the accuracy of table query results, while the large language model engine, by focusing on semantic reasoning of intermediate representations, makes the answers more consistent with the user's intent in the question, while ensuring that it always operates within the effective working range of the large language model, significantly improving the accuracy and relevance of question-answering results.

[0037] In one specific implementation, if the file type is a structured table, the task attributes include simple query statistics and complex query statistics, with the intermediate being executable code.

[0038] If the file type is an unstructured document, the task attributes include global issues and local issues, with the intermediate being a summary document or related text fragments.

[0039] Among them, the simple query and statistics category is for users whose questions are single-condition, single-step table data queries or statistics, such as "query the provinces with sales exceeding 1 million in 2023" or "calculate the average sales of each product".

[0040] Complex query statistics are queries or statistics that target users with multiple conditions and steps, such as "first grouping and statistically analyzing sales figures for 2022-2023 by region, then calculating the year-on-year growth rate for each group, and finally filtering regions with growth rates exceeding 20%", etc.

[0041] Global issues are those of the target users and require summarization, generalization, or overall analysis based on the semantics of the entire document, such as "summarizing the research conclusions of this paper" or "summarizing the core viewpoints of this report".

[0042] Locality problems are those where the target user's question focuses on specific details, fragments, or local information in the document, such as "What is the principle of the 'XX technology' mentioned in the text?" or "What solutions are discussed in Chapter 3?"

[0043] In one specific implementation, if the file type is a structured table and the task attribute is a simple query statistics class, S1 includes the following steps: The intent of the target user's question is identified to obtain the query intent corresponding to the target user's question.

[0044] Based on the query intent and the header information of the target file, generate executable code as an intermediate representation for querying data.

[0045] Correspondingly, S2 includes the following steps: The target file is loaded through the code execution engine, and the intermediate representation is run to obtain the target answer.

[0046] Among them, a pre-trained intent recognition model is used to perform semantic parsing of the target user's question and extract core query elements, including: query fields (such as "sales amount" and "quantity"), filtering conditions (such as "2023" and "region = East China"), statistical methods (such as "summation" and "average"), and target results (such as "return specific values" and "return a list of those that meet the conditions").

[0047] The header information in a structured table describes the meaning of the column data and reflects the table's data structure. By parsing the header information of the target file (such as table column names "Year", "Region", and "Sales Amount"), a mapping relationship between the header and the query fields is established. Based on a preset code generation template (such as a pandas code template), the query intent is transformed into structured code. For example, the code corresponding to the filtering condition is: df[(df['Year']==2023)&(df['Region']=='East China')]; the code corresponding to the statistical method is: .agg({'Sales Amount':'sum'}); and the complete code is generated by concatenating the header information: df[(df['Year']==2023)&(df['Region']=='East China')]['Sales Amount'].sum(), which serves as an intermediate representation to ensure that the number of characters in the code is much smaller than the first preset length threshold.

[0048] Furthermore, a code execution engine (such as an execution environment integrating the pandas library) reads structured table files (such as .xlsx and .csv) and converts them into DataFrame format, ensuring that the table data can be directly accessed by the code. The code execution engine parses and runs the generated executable code, performing filtering, statistical, and other operations based on the loaded table data, and directly outputs the code execution result as the target answer, without requiring additional semantic processing.

[0049] As described above, by accurately extracting query elements through intent recognition, the fields, conditions, and statistical methods that users need to query are clearly identified, avoiding the generation of redundant or irrelevant code and ensuring that the intermediate representation is highly matched with user needs. By combining table header information to generate executable code, it is ensured that the code can accurately call table data, thereby improving the adaptability of the code to the table structure and solving the query failure problem caused by mismatched field names. By running the code directly through the code execution engine, common factual errors such as numerical calculation deviations and missing conditions that are common when large language models process tables are avoided, reducing the consumption of computing resources and significantly improving the accuracy of simple query results.

[0050] In one specific implementation, if the file type is a structured table and the task attribute is a complex query statistics class, S1 includes the following steps: The target user's problem is broken down into several user sub-problems.

[0051] Intent recognition is performed on each user sub-question to obtain the query intent corresponding to each user sub-question.

[0052] Based on the query intent corresponding to each user sub-question and the table header information corresponding to the target file, generate executable code for querying data for each user sub-question. The set of executable code is an intermediate representation.

[0053] Correspondingly, S2 includes the following steps: The target file is loaded through the code execution engine, and each executable code is run to obtain the sub-answer corresponding to each user's sub-question.

[0054] Merge all the sub-answers to obtain the target answer.

[0055] The method employs a decomposition approach combining rule-based and large language model approaches. Specifically, it first identifies logical connectors in the question using pre-defined rules, such as "first...then...finally..." and "simultaneously...and...", and then uses a large language model to perform semantic segmentation on the complex semantics. For example, the target user question "First, group sales by region for 2022-2023, then calculate the year-on-year growth rate for each group, and finally filter regions with a growth rate exceeding 20%" is decomposed into three sub-questions: Sub-question 1: "Group sales by region for 2022 and 2023"; Sub-question 2: "Calculate the year-on-year growth rate of sales for each region in 2022 and 2023"; Sub-question 3: "Filter out regions with a year-on-year growth rate exceeding 20%".

[0056] For each sub-question, the same intent recognition method as for the simple query statistics class is used to extract the core elements such as query fields, conditions, and statistical methods. Based on the query intent of each sub-question, and combined with the table header information, corresponding sub-code is generated.

[0057] If the sub-answers are numerical or list-based, the data is directly integrated through the code execution engine; if natural language descriptions are involved, all sub-answers are logically linked together, and the final target answer is output after integrating all sub-step results.

[0058] As described above, by breaking down complex query tasks that cannot be completed in a single step into multiple simple sub-tasks, and by precisely processing and integrating the results of each sub-task, a highly efficient response to complex requirements can be achieved. This approach not only preserves the accuracy of code execution but also solves the problem that a single codebase cannot handle multi-step reasoning.

[0059] In one specific implementation, if the file type is an unstructured document and the task attribute is a global problem, S1 includes the following steps: Treat the target file as the file to be processed.

[0060] The file to be processed is divided into blocks to obtain several target sub-files, where adjacent target sub-files contain overlapping text content of a predetermined length.

[0061] Extract and merge the summaries corresponding to each target subfile to obtain the summary document.

[0062] If the number of characters in the summary document is less than the first preset length threshold, the summary document is determined as an intermediate representation; otherwise, the summary document is treated as a file to be processed, and the process returns to the step of dividing the file to be processed into blocks to obtain several target sub-files.

[0063] Correspondingly, S2 includes the following steps: The intermediate representation and the target user's question are combined and then input into the large language model engine to obtain the target answer.

[0064] The process involves dividing the file into contiguous sub-files according to a preset character length. Adjacent sub-files retain a predetermined length of overlapping content to ensure contextual coherence and avoid semantic breaks caused by segmentation. The specific values ​​for the preset character length and the predetermined length can be set by the implementer based on actual conditions. For example, the preset character length can be 3000 characters / block or 5000 characters / block, and the predetermined length can be 500 characters. For instance, a 100,000-word document divided into blocks of 3000 characters each, with adjacent blocks overlapping by 500 characters, will ultimately yield approximately 35 target sub-files.

[0065] The large language model engine is invoked to generate a structured summary for each target sub-file. The summary covers the core viewpoints, key data, and logical relationships of the target sub-file. The summaries of all target sub-files are then concatenated in the original file order to form a preliminary summary document.

[0066] Concatenate the text in the format of "target user question + summary document" (e.g., "Please summarize the core points of the following text: [Summary document content]"), ensuring that the total number of characters after concatenation is still less than the context window of the large language model. Based on the global semantics of the summary document and combined with the intent of the user question, the large language model engine generates a natural language answer that covers the core information of the entire text (e.g., "The core points of this article include three points: 1.…2.…3.…").

[0067] As described above, by performing multi-level segmentation and summary extraction on ultra-long documents, the core semantics of the whole text are preserved while controlling the total length. Finally, an intermediate representation that can cover global information is generated, enabling large language models to efficiently handle global problems within a limited context window. This achieves the transformation of ultra-long texts into concise and complete semantic carriers, and resolves the contradiction between the context length limitation of large models and the demand for global information.

[0068] In one specific implementation, if the file type is an unstructured document and the task attribute is a locality problem, S1 includes the following steps: The target file is divided into blocks to obtain several target sub-files, where adjacent target sub-files contain overlapping text content of a predetermined length.

[0069] The target user's questions are vectorized to obtain question vectors.

[0070] Calculate the similarity between each target subfile and the question vector.

[0071] All target sub-files that have a similarity greater than a preset similarity threshold are merged into an intermediate representation.

[0072] Correspondingly, S2 includes the following steps: The intermediate representation and the target user's question are combined and then input into the large language model engine to obtain the target answer.

[0073] This involves employing pre-trained semantic vector models (such as BAAI General Embedding and Sentence-BERT) to convert user questions into fixed-dimensional vectors (e.g., 768-dimensional), with the vector values ​​reflecting the semantic features of the question. Those skilled in the art will recognize that any existing semantic vector model falls within the scope of this invention, and will not be elaborated upon further here.

[0074] In one specific implementation, a semantic vector retrieval method is used to obtain the first similarity between each target sub-file and the question vector. A keyword matching retrieval method is then used to obtain the second similarity between each target sub-file and the question vector.

[0075] Each target sub-file is vectorized (with the same model and dimensions as the question vector). The cosine similarity between each target sub-file vector and the question vector is calculated as the first similarity, ranging from 0 to 1, with higher values ​​indicating greater semantic similarity. The core keywords of the user's question are extracted, and the word frequency relevance between each target sub-file and the keywords is calculated using the Best Matching 25 algorithm as the second similarity, with higher values ​​indicating a higher degree of word frequency matching.

[0076] The first and second similarities between each target sub-file and the question vector are weighted and fused to obtain a comprehensive similarity score. A preset similarity threshold is set. If any comprehensive similarity score corresponding to a target sub-file is greater than the preset similarity threshold, the target sub-file is selected and merged in the original file order. An intermediate representation is formed while ensuring that the total number of characters is less than a first preset length threshold. The specific value of the preset similarity threshold can be set by the implementer according to the actual situation, for example, 0.6.

[0077] As described above, long documents are broken down into controllable units through block processing. By combining similarity retrieval to filter sub-files that are highly relevant to the user's question, an intermediate representation focusing on local information is generated. This enables the large language model to efficiently locate and extract key details within a limited context, avoid interference from irrelevant information, and improve the accuracy and efficiency of local information retrieval in long documents.

[0078] In one specific embodiment, S2 further includes the following steps: The first historical Q&A information is obtained, which includes the target user's historical questions about the target file, the corresponding answers, and the Q&A timestamps.

[0079] If the number of characters in the first historical question and answer information is greater than or equal to the second preset length threshold, then the first historical question and answer information is parsed into a sequence of question and answer pairs sorted from oldest to newest according to the question and answer timestamps.

[0080] Initialize an empty list of reserved items and iterate backwards from the latest question-answer pair in the question-answer pair sequence.

[0081] During the traversal, the current question-and-answer pair is temporarily added to the retention list. If the total number of characters of all question-and-answer pairs in the retention list is less than the second preset length threshold, the current question-and-answer pair is officially retained, and the next question-and-answer pair with the adjacent question-and-answer timestamp is processed until the total number of characters is greater than or equal to the second preset length threshold. Then, the current question-and-answer pair is discarded and the traversal is terminated. The question-and-answer pairs in the retention list are used as the second historical question-and-answer information.

[0082] The intermediate representation, the target user's question, and the second historical question-and-answer information are combined and input into the large language model engine to obtain the target answer.

[0083] This involves extracting all historical interaction records of the target user for the current target file from the storage system, including historical questions, corresponding answers, and question-and-answer timestamps (interaction times accurate to the second).

[0084] The first historical Q&A information is a collection of all historical questions, answers, and timestamps of a user for a target file. It reflects the past interaction context and is used to provide contextual reference for the current Q&A. For example, if a user has asked a related question before, the answer should be of reference value to avoid gaps in the conversation.

[0085] The second preset length threshold is a critical value (less than the first preset threshold) used to limit the length of historical question-and-answer information. This ensures that the total length of historical information, intermediate representations, and the current question remains within the model context window. It balances the integrity of historical information with the model's processing capacity, preventing excessively long historical information from crowding out the space for intermediate representations and the question. The specific value of the second preset length threshold can be set by the implementer according to the actual situation, for example, 10,000 characters.

[0086] The second historical question-and-answer information consists of recent historical question-and-answer pairs that have been filtered and whose total length is less than a second preset length threshold. It is a condensed version of the first historical question-and-answer information and serves as an effective contextual input model, which enhances the coherence of the answers without taking up too much contextual space.

[0087] The text is concatenated in the order of "secondary historical Q&A information + target user question + intermediate representation," ensuring that the total length is less than the first preset length threshold. The large language model combines the core information of the historical interaction context (such as the user's previous focus), the current question intent, and the intermediate representation to generate a coherent answer that fits the historical intent (such as supplementing details by continuing the previous discussion logic).

[0088] As described above, by filtering the most relevant recent historical question-and-answer information (rather than redundant information and within a length threshold) and combining it with intermediate representations and the target question, the large language model can generate answers that better fit the user's intent based on the historical interaction context of the dialogue. This preserves the most valuable historical information within a limited context window, solves the problem of model performance degradation caused by excessively long historical question-and-answers, and enhances the coherence of the dialogue.

[0089] As described above, for extremely large files exceeding the context window of the large language model, by analyzing the structural features of the file and the task requirements of the user's question, the original file is converted into an intermediate representation with a controllable length that matches the task. This solves the problem of exceeding the file limit and ensures that the input information is highly relevant to the user's needs. By binding the file type with the question-answering processing engine, structured tables can be directly executed by the code execution engine without deep semantic analysis, avoiding format misunderstandings and calculation errors when the large language model processes tables. Unstructured documents can be processed by the large language model to obtain their simplified text fragments without redundant information filtering, making the answers more closely match the user's intent. At the same time, it is ensured that the process always occurs within the effective working range of the large language model, significantly improving the accuracy and relevance of the question-answering results.

[0090] Example 2 Embodiment 2 of the present invention provides a non-transitory computer-readable storage medium, which can be disposed in an electronic device to store at least one instruction or at least one program related to implementing a method in the method embodiment. The at least one instruction or at least one program is loaded and executed by the processor to implement the question-and-answer method based on document analysis technology provided in the above embodiment.

[0091] Example 3 Embodiment 3 of the present invention provides an electronic device, which includes a processor and the non-transitory computer-readable storage medium of Embodiment 2 of the present invention.

[0092] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make some modifications or alterations to the above-disclosed technical content to create equivalent embodiments without departing from the scope of the present invention. Any simple modifications, equivalent changes and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the scope of the present invention.

Claims

1. A question-answering method based on document analysis technology, characterized in that, The question-answering method based on document analysis technology includes the following steps: S1, if the total number of characters in the target file is greater than the first preset length threshold, then according to the file type of the target file and the task attribute of the target user question for the file type, the target file is parsed and converted to obtain an intermediate representation with a character count less than the first preset length threshold and matching the task attribute, wherein the file type includes structured tables and unstructured documents; S2, by using the question-answering processing engine corresponding to the file type, a preset operation corresponding to the type of the intermediate representation is executed to obtain the target answer. The question-answering processing engine includes a code execution engine and a large language model engine. If the file type is a structured table, the preset operation is executed by the code execution engine. If the file type is an unstructured document, the preset operation is executed by the large language model engine.

2. The question-answering method based on document analysis technology according to claim 1, characterized in that, If the file type is a structured table, then the task attributes include simple query statistics and complex query statistics, and the intermediate representation is executable code; If the file type is an unstructured document, the task attributes include global and local issues, and the intermediate representation is a summary document or related text fragments.

3. The question-answering method based on document analysis technology according to claim 2, characterized in that, If the file type is a structured table and the task attribute is a simple query statistics class, S1 includes the following steps: The intent of the target user's question is identified to obtain the query intent corresponding to the target user's question; Based on the query intent and the header information corresponding to the target file, generate executable code for querying data as the intermediate representation; Correspondingly, S2 includes the following steps: The target file is loaded by the code execution engine, and the intermediate representation is run to obtain the target answer.

4. The question-answering method based on document analysis technology according to claim 2, characterized in that, If the file type is a structured table and the task attribute is a complex query statistics class, S1 includes the following steps: The target user problem is broken down into several user sub-problems; Intent recognition is performed on each user's sub-question to obtain the query intent corresponding to each user's sub-question; Based on the query intent corresponding to each user sub-question and the table header information corresponding to the target file, generate executable code for querying data corresponding to each user sub-question, wherein the set of executable code is the intermediate representation; Correspondingly, S2 includes the following steps: The target file is loaded by the code execution engine, and each executable code is run to obtain the sub-answer corresponding to each user's sub-question; All sub-answers are merged to obtain the target answer.

5. The question-answering method based on document analysis technology according to claim 2, characterized in that, If the file type is an unstructured document and the task attribute is a global problem, S1 includes the following steps: The target file is used as the file to be processed. The file to be processed is divided into blocks to obtain several target sub-files, wherein adjacent target sub-files contain overlapping text content of a predetermined length. Extract and merge the summaries corresponding to each target sub-file to obtain the summary document; If the number of characters in the summary document is less than the first preset length threshold, then the summary document is determined as the intermediate representation; otherwise, the summary document is treated as a file to be processed, and the process returns to the step of dividing the file to be processed into blocks to obtain several target sub-files. Correspondingly, S2 includes the following steps: The intermediate representation and the target user question are combined and then input into the large language model engine to obtain the target answer.

6. The question-answering method based on document analysis technology according to claim 2, characterized in that, If the file type is an unstructured document and the task attribute is a locality problem, S1 includes the following steps: The target file is divided into blocks to obtain several target sub-files, wherein adjacent target sub-files contain overlapping text content of a predetermined length; The target user's question is vectorized to obtain a question vector; Calculate the similarity between each target sub-file and the question vector; obtain the first similarity between each target sub-file and the question vector using a semantic vector retrieval method; obtain the second similarity between each target sub-file and the question vector using a keyword matching retrieval method. All target sub-files that have a similarity greater than a preset similarity threshold are merged into the intermediate representation; Correspondingly, S2 includes the following steps: The intermediate representation and the target user question are combined and then input into the large language model engine to obtain the target answer.

7. The question-answering method based on document analysis technology according to claim 5 or 6, characterized in that, S2 also includes the following steps: Obtain the first historical question and answer information, wherein the historical question and answer information includes the target user's historical questions for the target file, the corresponding answers, and the question and answer timestamps; If the number of characters in the first historical question and answer information is greater than or equal to the second preset length threshold, then the first historical question and answer information is parsed into a question and answer pair sequence sorted from oldest to newest according to the question and answer timestamp; Initialize an empty hold list and iterate backwards from the latest question-answer pair in the question-answer pair sequence; During the traversal, the current question-and-answer pair is temporarily added to the retention list. If the total number of characters of all question-and-answer pairs in the retention list is less than the second preset length threshold, the current question-and-answer pair is officially retained, and the next question-and-answer pair with the question-and-answer timestamp is processed until the total number of characters is greater than or equal to the second preset length threshold. Then, the current question-and-answer pair is discarded and the traversal is terminated. The question-and-answer pairs in the retention list are used as the second historical question-and-answer information. The intermediate representation, the target user question, and the second historical question-and-answer information are merged and input into the large language model engine to obtain the target answer.

8. The question-answering method based on document analysis technology according to claim 1, characterized in that, The first preset length threshold is obtained through the following steps: On the large language model engine, performance testing was conducted using test datasets containing different context lengths, and performance test results were obtained. The test datasets included several question-answer pairs with known standard answers, and each question-answer pair was associated with a test file. The context length was changed by gradually increasing the number of characters in the test file. Based on the performance test results, a performance degradation curve corresponding to the large language model engine is constructed with context length as the horizontal axis and question-answering performance evaluation index as the vertical axis. Based on the performance degradation curve, the context length corresponding to the value of the performance evaluation index decreasing from the peak to the preset degradation ratio is determined as the first preset length threshold.

9. A non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores at least one instruction or at least one program segment, characterized in that, The at least one instruction or the at least one program segment is loaded and executed by the processor to implement the question-answering method based on document analysis technology as described in any one of claims 1-8.

10. An electronic device, characterized in that, Includes a processor and the non-transitory computer-readable storage medium as described in claim 9.