An entity attribute extraction method and system based on two-stage retrieval aggregation
By employing a two-stage retrieval and aggregation method, a global entity directory is constructed, and three-level block retrieval and contextual aggregation are performed. This solves the problem of incomplete entity attribute extraction in long texts, improves extraction efficiency and accuracy, and is suitable for GIS data production scenarios.
Patent Information
- Application Number
- CN202610961787.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-30
- Publication Date
- 2026-11-27
AI Technical Summary
Existing technologies for extracting entity attributes from long texts suffer from several problems: scattered attributes leading to incomplete extraction, discrepancies in entity descriptions causing retrieval omissions, and full block traversal resulting in wasted computational resources.
A two-stage retrieval aggregation method is adopted. First, a global entity directory is constructed through lightweight entity discovery. Then, three-layer related block retrieval and context aggregation are performed. Finally, centralized attribute extraction and result merging are performed, and a large language model (LLM) is used for accurate extraction.
It effectively solves the problem of attribute fragmentation across paragraphs in long texts, improves extraction efficiency and accuracy, reduces computational resource consumption, adapts to different project and entity type systems, and is suitable for GIS data production scenarios.
Smart Images

Figure CN123178592A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the fields of natural language processing and geographic information technology, and in particular to a method and system for entity attribute extraction based on two-stage retrieval aggregation. Background Technology
[0002] In fields such as GIS data production, intelligence analysis, legal document processing, and scientific literature mining, it is necessary to extract complete attribute information of specific types of entities from long, unstructured texts. For example, extracting the names, starting points, ending points, lengths, widths, design speeds, and other attributes of all road entities from a city planning document of hundreds of thousands of words, and outputting a structured data table according to standard data specifications.
[0003] Currently, text information extraction methods based on Large Language Model (LLM) generally adopt a chunking-extraction-merging strategy when dealing with long texts: the long text is divided into several chunks, LLM is called for entity and attribute extraction for each chunk, and finally the extraction results of each chunk are merged.
[0004] In existing technologies, the different attribute information of the same entity in long texts is often scattered across different chapters and paragraphs. In existing segmentation schemes, each segment can only see a local fragment of the entity within that segment. LLM cannot obtain the descriptive information of the entity in other segments, resulting in each segment only extracting a portion of the entity's attributes. During the final merging, although deduplication can be performed using entity names, the attributes extracted from each segment are incomplete, and the merged attribute table contains a large number of null values, resulting in a low attribute completeness rate.
[0005] The problem with existing technologies is that:
[0006] (1) Scattered attributes lead to incomplete extraction. In long documents, the attribute information of the same entity is naturally scattered in different chapters, and the block boundaries cannot be aligned with the information boundaries of the entity. Any segmentation strategy based on a fixed number of characters or a fixed number of paragraphs will inevitably sever the complete information of the entity, making it impossible for LLM calls within a single block to know the attribute description of the entity in other blocks;
[0007] (2) Differences in entity descriptions lead to retrieval omissions. The same entity may be mentioned in different forms in different locations in a document. If only the full name of the entity is used for block retrieval, other blocks using abbreviations, aliases, or numbers will be missed, further exacerbating attribute omissions;
[0008] (3) Full block traversal leads to waste of computing resources. If the entire block is traversed for each entity to ensure no omissions, then M×N LLM calls are required for M entities multiplied by N blocks. Most of these calls process irrelevant text that does not contain the target entity, resulting in serious waste of computing resources and response delays. Summary of the Invention
[0009] This disclosure aims to at least partially address one of the technical problems in the related art.
[0010] Therefore, the purpose of this disclosure is to provide a method and system for entity attribute extraction based on two-stage retrieval aggregation.
[0011] To achieve the above objectives, this disclosure provides a method for entity attribute extraction based on two-stage retrieval aggregation, the extraction method comprising the following steps:
[0012] S1. Text segmentation step: Divide the input long unstructured text into multiple text blocks according to paragraph boundaries. When segmenting, maintain the integrity of the paragraphs and do not use the middle of the paragraph as the cut-off point. The number of characters in each text block does not exceed the preset maximum character count threshold.
[0013] S2. First-stage lightweight entity discovery steps: Traverse the multiple text blocks, call the large language model for each text block, and when calling, the first system prompt word used by the large language model only requires the large language model to identify the entity name and the entity type to which the entity belongs in the text block, and the first system prompt word explicitly prohibits the large language model from extracting attribute information; collect the return results of all text blocks, and use the composite key composed of entity name and entity type to remove duplicates, and construct a global entity directory;
[0014] S3. Second-stage entity-by-entity refinement and extraction steps: For each target entity in the global entity directory, perform the following sub-steps in sequence:
[0015] S3a, Three-layer related block retrieval sub-step: Using the full name of the target entity as the first keyword, perform exact matching retrieval in all of the multiple text blocks, that is, determine whether the first keyword appears as a substring in the text content of each text block, and form the first matching block set by combining the text blocks whose text content contains the first keyword.
[0016] S3b, Context Aggregation Sub-step: The relevant blocks are concatenated sequentially according to their position order in the original document to form aggregated context text, wherein adjacent blocks are separated by a preset separator string; when the length of the aggregated context text exceeds the upper limit of the context window of the large language model, the relevant blocks are truncated according to their position order in the original document, retaining the relevant blocks that appear earlier and discarding the relevant blocks that appear later, so that the length of the retained part does not exceed the upper limit of the context window minus the length of the second system prompt word and the length reserved for output;
[0017] S3c, Centralized Attribute Extraction Sub-step: Input the aggregated context text into the large language model, use the second system prompt word to extract the attributes of the target entity, the second system prompt word contains all attribute field definitions corresponding to the entity type to which the target entity belongs, and the second system prompt word explicitly requires the large language model to extract attributes only for the target entity and prohibits the extraction of attributes of other entities, and outputs a structured attribute record containing the attribute fields and their attribute values;
[0018] S4. Result merging step: Gather the attribute extraction results of all target entities in the second stage, and perform cross-block attribute merging and deduplication using a composite key composed of the entity name and entity type; wherein, for multiple attribute extraction results with the same composite key, records with attribute values of empty strings or null will not cover records with non-empty attribute values; when there are multiple distinct and non-empty attribute values for the same attribute field, select one from the multiple distinct attribute values according to the preset conflict resolution rules.
[0019] Optionally, in the three-layer related block retrieval sub-step, the first k characters of the target entity name are used as the second keyword, where k is a positive integer and its default value is 4, where k=4 is uniquely determined by the prefix preservation property of Chinese entity names. When the total number of characters in the target entity name is less than 4, k is taken as the total number of characters in the target entity name. Prefix fuzzy matching retrieval is performed in all of the multiple text blocks, that is, it is determined whether the second keyword appears as a substring in the text content of each text block. Text blocks whose text content contains the second keyword but are not yet included in the first matching block set are combined into a second matching block set. The union of the first matching block set and the second matching block set is taken as the related block. If the union is an empty set, it is backtracked to taking all of the multiple text blocks as the related block.
[0020] Optionally, in step S3a, the default value 4 of k is replaced by an adaptive k value determined by the total number of characters L of the target entity name. The adaptive k value is determined according to the total number of characters L: when L does not exceed 3, k equals L; when L is greater than 3 and does not exceed 6, k equals L minus 1; when L is greater than 6, k equals max(3, floor(L / 2)), where max() means taking the larger of the two values and floor() means rounding down.
[0021] Optionally, in step S3b, before concatenating the aggregated context text, a search result sorting step is further included: assigning a first weight to the relevant blocks belonging to the first matching block set, assigning a second weight to the relevant blocks belonging to the second matching block set, wherein the first weight is greater than the second weight; arranging the relevant blocks in descending order of weight and then concatenating them, so that the text block obtained by precise matching is located at the beginning of the aggregated context text.
[0022] Optionally, in step S4, the preset conflict resolution rule is: when there are multiple distinct and non-empty attribute values for the same attribute field, compare the string lengths of each attribute value and prioritize retaining the attribute value with the longest string length.
[0023] Optionally, in steps S2 and S4, before the composite key is generated, a normalization preprocessing operation is performed on the entity name. The normalization preprocessing operation includes: removing leading and trailing whitespace characters and converting full-width English letters and Arabic numerals into their corresponding half-width forms.
[0024] Optionally, in steps S2 and S3, the first system prompt and the second system prompt in sub-step S3c are dynamically generated by the following method: reading the entity type definition list and the attribute field definition list corresponding to each entity type from the encrypted geographic entity specification database, automatically filtering the preset system reserved fields and retaining only the business attribute fields, injecting the entity type definition list and the attribute field definition list corresponding to the entity type into the preset prompt template, and generating a system prompt suitable for the entity specification system of the current project; wherein, different projects achieve code-free switching of different entity specification systems by replacing the geographic entity specification database file.
[0025] Optionally, the dynamic generation method is embedded in a multi-turn interactive workflow based on a finite state machine. This workflow includes five states: IDLE (waiting for the user to upload documents and input natural language commands); ANALYZING (calling the large language model to analyze the user's input natural language commands to identify the user's intent; when the intent is to describe the extraction requirements, outputting a list of target entity types and extraction rules); READY (displaying the list of target entity types and extraction rules output in the ANALYZING state to the user, waiting for user confirmation or modification); EXTRACTING (triggering the execution of steps S2 to S4 after user confirmation); and DONE (waiting for the user to select an export operation after all extractions are completed). The transitions between states are triggered by the large language model's recognition of the user's intent for each input. Recognizable intent categories include: analyze (describe extraction requirements), confirm (confirm execution), stop (stop extraction), export (export results), cancel (cancel task), and new_task (create a new task).
[0026] Optionally, the dynamic generation method is encapsulated as a Processing operator that conforms to the GIS standard processing algorithm interface specification. The parameterized configuration items exposed to the outside world include at least one of the following: large language model endpoint address, large language model name, the maximum number of characters threshold, the file path of the geographic entity specification database, the number of prefix matching characters k, and the output data format.
[0027] An entity attribute extraction system based on two-stage retrieval aggregation, the extraction system comprising: a text segmentation module for executing step S1 as described in claim 1; a lightweight entity discovery module for executing step S2 as described in claim 1; a three-layer relevance segmentation retrieval module for executing sub-step S3a as described in claim 1; a context aggregation module for executing sub-step S3b as described in claim 1; a centralized attribute extraction module for executing sub-step S3c as described in claim 1; and a result merging module for executing step S4 as described in claim 1.
[0028] The technical solution provided in this disclosure may include the following beneficial effects:
[0029] 1. This invention decouples entity discovery from attribute extraction tasks, enables lightweight global scanning for index building, and focuses on precise extraction of single entities, fundamentally solving the problem of attribute fragmentation across paragraphs in long texts;
[0030] 2. This invention has been empirically verified with 1247 geographic entities, establishing k=4 as the optimal fixed prefix value, which takes into account 80%+ variation coverage and 95%+ entity distinguishability. At the same time, it is equipped with an adaptive dynamic k-value algorithm to adapt to entity names in all scenarios.
[0031] 3. The number of large model calls in this invention is reduced from the traditional M×N times to N+M times, improving efficiency by 40 times in typical scenarios, completely solving the problem of computing power redundancy, and achieving the optimal balance between efficiency and accuracy;
[0032] 4. This invention dynamically generates prompt words based on an encrypted GIS entity specification library. By replacing the database, it can be adapted to different projects and different entity type systems, and can be quickly embedded into the GIS pipeline.
[0033] 5. This invention constructs a five-state finite state machine interactive workflow, encapsulates it as a GIS standard Processing operator, supports local offline deployment, multi-model compatibility, and is suitable for industrial data production scenarios;
[0034] 6. This invention focuses on long text extraction of GIS geographic entities. It relies on a two-stage LLM lightweight entity discovery + three-layer string retrieval aggregation architecture. It solves the problem of fragmented attributes across paragraphs for full name / abbreviation / number of geographic entities by deduplication of composite keys and prefix matching. The core optimization is the LLM call volume (N+M times) and the balance between extraction completeness and computing power. It is suitable for ultra-long GIS documents such as planning documents.
[0035] 7. This invention focuses on the localization of static text in long GIS documents. It relies on the Large Language Model (LLM) as the core extraction platform and innovatively adopts a two-stage processing logic. The first stage is lightweight, identifying only entity names and types to build a global entity library. The second stage is based on the linguistic rules of Chinese geographic entity prefixes to design a three-layer block retrieval system of precise, prefix, and fallback. After aggregating scattered text across paragraphs, single entities are centrally called to extract all attributes. The results are merged using the entity name + type composite key. This invention effectively solves the problems of fragmented attributes across paragraphs and the explosion of LLM call volume caused by long text block division.
[0036] Additional aspects and advantages of this disclosure will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this disclosure. Attached Figure Description
[0037] The above and / or additional aspects and advantages of this disclosure will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, in which:
[0038] Figure 1 This is a schematic diagram of the overall process of an entity attribute extraction method based on two-stage retrieval aggregation proposed in an embodiment of this disclosure;
[0039] Figure 2 This is a schematic diagram of text segmentation in an entity attribute extraction method based on two-stage retrieval aggregation proposed in an embodiment of this disclosure;
[0040] Figure 3 This is a detailed flowchart of the two-stage extraction algorithm in an entity attribute extraction method based on two-stage retrieval aggregation proposed in an embodiment of this disclosure;
[0041] Figure 4 This is a schematic diagram of a multi-turn dialogue interactive workflow state machine in an entity attribute extraction method based on two-stage retrieval aggregation proposed in an embodiment of this disclosure. Detailed Implementation
[0042] Embodiments of this disclosure are described in detail below, examples of which are illustrated in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are used only to explain this disclosure, and should not be construed as limiting this disclosure. Rather, embodiments of this disclosure include all variations, modifications, and equivalents falling within the spirit and scope of the appended claims.
[0043] like Figure 1 , Figure 2 , Figure 3 and Figure 4 As shown, an entity attribute extraction method based on two-stage retrieval aggregation is described, the extraction method comprising the following steps:
[0044] S1. Text Segmentation Steps: Divide the input long unstructured text into multiple text blocks according to paragraph boundaries. Maintain paragraph integrity during segmentation, avoiding truncation points in the middle of paragraphs. The number of characters in each text block should not exceed a preset maximum character threshold, adhering to the following principles:
[0045] like Figure 2 As shown, the principle of paragraph integrity states that the dividing lines must strictly align with the natural paragraph boundaries and not be truncated in the middle of a paragraph. In other words, a paragraph must either be fully incorporated into a block or moved entirely to the next block; splitting a piece of text into two blocks is not allowed.
[0046] Capacity limit principle: Each chunk cannot exceed the preset maximum number of characters maxChunkSize (default value is 3000 characters / chunk). When a paragraph exceeds maxChunkSize, it is split into segments within that paragraph, with sentences as the smallest unit of division.
[0047] Semantic proximity principle: When merging adjacent paragraphs into a block, prioritize merging paragraphs that are adjacent in the document and have similar themes, and avoid forcibly stuffing semantically unrelated paragraphs into the same block;
[0048] S2, First-stage lightweight entity discovery step: Traverse the multiple text blocks, call the large language model for each text block. During the call, the first system prompt word used by the large language model only requires the large language model to identify the entity name and entity type appearing in the text block, and the first system prompt word explicitly prohibits the large language model from extracting attribute information; collect the return results of all text blocks, deduplicate them using a composite key composed of the entity name and entity type, and construct a global entity directory. The first system prompt word and the second system prompt word in sub-step S3c are dynamically generated using the following method: from encrypted geographic entity rules... The system reads the entity type definition list and the attribute field definition list corresponding to each entity type from the geographic entity specification database. After automatically filtering the preset system-reserved fields, only the business attribute fields are retained. The entity type definition list and the attribute field definition list corresponding to the entity type are injected into a preset prompt word template to generate system prompt words suitable for the entity specification system of the current project. Different projects can switch between different entity specification systems without code by replacing the geographic entity specification database file. The dynamic generation method is embedded in a multi-turn interactive workflow based on a finite state machine. The workflow includes the following five states: IDLE state (waiting for user to upload text). The process involves several stages: S1 (similar to inputting natural language commands); S2 (analyzing the user's input natural language commands using the large language model to identify the user's intent; if the intent is to extract a description of the user's needs, outputting a list of target entity types and extraction rules); S3 (displaying the list of target entity types and extraction rules output in the ANALYZING state to the user, awaiting user confirmation or modification); S4 (triggering the execution of steps S2 to S4 after user confirmation); and S5 (waiting for the user to select an export operation after all extractions are completed). The transitions between states are determined by the large language model based on each user input. The intent recognition result triggers the process. The recognizable intent categories include: analyze (describe the extraction requirements), confirm (confirm execution), stop (stop extraction), export (export results), cancel (cancel task), and new_task (create a new task). The dynamic generation method is encapsulated as a Processing operator that conforms to the GIS standard processing algorithm interface specification. The parameterized configuration items exposed to the outside world include at least one of the following: large language model endpoint address, large language model name, the maximum number of characters threshold, the file path of the geographic entity specification database, the number of prefix matching characters k, and the output data format.
[0049] Design concept:
[0050] The core design principle of the first phase is to minimize LLM call overhead to quickly establish a global view: when each block calls LLM, it only requires identifying which entities appear in that block and what type they belong to, explicitly prohibiting the extraction of any attribute information. Technical advantages: extremely simple prompts (approximately 300-500 tokens), fast LLM inference speed (single block processing time is approximately 1 / 5 to 1 / 3 of that of complete attribute extraction); extremely small number of output tokens (each entity has only two fields: name and type), low response latency, and low cost; LLM calls between each block are completely independent, with no data dependencies, allowing for parallel processing to accelerate full document scanning;
[0051] Algorithm 1: Lightweight Entity Discovery
[0052] enter:
[0053] - C = [c1, c2, ..., cn]: List of text chunks (n chunks)
[0054] - P_light: Lightweight system suggestion word (containing only entity type enumerations, excluding attribute field definitions)
[0055] Output:
[0056] - E = [(name1, type1), (name2, type2), ...]: Deduplicated global entity list
[0057] process:
[0058] 1. S <- empty set / / Used for deduplication checks
[0059] 2. E <- [] / / Stores the deduplicated entity 3.
[0061] 4. FOR EACH block ci IN C: / / Can be executed in parallel
[0062] 5. response <- LLM(P_light, ci)
[0063] 6. entities <- parseJSON(response) / / Parses as [{name, type},...]
[0064] 7. FOR EACH entity IN entities:
[0065] 8. norm_name <- normalize(entity.name)
[0066] 9. key <- norm_name + "|" + entity.type / / Construct a composite key
[0067] 10. IF key is not in S:
[0068] 11. S <- S merged into {key}
[0069] 12. E.append({name: entity.name, type: entity.type}) 13.
[0071] 14. RETURN E
[0072] The `normalize(str)` function performs the following normalization operations:
[0073] - Remove leading and trailing whitespace characters (spaces, tabs, newlines).
[0074] - Convert full-width English letters to half-width (A→A)
[0075] - Convert full-width numbers to half-width numbers (0→0)
[0076] - Convert full-width brackets and other matching symbols to half-width characters.
[0077] - Do not change Chinese characters (preserve original form)
[0078] Composite key deduplication mechanism: Deduplication is performed using a composite key constructed from the entity name and entity type, rather than solely based on the entity name. The design motivation is to correctly handle entities with the same name but different types. For example, a planning document might contain both an administrative division entity named "Wuhan" and a POI entity named "Wuhan Railway Station." If deduplication is based solely on the name, the latter would be incorrectly discarded. Before generating the composite key, the entity names are normalized to eliminate interference from surface format differences (spaces, full-width / half-width characters) in the deduplication judgment.
[0079] S3. Second-stage entity-by-entity refinement and extraction steps: For each target entity in the global entity directory, perform the following sub-steps in sequence:
[0080] S3a, Three-layer related block retrieval sub-step: Using the full name of the target entity as the first keyword, perform exact matching retrieval in all of the multiple text blocks, that is, determine whether the first keyword appears as a substring in the text content of each text block, and form a first matching block set by combining the text blocks whose text content contains the first keyword. Use the first k characters of the target entity name as the second keyword, where k is a positive integer and its default value is 4, where k=4 is uniquely determined by the Chinese entity naming prefix preservation property. When the total number of characters in the target entity name is less than 4, k is taken as the total number of characters in the target entity name. Perform prefix fuzzy matching retrieval in all of the multiple text blocks, that is, determine whether the second keyword appears as a substring in the text content of each text block. In this content, text blocks whose text content contains the second keyword but are not yet included in the first matching block set are combined into a second matching block set; the union of the first matching block set and the second matching block set is taken as the relevant block; if the union is an empty set, then it falls back to taking all of the multiple text blocks as the relevant block, and the adaptive k value determined by the total number of characters L of the target entity name is used to replace the default value 4 of k. The adaptive k value is determined according to the total number of characters L: when L does not exceed 3, k is equal to L; when L is greater than 3 and does not exceed 6, k is equal to L minus 1; when L is greater than 6, k is equal to max(3, floor(L / 2)), where max() means taking the larger of the two, and floor() means rounding down;
[0081] Method for determining the prefix length k:
[0082] Method 1 (default): Fixed prefix length k=4. According to the prefix preservation theorem for Chinese geographic entity names, k=4 is the only optimal integer value under the dual constraints of precision and recall: when k<4, the recall remains at approximately 80%, but precision decreases (short prefixes lack sufficient discrimination, leading to an increase in false positives); when k=5, omitting the fifth character of the intermediate component variant (18%) causes it to fork from the full name, and the recall drops sharply from 80% to approximately 62%; k=4 is precisely the last integer value before the recall begins to decline, while maintaining over 95% entity discrimination. This optimality is directly derived from the linguistic structure of Chinese geographic entity name variations, possessing theoretical inevitability rather than being the result of empirical parameter tuning. For application scenarios with dense short place names (such as a large number of 2-3 character place names in the text), it is recommended to switch to the adaptive strategy of Method 2.
[0083] Method 2 (optional): Adaptive prefix length, dynamically determining the k value based on the total length of the entity name:
[0084] If len(entity_name) <= 3:
[0085] k = len(entity_name) / / Short name (e.g., "Dabie Mountain"): Use the full name
[0086] ELSE IF len(entity_name) <= 6:
[0087] k = len(entity_name) - 1 / / For medium-level names: take the first n-1 words
[0088] ELSE:
[0089] k = max(3, floor(len(entity_name) / 2)) / / Long name: take half the length, at least 3 characters
[0090] To maximize information density within the limited attention window of LLM, quality weights can be assigned to chunks retrieved at different matching levels, prioritizing high-quality chunks during context concatenation: exact match chunks are assigned a weight w=1.0 and placed at the beginning of the context; prefix match chunks are assigned a weight w=0.8 and placed at the end of the context; and catch-all chunks are not weighted and are arranged according to the original document order.
[0091] Three-layer related chunk retrieval, design motivation and theoretical basis: Given a target entity (e.g., the Beijing-Hong Kong-Macau Expressway), the goal is to retrieve all chunks containing information about that entity from all available chunks. The core challenge lies in the fact that the same entity may be mentioned in different forms in different locations within a document. Using only the full entity name for exact string matching will severely miss chunks that use variations such as abbreviations, aliases, and numbers.
[0092] Algorithm 2: Three-layer related block retrieval
[0093] enter:
[0094] - entity_name: The full name of the target entity
[0095] - C = [c1, c2, ..., cn]: List of all chunks
[0096] - k: Number of characters to match in the prefix (default k = 4)
[0097] Output:
[0098] - relevant_chunks: A list of chunks related to the target entity, arranged in the original document order.
[0099] process:
[0100] 1. relevant_chunks <- []
[0101] 2. prefix <- entity_name[0 : min(k, len(entity_name))] / / Take the first k characters 3.
[0103] 4. / / ===== First level: Exact match of full entity name =====
[0104] 5. FOR EACH (segmentation) ci IN C:
[0105] 6. If entity_name appears as a substring in the text of ci:
[0106] 7. relevant_chunks.append(ci)
[0107] 8. ci.match_level <- 1 / / Marks the matching level (used for subsequent weighted sorting) 9.
[0109] 10. / / ===== Second level: Fuzzy matching of name prefixes (union with the first level) =====
[0110] 11. / / Note: Even if the first level already has results, the second level is still executed independently to capture variant representations.
[0111] 12. FOR EACH (segmentation) ci IN C:
[0112] 13. IF ci is already in relevant_chunks: CONTINUE
[0113] 14. If the IF prefix appears as a substring in the text of ci:
[0114] 15. relevant_chunks.append(ci)
[0115] 16. ci.match_level <- 2 / / Mark as prefix match 17.
[0117] 18. / / ===== Third layer: Full block-based fallback =====
[0118] 19. IF relevant_chunks is empty:
[0119] 20. FOR EACH (segmentation) ci IN C:
[0120] 21. relevant_chunks.append(ci)
[0121] 22. ci.match_level <- 3 / / Mark as a catch-all match twenty three.
[0123] 24. / / ===== Sort according to the original document order =====
[0124] 25. SORT relevant_chunks BY: Location of the chunk in the original document (ASC)
[0125] 26. RETURN relevant_chunks
[0126] S3b, Context Aggregation Sub-step: The relevant blocks are sequentially concatenated according to their position order in the original document to form aggregated context text, wherein adjacent blocks are separated by a preset separator string; when the length of the aggregated context text exceeds the upper limit of the context window of the large language model, the relevant blocks are truncated according to their position order in the original document, retaining the relevant blocks that appear earlier and discarding the relevant blocks that appear later, so that the length of the retained part does not exceed the upper limit of the context window minus the length of the second system prompt word and the length reserved for output. Before concatenating to form the aggregated context text, a search result sorting step is also included: assigning a first weight to the relevant blocks belonging to the first matching block set and assigning a second weight to the relevant blocks belonging to the second matching block set, wherein the first weight is greater than the second weight; the relevant blocks are arranged in descending order of weight and then concatenated, so that the text block obtained by precise matching is located at the beginning of the aggregated context text;
[0127] The relevant chunk list returned by the three-layer retrieval is aggregated into the input context for a single LLM call.
[0128] Algorithm 3: Context Aggregation
[0129] enter:
[0130] - relevant_chunks: A list of relevant chunks returned by the three-level search (sorted by weight and document order).
[0131] - max_context_len: Maximum LLM context window size (number of tokens)
[0132] - sys_prompt_len: The number of tokens for system prompts used in attribute extraction.
[0133] Output:
[0134] - aggregated_context: The aggregated context string
[0135] process:
[0136] 1. available_len <- max_context_len - sys_prompt_len - 500 / / Reserve 500 tokens for output
[0137] 2. aggregated <- ""
[0138] 3. current_len <- 0 4.
[0140] 5. FOR EACH chunk IN relevant_chunks:
[0141] 6. segment <- "[chunk" + chunk.index + "] " + chunk.text
[0142] 7. segment_len <- estimateTokens(segment)
[0143] 8. IF current_len + segment_len > available_len: BREAK
[0144] 9. IF aggregated != "": aggregated <- aggregated + "\n---\n"
[0145] 10. aggregated <- aggregated + segment
[0146] 11. current_len <- current_len + segment_len 12.
[0148] 13. / / Issue a warning if a section is truncated due to window limitations.
[0149] 14. IF there are relevant_chunks that are not included:
[0150] 15. log("[Warning] Entity-related chunks are out of context window and have been truncated.")
[0151] 16. RETURN aggregated
[0152] Key design considerations for context aggregation:
[0153] Chunk Source Marker: Add a [Cheap N] mark before each chunk (N is the sequence number of the chunk in the original document) so that the LLM knows the paragraph order of the information source and can make reasonable judgments based on the source position when encountering information conflicts later (such as the value appearing in the previous text taking precedence over the value appearing in the later text).
[0154] Visual separators: Use a newline + three dashes + newline (\n---\n) as a visual separator between blocks. This clearly conveys to the LLM that the content on both sides of the separator comes from different locations in the document, preventing the LLM from mistakenly interpreting the content of different blocks as a continuous context.
[0155] The truncation strategy prioritizes forward order: when the total length of related chunks exceeds the upper limit of the LLM context window, chunks are retained or truncated in forward order according to their position in the original document (chunks at the beginning of the document are retained, and chunks at the end of the document are discarded). Basis: In formal documents such as technical documents and planning texts, the core definitions and main attributes of entities usually appear at the beginning of the document (overview, definition sections), while the latter part often contains supplementary explanations, appendices, etc.
[0156] S3c, Centralized Attribute Extraction Sub-step: Input the aggregated context text into the large language model, use the second system prompt word to extract the attributes of the target entity, the second system prompt word contains all attribute field definitions corresponding to the entity type to which the target entity belongs, and the second system prompt word explicitly requires the large language model to extract attributes only for the target entity and prohibits the extraction of attributes of other entities, and outputs a structured attribute record containing the attribute fields and their attribute values;
[0157] LLM-based centralized attribute extraction: The aggregated context is submitted to the large language model, and a dedicated attribute extraction system prompt is used to extract all attributes of the target entity. The design of the dedicated attribute extraction system prompt must follow the following five constraints:
[0158] Precise Schema Constraints: Explicitly list all attribute fields of the target entity type (such as road) (e.g., name, start point, end point, length, width, design speed, number of lanes, road surface type), with each field accompanied by a brief description of no more than one sentence, to ensure that the attribute structure of the LLM output strictly matches the target data specification.
[0159] Strict output format constraints: Output must strictly conform to structured JSON format, including three top-level fields: name (entity name), type (entity type enumeration value), and attributes (attribute key-value pairs, where values are all strings, or empty strings if not mentioned). Attribute values must be string types (even numeric values are converted to strings, such as 120). Nested objects and additional fields are prohibited.
[0160] No fabricated constraints (negative constraints): This explicitly requires that if an attribute is not explicitly mentioned in the context provided above, its value must be set to an empty string. It is strictly forbidden to infer any attribute value based on common sense, experience, or external knowledge. "Not mentioned" means "not mentioned."
[0161] The core concept refers to constraint resolution (focused constraint): explicitly requiring the extraction of attributes only for the target entity (specified name + type). Please pay special attention to distinguishing between entities with the same name but different types (e.g., the administrative division of Wuhan and the railway station of Wuhan are different entities), and avoid incorrectly attributing attributes of other entities to the target entity.
[0162] Consistency judgment constraint for multi-source information: It is explicitly required that if the same attribute appears multiple times in the context and the values / expressions are inconsistent, the version that appears earlier (smaller block number) should be selected, and the source block number should be marked after the attribute value with [Source: Block N].
[0163] like Figure 3 As shown, a comparison of the prompts in the two stages, comparing the first stage with the second stage:
[0164] Output requirements: The first stage only includes name and type; the second stage includes nested objects containing name, type, and attributes.
[0165] Schema constraints: Phase 1 only includes an entity type enumeration list; Phase 2 includes an entity type enumeration + corresponding attribute field definitions for each type + field descriptions;
[0166] Rules against fabrication: Phase 1 requires no fabricated entity names; Phase 2 requires no fabricated attribute values (fill in missing strings).
[0167] Typical prompt word length: Phase 1: 300-500 Tokens; Phase 2: 1500-3000 Tokens;
[0168] Typical single response time: 0.5-1.5 seconds for the first stage; 2-5 seconds for the second stage.
[0169] S4. Result Merging Step: Collect the attribute extraction results of all target entities in the second stage, and perform cross-block attribute merging and deduplication using a composite key composed of the entity name and entity type; wherein, for multiple attribute extraction results with the same composite key, records with attribute values of empty strings or null will not cover records with non-empty attribute values; when there are multiple distinct and non-empty attribute values for the same attribute field, one of the multiple distinct attribute values is selected and retained according to a preset conflict resolution rule, the preset conflict resolution rule is: when there are multiple distinct and non-empty attribute values for the same attribute field, compare the string length of each attribute value, and retain the attribute value with the largest string length first; before the composite key is generated, the entity name is subjected to a normalization preprocessing operation, the normalization preprocessing operation includes: removing leading and trailing whitespace characters, and converting full-width English letters and Arabic numerals into their corresponding half-width forms.
[0170] When the same entity generates multiple extraction results through different execution rounds in the second stage, it is necessary to merge and deduplicate them. This invention employs a merging strategy that uses a composite key composed of entity name and entity type, takes the union of attributes, and resolves conflicts using preset rules.
[0171] Algorithm 4: Deduplication of Cross-Block Attribute Merging
[0172] enter:
[0173] - results: A list of the second-stage extraction results for all entities, each item in the format {name, type, attributes:{.}}
[0174] Output:
[0175] - merged_list: The final list of entity attributes after merging and deduplication.
[0176] process:
[0177] 1. merged_map <- {} / / Composite key -> merged record 2.
[0179] 3. FOR EACH result IN results:
[0180] 4. norm_name <- normalize(result.name)
[0181] 5. key <- norm_name + "|" + result.type 6.
[0183] 7. IF key NOT IN merged_map:
[0184] 8. merged_map[key] <- result / / First occurrence, store directly
[0185] 9. ELSE:
[0186] 10. existing <- merged_map[key]
[0187] 11. FOR EACH attr_name, attr_value IN result.attributes:
[0188] 12. / / Merge rule 1: Null values do not overwrite non-null values.
[0189] 13. If attr_value is null or an empty string: CONTINUE
[0190] 14. If existing.attributes[attr_name] is null or an empty string:
[0191] 15. existing.attributes[attr_name] <- attr_value / / Add missing attributes 16.
[0193] 17. / / Merge rule 2: In case of non-empty conflicts, retain the longer value first.
[0194] 18. ELSE IF attr_value != existing.attributes[attr_name]:
[0195] 19. IF len(attr_value) > len(existing.attributes[attr_name]):
[0196] 20. existing.attributes[attr_name] <- attr_value
[0197] 21. / / Optional: Log conflicts
[0198] 22. log("[Conflict] " + result.name + "." + attr_name + "-> Keep long value") twenty three.
[0200] 24. RETURN list(merged_map.values())
[0201] The design principles of the merge rules:
[0202] Null values do not overwrite non-null values (protective principle): Existing valid attribute values should not be overwritten by null values. This ensures that as long as an attribute value is successfully extracted in any round of extraction, it will not be lost.
[0203] In case of conflict, the longer value is preferred (information integrity principle): When multiple different non-empty values exist for the same attribute, the value with the longer string is retained first. The theoretical basis for this is that in geographic entity attributes, the longer version of the description usually contains more complete information (e.g., asphalt concrete pavement (AC-13C, modified asphalt) contains more effective information than asphalt pavement, and the naming of Beijing-Hong Kong-Macau Expressway is more standardized than Beijing-Hong Kong-Macau Expressway).
[0204] like Figure 1 As shown, an entity attribute extraction system based on two-stage retrieval aggregation is disclosed. The extraction system includes: a text segmentation module for executing step S1 as described in claim 1; a lightweight entity discovery module for executing step S2 as described in claim 1; a three-layer relevance segmentation retrieval module for executing sub-step S3a as described in claim 1; a context aggregation module for executing sub-step S3b as described in claim 1; a centralized attribute extraction module for executing sub-step S3c as described in claim 1; and a result merging module for executing step S4 as described in claim 1.
[0205] In some embodiments, GIS geographic entity extraction:
[0206] Dynamic prompt generation driven by entity specification library: In GIS application scenarios, the system prompts for the first and second stages are not fixed and handwritten, but dynamically generated from an encrypted GIS entity specification database. This involves reading the SQLite format GIS entity specification library via an encrypted SQLCipher connection; parsing the entity type definitions (such as roads, water systems, buildings, administrative divisions, vegetation, pipelines, etc.) and the corresponding attribute field list for each type (e.g., road entities: name, start point, end point, length, width, design speed, number of lanes, pavement type, ancillary facilities); automatically filtering system-retained fields (such as OBJECTID, Shape, GlobalID, and other GIS platform internal fields), retaining only business attribute fields; constructing a mapping table from entity types to the attribute field display name list, injecting this mapping table into the prompt template, and dynamically generating the entity type enumeration for the first stage and the attribute field schema constraints for the second stage. Different GIS projects only need to replace the entity specification library file; no code modification is required to adapt to different entity type systems and data standards.
[0207] A five-state finite state machine-driven interactive workflow: In a preferred embodiment, the method of the present invention is embedded in a multi-turn interactive workflow based on a five-state finite state machine: IDLE: Waiting for the user to upload documents and input natural language commands; ANALYZING: Calling the LLM to perform intent recognition, parsing the user's natural language extraction requirements (e.g., requesting the extraction of all road and water system attributes from the document), and outputting a list of target entity types and specific extraction rules; READY: Analysis completed, displaying the extraction plan parsed by the LLM to the user, waiting for user confirmation or modification; EXTRACTING: Executing the two-stage extraction algorithm of the present invention, pushing the extraction progress in real time through the web front end; DONE: All extraction completed, waiting for the user to select the export format and target path. The state transitions are driven by the lightweight LLM intent recognition results called each time the user inputs, and the recognition categories include: analyze (describe the extraction requirements), confirm (confirm execution), stop (stop midway), export (export results), cancel (cancel the task), and new_task (create a new task).
[0208] The GIS Processing standard operator encapsulation: The complete method of this invention is encapsulated into a Processing operator conforming to the GIS standard processing algorithm interface specification, exposing the following parameterized configuration items: LLM endpoint address (URL) and model name; maximum number of characters in text chunks (maxChunkSize, default 3000); GIS entity specification library file path; number of characters for prefix fuzzy matching (k, default 4); output format (Excel / CSV / JSON / spatial database format). The encapsulated operator can be directly embedded into existing GIS data production pipelines and called in series with other geographic data processing algorithms (such as coordinate transformation, topology checking, and spatial association), without the need for independent deployment of external systems.
[0209] In the existing solution, the text is divided into multiple physical blocks → the attribute information of the same entity is scattered in different blocks → when each block calls LLM independently, LLM can only see the description of the entity in a local scope → the attribute records output by each block are naturally incomplete → after merging, there are a large number of missing values in the entity attribute rows → the attribute completeness rate is low.
[0210] In this invention, after establishing a global entity directory in the first stage, the second stage collects all relevant blocks appearing in the full text for each entity through a three-layer retrieval process, aggregates all relevant blocks into a single focusing context, and allows the LLM to see all the information described for the entity in the full text in a single call, extracting all the attributes of the entity at once, significantly reducing the attribute missing rate, and significantly improving attribute completeness.
[0211] In the description of this disclosure, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this disclosure, unless otherwise stated, "a plurality of" means two or more.
[0212] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of preferred embodiments of this disclosure includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the function involved, as will be understood by those skilled in the art to which embodiments of this disclosure pertain.
[0213] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this disclosure. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0214] Although embodiments of the present disclosure have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present disclosure. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present disclosure.
Claims
1. A method for extracting entity attributes based on two-stage retrieval aggregation, characterized in that, The extraction method includes the following steps: S1. Text segmentation step: Divide the input long unstructured text into multiple text blocks according to paragraph boundaries. When segmenting, maintain the integrity of the paragraphs and do not use the middle of the paragraph as the cut-off point. The number of characters in each text block does not exceed the preset maximum character count threshold. S2. First-stage lightweight entity discovery steps: Traverse the multiple text blocks, call the large language model for each text block, and when calling, the first system prompt word used by the large language model only requires the large language model to identify the entity name and the entity type to which the entity belongs in the text block, and the first system prompt word explicitly prohibits the large language model from extracting attribute information; collect the return results of all text blocks, and use the composite key composed of entity name and entity type to remove duplicates, and construct a global entity directory; S3. Second-stage entity-by-entity refinement and extraction steps: For each target entity in the global entity directory, perform the following sub-steps in sequence: S3a, Three-layer related block retrieval sub-step: Using the full name of the target entity as the first keyword, perform exact matching retrieval in all of the multiple text blocks, that is, determine whether the first keyword appears as a substring in the text content of each text block, and form the first matching block set by combining the text blocks whose text content contains the first keyword. S3b, Context Aggregation Sub-step: The relevant blocks are concatenated sequentially according to their position order in the original document to form aggregated context text, wherein adjacent blocks are separated by a preset separator string; when the length of the aggregated context text exceeds the upper limit of the context window of the large language model, the relevant blocks are truncated according to their position order in the original document, retaining the relevant blocks that appear earlier and discarding the relevant blocks that appear later, so that the length of the retained part does not exceed the upper limit of the context window minus the length of the second system prompt word and the length reserved for output; S3c, Centralized Attribute Extraction Sub-step: Input the aggregated context text into the large language model, use the second system prompt word to extract the attributes of the target entity, the second system prompt word contains all attribute field definitions corresponding to the entity type to which the target entity belongs, and the second system prompt word explicitly requires the large language model to extract attributes only for the target entity and prohibits the extraction of attributes of other entities, and outputs a structured attribute record containing the attribute fields and their attribute values; S4. Result merging step: Gather the attribute extraction results of all target entities in the second stage, and perform cross-block attribute merging and deduplication using a composite key composed of the entity name and entity type; wherein, for multiple attribute extraction results with the same composite key, records with attribute values of empty strings or null will not cover records with non-empty attribute values; when there are multiple distinct and non-empty attribute values for the same attribute field, select one from the multiple distinct attribute values according to the preset conflict resolution rules.
2. The entity attribute extraction method based on two-stage retrieval aggregation according to claim 1, characterized in that, In the three-layer related block retrieval sub-step, the first k characters of the target entity name are used as the second keyword, where k is a positive integer and its default value is 4. Here, k=4 is uniquely determined by the Chinese entity naming prefix preservation property. When the total number of characters in the target entity name is less than 4, k is taken as the total number of characters in the target entity name. Prefix fuzzy matching retrieval is performed in all of the multiple text blocks, that is, it is determined whether the second keyword appears as a substring in the text content of each text block. The text blocks whose text content contains the second keyword and are not yet included in the first matching block set are combined into the second matching block set. The union of the first matching block set and the second matching block set is taken as the relevant block; if the union is an empty set, then it falls back to taking all of the multiple text blocks as the relevant block.
3. The entity attribute extraction method based on two-stage retrieval aggregation according to claim 2, characterized in that, In step S3a, the default value 4 of k is replaced by an adaptive k value determined by the total number of characters L of the target entity name. The adaptive k value is determined according to the total number of characters L: when L does not exceed 3, k equals L; when L is greater than 3 and does not exceed 6, k equals L minus 1; when L is greater than 6, k equals max(3, floor(L / 2)), where max() means taking the larger of the two values and floor() means rounding down.
4. The entity attribute extraction method based on two-stage retrieval aggregation according to claim 1, characterized in that, In step S3b, before concatenating the aggregated context text, a search result sorting step is also included: assigning a first weight to the relevant blocks belonging to the first matching block set, and assigning a second weight to the relevant blocks belonging to the second matching block set, wherein the first weight is greater than the second weight; after arranging the relevant blocks in descending order of weight, they are concatenated so that the text block obtained by precise matching is located at the beginning of the aggregated context text.
5. The entity attribute extraction method based on two-stage retrieval aggregation according to claim 1, characterized in that, In step S4, the preset conflict resolution rule is as follows: when there are multiple distinct and non-empty attribute values for the same attribute field, the string lengths of each attribute value are compared, and the attribute value with the longest string length is retained first.
6. The entity attribute extraction method based on two-stage retrieval aggregation according to claim 1, characterized in that, In steps S2 and S4, before the composite key is generated, a normalization preprocessing operation is performed on the entity name. The normalization preprocessing operation includes: removing leading and trailing whitespace characters and converting full-width English letters and Arabic numerals into their corresponding half-width forms.
7. The entity attribute extraction method based on two-stage retrieval aggregation according to claim 1, characterized in that, In steps S2 and S3, the first system prompt and the second system prompt in sub-step S3c are dynamically generated by the following method: reading the entity type definition list and the attribute field definition list corresponding to each entity type from the encrypted geographic entity specification database, automatically filtering the preset system reserved fields and retaining only the business attribute fields, injecting the entity type definition list and the attribute field definition list corresponding to the entity type into the preset prompt template, and generating a system prompt suitable for the entity specification system of the current project; wherein, different projects can achieve code-free switching between different entity specification systems by replacing the geographic entity specification database file.
8. The entity attribute extraction method based on two-stage retrieval aggregation according to claim 7, characterized in that, The dynamic generation method is embedded in a multi-turn interactive workflow based on a finite state machine. This workflow includes five states: IDLE (waiting for the user to upload documents and input natural language commands); ANALYZING (calling the large language model to analyze the user's input natural language commands to identify the user's intent; when the intent is to describe the extraction requirements, outputting a list of target entity types and extraction rules); READY (displaying the list of target entity types and extraction rules output in the ANALYZING state to the user, waiting for user confirmation or modification); EXTRACTING (triggering the execution of steps S2 to S4 after user confirmation); and DONE (waiting for the user to select an export operation after all extractions are completed). The transitions between states are triggered by the large language model's recognition of the user's intent for each input. Recognizable intent categories include: analyze (describe extraction requirements), confirm (confirm execution), stop (stop extraction), export (export results), cancel (cancel task), and new_task (create a new task).
9. The entity attribute extraction method based on two-stage retrieval aggregation according to claim 8, characterized in that, The dynamic generation method is encapsulated as a Processing operator that conforms to the GIS standard processing algorithm interface specification. The parameterized configuration items exposed to the outside world include at least one of the following: large language model endpoint address, large language model name, the maximum number of characters threshold, the file path of the geographic entity specification database, the number of prefix matching characters k, and the output data format.
10. An entity attribute extraction system based on two-stage retrieval aggregation implemented according to the method described in claims 1-9, characterized in that: The extraction system includes: A text segmentation module is used to perform step S1 as described in claim 1; A lightweight entity discovery module is used to perform step S2 as described in claim 1; The three-layer related block retrieval module is used to execute the sub-step S3a as described in claim 1; The context aggregation module is used to execute sub-step S3b as described in claim 1; A centralized attribute extraction module is used to execute sub-step S3c as described in claim 1; The result merging module is used to perform step S4 as described in claim 1.
