A method, system and computer program for generating context adaptive compression
Patent Information
- Application Number
- CN202611385805.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-08
- Publication Date
- 2026-10-27
AI Technical Summary
[0008]本发明的目的是提供一种生成上下文自适应压缩方法、系统及计算机程序,以改善检索增强生成过程中候选文档占用词元资源超过大语言模型上下文资源限制时,现有上下文压缩方式难以同时兼顾上下文资源释放、必要证据保持以及动态压缩计算量控制的问题
1.本发明根据用户查询确定查询事项及对应证据需求,将候选文档划分形成候选证据单元,并建立候选证据单元与查询事项之间的证据对应关系;当候选证据单元形成的待压缩上下文超过大语言模型的上下文词元预算时,在候选证据单元实际移出之前,根据假定移出该候选证据单元后的剩余候选证据单元判断对应查询事项的证据需求是否仍能够得到满足,并仅将移出后仍能够保持相应证据需求的候选证据单元确定为可释放证据单元。因此,候选证据单元是否能够被释放由当前剩余候选证据的实际支持状态确定,而不是由压缩开始时形成的固定文本评价结果确定;一个候选证据单元被实际移出后,可以根据更新后的剩余证据状态重新确定相关候选证据单元的释放资格,从而降低多个初始具有替代关系的证据文本在连续压缩过程中被继续移出而造成必要证据缺失的可能性。
Smart Images

