A Focused Inference Method and Apparatus for Long Text Large Language Model Based on Hierarchical Semantics
By constructing a hierarchical semantic structure and performing focused filtering and cross-segment dependency completion, evidence packages are generated and mapped to location metadata. This solves the problems of incomplete evidence coverage and insufficient utilization of dependencies in long text processing, and achieves efficient and accurate long text reasoning results.
Patent Information
- Application Number
- CN202611044985.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-14
- Publication Date
- 2026-11-17
AI Technical Summary
Existing long text processing solutions struggle to accurately cover complete evidence and effectively utilize cross-segment dependencies when faced with long documents that exceed the model context window limit. This results in incomplete inference results and a lack of traceability, making it difficult to meet the needs of high-risk business scenarios.
By constructing a hierarchical semantic structure containing multi-level nodes, focusing filtering, cross-segment dependency completion, and dynamic budget allocation are performed to generate an evidence package. The output evidence identifiers are then mapped to location metadata to generate the final result with a reference chain.
It significantly improves the completeness and accuracy of long text reasoning, reduces the calling cost and reasoning latency of large language models, enhances the interpretability and auditability of results, and meets the application needs of high-risk scenarios.
Smart Images

Figure CN123117315A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a method and apparatus for focused reasoning based on a hierarchical semantic long text large language model. Background Technology
[0002] With the rapid development of Large Language Model (LLM) technology, LLM-based document understanding and question answering systems have been widely used. However, existing long text processing solutions still face significant technical bottlenecks when dealing with long documents that exceed the model context window limit.
[0003] Existing technologies typically employ the following methods: First, directly truncating or splicing the input, which easily leads to the loss of key contextual information, resulting in incomplete or even erroneous inferences; second, simple retrieval-enhanced generation (RAG), which selects several fragments for input into the model through vector retrieval, but this method often lacks a global understanding of the document structure and is prone to problems such as unstable fragment selection, insufficient evidence coverage, and difficulty in handling cross-paragraph dependencies; third, using a coarse-grained summarization approach, summarizing the whole before inference, but the summarization process may miss detailed evidence and make it difficult to locate the original source of the conclusion.
[0004] Meanwhile, limited by the length of the context window and the cost of inference, existing solutions struggle to achieve stable inference with low cost and low latency while ensuring accuracy, completeness, and interpretability. This makes it difficult to meet the needs of business scenarios with extremely high requirements for accuracy and traceability, such as contract review and compliance analysis. Summary of the Invention
[0005] This application provides a method and apparatus for focused reasoning based on a hierarchical semantic long text language model, in order to solve the problems in the prior art, such as truncation of long text processing due to the limitation of context window, difficulty in accurately covering complete evidence and effectively utilizing cross-segment dependencies, and lack of traceable evidence for reasoning results.
[0006] To address the aforementioned technical problems, this application adopts the following technical solution: a focused inference method for long-text large language models based on hierarchical semantics is provided, comprising: Retrieve the long text to be processed and the user task; Based on the long text, a hierarchical semantic structure containing multi-level nodes is constructed, and semantic representations and location metadata are generated for each level of node; Based on the user task and the semantic representation, focus filtering, cross-segment dependency completion and dynamic budget allocation are performed on the hierarchical semantic structure to generate an evidence package; The evidence package is input into the large language model, and the output evidence identifier is mapped to the location metadata to obtain the final result with a reference chain.
[0007] In one optional embodiment of this application, the step of generating an evidence package by performing focused filtering, cross-segment dependency completion, and dynamic budget allocation on the hierarchical semantic structure based on the user task and the semantic representation includes: In the first level of the hierarchical semantic structure, a first similarity between the user task and the semantic representation of each node is calculated to filter candidate chapters; In the second level within the candidate chapter, the user task is parsed to obtain at least one subtask, the second similarity between each node and the subtask is calculated, and preliminary evidence nodes are selected based on the coverage constraint rule. Cross-segment dependency completion is performed on the initially selected evidence nodes, and dynamic budget allocation is performed on the nodes after cross-segment dependency completion to generate the evidence package.
[0008] In an optional implementation of this application, performing cross-segment dependency completion on the initially selected evidence node includes: Traverse the text content of the initially selected evidence nodes and identify the undefined terms and text reference marks contained therein; Based on the pre-built dependency index, retrieve the definition node corresponding to the term to be defined, as well as the target node pointed to by the text reference mark; The retrieved definition nodes and target nodes are merged into the initial set of evidence nodes.
[0009] In one optional implementation of this application, the step of performing dynamic budget allocation on the nodes after cross-segment dependency completion to generate the evidence package includes: Based on the second similarity, information density, and dependency relationship of each of the preliminary evidence nodes, the importance score is calculated; Determine multiple candidate representation forms for each of the preliminary evidence nodes, including full text, excerpt, and summary; Under the preset context lexical budget constraint, based on the importance score, the optimal combination of representation forms is selected for each of the preliminary evidence nodes, and the evidence package is generated according to the selection result. In an optional embodiment of this application, the step of calculating the importance score based on the second similarity, information density, and dependency relationship of each of the initially selected evidence nodes includes: The effective information content in the text of each of the preliminary evidence nodes is statistically analyzed, and the ratio of the statistical value of the effective information content to the text length is calculated to obtain the information density. Based on the dependency relationships of each of the preliminary evidence nodes and the preset weight rules, the dependency weights of each of the preliminary evidence nodes are determined. The importance score is obtained by weighting and summing the second similarity, the information density, and the dependency weight.
[0010] In one optional embodiment of this application, the step of inputting the evidence package into a large language model and mapping the output evidence identifier to the location metadata to obtain the final result with a reference chain includes: The evidence package is input into the large language model, and the reasoning conclusion and evidence identifier are output, wherein the evidence identifier is a unique number of the node in the evidence package; Based on the evidence identifier, the corresponding node is retrieved in the hierarchical semantic structure, and the location metadata of the node is extracted; The location metadata is bound to the inference conclusion to generate the reference chain containing the original text location information, so as to obtain the final result.
[0011] In an optional embodiment of this application, before obtaining the final result with the reference chain, the following steps are further included: Consistency verification is performed on the inference conclusions output by the large language model; If the verification fails, extract the gap information corresponding to the verification failure. Based on the gap information, supplementary evidence retrieval conditions are generated, and supplementary evidence retrieval is performed in the long text to obtain supplementary evidence nodes; The supplementary evidence nodes are merged into the evidence package, and the reasoning and consistency verification are re-executed until the verification passes to generate the final result.
[0012] To address the aforementioned technical problems, another technical solution adopted in this application is: providing a focused inference device for long-text large language models based on hierarchical semantics, the device comprising: The acquisition module is used to acquire the long text to be processed and the user task; The hierarchical module is used to construct a hierarchical semantic structure containing multiple levels of nodes based on the long text, and to generate semantic representations and location metadata for each level of node; The focusing module is used to perform focusing filtering, cross-segment dependency completion, and dynamic budget allocation on the hierarchical semantic structure based on the user task and the semantic representation, and generate an evidence package. The reasoning module is used to input the evidence package into the large language model and map the output evidence identifier to the location metadata to obtain the final result with a reference chain.
[0013] To solve the above-mentioned technical problems, another technical solution adopted in this application is: to provide a computer device, including a memory, a processor and a computer program stored in the memory, characterized in that the processor executes the computer program to implement the steps of the above-mentioned focused reasoning method for long text large language models based on hierarchical semantics.
[0014] To solve the above-mentioned technical problems, another technical solution adopted in this application is: to provide a storage medium on which a computer program is stored, characterized in that the computer program, when executed by a processor, implements the steps of the above-mentioned focused inference method for long text large language model based on hierarchical semantics.
[0015] The beneficial effects of this application are as follows: Unlike existing technologies, this application discloses a method and apparatus for focused inference using a large language model for long texts based on hierarchical semantics. This method constructs a hierarchical semantic structure containing multi-level nodes and location metadata, combined with a coarse-to-fine focused filtering and cross-segment dependency completion mechanism. This effectively utilizes the global structural information of the document and accurately captures cross-segment dependencies, overcoming the problems of missing key information and inference bias caused by direct truncation or simple retrieval, significantly improving the completeness and accuracy of long text inference. Simultaneously, by optimizing the evidence package through a dynamic budget allocation strategy, efficient utilization of the context window is achieved while ensuring the integrity of key evidence, greatly reducing the calling cost and inference latency of the large language model. Furthermore, by accurately mapping the output evidence identifiers to location metadata, a reference chain containing original text location information is generated, enhancing the interpretability and auditability of the results, enabling it to better meet the application needs of high-risk scenarios such as contract review and compliance decision-making. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort, wherein: Figure 1 This is a flowchart illustrating an embodiment of the long text large language model focused reasoning method based on hierarchical semantics provided in this application; Figure 2 This is a schematic diagram of the structure of an embodiment of the long text large language model focused reasoning device based on hierarchical semantics provided in this application; Figure 3 This is a schematic diagram of the structure of an embodiment of the storage medium provided in this application; Figure 4 This is a schematic diagram of the structure of an embodiment of the computer device provided in this application. Detailed Implementation
[0017] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0018] The terms "first," "second," and "third" used in the embodiments of this application are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first," "second," or "third" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.
[0019] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0020] This application provides a focused reasoning method for long text large language models based on hierarchical semantics, see reference. Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the long-text large language model focused inference method based on hierarchical semantics provided in this application. The method includes: S10: Obtain the long text to be processed and the user task.
[0021] Perform data acquisition operations, receiving long texts uploaded by users to be processed and user-inputted tasks.
[0022] Specifically, long text data refers to the full text of documents requiring inference and analysis. Its content can encompass various forms of long documents, such as contracts, standards, R&D reports, or audit materials, and its text length typically exceeds the standard context processing window. The acquired long text data is marked as document text. For example, the long text to be processed could be the full text of a software service contract.
[0023] Simultaneously, user tasks are obtained, which typically manifest as natural language questions or instructions posed to long texts. User tasks are used to indicate specific objectives that require retrieval, comparison, or summarization within the long text. For example, a user task might ask under what conditions a contract can be terminated, how much notice is required, and what exceptions exist.
[0024] The obtained document text and user question string are used as the initial input objects for subsequent construction of hierarchical semantic structure and execution of focused inference.
[0025] S20: Construct a hierarchical semantic structure containing multiple levels of nodes based on long text, and generate semantic representations and location metadata for each level of nodes.
[0026] After acquiring the long text to be processed, the unstructured or semi-structured long text is transformed into a hierarchical semantic structure with rich metadata that can be understood by computers.
[0027] In one optional embodiment, the process of constructing a hierarchical semantic structure includes preprocessing and structure recognition, node generation, attribute calculation, and auxiliary index construction. Specifically: 1) Preprocessing and structure identification: First, the long text is cleaned and denoised to remove irrelevant characters and formatting interference. Then, deep analysis is performed to identify the document's hierarchical structure boundaries, specifically including chapter title recognition, paragraph boundary recognition, and sentence boundary recognition. Additionally, table of contents recognition and page / clause number parsing are performed. Table of contents recognition extracts the document's inherent table of contents structure to aid in constructing chapter hierarchies; page / clause number parsing extracts explicit numbering information (such as "Article X", "1.1") from the text as part of the structured identifier and is used for subsequent citation recognition and location metadata generation. A combination of rules and models is used, such as regular expression matching of heading patterns like "Article 1", or deep learning models (such as BERT) to identify the text's logical hierarchy.
[0028] While identifying the structure, the system calculates and records the positional metadata of each text unit within the original long text. This positional metadata includes not only structured information such as the chapter number, paragraph number, and clause number, but also character offsets. The character offsets are set to the beginning of the long text, precisely recording the starting and ending character indices of the node text within the original text. For example, if a piece of text is located between characters 1248 and 1273 of the original text, its positional metadata offset would be {start: 1248, end: 1273}.
[0029] 2) Generation of hierarchical semantic nodes: Based on the identified structural boundaries, a hierarchical node system is constructed to form a hierarchical semantic tree or hierarchical semantic graph. This structure contains multiple levels of nodes, from top to bottom: document nodes, chapter nodes, paragraph nodes, and sentence or key point nodes.
[0030] For each node in the aforementioned multi-level node hierarchy, a corresponding semantic representation is generated. This semantic representation is used to characterize the deep semantic features of the node text and is typically in the form of a high-dimensional vector. This is achieved by using pre-trained embedding models, such as bge-large, E5, or text-embedding-3, to map the node text into dense vectors.
[0031] For chapter nodes, a chapter summary is also generated, and semantic vectors are generated from the summary text to summarize the core content of the chapter. Specifically, the summary generation strategy includes same-level summaries and cross-level summaries. Same-level summaries refer to summaries of the content of the current level node (such as paragraphs), while cross-level summaries refer to summaries of the upper level generated based on the aggregation of lower-level nodes (such as generating chapter summaries based on paragraph content) to support semantic retrieval and understanding at different granularities.
[0032] Simultaneously, keyword and entity information is extracted for each node. This includes named entities, task keywords, and clause citation identifiers. This information is used for subsequent fine-tuning, scoring, and entity matching.
[0033] 3) Location metadata construction: Each node is bound to a complete location metadata object. This object is a structured data collection that includes chapter identifiers, article identifiers, paragraph identifiers, and character offset ranges. An example of the location metadata format is shown below: { "chapter": "Chapter Two", "article": "Article 5", "paragraph": 1, "offset": { "start": 1248, "end": 1273}} Character offsets are finer-grained positioning coordinates, in addition to chapter and paragraph numbers, supporting precise character-level positioning and highlighting in inference results.
[0034] 4) Auxiliary index construction.
[0035] To support subsequent cross-segment dependency completion and fast retrieval, a series of core auxiliary indexes are pre-built when constructing the hierarchical semantic structure.
[0036] 1. Define and construct the mapping table.
[0037] The system automatically scans all sentence nodes, identifies definition patterns, and establishes a mapping between terms and definition nodes. The identification process primarily relies on two types of signals: The first type is syntactic template signals, which are matched using pre-defined high-confidence regular expression templates. These templates include: "X" refers to Y, "X" refers to Y, "X" is defined as Y, etc. When a sentence matches the above template, the defined term and its corresponding definition text and the ID of the node it belongs to are extracted.
[0038] The second type is structural signals, which are determined based on the title of the chapter to which the node belongs. If the chapter title contains keywords such as "definition," "interpretation," or "terminology," then all sentences in that chapter are considered high-probability definition sentences and are further verified.
[0039] The identification results are written into a definition mapping table, where the key is the defined term and the value is an object containing the node ID, confidence level, and source type. This mapping table enables runtime completion of the definition operation to achieve a time complexity of O(1), avoiding full-text search.
[0040] 2. Construction of term vector index.
[0041] To handle term variations or words not explicitly appearing in the definition map, each defined term is also vectorized and written into a separate term embedding index. For example, if the original text defines "notification," but the evidence sentence contains "written notification," vector similarity can be used to associate "written notification" with the definition node of "notification."
[0042] 3. Reference mapping table and dependency graph construction.
[0043] The process analyzes the reference relationships between nodes, constructing a reference mapping table and a dependency graph. By identifying explicit reference markers and clause numbers in the text, the referenced target nodes are extracted. The reference mapping table records the mapping from referencing nodes to a list of target node IDs. The dependency graph is constructed as a directed graph, where nodes are clauses or paragraphs, and directed edges represent dependencies, such as from a referenced clause to a referencing clause, or from a precondition to a constrained clause. This provides the data foundation for dependency completion based on a graph structure.
[0044] 4. Construction of reference relationship index.
[0045] A coreference resolution model is used to pre-parse the referential relationships within each paragraph, recording the correspondences between pronouns (such as "this", "the", "its", "the above") and their antecedents, and generating a referential relationship index. This index is used to quickly resolve referential ambiguities at runtime.
[0046] Through the above steps, a hierarchical semantic structure containing rich semantic information, precise location metadata, and a complete auxiliary index is finally generated. This structure not only supports hierarchical navigation from chapter to sentence, but also provides underlying data support for subsequent focused filtering, cross-segment dependency completion, and dynamic budget allocation.
[0047] S30: Based on user tasks and semantic representations, perform focused filtering, cross-segment dependency completion, and dynamic budget allocation on a hierarchical semantic structure to generate an evidence package.
[0048] In an optional embodiment, step S30 above further includes: S31: At the first level of the hierarchical semantic structure, calculate the first similarity between the user task and the semantic representation of each node to filter candidate chapters.
[0049] In this optional embodiment, the first level of the hierarchical semantic structure is used to perform focused filtering (hereinafter referred to as coarse filtering for ease of understanding). The first level corresponds to the chapter level in the document, that is, the coarse filtering strategy is performed at the chapter level.
[0050] The first-level coarse screening has the following characteristics: the evaluation object is chapter nodes, which are large in granularity and few in number (usually dozens); the input text is chapter summary, chapter title and chapter vector; the goal is to quickly eliminate irrelevant chapters, with coverage being better than accuracy, and it is better to select more than to miss; the computational cost is low, and a heavy model can be used when the number of candidates is small; the features used include topic-level semantics and chapter structure signals.
[0051] The coarse screening algorithm includes two implementation methods: 1) Dual-tower vector similarity: The first similarity is the cosine similarity between the user task vector and the chapter summary vector, i.e. The specific approach is as follows: use sentence vector models (such as bge-large, E5, text-embedding-3) to encode the questions and chapter summaries, and usually perform approximate nearest neighbor (ANN) retrieval in a vector database (FAISS / Milvus).
[0052] 2) Weighted combination score: Specifically, the chapter summary, chapter title, and prior information of each chapter node in the first level are obtained. The first similarity between the user task and the semantic representation of each chapter node is calculated. The first similarity is calculated using a weighted combined score to fuse multiple signals; the formula is as follows: , formula 1; in, The first similarity; , representing the dense vector similarity of chapter summaries, is used to capture topic-level semantics; The score is based on keyword sparse retrieval, with a significant bonus when the chapter content matches trigger words such as "termination," "notification," and "deadline." Title similarity indicates the similarity between the chapter title and the question; the title signal is usually very strong. The prior weights are for chapters, such as "Definition Chapter" or "Supplementary Provisions" which usually have higher weights; α, β, γ, and δ are preset weight coefficients that can be adjusted according to the characteristics of the domain.
[0053] After calculating the first similarity, all chapters are sorted, and the top K (e.g., 3-8) chapters are selected as candidate chapters. In addition, a chapter expansion operation is performed, which automatically incorporates adjacent chapters or parent-child chapters of the selected chapter along the hierarchical semantic structure. For example, the chapter on "liability for breach of contract" is brought into the candidate set of "termination clause" to handle potential reference dependencies.
[0054] S32: At the second level within the candidate chapter, parse the user task to obtain at least one subtask, calculate the second similarity between each node and the subtask, and filter the initial evidence nodes based on the coverage constraint rule.
[0055] In this optional embodiment, a focused filtering process (hereinafter referred to as fine-tuning) is performed at the second level of the hierarchical semantic structure. The second level of the hierarchical semantic structure corresponds to the paragraph or sentence level in the document. That is, within the candidate chapters, a fine-tuning strategy is performed on all candidate paragraphs or candidate sentence nodes.
[0056] The second-level fine screening has the following characteristics: the evaluation object is paragraph or sentence nodes, with small granularity and a large number (possibly thousands); the input text is the original paragraph or sentence text, entities, and vectors; the goal is to accurately locate evidence sentences, with precision better than recall, retaining only sentences that can truly answer the question; the computational cost is constrained by the number of candidates, requiring lightweight pruning; the typical retention quantity is the Top-N sentences or paragraphs determined by the token budget; the features used include fine-grained term matching, entity matching, and contextual dependency.
[0057] First, intent recognition and constraint extraction are performed on the user task, parsing it into at least one subtask. These subtasks can be obtained through language model extraction, rule template matching, or dependency parsing of the question. Each subtask is accompanied by a set of keywords or entities.
[0058] Secondly, the second similarity between each node within the candidate chapter and each subtask is calculated. The second similarity, also known as the fine-tuning score, is calculated through multi-signal fusion, and the formula is as follows: , formula 2; in, The second similarity; to Preset weighting coefficients; It uses sentence vector similarity to perform the matching task of "semantically similar but with different wording"; To score sparse term hits, such as BM25 or SPLADE, capture precise keywords, especially suitable for terms, clause numbers, etc. Entity matching score; Information density, which is the average number of entities, numbers, and clause references per token, is used to penalize long and vague sentences and reward short and substantial clause sentences. To improve the interactive re-ranking of model scores, a concatenation-based interactive approach is adopted. The question text and sentence text are concatenated and then input into a BERT-like model for computation. The specific input format is: [CLS] Question Text [SEP] Sentence Text [SEP]. The concatenated text is then input into a BERT-like model (such as Roberta-large) for encoding, and a relevance score is output through an MLP (Multilayer Perceptron) layer. This method achieves significantly higher accuracy than the dual-tower model, but due to its O(N) computational cost, it is only used when the number of candidate nodes is limited.
[0059] After obtaining the second similarity score, a filtering process is performed to generate preliminary evidence nodes. This process is based on coverage constraint rules and further constrained by deduplication rules. The specific process is as follows: 1) Calculate the relevance between nodes and subtasks. For each candidate sentence, calculate its relevance score to each subtask. This relevance score is calculated based on entity or keyword overlap and vector similarity, i.e., aspect. score =Preset weight × Entity / keyword overlap + Preset weight × Vector similarity (Sentence, Subtask description). If the relevance exceeds the preset threshold, the sentence is considered to have hit the subtask. A sentence can hit multiple subtasks.
[0060] 2) Perform a safety net screening based on coverage constraints. Maintain a coverage vector representing how much evidence currently covers each subtask. Iterate through all subtasks, selecting at least one sentence from each subtask with the highest second-highest similarity (or relevance to that subtask) as safety net evidence. Add this sentence to the initial set of evidence nodes and update the coverage vector and the consumed token budget. This step ensures that each subtask has at least one piece of evidence supporting it, solving the problem of high-scoring evidence focusing on answering only one aspect of the question while ignoring others.
[0061] 3) Perform extended screening based on marginal gain and deduplication. Within the remaining budget after the baseline screening, further screen the remaining candidate nodes to supplement the evidence.
[0062] First, calculate the marginal coverage gain of each node. The calculation formula is: Marginal coverage gain = relevance score × (1 + preset weight × number of uncovered subtasks that the sentence can fill), so that sentences that can fill the gaps are selected first under the same relevance.
[0063] Secondly, to avoid selecting multiple sentences with almost identical semantics, the Maximum Marginal Relevance (MMR) algorithm is used for deduplication. The calculation formula is: MMR score = Preset weight × Relevance (question, sentence) (1 (Preset weight) × Similarity between this sentence and the most similar evidence in the selected evidence set.
[0064] The marginal coverage gain and MMR score are weighted and summed or multiplied to form a comprehensive evaluation index, which is then used to rank the remaining nodes. Under equal relevance, sentences that can fill in missing subtasks are prioritized, while the MMR algorithm avoids selecting semantically repetitive sentences. Nodes are added to the initial evidence node set according to the ranking results. Before adding a node, it is checked whether the node is too similar to already selected nodes (i.e., whether the MMR score meets a preset threshold). If it does, the node is added, and the coverage vector and used token budget are updated.
[0065] Finally, the output is a preliminary set of evidence nodes determined through the above filtering process. This set contains the optimal combination of nodes that covers all subtasks of the user's task and removes redundant information. In addition, if the aspect coverage rate (the ratio of the number of hit subtasks to the total number of subtasks) calculated at the end of the filtering is lower than a preset threshold, a second focusing is triggered to readjust the filtering scope.
[0066] In some embodiments, to prevent the screening results from being overly concentrated in certain subtasks while ignoring others, an evidence balance index can also be calculated. The formula for calculating the evidence balance index is: Evidence Balance Index = 1 (Standard deviation of the number of sentences hit in each subtask / Average number of sentences hit in each subtask). This metric measures the evenness of evidence distribution across different subtasks, preventing situations where there is too much evidence in one subtask and too little evidence in others.
[0067] S33: Perform cross-segment dependency completion on the initially selected evidence nodes, and perform dynamic budget allocation on the nodes after cross-segment dependency completion to generate an evidence package.
[0068] Cross-segment dependency completion is performed on initially selected evidence nodes to address the potential semantic isolation problem. In long documents, individual evidence sentences often become difficult for large language models to understand accurately when taken out of context due to citing other clauses, using specific terminology, or relying on preconditions. Cross-segment dependency completion automatically identifies and retrieves relevant definitions, citations, and precondition nodes to construct a complete evidence context.
[0069] In an optional embodiment, the cross-segment dependency completion performed on the initially selected evidence nodes in step S33 above further includes: S331: Traverse the text content of the initial evidence nodes and identify the undefined terms and text reference marks contained therein.
[0070] Each node in the initial set of evidence nodes is scanned, and key information that may have cross-segment dependencies is identified using rule matching, natural language processing models, and structured parsing techniques. The specific identification process includes the detection of the following four trigger scenarios: Explicit Citation Recognition (Trigger A): Utilizes a pre-defined regular expression template to detect text segments containing specific citation patterns. This includes recognizing clause numbers such as "Article X," "Chapter X," and "Section X," as well as citation keywords such as "see," "refer to," "based on," "according to," "applicable," "foreword," and "above." Upon a match, the citation's number or specific reference is extracted.
[0071] Definition Dependency Identification (Trigger B): Utilizing Named Entity Recognition (NER) models, word segmentation tools, or pre-built terminology dictionaries, noun phrases in the text are extracted as candidate terms. Special attention is paid to words with specific meanings within the domain and often have dedicated definitions (such as "notice," "force majeure," etc.). These terms are often defined in "definition chapters" or specific paragraphs, and their isolated appearance can lead to comprehension bias. To reduce noise in subsequent matching, filtering rules are applied to the extracted candidate terms: stop words, pronouns, and verbs are ignored, retaining only nouns or noun phrases, typically with a length of at least 2 characters, to improve the accuracy of subsequent matching.
[0072] Reference / Omission Resolution Identification (Trigger C): Identifies pronouns such as "this," "the," "its," and "the above" contained in the sentence at the beginning. It checks whether the sentence lacks a clear noun subject; if so, it is considered that there is a need for reference resolution, and the sentence containing the antecedent needs to be located.
[0073] Precondition identification (Trigger D): Based on syntactic analysis, identify sentences containing dependency conditions, such as "when the condition specified in Article X is met" or "in accordance with Article X". These sentences indicate that the content of the current node depends on the content of other clauses, and it is necessary to fetch the dependent nodes to ensure semantic integrity.
[0074] S332: Based on the pre-built dependency index, retrieve the definition node corresponding to the term to be defined, as well as the target node pointed to by the text reference mark.
[0075] Using the core data structure pre-established during the hierarchical semantic structure construction phase, the clues identified in S331 are accurately retrieved and located. The specific retrieval strategy is as follows: Define node retrieval (for trigger B): Query the definition mapping table (definition_map). To improve recall, a four-level matching strategy is employed: Level 1: Exact match, directly searching whether a term is a key in the definition_map; Level 2: Substring / morpheme decomposition. If an exact match fails, the term is decomposed according to the dictionary (e.g., "written notice" is decomposed into "written" + "notification"), and the substring is searched. Level 3: Vector nearest neighbor search. If no match is found, use the term vector index to perform a Top-1 search to obtain semantically similar definition nodes. Level 4: Runtime Active Retrieval (Last Resort). If the first three levels fail, runtime active retrieval is triggered. Specifically, a query set containing multiple definition templates is constructed, such as "X refers to", "X refers to", "what is called X", "X definition", and the term itself. The first four queries with explicit definition templates use sparse retrieval (e.g., BM25) for matching to accurately capture definition sentences; the last general query uses dense vector retrieval to recall semantically similar but differently expressed definitions. After recalling candidate sentences, a lightweight classifier or regular expression rule is used to perform secondary verification to determine whether it is a definition sentence and whether the terms it contains have a similarity to the query terms reaching a preset threshold. If the verification passes, the node is accepted.
[0076] Reference target retrieval (for trigger A): Query the reference map. Based on the extracted number or reference keyword, search the map for the list of target node IDs referenced by the current node; if no match is found, directly locate the corresponding chapter node using the document's hierarchical structure tree (such as chapter number index).
[0077] Coreference resolution retrieval (for trigger C): Query the coreference index. Based on the pronoun and its context, find its corresponding antecedent node ID in the index. If the index is not pre-built, a simplification strategy is used, extracting the title sentence or first sentence of the paragraph containing the current sentence as the coreference explanation node.
[0078] Precondition retrieval (for trigger D): Based on the dependency graph, a graph traversal is performed. Starting from the current node, the system traverses backwards along the directed edges for one to two hops (i.e., from the referenced clause to the referencing clause, or from the precondition to the constrained clause), including nodes with strong dependencies in the candidate scope.
[0079] S333: Merge the retrieved definition nodes and target nodes into the initial set of evidence nodes.
[0080] All dependent nodes retrieved in S332 are added to the initial set of evidence nodes to form the expanded evidence set. During the merging process, this optional embodiment executes iterative loops and logical control to ensure the completeness and controllability of the completion, as follows: Iterative loop: The newly retrieved set of nodes is merged with the current set of evidence. For newly added nodes, steps S331 and S332 are executed again, that is, these new nodes themselves are checked for unresolved definitions, references, or referents, thus triggering the next round of completion. This process can handle indirect dependencies (such as A referencing B, and B referencing C).
[0081] Deduplication and Role Labeling: Check if the new node already exists in the evidence set. If it already exists, do not add the text content again, but update the node's attributes and append a record of its completion reason (e.g., marked as "reference completion", "definition completion", "preceding completion") to reflect its multiple supporting roles in the evidence chain. If it is a new node, add it and label the corresponding role.
[0082] Termination Condition Control: To prevent the completion process from spreading infinitely, causing computational cost explosion or introducing noise, strict termination conditions are set. The loop stops when any of the following conditions are met: Hop limit: The iteration level reaches the preset maximum number of hops K (usually K=2, that is, only direct dependencies and first-level indirect dependencies are completed). Circular dependency detection: If a circular dependency is detected (e.g., A references B and B references A), duplicate processing is avoided by maintaining a visited set. Convergence check: No new nodes are added to the evidence set.
[0083] Dependency strength threshold control: During the merging process, only nodes with strong dependencies are completed, while nodes with weak dependencies are ignored. Strong dependencies refer to nodes with explicit numbered references (such as clause numbers like Article X, Chapter X, Section X, etc.) or terminological definitions (i.e., terms in the definition mapping table are matched). Weak dependencies refer to nodes that are only thematically similar or adjacent in documents, but without explicit numbered or definitional associations. By completing only strong dependencies and ignoring weak dependencies, the computational cost and evidence set size are controlled while ensuring the logical integrity of the evidence chain, preventing the completion process from spreading indefinitely.
[0084] Budget tiered reservation: During the merging process, referenced and definition nodes that have been completed are marked as "high-priority completion". This suggests that subsequent dynamic budget allocation steps should prioritize retaining summary versions of these nodes rather than discarding them directly, even under tight budget conditions, to ensure the integrity of the reasoning logic.
[0085] Through the above cross-segment dependency completion steps, a semantically complete and logically coherent set of evidence nodes is generated, laying a solid foundation for subsequent dynamic budget allocation and focused reasoning.
[0086] Unlike existing technologies where cross-chapter and cross-paragraph dependencies in long documents are difficult to utilize effectively, leading to errors or inability to make judgments in large language models based on isolated fragments, this application provides a focused reasoning method for long text large language models based on hierarchical semantics. This method identifies undefined terms and text citation markers by traversing initial evidence nodes and accurately retrieves and merges definition nodes and target nodes based on a pre-built dependency index. It can automatically complete cross-paragraph citations and definition contexts, significantly improving the completeness and accuracy of reasoning logic.
[0087] In an optional embodiment, step S33 above, which involves performing dynamic budget allocation on the nodes after cross-segment dependency completion to generate an evidence package, further includes: S334: Calculate the importance score based on the second similarity, information density, and dependency of each preliminary evidence node.
[0088] Importance scores not only consider the relevance of a node to the question (second similarity), but also integrate the information density of the node itself and its structural role in the chain of evidence to quantify the overall value of each candidate node in order to make choices within a limited context window.
[0089] In an optional embodiment, step S334 further includes: S3341: Calculate the amount of effective information in the text of each preliminary evidence node, and calculate the ratio of the statistical value of effective information to the text length to obtain the information density.
[0090] First, feature statistics are performed on each initially selected evidence node, and the following basic statistics are extracted: 1. Number of Named Entities: Count the number of entities such as person names, organization names, and terms contained in the text, denoted as E; 2. Numbers and Units: The numerical values and their units in the statistical text, denoted as N; 3. Number of clause citations: The number of times other clauses are cited in the text (e.g., "Article X"), denoted as R; 4. Keyword Hit Count: Count the number of times the text hits the user's task keywords, denoted as K; 5. Domain trigger word hit count: The number of domain-specific trigger words (such as "should", "must not", "release") is counted and denoted as C.
[0091] 6. Number of unique content words: Count the number of non-repeating content words after removing stop words, denoted as U.
[0092] To avoid diluting the information content of long texts due to their large size, the following formula is used to quantify information density: , formula 3; in, Information density; to The preset weight coefficients can be adjusted according to domain characteristics (e.g., the weight of citations and trigger words can be increased in legal contract texts); L is the token length of the node. The numerator is log-normalized to prevent an excessive number of entities from suppressing other signals; the denominator uses log(L) instead of L, which is more tolerant of sentences of medium length but with concise content.
[0093] Furthermore, an advanced information density calculation method can be employed, combining statistical and semantic information to enhance the task relevance of the computation. Specifically, the semantic information quantity `semantic_info` is calculated, defined as the cosine similarity between the node vector and the task vector, used to measure the semantic fit between the node text and the question. The advanced information density calculation formula is as follows: , formula 4; Where density is the basic density value calculated by formula 3 above; This gives density a "task-aware" characteristic, meaning that under the same statistical density, nodes that are closer to the semantics of the question receive a higher density score; q is the adjustment coefficient. This calculation method is particularly suitable for scenarios where it is necessary to distinguish between high-information but irrelevant distracting text.
[0094] S3342: Determine the dependency weight of each preliminary evidence node based on the dependency relationship of each preliminary evidence node and the preset weight rules.
[0095] Different basic weights are assigned to nodes based on their role in the evidence chain. Specific rules include: "definition completion" nodes and "reference completion" nodes retrieved through cross-segment dependency completion are given higher dependency weights (i.e., minimum weights) as necessary supporting information for understanding the main evidence; while nodes that directly serve as the main evidence are given standard weights, and secondary evidence with low relevance is given lower weights.
[0096] S3343: The importance score is obtained by weighting and summing the second similarity, information density, and dependency weights.
[0097] The importance score is calculated by linearly combining the above feature factors according to preset weights. The calculation formula is: , Formula 5; in, The second similarity is calculated in step S32; density is the information density. , where a, b, c, and d are the dependency weights; a, b, c, and d are the weighting coefficients for balancing the influence of each signal. Specifically, aspect_priority (subtask priority) is a weight parameter dynamically calculated based on the coverage analysis results in step S32. Its calculation logic is as follows: based on the coverage vector or statistical results maintained in step S32, analyze the coverage of each task sub-task (Aspect) in the initial selection stage. If the number of selected evidence for a sub-task is lower than a preset threshold (e.g., 0, or not meeting the minimum requirement), then the sub-task is determined to have a "coverage gap." Nodes belonging to such gap sub-tasks are assigned a high priority weight (e.g., 1.5) to improve their score in budget allocation and prevent them from being downgraded or eliminated due to budget constraints; nodes belonging to fully covered sub-tasks are assigned a standard weight (e.g., 1.0).
[0098] The long text large language model focused reasoning method provided in this application obtains information density by comprehensively calculating the ratio of effective information content to text length, and obtains importance score by weighted summation of dependency relation weight and second similarity. It can accurately quantify the comprehensive value of each node, effectively punish long and vague content and reward short and substantial clauses, thus improving the accuracy of key evidence selection.
[0099] S335: Determine multiple candidate representations for each preliminary evidence node, including full text, excerpt, and summary.
[0100] To balance information integrity and token cost, three candidate representations are defined for each node to form options for the multi-choice knapsack problem: Full text format: The original text of the node is preserved, the token cost is L, and the profit coefficient is 1.0 (no information loss).
[0101] Extraction format: Key sentences and the context window around the entity are preserved. The token cost is approximately 0.4×L, and the return factor is 0.75 (with slight information loss).
[0102] Summary format: Only the node summary or key points are retained. The token cost is approximately 0.15×L, and the return coefficient is 0.45 (information mainly relies on the summary). Meanwhile, the token cost setting for the summary format needs to consider a lower limit protection, i.e., the token cost is max(0.15×L, F_min), where F_min is the preset minimum number of tokens (e.g., 15), to prevent the loss of key information due to insufficient tokens in the summary of excessively short nodes.
[0103] S336: Under the preset context lexical budget constraint, based on the importance score, select the optimal combination of representation forms for each preliminary evidence node, and generate an evidence package based on the selection result. This step transforms the evidence package generation problem into a "multi-choice 0 / 1 knapsack problem," maximizing the overall benefit through a multi-level strategy within a budget constraint B. The specific process is as follows: 1) Calculate the total budget and the minimum guarantee allocation.
[0104] First, calculate the available evidence package budget B. B is typically the remaining value after subtracting the system prompts, question descriptions, and output space from the model's maximum context window. That is, B = M. ctx T sys T q T inst T reserve Among them, M ctx T represents the maximum context window size of the model. sys The number of tokens used for system prompts and character descriptions, T q T represents the number of tokens used for user questions and task descriptions. inst The number of tokens used for instructions such as referencing rules and output format specifications, T reserve To reserve the number of tokens for model output.
[0105] Subsequently, a mandatory guaranteed minimum allocation will be implemented: In terms of task guarantee: Select the node with the highest importance score from each task's sub-task (Aspect), force it to be selected in full text form, and deduct its token cost to ensure that each sub-question has at least one detailed piece of evidence.
[0106] Dependency Node Guarantee: All referenced definition nodes and prerequisite nodes are selected in at least the form of a digest, and the corresponding token cost is deducted to ensure the integrity of the logical chain.
[0107] 2) Greedy filling and upgrading under the remaining budget.
[0108] In the remaining budget B remain Next, optimize the shape of the remaining nodes and the selected nodes: Calculate the unit token revenue (efficiency): For each optional form (including upgrading the selected summary form to an excerpt or full text), calculate its unit token revenue, i.e., efficiency = (importance score × revenue coefficient) / form token cost.
[0109] Greedy selection: Sort by efficiency from highest to lowest, and sequentially select nodes or perform "upgrades" to node types (e.g., upgrade from summary to extract) until adding the next item or performing an upgrade exceeds the budget B.remain Until then. If a small amount of budget remains after the greedy selection process, but is insufficient to place any complete node or upgrade an existing node, then pre-defined transition text (such as "Other parts of this chapter are omitted...") is used to fill the gaps and maintain contextual coherence.
[0110] Furthermore, to reduce computational complexity in engineering scenarios, a simplified linear proportional allocation strategy can be adopted. Specifically, the importance percentage of each node is calculated, and tokens are allocated proportionally based on the total budget. The corresponding representation format is then determined by working backward from the allocated token amount. For example, if the allocated tokens are sufficient to write the entire sentence (i.e., greater than or equal to the original text length L), the full text is retained; if not enough to write the full text, but at least 40% of the original text, only excerpts (key sentences) are retained; if even fewer, but at least 15% of the original text, only a summary is retained; if the allocated tokens are less than 15% of the original text, it indicates a tight budget, and this node is discarded and not included in the evidence package. This strategy has a computational complexity of O(N), which, while slightly less accurate than the greedy knapsack algorithm, is faster.
[0111] Unlike existing technologies where limited context windows prevent the complete input of key evidence, or where direct truncation or splicing leads to excessive costs and latency hindering engineering deployment, this application provides a layered semantic long-text large language model focused inference method. By using importance scores and contextual lexical budget constraints, it adaptively selects the optimal combination of full text, excerpts, or summaries for each node. This maximizes the effective information content of the task within a limited budget, ensuring the integrity of key evidence while significantly reducing invocation costs and inference latency.
[0112] 3) Generate evidence package.
[0113] The final selected nodes and their determined representations (full text / excerpt / summary) are assembled, and corresponding location metadata (such as chapter number and offset) is attached to generate the final evidence package. This evidence package maximizes the amount of effective information within budget constraints while ensuring the integrity of key evidence.
[0114] Unlike existing technologies that rely on simple retrieval enhancements and lack a global understanding of document structure, leading to issues such as unstable fragment selection, insufficient evidence coverage, and difficulties in cross-segment reasoning, this application provides a focused reasoning method for long texts based on hierarchical semantics. This method employs coarse-to-fine focused filtering and coverage constraints at different levels of the hierarchical semantic structure, combined with cross-segment dependency completion and dynamic budget allocation to generate evidence packages. This effectively improves the stability and coverage of evidence selection and enhances the ability to perform complex reasoning on long texts.
[0115] S40: Input the evidence package into the large language model and map the output evidence identifiers to the location metadata to obtain the final result with the reference chain.
[0116] This step utilizes a large language model to perform reasoning based on the selected high-precision evidence package. At the same time, it completely eliminates the illusion of citation by using the technical means of "stable ID + constraint generation + position backfilling" to ensure that the output conclusion has complete traceability and auditability.
[0117] In an optional embodiment, step S40 above further includes: S41: Input the evidence package into the large language model and output the reasoning conclusion and evidence identifier, where the evidence identifier is the unique number of the node in the evidence package.
[0118] Input prompts are constructed to input the task description, evidence package, and citation rules into the large language model. Each piece of evidence in the evidence package is labeled according to a specific format, including a unique number (e.g., N_c5_p2) and its corresponding text fragment and auxiliary location information. The specific format is: [id=node ID] [chapter=chapter][paragraph=paragraph] [offset=offset], where the text fragment is presented in conjunction with the location information. Simultaneously, the prompts include Few-shot example reinforcement, providing correct and incorrect citation examples (e.g., incorrect examples using non-whitelisted IDs or natural language chapter numbers) to strengthen the model's adherence to the citation rules. The key design is to force the large language model to output only unique numbers as evidence identifiers, prohibiting it from generating chapter numbers in natural language formats such as "Article 5" or "Section 1". The specific implementation includes two layers of constraints: 1) Input-side constraints: The prompt explicitly lists a whitelist of unique IDs that are allowed to be referenced, and requires the output to conform to the preset JSON Schema. The evidence_ids field is strictly restricted to an enumeration type and can only take values from the whitelist. At the same time, the prompt contains strong instructions to prohibit the model from reciting chapter numbers or using external knowledge.
[0119] In addition, to ensure that the model accurately understands the evidence context and follows the citation rules, the input evidence package adopts a specific annotation format: [id=node ID] [chapter=chapter name] [paragraph=paragraph] [offset=offset] text fragment... At the same time, the prompt words contain strong constraint instructions, specifically including: (1) explicitly listing a whitelist of unique numbers that are allowed to be cited, requiring that the evidence_ids field can only take values from the whitelist, and prohibiting the use of natural language chapter numbers; (2) prohibiting the model from repeating positional information such as chapter numbers, clause numbers, and offsets; (3) prohibiting the use of external knowledge, and information not mentioned is considered as not explicitly stated in the original text; (4) requiring the output to conform to the preset JSON Schema, and forcing each conclusion to include the evidence_ids field. In addition, the prompt words include Few-shot example reinforcement, showing the correct citation format (using ID) and the incorrect citation format (using chapter numbers or fake IDs) to strengthen the model's compliance with the citation rules.
[0120] 2) Generation-side constraints: During the model inference generation phase, a trie structure containing all legal tokens is constructed. Preferably, Logits masking is used for constraint decoding. When generating each token, the prefix of the currently legal token is calculated, and the probability of tokens that do not belong to the whitelist path is set to negative infinity, physically blocking the possibility of the model generating illegal tokens.
[0121] Based on the above constraints, the large language model outputs structured reasoning results. Each reasoning conclusion is accompanied by at least one evidence identifier, forming a preliminary "conclusion-identifier" association.
[0122] S42: Based on the evidence identifier, retrieve the corresponding node in the hierarchical semantic structure and extract the node's location metadata.
[0123] The system utilizes the index mapping relationship pre-established during the hierarchical semantic construction phase to perform position backfilling. The system parses the evidence identifiers output by the large language model (such as N_c5_p2) and locates the corresponding node objects in the hierarchical semantic structure with a time complexity of O(1).
[0124] Extract the node object's location metadata within the original document. This metadata includes, but is not limited to, chapter title, clause number, paragraph number, and precise character offset. Simultaneously, extract the node's role tags (such as primary evidence, definition completion, and citation completion) to clearly distinguish the supporting type of evidence in subsequent steps.
[0125] Through this lookup-style backfilling process, machine-friendly abstract IDs are transformed into human-readable structured location information, completely eliminating the illusion of "reference misalignment" caused by model memory bias.
[0126] S43: Bind the location metadata to the reasoning conclusion to generate a reference chain containing the original text location information in order to obtain the final result.
[0127] This step aims to eliminate the illusion of referencing location information and achieve a precise mapping from machine identifiers to human-readable addresses. After receiving the structured data output from the large language model, the evidence identifiers (such as N_c5_p2) are parsed, and an O(1) complexity location backfilling operation is performed using the index table pre-built during the hierarchical semantic construction phase.
[0128] Specifically, based on the evidence identifier, the corresponding node object is located, and its location metadata, such as chapter title, clause number, paragraph number, and precise character offset, is extracted. Simultaneously, the node's role label within the evidence package (e.g., main evidence, definition completion, citation completion) is extracted. This information is then data-bound with the reasoning conclusion text to construct a complete citation chain object. At this point, a "three-level cascade" consistency check is performed. If the check passes, the final result containing the original text's location information is directly generated, allowing users to click and locate the information. If the check fails, the iterative supplementary evidence process described in steps S431-S434 is triggered.
[0129] Unlike existing technologies that lack evidentiary citation and interpretability, large language models are prone to generating illusory citations and are difficult to audit and verify. This application provides a focused reasoning method for long-text large language models based on hierarchical semantics. By having the large language model output only a unique evidence identifier, and then having the system automatically retrieve and backfill precise location metadata to generate a citation chain, this method completely eliminates the illusion of fabricated or misquoted location information at the physical level. It achieves character-level precise traceability from conclusions to the original text, meeting the auditing needs of compliance and high-risk scenarios.
[0130] In an alternative embodiment, before obtaining the final result with the reference chain, the method further includes: S431: Perform consistency verification on the inference conclusions output by the large language model.
[0131] A three-tiered cascading mechanism of "rules + lightweight model + LLM self-check" is adopted for consistency verification. The authenticity and accuracy of the citation chain are filtered in order of increasing cost and strictness of misjudgment to solve the problems of "unfounded citation" and "citation misalignment".
[0132] The first layer: Structured rule validation. This intercepts obvious formatting and literal errors. This includes checking if evidence identifiers exist in the evidence package whitelist (intercepting false citations), verifying that key values (date, amount, percentage) in the conclusion match the original evidence (intercepting field mismatches), and scanning for the appearance of weak words like "usually" and "may" without supporting citations (intercepting unfounded assertions). Additionally, it includes enumeration value closure validation, checking if the number of conclusion items meets the task's quantity constraints (e.g., if the question asks for all exceptions but the number of output items is less than the number of evidence coverage items), and unit consistency validation (e.g., normalizing and comparing '30 days' and '30 working days' to ensure logical consistency).
[0133] The second layer: NLI / Evidence Implication Model Validation. Utilizing a natural language reasoning model (such as DeBERTa-v3-NLI), it determines whether the reasoning conclusion is semantically implied by the evidence fragments, covering rewriting and reasoning that rules cannot capture. If determined to be contradictory or a neutral state with low confidence, it is marked as an anomaly. It supports FactScore atomic fact decomposition, breaking down the conclusion into atomic facts for individual verification. Furthermore, it employs token-level tracing, using attention analysis or saliency methods to mark the tracing position of each token in the conclusion within the evidence package to identify large sections of seemingly illusory information without tracing. This is typically only enabled in high-risk scenarios (such as compliance, medical, and legal review).
[0134] The third layer: LLM self-check. For complex logic that the first two layers cannot determine, an independent large language model is invoked to reverse-verify the conclusion based on evidence, clearly determining whether it is "implied," "contradictory," or "insufficient evidence." Specifically, a structured prompt is used to define the role of a "strict evidence checker," forcing it not to use external knowledge, and a structured output schema (including verdict, supporting_evidence_ids, reasoning, and missing_aspects fields) is adopted. The temperature parameter is set to 0 to ensure that the model outputs the most probable deterministic result, avoiding evaluation bias caused by randomness. In high-reliability scenarios, a multi-critic voting mechanism can be adopted, that is, multiple different prompts (or different models) are allowed to make independent judgments, with the majority vote determining the outcome.
[0135] S432: If the verification fails, extract the gap information corresponding to the verification failure.
[0136] When the consistency verification conclusion contains "insufficient evidence" or "contradictory evidence," meaning the consistency verification fails, the corresponding gap information is extracted. The gap information specifically includes: 1. Gap type: identified as aspect missing (G1, no evidence for a certain sub-issue), insufficient evidence (G2, lack of support for the conclusion), contradictory evidence (G3, conflict between evidence), or missing atomic facts (G4, no support for atomic facts).
[0137] 2. Target retrieval elements: entities, keywords, extended sets of synonyms, and target entity constraints extracted based on failure conclusions.
[0138] 3. Anchor Evidence: Existing related evidence node IDs, used to provide contextual location and the starting point for dependency graph traversal.
[0139] 4. Exclusion Set: A list of node IDs that have already been searched and are invalid, to avoid duplicate searches.
[0140] 5. Scope hints: Potential areas inferred from the document structure, such as "Definition Chapter", "Supplementary Provisions", or specific chapter numbers.
[0141] S433: Generate supplementary evidence retrieval conditions based on gap information, and perform supplementary evidence retrieval in long text to obtain supplementary evidence nodes.
[0142] This step performs "reverse retrieval for supplementary evidence," transforming the abstract gap into an executable retrieval query. The specific process is as follows: 1) Query rewriting: Use multiple strategies to generate search queries.
[0143] 1. Rule Template Filling: Apply preset templates for different gap types, such as generating a query in the format of "term + definition / refers to / means as" for gaps with missing definitions.
[0144] 2. LLM-assisted rewriting: Utilize a large language model to generate multiple variant queries based on the gap description, covering synonyms, hypernyms, and implicit conditions.
[0145] 3. Hypothetical Document Embedding: To address the gap in insufficient evidence, a possible piece of original evidence (hypothetical evidence) is generated using a large language model, and the vector of this hypothetical evidence is used for retrieval to improve recall.
[0146] 2) Targeted retrieval execution: Use the rewritten query to perform retrieval in the index of long text.
[0147] 1. Narrowing the scope: Based on location metadata such as scope hints or anchor evidence, the search scope is limited to specific chapters or adjacent nodes.
[0148] 2. Index Switching: Switch indexes based on the gap type. For example, use an inverted index for precise entity retrieval when atomic facts are missing, and directly query the definition_map when definitions are missing.
[0149] 3. Exclusion Filtering: Directly remove nodes from the exclusion set in the search results.
[0150] Through the above-mentioned correction retrieval, the final set of supplementary evidence nodes is obtained.
[0151] S434: Merge the supplementary evidence nodes into the evidence package, re-execute the reasoning and consistency check until the check passes to generate the final result.
[0152] After obtaining the supplementary evidence nodes, the fusion and iterative closed loop is executed. The specific process is as follows: 1) Evidence fusion: Merge the supplementary evidence nodes with the original evidence package, perform deduplication, and trigger cross-segment dependency completion again for the new nodes to complete the definition or reference dependencies that the new evidence may introduce.
[0153] 2) Dynamic budget reallocation: Based on the merged evidence set, recalculate the node importance score, execute the dynamic budget allocation algorithm (multiple choice knapsack solution), determine the final evidence package content, and squeeze the budget of the original low-scoring nodes if necessary.
[0154] 3) Incremental Reasoning: The large language model is invoked again for reasoning based on the updated evidence set. To save costs, an incremental prompting strategy can be adopted, in which the prompt words include the previous output, the list of gaps that need to be corrected, and the new evidence set, requiring the model to correct and output a complete conclusion.
[0155] 4) Iteration Control and Termination: Perform a consistency check (S431) on the newly generated conclusions again. Set strict termination conditions, including all checks passing, reaching the upper limit of iterations (e.g., 2-3 times), the gap list failing to converge twice consecutively, or no results found in reverse retrieval. If the termination conditions are met and the checks pass, the final result with a reference chain is generated; if the upper limit of iterations is reached and the checks still fail, a downgraded output mode is triggered, marked "insufficient evidence," and the existing conclusion is returned to avoid infinite loops.
[0156] Unlike existing technologies where single-retrievement searches inherently lead to insufficient evidence or inconsistencies that cannot be self-corrected, thus affecting the accuracy of complex reasoning, this application provides a long-text, large-language-model focused reasoning method based on hierarchical semantics. This method verifies the consistency of reasoning conclusions and extracts gap information. Based on these gaps, it performs targeted supplementary evidence searches and iterative re-reasoning. Through closed-loop verification, it accurately fills evidence gaps, effectively eliminating omissions and reasoning biases from single searches, ensuring the sufficiency and consistency of the final conclusion.
[0157] To enable those skilled in the art to better understand the technical solution of this application, the following section provides a detailed explanation of the long text large language model focused reasoning method based on hierarchical semantics.
[0158] Suppose the acquired long text is a software service contract containing multiple clauses, including definition clauses, scope of service, service period, termination clause (Article 5), liability for breach of contract, and exception clauses (Article 7). The user task is a natural language question: "Under what conditions can the contract be terminated? How much notice is required? What are the exception clauses?" 1) Construction of hierarchical semantic structure and preparation of auxiliary indexes.
[0159] The contract is preprocessed and its structure identified, generating a multi-level node system consisting of document nodes, chapter nodes, and paragraph / sentence nodes. Taking the definition of "notice" in Article 1, Paragraph 1 as an example, a corresponding paragraph node is generated, with the text content "'Notification' refers to a written notice sent by registered mail...", and its location metadata is recorded (e.g., Article 1 as the chapter, Paragraph 1 as the paragraph, offset [25, 78]). Simultaneously, semantic representations are generated for each node, and keywords and entities are extracted.
[0160] While constructing the hierarchical semantic structure, a core auxiliary index is pre-built. For example, when scanning "'notification' refers to...", the syntactic template is hit, "notification" is used as the key, and the corresponding node identifier is written into the definition mapping table; terms such as "working day" and "force majeure" are also written into this table. The reference relationships between nodes are analyzed. For example, if Article 5, Paragraph 2 references the provisions of Article 1, then a directed edge is established in the dependency graph from the node of Article 5, Paragraph 2 to the relevant node of Article 1.
[0161] 2) Problem understanding and focused screening.
[0162] The user task is parsed, and its intent is identified as a contract clause query. It is then broken down into three sub-tasks: the first sub-task (termination conditions), the second sub-task (notification period), and the third sub-task (exceptions). Each sub-task is accompanied by a corresponding set of keywords and entities.
[0163] A coarse screening is performed at the first level (chapter level) of the hierarchical semantic structure: the first similarity between the user task and the semantic representation of each chapter node is calculated. By fusing vector similarity, sparse term hit score and chapter prior weight, the fifth (termination clause), the seventh (exceptional case), and the first (definition) clauses are selected as candidate chapters due to their high scores.
[0164] A fine-tuning process is performed at the second level (paragraph / sentence level) within the candidate chapters: the second similarity between each node within the candidate chapter and each subtask is calculated. This second similarity integrates dense semantic matching, sparse term matching, entity matching, information density, and the interactive rearrangement model score. Based on coverage constraint rules, at least one node with the highest second similarity from each subtask is selected as backup evidence and added to the initial set of evidence nodes. For example, the node in Article 5, Paragraph 1 covers the first subtask, the node in Article 5, Paragraph 2 covers the second subtask, and the node in Article 7 covers the third subtask, ensuring that the aspect coverage meets the requirements.
[0165] 3) Cross-segment dependency completion.
[0166] Cross-segment dependency completion is performed on the initially selected evidence nodes. The node text is traversed. When the undefined term "written notice" in Article 5, Paragraph 1 is encountered, the system first performs an exact match in the definition mapping table, which fails. Then, a substring / morpheme decomposition strategy is used to break down "written notice" into "written" and "notification," successfully matching the definition node corresponding to "notification" on the second search. If still no match is found, vector nearest neighbor search or runtime proactive retrieval is used as a fallback. Upon successful matching, the definition node is merged into the initially selected evidence node set and its role is marked as "definition completion." Similarly, the definition node corresponding to "working day" is also merged into the set, thus resolving the semantic isolation problem of the initially selected evidence nodes and constructing a complete evidence context.
[0167] 4) Dynamic budget allocation.
[0168] Assuming this is a tight-budget scenario, the model's maximum context window is limited, and the available evidence package budget B has only 400 tokens remaining. In this case, dynamic budget allocation needs to be performed on the nodes after cross-segment dependency completion. First, the effective information content of each node is calculated to determine the information density. Combining the second similarity and dependency weights, the importance score of each node is calculated. Second, multiple candidate representation formats for each node are determined, including full-text representation (token cost equal to the original text length, benefit coefficient of 1.0), extract representation (token cost approximately 0.4 times the original text length, benefit coefficient of 0.75), and summary representation (token cost approximately 0.15 times the original text length or the lower limit protection value, benefit coefficient of 0.45).
[0169] Under budget constraints, a multi-level strategy maximizes overall returns: The first step involves a guaranteed allocation, forcing the main evidence nodes for the three sub-tasks to be selected in full-text format, deducting the corresponding budget; and ensuring that dependent nodes such as definition completion are selected at least in summary format. The second step, using the remaining budget, executes a greedy filling and upgrading process, sorting nodes by unit token return from high to low, upgrading some definition nodes from summary format to full-text format, and introducing excerpts of some secondary evidence. This ultimately generates an optimized evidence package with a total cost of approximately 395 tokens, maximizing the effective information content of the tasks under strict budget constraints.
[0170] 5) Focus on reasoning and constraint generation.
[0171] The generated evidence package is input into a large language model for focused reasoning. The input prompts explicitly list a whitelist of allowed unique citation numbers. During model generation, a trie structure containing these legal numbers is constructed, and constraint decoding is performed using Logits masking: when the model attempts to generate a prefix of a number not in the whitelist, the probability of that token is set to negative infinity, thus physically preventing the illusion of "fabricating citation numbers." Ultimately, the model only outputs the conclusion (e.g., "Written notice must be given 30 business days in advance") and the corresponding evidence identifier (e.g., unique node number), without generating any chapter numbers in natural language form.
[0172] 6) Location backfilling and consistency verification.
[0173] After the large language model outputs, the corresponding node is retrieved in the hierarchical semantic structure with O(1) complexity based on the evidence identifier, and the location metadata (such as the fifth article, the second article, the offset [222, 268]) and role tags are extracted and bound to the conclusion text to generate a citation chain containing the original text location information, thus completely eliminating the illusion of "citation misalignment".
[0174] Subsequently, a three-layer cascade mechanism is employed to verify the consistency of the reasoning conclusion: the first layer, structured rule verification, confirms that the identifier exists in the whitelist and that the numerical units are consistent; the second layer, natural language reasoning model verification, checks that the conclusion and evidence are semantically implied (confidence level 0.91), and passes the verification. If the verification fails at this point (e.g., a gap of "insufficient evidence" appears), the gap information is extracted, and supplementary evidence retrieval conditions are generated based on strategies such as hypothetical document embedding. A reverse supplementary evidence retrieval is then performed within a specific range of the long text. After obtaining the supplementary evidence nodes, they are merged into the evidence package, and dynamic budget allocation and reasoning are re-executed until the verification passes. Finally, an auditable question-and-answer report and evidence citation chain are output, allowing users to click and locate the original clause.
[0175] This application provides a focused reasoning device for long-text large language models based on hierarchical semantics, see reference. Figure 2 , Figure 2This is a schematic diagram of an embodiment of the long text large language model focusing inference device based on hierarchical semantics provided in this application. The long text large language model focusing inference device based on hierarchical semantics includes: Module 10 is used to acquire the long text to be processed and the user task; The hierarchical module 20 is used to construct a hierarchical semantic structure containing multiple levels of nodes based on the long text, and to generate semantic representations and location metadata for each level of node; Focusing module 30 is used to perform focusing filtering, cross-segment dependency completion, and dynamic budget allocation on the hierarchical semantic structure based on the user task and the semantic representation to generate an evidence package; The reasoning module 40 is used to input the evidence package into the large language model and map the output evidence identifier to the location metadata to obtain the final result with the reference chain.
[0176] In an optional embodiment, the focusing module 30 is specifically used for: In the first level of the hierarchical semantic structure, a first similarity between the user task and the semantic representation of each node is calculated to filter candidate chapters; In the second level within the candidate chapter, the user task is parsed to obtain at least one subtask, the second similarity between each node and the subtask is calculated, and preliminary evidence nodes are selected based on the coverage constraint rule. Cross-segment dependency completion is performed on the initially selected evidence nodes, and dynamic budget allocation is performed on the nodes after cross-segment dependency completion to generate the evidence package.
[0177] In an optional embodiment, the focusing module 30 is further configured to: Traverse the text content of the initially selected evidence nodes and identify the undefined terms and text reference marks contained therein; Based on the pre-built dependency index, retrieve the definition node corresponding to the term to be defined, as well as the target node pointed to by the text reference mark; The retrieved definition nodes and target nodes are merged into the initial set of evidence nodes.
[0178] In an optional embodiment, the focusing module 30 is further configured to: Based on the second similarity, information density, and dependency relationship of each of the preliminary evidence nodes, the importance score is calculated; Determine multiple candidate representation forms for each of the preliminary evidence nodes, including full text, excerpt, and summary; Under the preset context lexical budget constraint, based on the importance score, the optimal combination of representation forms is selected for each of the preliminary evidence nodes, and the evidence package is generated according to the selection result. In an optional embodiment, the focusing module 30 is further configured to: The effective information content in the text of each of the preliminary evidence nodes is statistically analyzed, and the ratio of the statistical value of the effective information content to the text length is calculated to obtain the information density. Based on the dependency relationships of each of the preliminary evidence nodes and the preset weight rules, the dependency weights of each of the preliminary evidence nodes are determined. The importance score is obtained by weighting and summing the second similarity, the information density, and the dependency weight.
[0179] In an optional embodiment, the inference module 40 is specifically used for: The evidence package is input into the large language model, and the reasoning conclusion and evidence identifier are output, wherein the evidence identifier is a unique number of the node in the evidence package; Based on the evidence identifier, the corresponding node is retrieved in the hierarchical semantic structure, and the location metadata of the node is extracted; The location metadata is bound to the inference conclusion to generate the reference chain containing the original text location information, so as to obtain the final result.
[0180] In an optional embodiment, the inference module 40 is further configured to: Consistency verification is performed on the inference conclusions output by the large language model; If the verification fails, extract the gap information corresponding to the verification failure. Based on the gap information, supplementary evidence retrieval conditions are generated, and supplementary evidence retrieval is performed in the long text to obtain supplementary evidence nodes; The supplementary evidence nodes are merged into the evidence package, and the reasoning and consistency verification are re-executed until the verification passes to generate the final result.
[0181] Since the embodiments of the device part correspond to the embodiments of the above method, the description of the long text large language model focused reasoning device based on hierarchical semantics provided in this application is referred to the above method embodiments. This application will not repeat it here. It has the same beneficial effects as the above-mentioned long text large language model focused reasoning method based on hierarchical semantics.
[0182] See Figure 3 , Figure 3 This is a schematic diagram of an embodiment of the storage medium provided in this application.
[0183] The storage medium 300 stores program data 310, which, when executed by the processor, implements, as follows: Figure 1 The steps of the focused inference method for long text large language models based on hierarchical semantics are described.
[0184] The program data 310 is stored in a storage medium 300 and includes several instructions for causing a network device (which may be a router, personal computer, server, or other network device) or processor to execute all or part of the steps of the methods described in the various embodiments of this application.
[0185] Optionally, the storage medium 300 can be any medium capable of storing program data, such as a USB flash drive, portable hard drive, read-only memory (ROM), random access memory (RAM), disk, or optical disc.
[0186] See Figure 4 , Figure 4 This is a schematic diagram of the structure of an embodiment of the computer device provided in this application.
[0187] The device 400 includes a processor 420 and a memory 410 interconnected. The memory 410 stores a computer program, and when the processor 420 executes the computer program, it implements, for example, Figure 1 The steps of the focused inference method for long text large language models based on hierarchical semantics are described.
[0188] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on its differences from other embodiments. In particular, the storage medium embodiments and computer device embodiments are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0189] This application can be used in a wide range of general-purpose or special-purpose computing system environments or configurations. For example: personal computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, network PCs, minicomputers, distributed computing environments including any of the above systems or devices, etc.
[0190] In the several embodiments provided in this application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device embodiments described above are merely illustrative; multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed.
[0191] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0192] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0193] The above description is merely an embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A long text large language model focusing inference method based on hierarchical semantics, characterized in that, include: Retrieve the long text to be processed and the user task; Based on the long text, a hierarchical semantic structure containing multi-level nodes is constructed, and semantic representations and location metadata are generated for each level of node; Based on the user task and the semantic representation, focus filtering, cross-segment dependency completion and dynamic budget allocation are performed on the hierarchical semantic structure to generate an evidence package; The evidence package is input into the large language model, and the output evidence identifier is mapped to the location metadata to obtain the final result with a reference chain.
2. The hierarchical semantic-based long text large language model focusing inference method according to claim 1, characterized in that, Based on the user task and the semantic representation, the process of performing focused filtering, cross-segment dependency completion, and dynamic budget allocation on the hierarchical semantic structure generates an evidence package, including: In the first level of the hierarchical semantic structure, a first similarity between the user task and the semantic representation of each node is calculated to filter candidate chapters; In the second level within the candidate chapter, the user task is parsed to obtain at least one subtask, the second similarity between each node and the subtask is calculated, and preliminary evidence nodes are selected based on the coverage constraint rule. Cross-segment dependency completion is performed on the initially selected evidence nodes, and dynamic budget allocation is performed on the nodes after cross-segment dependency completion to generate the evidence package.
3. The hierarchical semantic-based long text large language model focusing inference method according to claim 2, characterized in that, The step of performing cross-segment dependency completion on the initially selected evidence nodes includes: Traverse the text content of the initially selected evidence nodes and identify the undefined terms and text reference marks contained therein; Based on the pre-built dependency index, retrieve the definition node corresponding to the term to be defined, as well as the target node pointed to by the text reference mark; The retrieved definition nodes and target nodes are merged into the initial set of evidence nodes.
4. The hierarchical semantic-based long text large language model focusing inference method according to claim 2, characterized in that, The process of performing dynamic budget allocation on nodes after cross-segment dependency completion to generate the evidence package includes: Based on the second similarity, information density, and dependency relationship of each of the preliminary evidence nodes, the importance score is calculated; Determine multiple candidate representation forms for each of the preliminary evidence nodes, including full text, excerpt, and summary; Under the preset context lexical budget constraint, based on the importance score, the optimal combination of representation forms is selected for each of the preliminary evidence nodes, and the evidence package is generated according to the selection result.
5. The hierarchical semantic-based long text large language model focusing inference method according to claim 4, characterized in that, The importance score is calculated based on the second similarity, information density, and dependency relationship of each of the initially selected evidence nodes, including: The effective information content in the text of each of the preliminary evidence nodes is statistically analyzed, and the ratio of the statistical value of the effective information content to the text length is calculated to obtain the information density. Based on the dependency relationships of each of the preliminary evidence nodes and the preset weight rules, the dependency weights of each of the preliminary evidence nodes are determined. The importance score is obtained by weighting and summing the second similarity, the information density, and the dependency weight.
6. The hierarchical semantic-based long text large language model focusing inference method according to claim 1, characterized in that, The step of inputting the evidence package into the large language model and mapping the output evidence identifier to the location metadata to obtain the final result with a reference chain includes: The evidence package is input into the large language model, and the reasoning conclusion and evidence identifier are output, wherein the evidence identifier is a unique number of the node in the evidence package; Based on the evidence identifier, the corresponding node is retrieved in the hierarchical semantic structure, and the location metadata of the node is extracted; The location metadata is bound to the inference conclusion to generate the reference chain containing the original text location information, so as to obtain the final result.
7. The hierarchical semantic-based long text large language model focusing inference method according to claim 1, characterized in that, Before obtaining the final result with the reference chain, it also includes: Consistency verification is performed on the inference conclusions output by the large language model; If the verification fails, extract the gap information corresponding to the verification failure. Based on the gap information, supplementary evidence retrieval conditions are generated, and supplementary evidence retrieval is performed in the long text to obtain supplementary evidence nodes; The supplementary evidence nodes are merged into the evidence package, and the reasoning and consistency verification are re-executed until the verification passes to generate the final result.
8. A layered semantic-based long text large language model focused reasoning apparatus, characterized in that, include: The acquisition module is used to acquire the long text to be processed and the user task; The hierarchical module is used to construct a hierarchical semantic structure containing multiple levels of nodes based on the long text, and to generate semantic representations and location metadata for each level of node; The focusing module is used to perform focusing filtering, cross-segment dependency completion, and dynamic budget allocation on the hierarchical semantic structure based on the user task and the semantic representation, and generate an evidence package. The reasoning module is used to input the evidence package into the large language model and map the output evidence identifier to the location metadata to obtain the final result with a reference chain.
9. A computer device comprising a memory, a processor, and a computer program stored on the memory, wherein the computer program comprises instructions that, when executed by the processor, cause the processor to perform the method of any one of claims 1-8. The processor executes the computer program to implement the steps of the long text large language model focused inference method based on hierarchical semantics as described in any one of claims 1-7.
10. A storage medium having stored thereon a computer program, characterized in that When executed by a processor, the computer program implements the steps of the long text large language model focused inference method based on hierarchical semantics as described in any one of claims 1-7.