Figure CN122986015A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a context-adaptive compression method, system, and computer program, belonging to the field of artificial intelligence technology. Background Technology
[0002] Retrieval enhancement generation is a technique that incorporates external retrieval results into the generation process of a large language model. In this process, candidate documents can be retrieved from knowledge bases, document indexes, or other data sources based on user queries. The text content of these candidate documents is then used as the retrieval enhancement context and input into the large language model, enabling the model to generate corresponding output content based on this context.
[0003] Large language models are typically limited by the context window capacity to receive the entire context during a single inference process. When the number of candidate documents retrieved based on a user query is large, or when the candidate documents contain lengthy text, the retrieval enhancement context formed by these candidate documents may consume a significant amount of lexical resources, even exceeding the context capacity that the large language model can receive. Therefore, the retrieval enhancement context can be compressed before the candidate documents are input into the large language model. Based on the relevance, importance, or other text evaluation results of the candidate texts, some candidate texts can be retained while others are removed, thereby reducing the number of lexical resources required by the retrieval enhancement context.
[0004] However, a user query may include multiple unanswered items, and the same unanswered item may be supported by multiple candidate texts providing the same or complementary evidence. During context compression, whether a candidate text can be removed depends not only on the information it carries but also on whether other currently retained candidate texts can continue to provide corresponding evidence. At the start of compression, a candidate text may have other evidence texts that can replace it, and thus it can be removed; once the corresponding alternative evidence has been removed in previous compression processes, the candidate text may be transformed into the text required to maintain the corresponding evidence among the remaining text.
[0005] Therefore, if compression is performed continuously according to the text evaluation results or text deletion order determined at the beginning of compression, it is difficult to reflect the changes in the status of remaining evidence after the removal of previous texts in a timely manner, which may lead to the continued removal of candidate texts that were originally interchangeable. If the evidence status of all candidate texts is reassessed after each candidate text is removed, a lot of redundant data processing will occur as the number of candidate documents increases.
[0006] In addition, candidate documents are usually divided into multiple text units according to paragraphs, sentences, or preset text lengths. When a part of the text in a text unit carries the evidence content that needs to be retained, the entire text unit may not be removed, and the other text in the text unit may not necessarily carry the corresponding evidence function. As a result, some text that can be further compressed will share the contextual lexical resources of the large language model along with the necessary evidence.
[0007] Therefore, it is necessary to provide a retrieval enhancement generation context compression scheme to handle the resource release state of candidate texts under the constraint of large language model context lexical resources. Summary of the Invention
[0008] The purpose of this invention is to provide a context-adaptive compression method, system, and computer program to improve the problem that existing context compression methods cannot simultaneously take into account context resource release, necessary evidence preservation, and dynamic compression computation control when candidate documents occupy more lexical resources than the context resource limit of a large language model during the retrieval enhancement generation process.
[0009] To solve the above-mentioned technical problems, the present invention is implemented using the following technical solution.
[0010] On one hand, this invention provides a context-adaptive compression method, comprising: acquiring a user query, a candidate document set corresponding to the user query, and a context lexical budget of a large language model; parsing the user query, forming at least one query item based on the query object, query attribute, limiting elements, and relational predicates in the user query, and determining the evidence requirements corresponding to each query item; dividing the candidate document set into multiple candidate evidence units, and establishing an evidence correspondence between the candidate evidence units and the query items based on the evidence elements actually carried by each candidate evidence unit and the relationships between the evidence elements; forming a context to be compressed based on the current candidate evidence units, and determining the current lexical occupancy of the context to be compressed; when the current lexical occupancy exceeds the context lexical budget, determining the amount of lexical units to be released based on the number of lexical units exceeding the budget; and for the candidate evidence units, under the assumption of shifting... In the current state of candidate evidence units, the query items affected by the current assumed removal action are determined according to the evidence correspondence, and it is determined whether the remaining candidate evidence units still meet the evidence requirements of the query items respectively; when the evidence requirements of the corresponding query items are all met, the current candidate evidence unit is determined as a releasable evidence unit; the releasable evidence units are actually removed according to the number of lexical units to be released, and after each candidate evidence unit is actually removed, the current lexical occupancy status of the context to be compressed is updated, and the candidate evidence units affected by this release action are determined according to the query items corresponding to the removed candidate evidence units. Only the affected candidate evidence units are re-evaluated for releasability; when the current lexical occupancy is reduced to no more than the context lexical budget, the target context is formed according to the remaining candidate evidence units, and the target context is provided to the large language model.
[0011] Preferably, a bidirectional index is established based on the evidence correspondence between candidate evidence units and query items. The first index points from the query item identifier to the corresponding evidence unit identifier, and the second index points from the evidence unit identifier to the corresponding query item identifier. After a candidate evidence unit is actually removed, the affected query item is determined through the second index, and then the candidate evidence unit that needs to be re-evaluated for release is determined through the first index.
[0012] Preferably, query items are formed based on the semantic relationships between relational predicates in the user query and the query object, the query attribute, and the limiting elements, and the corresponding evidence elements and the relationships between evidence elements are determined based on the objects, attributes, limiting content, and relationship types in the query items.
[0013] Preferably, when establishing the evidence correspondence between candidate evidence units and query items, the candidate evidence elements in the candidate evidence units and the relationships between the candidate elements are analyzed and matched with the evidence requirements of the query items; when a single candidate evidence unit cannot fully provide the evidence required for the corresponding query item, one or more supplementary evidence units that have a semantic dependency relationship with the candidate evidence unit are determined.
[0014] Preferably, when multiple releasable evidence units exist simultaneously, each releasable evidence unit is simulated for removal, and a target retention set is formed from the remaining candidate evidence units after the simulated removal according to the unmet evidence elements and the relationships between the evidence elements; the retention resource quantity corresponding to the current releasable evidence unit is formed according to the word resources occupied by the target retention set, and releasable evidence units with smaller retention resource quantities are removed first.
[0015] Preferably, the amount of lexical units to be released is released in multiple resource release rounds. The current resource deviation is formed based on the current lexical unit occupancy and the context lexical unit budget. Proportional adjustment, integral adjustment and differential adjustment are implemented based on the current resource deviation, cumulative resource deviation and deviation change, respectively, to determine the target release amount for the current resource release round. After each candidate evidence unit is actually removed in a resource release round, the release eligibility of the candidate evidence unit is re-determined according to the updated evidence status.
[0016] Preferably, when the total number of tokens occupied by all currently releasable evidence units is insufficient to cover the remaining number of tokens to be released, the evidence units to be refined are determined from the currently unreleasable candidate evidence units, and they are divided into multiple candidate evidence sub-units; based on the query items corresponding to the parent candidate evidence unit, the actual evidence content carried by each candidate evidence sub-unit is re-evaluated, and the candidate evidence sub-units that meet the release conditions are re-entered into the resource release process.
[0017] Preferably, during the refinement of candidate evidence units, the original text segments that actually bear the evidence elements or the relationships between evidence elements in the evidence unit to be refined are located according to the evidence requirements. The corresponding original text segments are formed into retained evidence sub-units, and the other original texts are formed into evidence sub-units to be judged. The retained evidence sub-units only establish query matters relationships corresponding to the evidence content they actually bear. The evidence sub-units to be judged re-execute the evidence correspondence and release qualification judgment.
[0018] On the other hand, the present invention provides a retrieval-enhanced generation context adaptive compression system, including a processor and a memory, wherein the memory stores a computer program, and when the processor executes the computer program, it causes the system to perform the above-described generation context adaptive compression method.
[0019] On the other hand, the present invention provides a computer program, including a computer program that, when executed by a processor, implements the above-described generation context adaptive compression method.
[0020] Compared with the prior art, the beneficial effects achieved by the present invention are as follows: 1. This invention determines the query items and corresponding evidence requirements based on user queries, divides candidate documents into candidate evidence units, and establishes an evidence correspondence between candidate evidence units and query items. When the context to be compressed formed by a candidate evidence unit exceeds the context lexical budget of the large language model, before the candidate evidence unit is actually removed, it is determined whether the evidence requirements of the corresponding query item can still be met based on the remaining candidate evidence units after the removal of the candidate evidence unit. Only candidate evidence units that can still maintain the corresponding evidence requirements after removal are identified as releaseable evidence units. Therefore, whether a candidate evidence unit can be released is determined by the actual support status of the current remaining candidate evidence, rather than by the fixed text evaluation result formed at the beginning of compression. After a candidate evidence unit is actually removed, the release eligibility of related candidate evidence units can be re-determined based on the updated remaining evidence status, thereby reducing the possibility of multiple initially substitutable evidence texts being removed during continuous compression, resulting in the loss of necessary evidence.
[0021] 2. After each candidate evidence unit is actually removed, the candidate evidence units that need to be re-evaluated for release eligibility are limited according to the query items corresponding to the removed candidate evidence units. This allows the change in evidence status caused by the release action to propagate within the data scope associated with the corresponding query item, without having to re-perform the release eligibility judgment for all candidate evidence units, thereby reducing the amount of candidate text data that is repeatedly processed during dynamic context compression.
[0022] 3. When the number of candidate evidence units that can be safely released at the current text granularity is insufficient to meet the release requirements of the remaining tokens, finer-grained candidate evidence subunits are formed based on the original text segments that actually serve as evidence within the unreleaseable candidate evidence units. Their evidence correspondence and release eligibility are then reassessed, allowing text that does not actually serve as necessary evidence to be separated from the evidence text that needs to be retained and re-enter the resource release process. Therefore, without changing the conditions for retaining evidence for the corresponding query, the amount of contextual content retained along with necessary evidence due to coarse-grained text division can be further reduced, improving the utilization of limited contextual token resources. Attached Figure Description
[0023] Figure 1 This is a flowchart illustrating a retrieval enhancement context-adaptive compression method. Figure 2 A flowchart illustrating the process of releasing candidate evidence units and updating local states; Figure 3 A schematic diagram illustrating an application scenario for enhancing retrieval by generating context compression; Figure 4 A schematic diagram of the phased processing flow of the context-adaptive compression method for enhanced retrieval; Figure 5 This is a schematic diagram of the overall process of the context-adaptive compression method; Figure 6 This is a schematic diagram of the local refinement process when the granularity of candidate evidence units is limited. Detailed Implementation
[0024] This invention can be modified in many ways and has many embodiments, with specific embodiments shown in the accompanying drawings for detailed description. However, this does not mean that the invention is limited to a specific implementation; it should be understood that all modifications, equivalents, and even substitutions falling within the concept and technical scope of this invention are included in this invention. Similar reference numerals are used for similar constituent elements in the description of the drawings.
[0025] The terms “first,” “second,” “A,” “B,” etc., are used to describe a wide variety of constituent elements, but these constituent elements are not limited by these terms. These terms are used to distinguish one constituent element from others. For example, without departing from the scope of the invention, a first constituent element may be named a second constituent element, and similarly, a second constituent element may be named a first constituent element. The term “and / or” includes a combination of multiple associated descriptions, or one of multiple associated descriptions.
[0026] When it is mentioned that a certain constituent element is "connected" or "linked" to other constituent elements, it can mean not only that the element is directly connected or linked to the other constituent element, but also that there are other constituent elements in between. Conversely, when it is mentioned that a certain constituent element is "directly connected" or "directly linked" to other constituent elements, there are no other constituent elements in between.
[0027] The terminology used in this application is for illustrative purposes only and is not intended to limit the scope of the invention. Singular expressions include plural expressions unless the context clearly indicates otherwise. Terms such as "comprising" or "having" as used herein do not preclude the possibility of the presence or addition of features, numbers, stages, actions, constituent elements, components, or combinations thereof described in the specification.
[0028] Unless otherwise defined, all terms used herein, including technical or scientific terms, have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.
[0029] Terms defined in common dictionaries should be interpreted as having the same meaning as in the context of the relevant technology, and should not be interpreted as having an ideal or overly formal meaning unless explicitly defined in this application.
[0030] Example 1 The selective release described in this embodiment does not use the uniform relevance or fixed importance threshold of the candidate text itself as a direct deletion condition. Instead, it forms at least one query item based on the user query and determines the evidence requirements that need to be retained by the candidate text for each query item. After the candidate document is divided into multiple candidate evidence units, the actual evidence content carried by each candidate evidence unit is further determined, and an evidence correspondence relationship is established between the candidate evidence units and the query items. When context resources need to be released, before the candidate evidence unit is actually removed, it is first determined whether the evidence requirements of the corresponding query item can still be met based on the assumed state of the remaining evidence after removal. Only when all associated query items maintain a state of satisfied evidence requirements are the candidate evidence units allowed to enter the subsequent resource release process.
[0031] refer to Figures 1 to 6 As shown in this embodiment, a generation context adaptive compression method is introduced, including: S101, obtain the user query, the candidate document set corresponding to the user query, and the context lexical budget of the large language model.
[0032] S102, perform structured parsing on the user query, determine at least one query item, and form corresponding evidence requirements for each query item.
[0033] S103, the candidate document set is divided into candidate evidence units, the evidence content of the candidate evidence units is parsed, the evidence correspondence between the candidate evidence units and the query items is established, and an evidence support record is formed to describe the actual support status of the evidence requirement.
[0034] S104, form a context to be compressed based on the currently valid candidate evidence units; determine the number of words to be released when the word occupancy of the context to be compressed exceeds the context word budget, and determine the currently releaseable evidence units by assuming the removal of candidate evidence units.
[0035] S105, determine the amount of reserved resources in the corresponding simulated removal state for each currently releasable evidence unit, determine the current evidence unit to be removed based on the amount of reserved resources, and perform actual resource release.
[0036] S106, update the evidence support status according to the candidate evidence units that have actually been removed, and limit the data range for re-evaluation of release eligibility according to the evidence correspondence between the candidate evidence units and the query items.
[0037] S107, continue to release candidate evidence units according to the updated current word unit occupancy status; when there are insufficient safe releaseable resources at the current candidate evidence unit granularity, implement local refinement of the unreleaseable candidate evidence units, and make the refined candidate evidence sub-units re-enter the evidence correspondence and release qualification judgment process; when the current word unit occupancy does not exceed the context word unit budget, form the target context according to the remaining candidate evidence units and input it into the large language model.
[0038] In this process, the evidence requirements formed in S102 constitute the evidence protection conditions for subsequent candidate texts; S103 maps the evidence protection conditions to specific texts in the candidate documents; S104 forms release eligibility based on the assumed evidence state after removal; S105 combines the release eligibility with the context resource requirements to form the actual release action; S106 processes the local evidence state changes caused by the actual release; and S107 determines whether to continue releasing, reduce the text processing granularity, or form a target context based on the updated resource state, thereby forming a continuous context resource compression closed loop.
[0039] S101, forming the basic input for the context compression task Obtain the user query corresponding to this search enhancement generation task, and retrieve the set of candidate documents returned by the search service based on the user query.
[0040] A task identifier is generated for this context compression task, and a task status record corresponding to the task identifier is established in the memory space. The task status record includes at least the following fields: context lexical budget field, current lexical occupancy field, current lexical occupancy to be released field, and task execution status field.
[0041] For each candidate document in the candidate document set, a document record is created. The document record includes at least a document identifier, the main text, and a source identifier. When a candidate document belongs to a local section of a parent document, the parent document identifier, as well as the start and end positions of the original text of the current candidate document within the parent document, are further saved. This allows subsequently formed candidate evidence units or candidate evidence subunits to reread the corresponding original text based on the stated source positions.
[0042] Furthermore, the context capacity and corresponding lexical encoding rules of the target large language model are read based on the model identifier corresponding to the target large language model. Lexical encoding is then performed on the system prompt text, user query text, and message fields that need to be fixedly retained in this call according to the lexical encoding rules. The amount of lexical resources already occupied by the non-retrieval text is obtained based on the length of the lexical sequence of the corresponding encoding results.
[0043] Subtract the amount of lexical resources already occupied by the non-retrieval text and the number of lexical resources reserved for the output of the large language model from the context capacity of the target large language model, determine the remaining lexical resources as the context lexical budget that can be occupied by candidate documents, and write it into the task status record.
[0044] In one implementation, context encapsulation resources are further reserved for document source identification, text delimiter fields, and message encapsulation fields when determining the context lexical budget. Therefore, the resource release of subsequent candidate evidence units is performed according to the actual lexical measurement caliber used by the target large language model, ensuring that the lexical occupancy status recorded during compression directly corresponds to the final model input resources, rather than approximating the target model's actual lexical resources with the number of characters or bytes.
[0045] S102, which involves structured parsing of user queries and generating evidence requirements, also includes: S1021, Create query term record The user query obtained by S101 is subjected to character normalization processing, which unifies different character encodings, full-width characters and half-width characters, merges consecutive spaces and repeated control characters that have no semantic function, and retains negative expressions, comparison expressions, conditional expressions, time expressions and quantity expressions.
[0046] The normalized user query is segmented into tokens according to a preset text segmentation method, and a query token record is created for each query token. The query token record includes at least the query token identifier, the start and end positions of the original text, the part-of-speech category, and the original text.
[0047] Named entity recognition is performed on the query term sequence, and the identified object entity, time entity, location entity, and quantity entity are written to the corresponding query term record. When the same object has an abbreviation, full name, or a pre-established alias, it is converted to the same standard entity identifier according to the entity alias mapping record.
[0048] For time expressions, different formats of year, quarter, date, or relative time are converted into a unified time field; for quantity expressions, numerical content and units are recorded separately; for negation words, comparison words, causal words, and conditional words, corresponding semantic tags are saved in the query term records.
[0049] Through the above processing, the original natural language query is converted into query term records with definite original text location and standardized semantic identifiers, providing a unified data foundation for the formation of subsequent query matters and evidence requirements.
[0050] S1022, Create query semantic relationship records Dependency analysis is performed based on the query term records. For query terms with dependency relationships, the dependency start point, dependency end point, and dependency relationship type are saved. The relation predicates in the user query are determined based on the formed dependency structure.
[0051] For a relational predicate, determine the corresponding query object along the subject-predicate relationship, determine the query object or query attribute along the verb-object relationship or prepositional object relationship, and determine the corresponding time, condition, scope, and comparison benchmark form limiting elements along the noun-head relationship, adverbial-head relationship, and time modification relationship.
[0052] When explicit attribute terms exist in a user query, the explicit attribute terms are standardized and written into the attribute field to be queried. When there are no independent explicit attribute terms, but the relational predicate directly acts on the fact object, state object, or event object, the semantic center identifier corresponding to the fact object, state object, or event object is used as the attribute identifier to be queried, so that the formation of the attribute to be queried still has the direct semantic source in the user query, rather than being formed by generating new natural language attribute content.
[0053] When different relational predicates correspond to query content that can be answered independently, different query semantic relation records are established; when multiple parallel query objects are constrained by the same relational predicate and the same query attribute, the identifiers of multiple query objects are stored in the same query semantic relation record.
[0054] Each query semantic relationship record includes at least the relationship record identifier, the query object identifier, the attribute identifier to be queried, the limiting element identifier, the original text position of the relationship predicate, and the relationship direction.
[0055] S1023, Create query item Traverse the query semantic relationship records formed in S1022, merge the query semantic relationship records corresponding to the same content to be answered into the same query item, and assign a query item identifier to each query item.
[0056] A query record must include at least a query item identifier, a query object field, a query attribute field, a limiting element field, and a relationship type field. The query object field references a standard entity identifier, the query attribute field references a standard attribute identifier or a fact semantic center identifier, and the limiting element field stores uniformly formatted time, location, conditions, quantity, or comparison benchmark.
[0057] The relation type is determined based on the relational predicate and its corresponding semantic role. When a query is used to obtain an object's attribute or state, the relation type is determined to be an attribute relation; when there is both a target state and a baseline state and it is required to determine the change of both, it is determined to be a change relation; when there are two or more comparison objects and common comparison attributes, it is determined to be a comparison relation; when there are causal facts and explained facts, it is determined to be a causal relation; when there are future constraints and it is required to obtain a predicted state or trend, it is determined to be a predictive relation.
[0058] When the aforementioned relationship type cannot be uniquely determined by the existing query structure, the relationship type is recorded as a general fact relationship, while retaining the original relationship predicate and corresponding semantic roles. No causal, comparative, or predictive facts that are not required by the user query itself are artificially added based on uncertain classification results.
[0059] S1024, Formation of Evidence Requirement Items For each query, the query object, the attribute to be queried, the limiting elements, and the relationship type are read, and the corresponding evidence requirements are established based on the data.
[0060] In this embodiment, the evidence elements included in the evidence requirements of the claims and the relationships between the evidence elements are respectively represented as necessary evidence requirement items, and an evidence requirement identifier is set for each necessary evidence requirement item.
[0061] The attribute relationship requires at least the establishment of object evidence requirements, attribute evidence requirements, and object-attribute relationship evidence requirements; when the user query includes time, location, or conditional restrictions, corresponding limiting evidence requirements should be established.
[0062] The change relationship further establishes the evidence requirements for the target state, the baseline state, and the change relationship; the comparison relationship establishes the comparison object, common comparison attributes, comparability limits, and the comparison relationship evidence requirements; the causal relationship establishes the explained fact, the causal fact, and the cause-effect relationship evidence requirements; and the prediction relationship establishes the prediction subject, the prediction object, the target limit, and the prediction state relationship evidence requirements.
[0063] Each evidence request record must include at least the evidence request identifier, the identifier of the query item to which it belongs, the request type, the standardized request content, the necessary status, and a list of supporting records.
[0064] For relational evidence requirements, the system further preserves the first relation endpoint identifier, the second relation endpoint identifier, the relation type, and the relation direction. The first and second relation endpoints reference existing object evidence requirement items or factual evidence requirement items, making the relationship between evidence elements appear as a specified relationship that needs to be established between two defined evidence endpoints.
[0065] Therefore, the relation type does not directly generate new facts, but only determines the evidence structure in which the objects, attributes, facts and limiting content already parsed and obtained in the user query participate in the subsequent candidate text judgment.
[0066] S1025, Establish Evidence Requirement Status Record For each query, establish an evidence requirement status record according to its necessary evidence requirements.
[0067] Before evidence matching is performed on the candidate documents, all necessary evidence requirements are initialized to an unmet state, and the corresponding list of supported records is empty.
[0068] After S103 generates a valid supporting record that can actually support a certain evidence requirement, the corresponding supporting record identifier is written into the supporting record list of the evidence requirement. As long as there is at least one currently valid supporting record in the supporting record list, the corresponding necessary evidence requirement is set to a satisfied state.
[0069] Through the above processing, "whether the evidence requirements of the query matter are still met" can be transformed into whether each of the necessary evidence requirements in the query matter has at least one valid supporting record, so that the subsequent release eligibility judgment has a data status that can be directly read and updated by the program.
[0070] S103, convert candidate documents into candidate evidence units and establish evidence support relationships. S1031, Forming candidate evidence units Read the candidate document text, identify paragraph and sentence boundaries, and use the target model lexical encoding rules determined by S101 to count the number of lexical units in the corresponding text segments.
[0071] Initial text segments are formed first based on paragraph boundaries; if the initial text segment exceeds the preset candidate evidence unit processing length, it is further divided according to the end position of the sentence, and consecutive sentences are combined to form candidate evidence units while maintaining sentence integrity.
[0072] Assign an evidence unit identifier to each candidate evidence unit and establish an evidence unit record. The evidence unit record shall at least store the evidence unit identifier, source document identifier, original text start position, original text end position, candidate evidence text, token occupancy, current valid state, current releaseable state, and set of identifiers for the evidence requirements.
[0073] When it is necessary to preserve cross-boundary semantics, adjacent candidate evidence units can retain a certain range of overlapping original text. During the resource statistics process, the corresponding words in the overlapping text are measured according to the actual number of texts entering the context to be compressed, thereby ensuring that the resource status is consistent with the real input data of the target large language model.
[0074] S1032, Forming a record of candidate evidence content For candidate evidence units, entity identification, attribute identification, limited element identification, and relational structure analysis are performed using the same data standardization criteria as S102.
[0075] Entities in candidate evidence texts are converted into standard entity identifiers, attribute expressions are converted into standard attribute identifiers, and time, location, quantity, and condition expressions are converted into data fields in the same format as those on the query side.
[0076] Candidate relation records are established for the relation predicates in the candidate evidence units. The candidate relation record includes at least the first relation endpoint, the second relation endpoint, the relation type, the relation direction, the relation polarity, and the original position of the relation predicate.
[0077] Relation polarity must at least distinguish between affirmative, negative, and uncertain states. When a candidate text explicitly negates a relation required by the query, the corresponding candidate relation is not considered valid evidence supporting the affirmative relation requirement.
[0078] S1033, Matching Evidence Elements Read the necessary evidence requirements for each query item and compare the candidate evidence content according to the requirement type.
[0079] Object-type evidence requires comparison of standard entity identifiers; attribute-type evidence requires comparison of standard attribute identifiers; time, location, quantity, and condition-type constraint requirements require comparison of standardized fields after unified conversion.
[0080] When the standardized content of a candidate evidence unit satisfies the corresponding evidence requirement, the candidate evidence unit is recorded as a candidate support unit for that evidence requirement.
[0081] In one implementation, semantic encoding results are used to initially screen the query items and candidate evidence units before the aforementioned evidence-level comparison, preventing obviously irrelevant candidate evidence units from entering subsequent field-level evidence matching. This semantic screening is only used to limit the calculation scope and does not directly generate an evidence correspondence between candidate evidence units and the query items.
[0082] S1034, Matching relationships between evidentiary elements For relational evidence requirements, read the first relation endpoint, the second relation endpoint, the required relation type, and the relation direction.
[0083] Traverse the candidate relationship records in the candidate evidence unit, determine whether the two relationship endpoints in the candidate relationship record can be mapped to the first relationship endpoint and the second relationship endpoint respectively, and further check the relationship type, relationship direction and relationship polarity.
[0084] When the relation endpoints match, the relation types are consistent, the relation directions meet the requirements, and there is no conflict in the relation polarity, it is determined that the current candidate relation can support the relational evidence requirement.
[0085] When necessary relation endpoints are missing, the relation direction is opposite, or the relation polarity is conflicting, corresponding relational evidence is not established to support the claim.
[0086] Therefore, relational evidence is not obtained based on overall semantic similarity, but is formed by the continuous confirmation of relation endpoints, relation type, relation direction, and relation polarity.
[0087] S1035, Establish unit support record When a candidate evidence unit can independently support a certain necessary evidence requirement, a unit support record is established for the evidence requirement.
[0088] The unit support record should at least save the support record identifier, evidence requirement identifier, evidence unit identifier, the start and end positions of the original text of the evidence actually provided, and its current validity status.
[0089] The supporting record identifier is written into the supporting record list of the corresponding evidence requirement item, and the evidence requirement identifier is written into the set of carrying evidence requirement identifiers of the candidate evidence unit.
[0090] The actual original location of the evidence is used to determine the scope of evidence protection within the parent candidate evidence unit during the subsequent refinement process, so that local refinement does not require re-inferring the location of the core evidence through generative processing.
[0091] S1036, Identifying Supplementary Evidence Units and Joint Supporting Relationships When a candidate evidence unit can support at least one of the necessary evidence requirements in the corresponding query, but cannot support all the necessary evidence requirements in the corresponding query, the evidence requirements that are currently unsupported in the query are read.
[0092] From other candidate evidence units that correspond to the same query item as the current candidate evidence unit, determine the candidate evidence unit that can support the missing evidence requirement.
[0093] Further examine whether the current candidate evidence unit and the other candidate evidence units point to the same unanswered fact through the same standard entity identifier, the same fact object, referential inheritance, causal inheritance, comparative inheritance, numerical object inheritance, or conditional continuation relationship. When the corresponding semantic dependency conditions are met, the corresponding candidate evidence unit is determined as a supplementary evidence unit.
[0094] When the current candidate evidence unit and one or more supplementary evidence units independently support different necessary evidence requirements, and these necessary evidence requirements together enable the query to reach a state of complete support, each evidence requirement retains the corresponding unit support record, and records the semantic association of related candidate evidence units for the same query.
[0095] If a relational requirement for necessary evidence requires two or more candidate evidence units to be valid, then a joint support record is established.
[0096] The joint support record should at least store the support record identifier, evidence requirement identifier, set of member evidence unit identifiers, semantic dependency type between members, original text location of the evidence content undertaken by each member, and current validity status.
[0097] When any necessary member in a union support record fails, the entire union support record fails, thus avoiding situations where only the relational conclusion is retained while necessary antecedent facts are deleted, or only referential text is retained while the referred object is deleted, during resource release.
[0098] S1037, Establish evidence correspondence and two-way indexing Establish the evidence correspondence between candidate evidence units and query items based on the existing unit support records and joint support records.
[0099] When a candidate evidence unit participates in any necessary evidence requirement unit support record or joint support record in a query matter, the query matter identifier is written into the query matter set corresponding to the candidate evidence unit.
[0100] Establish the first index relationship and the second index relationship.
[0101] The first index relationship uses the query item identifier as the index key to store the set of evidence unit identifiers that correspond to the query item; the second index relationship uses the evidence unit identifier as the index key to store the set of query item identifiers that correspond to the current candidate evidence unit.
[0102] Evidence support records are used to determine which candidate evidence units currently provide actual support for specific necessary evidence needs. Bidirectional indexes are used to determine the scope of query items and the scope of evidence units to be updated after the state of evidence units changes, thereby respectively undertaking the functions of judging the integrity of evidence and limiting the scope of local recalculation.
[0103] S1038, Perform evidence status check before compression. In one implementation, before proceeding to S104, the initial candidate documents are checked to see if they have formed complete and necessary evidence to support each query.
[0104] Read all necessary evidence requirements in the query and check the corresponding supporting record list for each item.
[0105] If a necessary evidence requirement item has at least one currently valid supporting record or joint supporting record, the initial coverage status of the evidence requirement item is set to covered; if no valid supporting record exists, it is set to uncovered.
[0106] When all necessary evidence requirements are covered, the initial evidence status of the corresponding query item is determined to be complete.
[0107] When there are any missing necessary evidence requirements, a record of supplementary evidence requirements is generated based on the missing evidence requirements, and the supplementary evidence requirements are provided to the upstream retrieval service to supplement candidate documents for the missing query objects, attributes, limited content, or relation endpoints; or the status of insufficient retrieval evidence is output, and the subsequent compression process is carried out after a set of candidate documents that meet the initial evidence integrity conditions is obtained again.
[0108] Therefore, the two types of states are distinguished: the absence of necessary evidence in the retrieval phase and the loss of existing evidence during the compression process. This allows S104 to evaluate the impact of the context release action on the existing evidence state.
[0109] In one implementation, a set of reference evidence reserves covering all necessary evidence requirements can be constructed based on the currently formed valid support records. The lexical occupancy of the reference evidence reserves is then calculated according to the target large language model's lexical encoding rules. This calculation is used to determine the fit between the current query evidence size and the model context resources before dynamic compression. This process serves only as a pre-check of the input state for the compression task and does not replace the amount of reserves calculated for specific candidate evidence units in S105.
[0110] S104, Determine the releasable evidence units based on the assumed state of the remaining evidence after removal. The candidate evidence units currently in a valid state are arranged into a context to be compressed according to the order of input into the large language model, and the current word occupancy is counted using the target model word encoding rules determined in S101.
[0111] If the current lexical occupancy does not exceed the context lexical budget, no resource release is performed, and the process proceeds to S107 to form the target context.
[0112] When the current word element occupancy exceeds the context word element budget, the excess word elements are determined as the number of word elements to be released.
[0113] Perform a hypothesis removal decision for each currently valid candidate evidence unit.
[0114] For each candidate evidence unit to be judged, a temporary masking record is created in memory, and the identifier of the candidate evidence unit to be judged is written into the temporary masking record. The temporary masking only applies to the release eligibility calculation in this round and does not modify the true valid status in the candidate evidence unit record.
[0115] Read the second index of the candidate evidence unit to be judged, and obtain the query items that have an evidence correspondence with the candidate evidence unit.
[0116] For each related query, all necessary evidence requirements and corresponding supporting records are retrieved.
[0117] For unit support records, when the corresponding evidence unit identifier exists in the temporary masking record, the temporary state of the support record in this round of judgment is set to invalid; when the corresponding candidate evidence unit is not masked and the real state remains valid, the support record remains valid.
[0118] For a joint support record, if any member of the necessary member evidence unit exists in the temporary mask record or the real state has expired, the current temporary state of the joint support record is determined to be invalid; if all necessary members remain valid, the joint support record remains valid.
[0119] Check the necessary evidentiary requirements for each item in the current query. If a necessary evidentiary requirement still has at least one valid supporting record, set the temporary state of that necessary evidentiary requirement to be satisfied.
[0120] When all necessary evidence requirements for the current query are met, the temporary evidence status of the query is set to met.
[0121] When all query items that correspond to the candidate evidence unit to be judged are satisfied, the candidate evidence unit to be judged is determined as a releasable evidence unit; when any related query item loses all valid support for its necessary evidence requirements, the candidate evidence unit is kept in a non-releasable state.
[0122] In the second index, candidate evidence units that do not actually provide necessary evidence support for the current query can be directly identified as releasable evidence units.
[0123] By constructing a temporary shielded state and checking the evidence support records before actual deletion, the change in evidence status caused by the disappearance of candidate evidence units can be determined without modifying the actual context to be compressed. This ensures that the eligibility for release comes from the actual evidentiary consequences of the deletion action, rather than the static relevance attributes of the candidate evidence units themselves.
[0124] S105, Determine the evidence units to be removed based on the amount of retained resources. Read the set of currently releasable evidence units formed in S104.
[0125] If there is only one releasable evidence unit, then that unit is designated as the current evidence unit to be removed.
[0126] When there are multiple releasable evidence units, a simulated removal state is formed for each releasable evidence unit, and the corresponding amount of reserved resources is determined.
[0127] For a candidate evidence unit to be evaluated and released, the candidate evidence unit is written into a temporary masking record, and a set of evidence requirements to be satisfied is established for each query item that has an evidence correspondence with the candidate evidence unit. The set of evidence requirements to be satisfied initially contains all the necessary evidence requirements for the current query item.
[0128] For the remaining candidate evidence units after the simulation removal, read the evidence requirement identifier directly carried by each candidate evidence unit, and count the number of evidence elements or relationships between evidence elements that still belong to the set of evidence requirements to be met. The obtained number is determined as the number of new evidence coverage for the current candidate evidence unit.
[0129] When a candidate evidence unit exists as only one member of a joint support record for a certain necessary evidence requirement, the other necessary members of the joint support record are read, and the necessary members that have not yet entered the target retention set are identified as the associated evidence units corresponding to the candidate evidence unit.
[0130] When determining the number of newly added lexical entries in the current candidate evidence unit, the number of lexical entries corresponding to the current candidate evidence unit and the corresponding necessary related evidence units that have not yet entered the target retention set are calculated together.
[0131] Each time a selection is made, priority is given to candidate evidence units that cover a larger number of newly added evidence units.
[0132] When multiple candidate evidence units with the same number of newly added evidence units exist, the candidate evidence unit with the smaller number of newly added lexical units after the necessary related evidence units are added should be selected first.
[0133] The selected candidate evidence units and their corresponding necessary related evidence units are written into the target retention set. Based on the effective unit support records and joint support records actually formed by the candidate evidence units, the necessary evidence requirement items that have been supported are deleted from the set of evidence requirements to be satisfied.
[0134] Continue the selection process described above until the set of evidence requirements to be met is empty, thus obtaining the target retention set for the corresponding query item.
[0135] If, after traversing the remaining candidate evidence units, there are still necessary evidence requirements that cannot be effectively supported, it indicates that there is an inconsistency between the releaseable state of the current candidate evidence unit and the actual supporting record. The candidate evidence unit will then be reset to non-releaseable, and the calculation of the reserved resource quantity for that candidate evidence unit will be stopped.
[0136] When the same releasable evidence unit to be evaluated is associated with multiple query items, a target retention set corresponding to each query item is formed. The evidence unit identifiers in different target retention sets are merged, and duplicate evidence unit identifiers are removed.
[0137] Read the lexical occupancy of all candidate evidence units after deduplication and sum them up. Determine the number of lexical units obtained as the amount of reserved resources corresponding to the evidence unit to be evaluated and released.
[0138] Among the candidate evidence units that are still eligible for release, those with smaller retained resources are prioritized as evidence units to be removed; when the retained resources are the same, those with larger word occupancy are selected as evidence units to be removed.
[0139] Therefore, when multiple candidate evidence units can be safely released at present, the release order depends not only on how many words the current unit can release, but also on the scale of evidence resources that must be locked to maintain the related query after the current deletion action is implemented, so as to avoid prematurely compressing the space of subsequently adjustable evidence resources by releasing them at once.
[0140] Furthermore, a round-robin feedback method is adopted to control the actual resource release in each round. In one implementation, the current amount of lexical units to be released is distributed across multiple resource release rounds.
[0141] At the start of each resource release round, the current resource deviation is determined based on the current lexical occupancy and the context lexical budget, and the resource deviation corresponding to the previous resource release round is read.
[0142] A proportional adjustment component is formed based on the current resource deviation; the resource deviations generated in this compression task are accumulated and a cumulative resource deviation is formed within a preset integral limit range, and an integral adjustment component is formed based on the cumulative resource deviation; a deviation change amount is formed based on the change of the current resource deviation relative to the resource deviation of the previous resource release round, and a differential adjustment component is formed based on the deviation change amount.
[0143] The target release amount for this round is determined based on the proportional adjustment component, the integral adjustment component, and the derivative adjustment component, and the target release amount for this round is limited to no more than the current remaining number of words to be released.
[0144] If there is no resource deviation in the previous round in the first round of resource release, the resource deviation in the previous round is initialized to the current resource deviation, so that the change in the deviation in the first round is zero.
[0145] It should be noted that in the same resource release round, after each candidate evidence unit is actually removed, the evidence status update and partial release eligibility re-judgment described in S106 are performed, and the next evidence unit to be removed is re-determined based on the updated releasable evidence units, instead of continuously deleting multiple candidate evidence units according to the old release list formed at the beginning of the resource release round.
[0146] The number of candidate evidence units that have been actually removed in this round is accumulated to form the cumulative number of released tokens in this round. If the cumulative number of released tokens in this round does not reach the target number of released tokens in this round and the current number of tokens occupied still exceeds the context token budget, S105 continues to be executed based on the updated evidence state; the current resource release round ends when the cumulative number of released tokens in this round reaches or exceeds the target number of released tokens in this round for the first time.
[0147] Therefore, the feedback adjustment only controls the expected release scale of resources in one resource release round, without changing the evidence protection conditions corresponding to S104, nor the dynamic processing logic of re-judging release eligibility after each actual removal.
[0148] S106, Release eligibility partially updated based on removed evidence unit Before performing a true state update on the evidence unit to be removed, read the query item identifier stored in the current second index of the evidence unit to be removed, and save the query item identifier as the set of affected query items in this round.
[0149] Change the current valid status of the evidence unit to be removed to "removed" and delete the corresponding evidence unit identifier from the current valid context sequence.
[0150] Read all supporting evidence records from the evidence units that have been removed.
[0151] For a unit support record, when its corresponding evidence unit is a removed evidence unit, the validity status of the corresponding support record is set to invalid.
[0152] For a joint support record, if its set of necessary member evidence units contains an evidence unit that has been removed, the entire joint support record is set to invalid.
[0153] The current fulfillment status of each necessary evidence requirement in the affected query items is reassessed based on the updated support records.
[0154] Furthermore, based on the already saved set of affected query items, the first index is read to obtain the candidate evidence unit identifier that still has an evidentiary relationship with the affected query item and whose true state remains valid.
[0155] The candidate evidence unit identifiers obtained from multiple affected query items are merged and deduplicated to form a set of evidence units to be updated.
[0156] The assumed removal process in S104 is re-executed only for the set of evidence units to be updated, and the current releaseable state of the corresponding candidate evidence unit is re-determined based on the updated remaining evidence state.
[0157] Other candidate evidence units that have not entered the set of evidence units to be updated will not undergo a reassessment of their eligibility for release in this round.
[0158] After completing the partial qualification update, update the current word usage based on the number of words actually removed from the evidence unit, and redetermine the remaining word usage to be released based on the current word usage and the context word budget.
[0159] The above process first saves the query items corresponding to the removed evidence units before updating the actual state, then updates the supporting records, and finally uses the affected query items to reverse locate the candidate evidence units that need to be recalculated. This allows the state change caused by the release of a candidate evidence unit to propagate along the local data path of "removed evidence units - affected query items - evidence units to be updated" without having to rescan all currently valid candidate evidence units.
[0160] S107, based on the updated resource status, continue to release, refine candidate evidence units, or form target context. Read the current word occupancy after S106 update.
[0161] When the current word element occupancy does not exceed the context word element budget, the target context formation process begins.
[0162] When the current word element occupancy still exceeds the context word element budget, the excess amount of the current word element occupancy exceeding the context word element budget is determined as the remaining word element occupancy to be released, and the sum of the word element occupancy of all currently releaseable evidence units is calculated, and the sum of the word element occupancy is taken as the current safe releaseable resource quantity.
[0163] If the current amount of safe and releaseable resources is not less than the remaining amount of tokens to be released, return to S105 and redetermine the next evidence unit to be removed based on the updated candidate evidence status.
[0164] When the current amount of safe and releaseable resources is lower than the remaining amount of tokens to be released, it indicates that there are not enough text resources that can be directly qualified for release at the current candidate evidence unit processing granularity, and local refinement of candidate evidence units is performed.
[0165] For the current unreleaseable candidate evidence unit, read all the corresponding valid unit support records and joint support records, and obtain the actual evidence original text location where the support records are stored.
[0166] The original text locations of each actual piece of evidence are mapped to the original text range of the corresponding candidate evidence unit. Overlapping original text segments of evidence are merged to form protected segments; when there are relational predicates, negations, qualifiers, or semantically connecting texts between different original text segments of evidence that are necessary to maintain the corresponding evidence relationship, the corresponding intermediate texts are also incorporated into the protected segments.
[0167] Based on the semantic dependency types preserved in the joint support record, further examine the original texts that play the roles of referential release, causal connection, condition limitation, comparison object acceptance, or numerical object acceptance, and include the original texts necessary to maintain the joint support relationship in the corresponding protected area.
[0168] Calculate the total number of lexical units occupied by candidate evidence units and the actual number of lexical units occupied by protected segments. The text not covered by protected segments constitutes the refined text range of the corresponding candidate evidence unit.
[0169] From the currently unreleaseable candidate evidence units, select candidate evidence units with a refinable text range as the evidence units to be refined. In one implementation, candidate evidence units with a larger number of terms corresponding to the refinable text range are preferentially selected.
[0170] Read the second index of the evidence unit to be refined, and determine the set of query item identifiers currently corresponding to the parent evidence unit to be refined as the set of query items to be matched for the subsequent candidate evidence subunits.
[0171] Based on the source document identifier and original text location saved in the evidence unit to be refined, the corresponding original text is read, and candidate evidence sub-units are formed based on the already formed protected area and other text boundaries.
[0172] When multiple original text segments of evidence used to jointly satisfy the evidentiary requirements of the same query are consecutive to each other, or when the text between multiple original text segments is the connecting text necessary to maintain the evidentiary relationship, the multiple original text segments of evidence and their corresponding connecting texts are combined to form a preserved evidentiary subunit.
[0173] When multiple original text segments of actual evidence are not continuous and the intermediate text is not the original text necessary to maintain the corresponding evidence relationship, multiple preserved evidence sub-units are formed respectively, and the same joint support identifier or corresponding semantic dependency identifier is recorded for the multiple preserved evidence sub-units, so that multiple non-continuous original text segments can jointly participate in the judgment of evidence requirement satisfaction without having to regenerate a summary text to replace the original text.
[0174] The text other than the retained evidence sub-units in the evidence unit to be refined are formed into evidence sub-units to be judged according to sentence boundaries, clause boundaries, or other original text boundaries that can maintain independent semantics.
[0175] For each retained evidence subunit and the evidence subunit to be judged, the evidence content matching in S103 is only re-executed within the original set of query items to be matched of the parent evidence subunit to be refined, without causing the newly formed candidate evidence subunit to be re-matched with all query items.
[0176] When a candidate evidence subunit actually carries the evidence elements or the relationship between evidence elements for a certain query, the evidence correspondence between the subunit and the corresponding query is re-established; when a candidate evidence subunit does not actually carry the evidence required for a certain query in the original parent candidate evidence unit, the query correspondence is not inherited.
[0177] During the same context state update process, the effective state of the parent evidence unit to be refined is set to invalid, and the newly formed retained evidence subunit and the evidence subunit to be judged are added to the current effective context.
[0178] The exit of parent candidate evidence units and the addition of child candidate evidence units are performed using a replacement method, so that the same original text will not participate in the current word resource statistics in both the form of parent evidence units and child evidence units at the same time.
[0179] Re-establish support records and bidirectional indexes for the formed candidate evidence sub-units, and return to S104 to perform the assumption removal judgment.
[0180] If, after the sub-unit of evidence to be determined is removed, the related query items still meet the necessary evidence requirements, the sub-unit of evidence to be determined is identified as a newly released evidence unit, and it re-enters S105 to participate in the release of the remaining token resources.
[0181] Therefore, the fact that a coarse-grained candidate evidence unit as a whole cannot be released only indicates that the candidate evidence unit contains necessary evidence content that cannot be lost at present, and does not mean that all the original text within the unit serves as necessary evidence. After separating the evidence protection section from other texts based on the location of the actual evidence text that has already been saved, other texts that were originally locked by the coarse-grained unit along with the necessary evidence can regain the eligibility for release without lowering the original evidence requirement judgment conditions.
[0182] When the current word element occupancy does not exceed the context word element budget, the candidate evidence units and candidate evidence subunits that are still in a valid state are identified as target evidence units.
[0183] For target evidence units originating from the same candidate document, the original relative order is restored based on the original text start position saved for each target evidence unit.
[0184] When different target evidence units jointly form a valid joint support relationship, the association identifier or necessary relative order of the corresponding target evidence units shall be maintained according to the semantic dependency relationship in the joint support record.
[0185] The recombined target evidence units are used to form the target context, and the lexical occupancy of the complete target context is recalculated using the target large language model lexical encoding rules corresponding to S101.
[0186] When the number of lexical units in the target context does not exceed the context lexical budget, the target context is written into the input data area of the large language model and provided to the large language model together with the user query.
[0187] Through S101 to S107, user queries are transformed into evidence requirements with a clear data structure, and candidate documents are transformed into candidate evidence units with original text positions and lexical resource states. Evidence requirements and candidate evidence units are linked through support records and bidirectional indexes. Actual resource release, in turn, controls the release eligibility of subsequent candidate evidence units based on the updated evidence support state, thus forming a continuous processing closed loop from resource input, evidence constraints, dynamic release, local state updates to target context output.
[0188] Example 2 This embodiment provides a retrieval-enhanced generation context adaptive compression system, including a processor and a memory.
[0189] The memory is communicatively connected to the processor and stores computer programs that can be executed by the processor. When the processor executes the computer program, it implements the context-adaptive compression method described in Embodiment 1.
[0190] In one implementation, the system is positioned between the retrieval service and the large language model inference service. The system obtains the user query and candidate document set through the retrieval data interface, obtains the context capacity and lexical encoding configuration corresponding to the target large language model through the model configuration interface, and sends the target context to the large language model through the model input interface.
[0191] When the retrieval service, large language model, and context compression system are deployed on the same computing node, the above data can be transferred through inter-process calls or shared memory, without requiring the configuration of independent physical communication interfaces.
[0192] The memory establishes a task work area for each context compression task, which includes at least a task status data area, a query item data area, an evidence unit data area, an evidence support data area, and an evidence index data area.
[0193] The task status data area stores the task identifier, context lexical budget, current lexical occupancy, current number of lexicals to be released, target release amount for this round, and task execution status.
[0194] The query item data area stores query term records, query semantic relationship records, query item records, evidence requirement records, and evidence requirement status records.
[0195] The evidence unit data area stores candidate evidence unit records and candidate evidence sub-unit records formed through local refinement. Each evidence unit record includes at least the evidence unit identifier, source document identifier, original text location, text content, token occupancy, current valid state, and current releaseable state.
[0196] The evidence support data area stores support records and joint support records. Joint support records use multiple member evidence unit identifiers to represent common evidence support relationships, and simultaneously store the corresponding semantic dependency type and the original text location of the evidence content actually undertaken by each member.
[0197] The evidence index data area stores a first index relationship and a second index relationship. In one implementation, the first and second index relationships are stored using a hash mapping combined with a variable-length evidence unit identifier list, so that empty index entries are not required between query items and candidate evidence units that do not form an evidence correspondence.
[0198] After receiving a user query, the processor establishes a data record space corresponding to this task in the query data area and forms the query items and evidence requirements.
[0199] After the processor reads the candidate document set, it forms candidate evidence unit records in the evidence unit data area, and establishes unit support records or joint support records in the evidence support data area according to the actual evidence elements carried by the candidate evidence text and the relationships between the evidence elements. At the same time, it establishes the first index relationship and the second index relationship in the evidence index data area.
[0200] When performing the release qualification judgment, the processor obtains the corresponding query item according to the second index of the candidate evidence unit to be judged, reads the corresponding necessary evidence requirements from the query item data area, reads the corresponding support record from the evidence support data area, and establishes the temporary masking state of the current candidate evidence unit to be judged in the independent temporary storage space.
[0201] The temporary masking state does not change the state of the actual candidate evidence unit. After the assumed removal calculation is completed, the processor releases the temporary masking data.
[0202] When removing a real candidate evidence unit, the processor reads the second index and saves the set of affected query items before modifying the status of the candidate evidence unit; then it sets the target candidate evidence unit to the removed state, invalidates the corresponding unit support record and the joint support record containing the candidate evidence unit, and updates the current term occupancy.
[0203] The first index is read based on the already saved set of affected query items to obtain the set of evidence units to be updated. Only the set of evidence units to be updated is recalculated for release eligibility.
[0204] In one implementation, the correlation update of the candidate evidence unit's true state, evidence support state, and current term occupancy is performed using task-level write locks or atomic update processing that can achieve consistency of the same state, so that different processing threads in the same context compression task cannot read the evidence state and resource state belonging to different state times.
[0205] When the processor determines that there are insufficient safe and releasable resources, it reads the actual original text location of the candidate evidence unit corresponding to the unreleasable evidence unit from the evidence support data area, determines the evidence protection section based on the original text location, and reads the original text based on the source document identifier recorded and saved in the evidence unit record.
[0206] After forming the retained evidence sub-unit and the evidence sub-unit to be judged, the processor sets the parent candidate evidence unit to invalid and writes the newly formed candidate evidence sub-unit into the evidence unit data area during the same state update process.
[0207] For candidate evidence sub-units, evidence content matching is re-executed only within the original query item range corresponding to the parent candidate evidence unit, and the evidence support records and bidirectional indexes affected by the parent-child replacement are updated; other candidate evidence units that did not participate in this local refinement do not need to re-execute text evidence parsing.
[0208] Once the current lexical occupancy meets the context lexical budget, the processor reads the target evidence units that are still valid from the evidence unit data area, forms the target context based on the source document identifier, original text location, and joint support relationship, and provides the target context to the large language model.
[0209] Therefore, in the method embodiment, the query items, evidence requirements, candidate evidence units, evidence support records, bidirectional indexes, temporary shielding status, and parent-child evidence unit replacement relationships all have corresponding data carriers and data update paths in the system, rather than mechanically repeating the method steps through functional module names.
[0210] Example 3 This embodiment provides a computer-readable storage medium in which a computer program is stored.
[0211] When the computer program is executed by the processor, it implements the context-adaptive compression method described in Embodiment 1.
[0212] When a computer program initiates a context compression task, it establishes a corresponding task work area based on the task identifier, and forms task status records, query item records, evidence requirement records, candidate evidence unit records, evidence support records, and evidence index records in the task work area.
[0213] After reading the user's query, the computer program generates query term records and query semantic relationship records for the user's query, and generates query items and corresponding evidence requirements based on the query term records and query semantic relationship records.
[0214] After reading the candidate document set, the computer program forms candidate evidence units based on the original document position and text boundaries. It then performs entity standardization, attribute standardization, content limitation parsing, and relation endpoint, relation type, relation direction, and relation polarity parsing on the candidate evidence units. Based on the parsing results, it forms unit support records or joint support records.
[0215] When performing the qualification judgment for releasing candidate evidence units, the computer program establishes a temporary shielding state for the candidate evidence units to be judged, and checks whether each necessary evidence requirement item still has a valid supporting record in the corresponding temporary state without modifying the valid state of the real evidence units. Based on the check results, a set of currently releasable evidence units is formed.
[0216] When there are multiple releasable evidence units, the computer program establishes a simulated removal state for each releasable evidence unit. Based on the unmet evidence elements actually added by the remaining candidate evidence units and the relationships between the evidence elements, a target retention set is formed sequentially. The amount of retention resources is determined based on the actual word occupancy of the candidate evidence units in the target retention set.
[0217] When a genuine evidence unit is removed, the computer program modifies the true and valid status of the removed candidate evidence unit and simultaneously invalidates the corresponding evidence support record; the set of evidence units to be updated is determined based on the query items originally corresponding to the removed evidence units, and the release qualification judgment is re-executed only for the evidence units to be updated.
[0218] When the computer program detects that there are insufficient safe and releasable resources at the current candidate evidence unit granularity, it determines the evidence protection zone within the parent candidate evidence unit based on the actual original evidence text location saved in the evidence support record, forms a reserved evidence sub-unit and an evidence sub-unit to be judged based on the protected zone, and causes the parent candidate evidence unit to exit the current valid context.
[0219] For newly formed candidate evidence sub-units, re-establish evidence support records and bidirectional indexes, and enable the pending evidence sub-units that meet the release conditions to re-enter the subsequent resource release process.
[0220] When the current lexical occupancy does not exceed the context lexical budget, the computer program forms a target context based on the current valid target evidence unit and outputs the target context to the input interface of the large language model or to the input data area for the large language model to read.
[0221] In one embodiment, the computer-readable storage medium is a non-transitory computer-readable storage medium, including solid-state storage media, magnetic storage media, or other non-transitory program storage media capable of storing the computer program and being read by a processor.
[0222] Furthermore, the computer program can be packaged into a computer program. The computer program can be stored, transmitted, or deployed in the form of a server program, software installation package, software development kit, or containerized deployment program.
[0223] After the computer program is loaded into the computing device and executed by the processor, the aforementioned task work area and corresponding data records are established in the corresponding computing device, and the target context is formed according to the query parsing, candidate evidence unit formation, evidence support relationship establishment, hypothesis removal judgment, resource release, local state update and candidate evidence unit refinement process described in Embodiment 1.
[0224] Therefore, the computer program is not only used to implement the result-oriented function of "compressing the retrieval context", but also enables the computing device running the computer program to implement the adaptive compression method for generating context described in this invention by executing a data processing flow with explicit input data, intermediate state data, processing conditions and output data.
[0225] Working principle and effects In summary, the working principle of the present invention is to first convert user queries into evidence constraints that can be actually verified by candidate documents, and then convert the resource release of candidate texts into a dynamic state maintenance process for the evidence constraints.
[0226] Once a retrieval enhancement generation task begins, at least one query item is generated based on the user query parsing. The query objects, attributes, limiting content, and relationships between elements required for each query item are then converted into evidence requirements. After candidate documents are divided into multiple candidate evidence units, the evidence elements and relationships actually carried by each candidate evidence unit are parsed, and an evidence correspondence between the candidate evidence units and the query item is established accordingly. Thus, the original retrieval context consisting only of natural language text is transformed into a set of candidate evidence with clear evidence support relationships and lexical resource status.
[0227] When the lexical resources occupied by the candidate evidence set exceed the context lexical budget allowed by the target large language model, a number of lexical units to be released are formed based on the amount of excess resources. For the current candidate evidence unit, deletion is not decided directly based on its own score. Instead, a hypothetical removal state is established before the candidate evidence unit is actually removed, and it is checked whether the necessary evidence for the related query items can still be provided by other candidate evidence units after the candidate evidence unit disappears. Only candidate evidence units that maintain a state where the evidence requirements are met for all related query items after deletion are eligible for current release.
[0228] Once a releasable evidence unit is actually removed, the original evidence substitution relationships change accordingly. The system uses the index from the evidence unit to the query item to determine the query item actually affected by this deletion, and then uses the index from the query item to the evidence unit to reversely obtain candidate evidence units that may have changed their eligibility for release. The hypothetical removal judgment is only re-executed on this local data set. Thus, a single text release action simultaneously generates changes in resource status and local evidence status. These status changes then serve as the basis for judging the next resource release, forming a closed loop that is continuously updated throughout the compression process, rather than continuously deleting text based on a one-time sorting result at the beginning of compression.
[0229] When multiple candidate evidence units can be released simultaneously, the amount of evidence resources that need to be retained after different release actions is formed by simulating the release actions, so that the current actual release action takes into account the subsequent locked state of evidence resources; when the current coarse-grained candidate evidence unit can no longer provide enough safe release space, the original text section that actually bears the necessary evidence is separated from other texts according to the position of the original text, so that other texts can re-enter the same evidence qualification judgment process as finer candidate evidence sub-units.
[0230] Therefore, by ensuring that each text release during context compression is based on the technical basis of the current remaining evidence state, the resource release amount is constrained by the model context window, and the text release position is constrained by the query evidence requirements. Furthermore, local state propagation reduces redundant computation of data unaffected by the current release action. The resulting target context, while satisfying the lexical resource limitations of the large language model, maintains the evidence elements required for the corresponding query and the relationships between these elements, providing a resource-compressed and evidence-supported retrieval enhancement context for subsequent large language model inference.
[0231] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer programs. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0232] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer programs according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0233] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1The function specified in one or more boxes.
[0234] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0235] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims. All of these forms are within the protection scope of the present invention.
Claims
1. A generative context adaptive compression method, characterized in that, include: Obtain the user query, the candidate document set retrieved based on the user query, and the context lexical budget of the large language model; Analyze the user query to determine at least one query item, and determine the evidence requirements for each query item, including evidence elements and the relationships between evidence elements; The candidate document set is divided into candidate evidence units, and an evidence correspondence relationship is established between the candidate evidence units and the query items. A context to be compressed is formed based on the candidate evidence units; When the number of lexical units occupied by the context to be compressed exceeds the context lexical budget, the excess amount is determined as the number of lexical units to be released. For each candidate evidence unit, assuming that the candidate evidence unit is removed, it is determined whether the remaining candidate evidence units still satisfy the evidence requirements of each related query item. If all conditions are met, the candidate evidence unit is determined as a releasable evidence unit; the releasable evidence units are then removed sequentially according to the number of terms to be released. After each removal, the token occupancy is updated, and only candidate evidence units that are associated with at least one of the same query items as the removed evidence units are reassessed as releasable evidence units, until the token occupancy does not exceed the context token budget. The target context is formed based on the remaining candidate evidence units and then input into the large language model.
2. The method according to claim 1, characterized in that, The evidence correspondence includes: A first index relationship and a second index relationship; the first index relationship uses the query item identifier as the index entry and records candidate evidence units that have an evidence correspondence with the corresponding query item; the second index relationship uses the candidate evidence unit identifier as the index entry and records query items that have an evidence correspondence with the corresponding candidate evidence unit; after each removal, the affected query item is determined according to the second index relationship of the removed evidence unit, and the candidate evidence unit that needs to be re-judged is determined according to the first index relationship of the affected query item.
3. The method according to claim 1, characterized in that, The process of parsing the user query and determining the evidence requirements for each query item includes: Identify the query object, query attribute, limiting element, and relational predicate from the user query; form query items based on the semantic relationship between the relational predicate and the query object, query attribute, and limiting element; determine the corresponding evidence elements and the relationship between evidence elements based on the query object, query attribute, limiting element, and relationship type in each query item.
4. The method according to claim 1, characterized in that, The process of establishing the evidence correspondence between the candidate evidence units and the query items includes: Extract candidate evidence elements and relationships between candidate evidence elements from candidate evidence units; match the candidate evidence elements and relationships between candidate evidence elements with the evidence requirements of each query; when a single candidate evidence unit cannot fully satisfy the evidence requirements of the corresponding query, determine one or more supplementary evidence units that have semantic dependencies on the candidate evidence unit from other candidate evidence units; establish the evidence correspondence relationship based on the common carrying state of the candidate evidence unit and the supplementary evidence unit for the evidence requirements.
5. The method according to claim 1, characterized in that, The step of determining the evidence unit to be removed from the releasable evidence units includes: For each releasable evidence unit, the releasable evidence unit is simulated to be removed. For each query item associated with the releasable evidence unit, a target retention set is formed from the remaining candidate evidence units. When forming the target retention set, each time, candidate evidence units carrying a large number of unmet evidence elements or relationships between evidence elements are selected first. If the number is the same, candidate evidence units with a smaller number of newly added lexical units are selected first, until the evidence requirements of the corresponding query item are met. The target retention sets of each query item are merged and deduplicated. The retention resource amount is determined based on the lexical unit occupancy of the deduplicated candidate evidence units. Releasable evidence units with a smaller retention resource amount are prioritized as evidence units to be removed. If the retention resource amounts are the same, releasable evidence units with a larger lexical unit occupancy are prioritized.
6. The method according to claim 1, characterized in that, The step of sequentially removing releasable evidence units according to the number of terms to be released includes: The release of candidate evidence units is divided into multiple resource release rounds. The current resource deviation is determined based on the current token occupancy and the context token budget. Proportional adjustment components, integral adjustment components, and differential adjustment components are formed based on the current resource deviation, cumulative resource deviation, and the change of the current resource deviation relative to the resource deviation of the previous resource release round, respectively. The target release amount for this round is determined based on the proportional adjustment component, the integral adjustment component, and the differential adjustment component. Within the same resource release round, the release eligibility of the affected candidate evidence units is reassessed after each evidence unit to be removed is removed, until the cumulative release amount for this round reaches or exceeds the target release amount for the first time.
7. The method according to claim 1, characterized in that, When the sum of the token occupancy of all currently releasable evidence units is less than the amount by which the current token occupancy exceeds the context token budget, the evidence units to be refined are determined from the non-releasable candidate evidence units. The evidence unit to be refined is divided into multiple candidate evidence sub-units; based on the query items corresponding to the evidence unit to be refined, the evidence correspondence between each candidate evidence sub-unit and the query items is re-established, and each candidate evidence sub-unit is re-determined as a releasable evidence unit; the newly determined releasable evidence sub-units are added to the subsequent resource release process.
8. The method according to claim 7, characterized in that, The step of dividing the evidence unit to be refined into multiple candidate evidence sub-units includes: Based on the evidence requirements of the query items corresponding to the evidence unit to be refined, determine one or more original text segments in the evidence unit to be refined that are used to carry evidence elements and the relationships between evidence elements; form the one or more original text segments into a retained evidence subunit; form the text in the evidence unit to be refined other than the original text segments into a pending judgment evidence subunit; re-establish the evidence correspondence relationship for the retained evidence subunit and the pending judgment evidence subunit respectively, and re-determine whether the pending judgment evidence subunit is a releasable evidence unit.
9. A retrieval-enhanced generation context-adaptive compression system, characterized in that, The system includes a processor and a memory, wherein the memory stores a computer program that, when executed by the processor, causes the system to perform the generation context adaptive compression method as described in any one of claims 1-8.
10. A computer program, characterized in that, It includes a computer program, which, when executed by a processor, implements the generation context adaptive compression method as described in any one of claims 1-8.