Knowledge graph-based context organization method and system
By using a knowledge graph-based context organization method, the problems of information redundancy and integration difficulties in complex business scenarios of large language models are solved, achieving efficient and structured context construction and improving generation quality and efficiency.
Patent Information
- Application Number
- CN202610083743.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-22
- Publication Date
- 2026-05-01
AI Technical Summary
Existing technologies suffer from problems such as redundant expansion of contextual information, difficulty in integrating heterogeneous information from multiple sources, and lack of structured semantics in complex business scenarios, leading to a decline in the quality of large-scale language model generation and excessive consumption of computing resources.
We adopt a knowledge graph-based context organization method, which constructs structured context text through multi-source information fusion, dual-path parallel graph retrieval, and agent-driven iterative evaluation and completion. This includes entity relationship queries and community topic queries. Combined with a self-reflective and self-evolving agent, we ensure the integrity and logic of the information.
It enables accurate retrieval and efficient organization of contextual information, improves the accuracy and efficiency of generating large-scale language models in professional fields, reduces computational load, and generates more professional and compliant content.
Smart Images

Figure CN121958573A_ABST
Abstract
Description
Context organization methods and systems based on knowledge graphs Technical Field
[0001] This invention relates to the fields of artificial intelligence and natural language processing technology, and more specifically, to a method and system for enhancing the generation capability of large language models, particularly to a context organization method and system based on knowledge graphs. Background Technology
[0002] In recent years, artificial intelligence technologies, represented by large language models (LLMs), have been increasingly applied to intelligent applications across various industries. Retrieval-enhanced generation (RAG) technology effectively supplements the model's domain knowledge and timeliness information by retrieving relevant information from external knowledge sources and populating the model's context, mitigating the "illusion" problem. As application scenarios become more complex, the dimensions of contextual information required for large model inference have increased dramatically. This includes not only external knowledge retrieved by RAGs but also the integration of heterogeneous information from multiple sources, such as user identity, dialogue history (short-term memory content), user profiles (long-term memory content), system role settings, and environmental states.
[0003] Traditional RAG (Related Aspects of Querying) solutions typically rely on vector databases or keyword matching to retrieve relevant text fragments from unstructured document libraries, then simply concatenate these fragments using predefined templates before inputting them into the model. This approach has significant drawbacks when facing high-dimensional, dynamic business scenarios with strict requirements for logical structure (such as official document drafting, policy consultation, and compliance review): First, text similarity-based retrieval easily introduces semantic repetition or redundant content, leading to a rapid expansion of the context length (token count). This not only significantly increases the GPU memory consumption and computational latency during the large model pre-filling stage but may also interfere with the model's grasp of core semantic focus due to information overload. Second, the fixed template concatenation method lacks an understanding of the inherent semantic relationships within the information, making it difficult to effectively hierarchically and logically organize the retrieved scattered facts, macro-level guiding principles, and historical case data. This results in generated answers that may lack structure, consistency, and completeness of evidence.
[0004] Existing technologies, when utilizing knowledge graphs to dynamically organize the context of large models, either focus solely on the graph technology itself or fail to deeply integrate the semantic retrieval advantages of knowledge graphs with the real-time integration requirements of multi-source contexts. They have yet to form an automated construction mechanism capable of supporting complex business scenarios and achieving highly relevant, logically sound, length-controllable, and information-complete contexts. Therefore, an innovative approach is urgently needed to build high-quality structured knowledge systems offline and, during online service, achieve accurate retrieval, iterative completion, and efficient organization of contextual information through intelligent processes. This would systematically improve the accuracy, compliance, and operational efficiency of large models in specialized domain tasks. Summary of the Invention
[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide a knowledge graph-based context organization method and system to solve the problems faced by large language models in complex business scenarios, such as redundant expansion of context information, difficulty in integrating multi-source heterogeneous information, lack of structured semantics, and the resulting decline in generation quality and excessive consumption of computing resources.
[0006] To achieve the above objectives, the present invention adopts the following technical solution:
[0007] In a first aspect, the present invention provides a context organization method based on knowledge graphs, comprising the following steps:
[0008] S1: Multi-source information fusion and standardized query generation: Receives the user's original query statement and simultaneously acquires the user's identity information, short-term memory content, and long-term memory content associated with the query. Performs joint semantic parsing and fusion on the above multi-source information to generate a standardized, structured retrieval query statement.
[0009] S2: Dual-path Parallel Graph Retrieval: Based on the standardized retrieval query, a dual-path parallel retrieval is performed in the pre-constructed domain knowledge graph. The first path is an entity relationship query, starting with the core entity in the query and performing multi-hop traversal along attribute edges, relationship edges, and semantic edges in the knowledge graph to obtain fine-grained entity attributes, related entities, and relationship paths, constituting mid-level detailed information. The second path is a community topic query, which vectorizes the query and performs a similarity search in a vector library constructed based on the knowledge graph community summary, returning macroscopic, topical community summary text, constituting high-level background information.
[0010] S3: Agent-Driven Iterative Evaluation and Completion: A self-reflective agent is invoked, which embeds a lightweight language model and performs a completeness evaluation of the retrieved mid-level detail information and high-level background information based on multiple preset evaluation dimensions. If the evaluation finds missing information, a specific description of the missing information is generated. Subsequently, a self-evolving agent is triggered, which dynamically adjusts the query strategy based on the missing information description, performs supplementary retrieval, and merges the new retrieval results with the existing information. This process is iterated until the information meets the completeness requirements or reaches the preset number of iterations.
[0011] S4: Structured Context Construction and Injection: Integrating the multi-round retrieval results after iterative completion. First, the main entity is identified; then, using the main entity as the organizational core, other information units are layered according to the semantic correlation strength between the main entity and the main entity in the knowledge graph; next, the information in each layer is classified and sorted according to a preset logical framework, and deduplication and alignment operations are performed; finally, the structured information is converted into coherent and orderly natural language paragraphs, forming hierarchical context text, which is injected into the input sequence of the target large-scale language model.
[0012] Furthermore, in step S1, generating a standardized retrieval query statement specifically includes: performing named entity recognition and dependency parsing on the original query statement to extract the target entity and query intent; associating and parsing the structured fields in the user identity information with the timestamps and pronouns in the short-term memory content to construct an enhanced contextual semantic chain; and using the thesaurus and ontology mapping relationships in the pre-built knowledge graph to perform standardized mapping and semantic completion on the candidate entities in the semantic chain to output an accurate retrieval query statement.
[0013] Furthermore, the pre-built domain knowledge graph is generated through an offline data governance process, which includes: performing deep analysis on the original domain documents to extract structured entity, attribute, and relation triples; constructing a knowledge graph pattern containing multiple node types and relation types; and normalizing different representations of the same entity to establish a thesaurus and abbreviation index.
[0014] Furthermore, the construction of the community summary vector library (i.e., a database that stores community summary semantic vectors based on the knowledge graph) includes: running a community discovery algorithm on the knowledge graph to identify semantic subgraph clusters with close internal connections; generating a text summary summarizing the core theme of each subgraph cluster; using a pre-trained text encoding model to convert the summary into a high-dimensional vector, and establishing a vector index database.
[0015] Furthermore, in step S3, the preset evaluation dimensions include at least three of the following: guiding principles from higher authorities, policy and legal basis, historical practical experience, current objective data, future planning direction, and constraints of current conditions.
[0016] Furthermore, in step S4, the method for identifying the main entity includes: counting the frequency of occurrence of entities in all search results, calculating the semantic relevance score of each entity to the original query statement, and selecting the entity with the highest score as the main entity.
[0017] In a second aspect, the present invention provides a knowledge graph-based context organization system, the system being used to perform the method as described in the first aspect, the system comprising:
[0018] The query generation module is configured to generate standardized search query statements.
[0019] The graph retrieval module is configured to perform entity relationship queries and community topic queries.
[0020] The agent iteration module includes a self-reflection unit and a self-evolution unit, configured to perform a completeness assessment of the retrieved information and trigger supplementary retrieval;
[0021] The context building module is configured to generate hierarchical context text.
[0022] Thirdly, the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the first aspect above.
[0023] Compared with the prior art, the technical solution provided by the present invention has the following beneficial effects:
[0024] It improves the completeness and relevance of contextual information: By introducing a structured knowledge graph as the core knowledge source and using its explicit semantic relationships for multi-hop retrieval, it can break through the limitations of traditional text similarity matching. It can not only obtain surface information directly related to the query, but also automatically associate implicit higher-level policies, similar historical cases, relevant data indicators, etc., which greatly enhances the completeness and logical relevance of information in the context and provides a more solid basis for the model's reasoning.
[0025] This approach achieves intelligent compression and structured presentation of context length: employing a dual-path retrieval mechanism of "entity relationship query (mid-level details) + community topic query (high-level background)," combined with a structured organization strategy of "main entity as the core, hierarchical association strength, and logical dimension classification," it can automatically extract the macro-framework and micro-evidence of information, effectively avoiding the simple piling up and redundancy of the original text. This method incorporates higher information density content within a limited context window, achieving intelligent compression and reducing the computational load on the model.
[0026] Information quality is ensured through a dynamic iteration mechanism: a self-reflective and self-evolving intelligent agent driven by a lightweight model is introduced to form a closed-loop quality control process. This mechanism can dynamically evaluate the completeness of search results and proactively initiate targeted supplementary queries to ensure that the final constructed context covers all key aspects required for the answer, effectively avoiding the problem of incomplete or inaccurate generated content due to incomplete searches in a single search.
[0027] Significantly improved the generation quality and efficiency of large-scale models in specialized fields: Due to the more refined, clearly structured, and highly relevant input context, large-scale language models can understand the core of the problem and its background more quickly and accurately, thereby generating more professional, logical, and compliant answers. This is particularly effective in scenarios with extremely high requirements for accuracy and structure, such as official document drafting, policy consultation, and knowledge-based question answering. Attached Figure Description
[0028] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this invention, illustrate exemplary embodiments of the invention and are used to explain the invention, but do not constitute an undue limitation of the invention. In the drawings:
[0029] Figure 1 is a schematic diagram of the overall process of the knowledge graph-based context organization method provided in an embodiment of the present invention;
[0030] Figure 2 is a schematic diagram of the offline processing flow for knowledge graph construction and community summary vector library generation in an embodiment of the present invention;
[0031] Figure 3 is a schematic diagram of the online processing flow of the map retrieval module performing dual-path retrieval in an embodiment of the present invention;
[0032] Figure 4 is a schematic diagram of the logical flow of the context building module generating hierarchical context in an embodiment of the present invention;
[0033] Figure 5 is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation
[0034] To make the objectives, technical solutions, and advantages of the present invention clearer, the embodiments of the present invention will be described in detail below with reference to the accompanying drawings. The specific embodiments described herein are for illustrative purposes only and are not intended to limit the present invention.
[0035] The core concept of this invention lies in constructing a novel Retrieval Enhancement Generation (RAG) framework centered on a structured knowledge graph, deeply integrating real-time user context, and ensuring information completeness through an intelligent agent iteration mechanism, ultimately outputting high-quality, structured context. The following detailed description, using a government intelligent document drafting scenario, illustrates this invention in practice. Those skilled in the art will understand that this method and system are also applicable to other fields requiring specialized knowledge and rigorous logic, such as finance, healthcare, and law.
[0036] Overall system architecture and process:
[0037] As shown in Figure 1, the online processing flow of this invention begins with a user inputting an initial query S101 through the client, such as a document drafting request: "Draft a request for our bureau to apply for the 2025 'Smart City' pilot project, which needs to explain the necessity of the project, the construction content and the expected benefits."
[0038] Meanwhile, the system automatically obtains three parts of auxiliary information related to the session / user through the backend interface: user identity information S102 (for example, obtained from the unified identity authentication system, including structured fields such as the user's unit "XX City Data Resources Bureau", department "Planning Section", and job level), short-term memory content S103 (for example, the preceding dialogue extracted from the Redis session cache, which may include information such as "last week's office meeting mentioned striving for pilot projects"), and long-term memory content S104 (for example, extracted from the user profile database, indicating that the user often handles "project application" and "funding application" type businesses and pays attention to the "digital economy" field).
[0039] The above four types of information are simultaneously sent to the query generation module S105. This module first uses natural language processing tools to parse the original query S101, identifying the core intent "writing a project request" and the key entity "smart city pilot project." Then, it associates the user identity information "XX Municipal Data Resources Bureau" and "Planning Section" in S102 with the short-term memory content "last week's office meeting" in S103, and supplements the domain preferences in long-term memory S104, forming an enhanced contextual semantic chain. Next, the module uses a pre-loaded knowledge graph thesaurus and ontology to map "smart city pilot project" to the standard node "new smart city construction project" in the knowledge graph, and completes information such as possible superior policy basis (e.g., "digital transformation strategy") and responsible management department based on the graph relationships. Finally, the query generation module S105 outputs a precise and standardized retrieval query statement S106, such as: "New Smart City Construction Project Application Request Writing Guidelines Policy Basis Construction Content Template Benefit Analysis Case XX Municipal Data Resources Bureau 2025".
[0040] The standardized retrieval query S106 is passed to the graph retrieval module S107. Based on this query, this module performs parallel searches in two knowledge sources: a structured domain knowledge graph S108 (e.g., stored in the Neo4j graph database) and a community summary vector library S109 generated based on this graph (e.g., stored in the Milvus vector database). The retrieval yields preliminary structured knowledge fragments S110 containing mid-level details and high-level background information.
[0041] Next, the self-reflective agent S111 is activated. This agent integrates a small-parameter open-source language model (e.g., ChatGLM3-6B). It receives the current knowledge fragment S110 and assesses the completeness of the information based on a predefined evaluation framework strongly relevant to official document writing (e.g., dimensions including "strategic basis," "policy provisions," "historical similar project status," "current data support," "future planning alignment," and "formatting requirements"). Suppose the evaluation finds that the knowledge fragment contains national-level strategies and project templates, but lacks specific action plans for "smart cities" at the provincial and municipal levels, as well as relevant financial support data for the past three years. Then, the self-reflective agent S111 will generate a missing information description S112: "It is necessary to supplement the specific deployment of smart cities in the province's 'Digital Powerhouse' action plan, as well as the municipal-level financial investment data for information technology projects in the past three years."
[0042] The self-reflective agent S111 receives the current knowledge fragment S110, and its embedded lightweight language model performs the following operations based on preset evaluation dimensions: First, it extracts and categorizes key elements (such as entities, relationships, and data) under each dimension from the input information; second, it compares the extraction results with preset integrity threshold rules for each dimension. The integrity threshold rules are specific and verifiable. For example, for the "policy and regulatory basis" dimension, the rule can be set to include at least one relevant national-level and one local-level policy entity; for the "current objective data" dimension, the rule can be set to include at least one core statistical indicator and its value. If a dimension does not meet its rules, the information in that dimension is determined to be incomplete, and a structured description of missing information S112 is generated (e.g., "lacking specific action plans for the XX topic in this province").
[0043] This description triggers the self-evolving agent S113 to execute a supplementary retrieval operation S114. The self-evolving agent S113 analyzes the missing information and determines a new retrieval strategy: starting from the "New Smart City Construction Project" node in the knowledge graph, it searches for relevant content under the "XX Province Digital Economy Development Plan" node along the "Region -> Province" relationship edge; simultaneously, starting from the "XX City Data Resources Administration Bureau" node, it searches for relevant data nodes in its "Published" "Annual Departmental Budget" or "Project Expenditure Performance Report". The new retrieval request is then sent again to the graph retrieval module S107. After obtaining the supplementary information, it is merged with the original knowledge fragment S110 to form an updated multi-round retrieval result S115. This "evaluation-completeness" cycle can be performed multiple times (e.g., setting a maximum number of iterations to 3) until the information meets the requirements or the iteration limit is reached.
[0044] Finally, the multi-round retrieval results S115 are sent to the context building module S116. This module performs a series of structured operations: First, it identifies the main entity (e.g., "new smart city construction project"). Then, it hierarchically ranks the main entity based on the length of the association path and the relationship type between other information (e.g., policy nodes, data nodes) and the main entity in the knowledge graph. Next, it categorizes and sorts the information at each level according to the logical dimensions of "strategic background and basis -> specific policy requirements -> local status and foundation -> detailed project plan -> expected benefits and risk assessment -> request format specifications". During this process, the system eliminates duplicate information fragments and ensures consistency of expression. Finally, through a converter combining templates and natural language generation technology, the structured information is generated into a well-organized, complete, and formatted hierarchical context text S117.
[0045] The hierarchical context text S117 is concatenated into the system command and ultimately submitted to the target large-scale language model S118 (such as GPT-4, Wenxin Yiyan, or other commercial or open-source models) for document content generation. Based on this high-quality, structured context, the model can generate a draft project request document that is complete in elements, well-supported, and formatted in a standardized manner, significantly reducing the user's writing burden and improving the quality of the document.
[0046] Offline knowledge construction process
[0047] Figure 2 illustrates the offline construction process that provides core knowledge support for this invention.
[0048] The original materials, namely a large number of domain-specific original documents S201 (in the context of government affairs, these may include government gazettes, laws and regulations, departmental rules, policy documents, work summaries, annual reports, project database data, etc.), are the starting point for processing.
[0049] First, document parsing and information extraction (S202) are performed. This step comprehensively utilizes Optical Character Recognition (OCR) and Natural Language Processing (NLP) technologies, including but not limited to: text segmentation, Named Entity Recognition (NER), Relation Extraction (RE), Attribute Extraction, and Event Extraction. For example, from a policy document, the following might be extracted: (Entity: "Digital Economy Development Plan", Type: Policy and Regulation, Attribute: Issuing Unit = XXX Unit, Effective Date = 2021-12-12), (Entity: "Gigabit City", Type: Construction Project, Attribute: Leading Department = Ministry of Industry and Information Technology), (Relationship: "Digital Economy Development Plan", Promotion, "Gigabit City").
[0050] Next, triple standardization and mapping S203 is performed. The entities and relations extracted in the previous step, whose representations may be inconsistent, are mapped to a predefined domain ontology S204. The domain ontology defines the hierarchical structure (taxonomy) and relation types of all concepts within the domain. For example, node types may include: Policy, Organization, Project, Indicator, Region, etc. Relation types may include: publishedBy, applyTo, underJurisdictionOf, implements, hasPart, references, etc. Through ontology mapping, knowledge standardization is achieved.
[0051] Next, entity linking and disambiguation (S205) are performed. This is a crucial step in ensuring the quality of the knowledge graph. The system needs to identify and merge multiple representations pointing to the same real-world object. For example, "MIIT", "Ministry of Industry and Information Technology", and "Ministry of Industry and Information Technology of the People's Republic of China" should be linked to the standard node Organization:MIIT. Simultaneously, indexes for synonyms, abbreviations, and former names are created for each standard node to facilitate terminology alignment during online queries.
[0052] After completing the above steps, a high-quality, unambiguous domain knowledge graph S206 can be constructed and stored in a graph database.
[0053] To support efficient macro-topic retrieval, a community summary vector library S209 needs to be constructed in parallel. A community detection algorithm S207 (such as the Louvain algorithm or Infomap algorithm) is run on the constructed knowledge graph S206. Based on the tightness of the relationships between nodes, the graph is divided into multiple semantic subgraph clusters S208 (i.e., communities) with dense internal connections and sparse external connections. For example, all nodes highly related to "digital economy," "smart city," "5G infrastructure," and "big data center" may automatically cluster into a community. The community detection algorithm clusters nodes based on edge weights and relationship types in the knowledge graph to identify semantically cohesive subgraph structures.
[0054] The community detection algorithms (such as the Louvain algorithm and the Infomap algorithm) take the nodes and edges (which may include relation type weights) of the knowledge graph as input. By optimizing indicators such as modularity or information flow, they automatically divide the graph into multiple semantic subgraph clusters (i.e., communities) with tight internal connections and sparse external connections. Each identified community corresponds to a high-level topic category, which serves as the basis for generating community summaries and constructing a vector library.
[0055] Next, a community summary S210 is generated for each subgraph cluster. This can be achieved by extracting the labels and key relation predicates of the core nodes (high centrality nodes) within the community, or by using a small language model (such as a finely tuned T5 model) to provide a general description of the important triples within the community. The summary text should concisely reflect the core theme of the community, for example: "Policy system and project layout at the national and local levels regarding the construction of digital economy infrastructure (such as 5G, gigabit optical networks, and data centers)".
[0056] Finally, a pre-trained text encoding model S211 (such as Sentence-BERT, BGE, etc.) is used to transform each community summary text into a fixed-dimensional high-dimensional vector. All these vectors are stored in a dedicated vector database, thus building the community summary vector library S212. This vector library supports fast approximate nearest neighbor search based on metrics such as cosine similarity.
[0057] Detailed Explanation of Dual-Path Spectrum Retrieval
[0058] Figure 3 illustrates in detail the internal workflow of the map retrieval module (corresponding to S107 in Figure 1) in the online service. The input is the standardized retrieval query statement S301.
[0059] One path is the entity relationship query path. First, core entity and intent parsing is performed (S302) to extract the most core entity objects (e.g., "new smart city construction project") and the user's action intent (e.g., "apply" or "write a request") from the query statement. Using this core entity as the starting node, a multi-hop semantic traversal query (S304) is initiated within the domain knowledge graph (S303). The traversal process is guided by the query intent, exploring meaningful semantic paths within the graph, for example:
[0060] Jump to step 1: Find the direct attributes of the "Project" node, such as approvalAuthority (approving department) and applicationDeadline (application deadline).
[0061] Jump to step 2: Along the implements relationship edge, find the superior "policy" node on which the project is based (such as the "XX Province New Smart City Construction Action Plan").
[0062] Jump to step 3: Starting from the policy node, follow the publishedBy edge to find the issuing "organization" node (e.g., XX unit).
[0063] Jump to step 4: Starting from the project node, follow the similarTo edge to find the historically completed similar "project" nodes and obtain the "benefit data" from their finalReport.
[0064] Through this purposeful and interpretable graph traversal, fine-grained entity relationship query results S305, i.e., mid-level detailed information, directly related to the user's question, can be precisely assembled. This information typically exists in the form of triples (entity, relation, entity / attribute value) or structured lists.
[0065] The other approach is the community topic query path. The standardized retrieval query S301 is directly fed into the same text encoding model S211 as in the offline stage for query vectorization S306, obtaining its semantic vector representation. Subsequently, this vector undergoes an approximate nearest neighbor search S307 in the community summary vector library S212. The vector library returns the Top K (e.g., K=3) community summary vectors that are semantically closest to the input vector, and their corresponding summary texts are found through mapping. These summaries provide a macro-level background and thematic framework, such as "Local Innovation Practices under the National Digital Transformation Strategy" or "Project Application and Management System for Public Finance Supporting Technological Innovation." This is the community topic query result S308, i.e., high-level background information.
[0066] Finally, the graph retrieval module merges and preliminarily structures the mid-level detailed information S305 and the high-level background information S308 S309 to form a structured knowledge fragment that contains both specific factual evidence and a macro-strategic perspective (corresponding to S110 in Figure 1), which is then output to the subsequent intelligent agent iteration module.
[0067] The self-reflective agent receives retrieved mid-level details and high-level background information as input. Its embedded lightweight language model (e.g., a small-scale model fine-tuned by instructions) performs the following processing: First, based on a preset evaluation dimension framework, it extracts and categorizes key elements (such as entities, relationships, and data) from the input information; second, it compares and analyzes the actual information under each dimension with the rules corresponding to the aforementioned 'completeness threshold'; finally, it outputs a completeness status judgment for each dimension and generates a structured description of missing information for incomplete dimensions (e.g., 'lacking specific action plans for the XX topic in this province') to drive subsequent supplementary retrieval.
[0068] Structured Context Construction Logic
[0069] Figure 4 illustrates the process by which the context building module (corresponding to S116 in Figure 1) transforms multi-round search results into final prompts. The input is the iteratively completed multi-round search results S401, which includes triples, attribute values, text fragments, and community summaries from the knowledge graph.
[0070] The first step is principal entity identification (S402). This module analyzes all entities appearing in the search results, comprehensively calculating their frequency of occurrence, semantic relevance score to the original query (calculated through the similarity between the query vector and the entity name vector), and centrality measure (such as degree centrality) of the entity within the subgraph involved in this search. By weighting these indicators, a principal entity is determined. This principal entity will become the "anchor" for organizing all information and the main narrative thread, typically the direct core object of the user's question (e.g., "XX Smart Park Construction Project").
[0071] The entity's overall score is calculated using a weighted formula, for example: ,in The entity with the highest score is selected as the main entity.
[0072] The second step is information unit association layering (S403). Using the main entity as the center, the semantic association strength between each other information unit (which can be an entity, attribute-value pair, or relation statement) and the main entity in the knowledge graph is calculated. Association strength can be comprehensively measured by the shortest path distance, the weight of relations along the path, and the semantic importance of the relation type. Directly related information with a distance of 1 (such as the direct attributes of a project or the policies directly relied upon) is assigned to the core layer; indirectly related information with a distance of 2 (such as policy-issuing agencies or similar projects) is assigned to the extension layer; and so on. This layering reflects the direct relevance of information to the core issue.
[0073] The third step is logical dimension classification (S404). The layered information is further classified according to the logical dimensions required by the business scenario. This invention presupposes a general dimension framework applicable to scenarios such as official document drafting and policy consultation, for example:
[0074] D1: Strategic Background and Guiding Principles: National or provincial strategic guidelines and planning outlines (usually derived from high-level community summaries or higher-level policy nodes).
[0075] D2: Policies, Regulations and Basis: Specific enforceable laws, regulations, management measures, and technical standards (specific policy and regulatory entities and their clauses).
[0076] D3: Current Situation Analysis and Data Foundation: Current relevant statistical data, development level, and existing work foundation (data indicator entities, current situation description nodes).
[0077] D4: Specific plans and implementation paths: Specific construction content, methods, steps, and technical routes for the main entity (project attributes and plan descriptions).
[0078] D5: Benefit Assessment and Risk Analysis: Expected Outcomes, Economic Benefits, Social Benefits, Potential Risks and Countermeasures (Benefit Indicators, Risk Assessment Nodes).
[0079] D6: Formatting Guidelines and Procedures: Text style requirements, application process, list of materials, and timelines (format templates, procedure rules).
[0080] Each information unit is categorized into one or more of the most relevant dimensions based on its semantic content.
[0081] The fourth step is structural alignment, deduplication, and refinement (S405). In this step, the system performs the following operations: 1) Deduplication: Eliminates completely duplicated or highly similar information fragments that may result from multiple rounds of queries. 2) Alignment: Ensures that the descriptions of the same entity or concept appearing in different dimensions or levels remain consistent (e.g., using standard names throughout). 3) Refinement: Summarizes or extracts key sentences from lengthy text descriptions to save tokens.
[0082] The fifth step is metadata annotation S406. To improve the transparency of the generation process and the interpretability of the results, lightweight metadata is attached to key information fragments. For example, annotations or specific tag formats can be used to indicate [Source: "XX City 2024 Government Work Report", Confidence: High] or [Related Path: Project -> Basis -> Policy -> Release -> Provincial Government]. This metadata can be selectively retained in the final context to prompt the model to pay attention to the source of the information.
[0083] The sixth step is Natural Language Processing (NLP) and Sequencing (S407). The structured information, after being layered, categorized, and refined, is transformed into a fluent, coherent, and logically clear narrative text using a well-designed NLP template. The template ensures that the content is presented in the logical order of "D1 -> D2 -> D3 -> D4 -> D5 -> D6," naturally embedding entities and relationships into the narrative. During the transformation, it is important to maintain an objective and accurate tone and retain core technical terminology. For example:
[0084] "I. Project Background and Strategic Basis (D1 & D2): To implement the national 'Digital Economy Development Plan' (〔2021〕XX) and the provincial 'Action Plan for Building a Digital Powerhouse Province' (X Government Document 〔2022〕XX) regarding accelerating the construction of new smart cities (Source: Policy Node ID-P001, Related Path: This Project -> Implementation -> Provincial Action Plan -> Basis -> National Plan)..."
[0085] "II. Local Infrastructure and Current Status (D3): Our city has built XXX 5G base stations and has been selected as a provincial 'Gigabit City' (Source: Data Node ID-D005). However, there is still room for improvement in the city's 'unified network management' level..."
[0086] "III. Main Project Construction Contents (D4): This project plans to focus on building two core modules: a 'City Digital Twin Platform' and a 'Smart Emergency Management System'... (Source: Project Scheme Node ID-PLAN01)"
[0087] The output is the final hierarchical context text S408 (corresponding to S117 in Figure 1), which is concatenated with system instructions (such as "You are a government document writer. Please write a request document about... based on the following background information") to form a complete Prompt, which is then fed into a large language model.
[0088] Examples and Effects Analysis
[0089] To verify the effectiveness of the present invention, it was tested in a simulated government document processing system.
[0090] Test scenario: A user (a staff member of a district science and technology bureau) enters the query: "Write a request for the construction of an 'Artificial Intelligence Open Innovation Platform', which needs to explain the necessity, foundation and plan."
[0091] Traditional RAG method: Retrieves several news reports, scientific paper abstracts, and policy document fragments about "artificial intelligence" and "innovation platforms" from a vector library, simply concatenates them, and inputs them into the model. The generated request document has the following problems: 1) It fails to accurately cite the specific industrial plans for artificial intelligence of the province and city; 2) The description of the construction content and operation model of the "open innovation platform" is vague; 3) It lacks combined analysis with the existing industrial base and data resources of the region.
[0092] Using the method of the present invention:
[0093] 1. The query generation module combines the user's identity (a district science and technology bureau) and memory to standardize the query as: "Application for approval of the construction of an artificial intelligence open innovation platform, basic plan [a province][a city][a district] Science and Technology Bureau".
[0094] 2. The graph retrieval module, through entity queries, accurately located the clauses regarding "layout of public computing power platforms" in the "Three-Year Action Plan for the Development of Artificial Intelligence Industry in a Certain Province" and the "Science and Technology Innovation Plan of a Certain City," as well as the data nodes of the "List of High-tech Enterprises" and "Distribution of Data Centers" in this district. Through community queries, it obtained the thematic abstract of "Construction of Local Innovation Carriers under the National Strategy for New Generation Artificial Intelligence."
[0095] 3. The self-reflection assessment of the intelligent agent revealed a lack of information on "the sustainable operation model of the platform" and "considerations on linkage with existing large scientific facilities in the city," which triggered the completion of these aspects.
[0096] 4. The context building module uses the "Artificial Intelligence Open Innovation Platform" as the main entity, organizing information as follows: strategic basis (AI strategy, provincial three-year action plan), local foundation (number of high-tech enterprises in the district, data center), specific solutions (computing power supply, data openness, application incubation), operation model (government-led, enterprise-led, market-oriented operation), and collaborative planning (cooperation with the municipal supercomputing center). This ultimately generates a clearly structured, well-founded, and comprehensive context.
[0097] Comparison of Generated Results: Based on the context provided by this invention, the request documents generated by the large model significantly outperform the results of the traditional RAG method in terms of policy citation accuracy, specificity of the solutions, and depth of integration with local contexts. Expert review indicates that the usability (directly modifiable and usable) of documents generated using this invention has increased from approximately 30% to over 80%.
[0098] Through the close collaboration between offline construction and online processing, this invention achieves the intelligent transformation from massive unstructured documents to accurate, structured, iterative, and high-quality large model contexts, providing a solid technical foundation for the efficient and reliable application of large models in complex professional fields.
[0099] Figure 5 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. As shown in Figure 5, the electronic device may include: a processor (CPU) 501, a memory 502, a communication interface 503, and a bus 504. The processor 501, memory 502, and communication interface 503 communicate with each other through the bus 504. The communication interface 503 is used for communication between the device and other external devices. The memory 502 stores a computer program that can be executed by the processor 501, and the processor 501 executes the computer program to implement the methods provided in the above-described method embodiments. The electronic device may be a server, workstation, or personal computer, etc.
[0100] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. 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 product embodied 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.
[0101] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A context organization method based on knowledge graphs, characterized in that, include: It receives the user's original query input and retrieves the associated user identity information, short-term memory content, and long-term memory content; Based on the original query, user identity information, short-term memory content, and long-term memory content, a standardized retrieval query statement is generated; based on the standardized retrieval query statement, an entity relationship query is performed in the pre-constructed knowledge graph to obtain mid-level detailed information, and at the same time, a community topic query is performed in the community summary vector library constructed based on the knowledge graph to obtain high-level background information; The self-reflective agent is invoked to evaluate the completeness of the acquired mid-level detailed information and high-level background information. If the evaluation indicates that the information is incomplete, a description of the missing information is generated and the self-evolving agent is triggered to perform supplementary retrieval. The results of the initial retrieval and supplementary retrieval are integrated and organized in a structured and hierarchical manner with the main entity as the core to generate hierarchical context text. The hierarchical contextual text is injected into the input sequence of the target large language model.
2. The method according to claim 1, characterized in that, The process of generating standardized search query statements includes: performing semantic parsing on the original query to extract target entities and query intent; integrating structured fields in the user identity information with contextual referential information in the short-term memory content to construct an enhanced contextual semantic chain; and using terminology standardization resources in the knowledge graph to map and semantically complete the entities in the semantic chain to form the standardized search query statement.
3. The method according to claim 1, characterized in that, The execution of entity relationship query includes: taking the core entity in the standardized retrieval query statement as the starting node, performing multi-hop semantic traversal along attribute edges and relationship edges in the knowledge graph to obtain relevant attribute values, associated entities and relationship paths as the middle-level detailed information; the execution of community topic query includes: vectorizing the standardized retrieval query statement, performing a similarity search in the community summary vector library, and returning the K most relevant community summary texts as the high-level background information.
4. The method according to claim 1, characterized in that, The process of invoking a self-reflective intelligent agent to perform integrity assessment includes: evaluating the current information based on multiple preset assessment dimensions, which include at least three dimensions from the following: guiding principles, policy and regulatory basis, historical practical experience, current objective data, future planning direction, and current constraints; invoking a lightweight language model to determine whether the information under each dimension meets the preset integrity threshold; and if there are any unmet dimensions, generating a description of the missing information for that dimension.
5. The method according to claim 4, characterized in that, The process of triggering the self-evolving agent to perform supplementary retrieval includes: parsing the missing information description and dynamically adjusting the retrieval strategy. The strategy includes at least one of modifying the traversal path or constraints of the entity relationship query and initiating a new community topic query to obtain the missing information.
6. The method according to claim 1, characterized in that, The structured and hierarchical organization centered on the main entity includes: identifying the core entity most relevant to the original query from all search results as the main entity; layering information units according to the semantic association strength between each information unit and the main entity in the knowledge graph; classifying and sorting the layered information according to a preset logical dimension framework; deduplicating and aligning the information for consistency, and converting it into coherent natural language paragraphs to form the hierarchical context text.
7. The method according to claim 1, characterized in that, The pre-built knowledge graph is generated through the following offline process: parsing and extracting information from the original domain documents to obtain entity, attribute, and relation triples; mapping the triples to nodes and edges of the knowledge graph according to a predefined ontology pattern; Normalize multiple entity representations that refer to the same real-world object and establish a thesaurus.
8. The method according to claim 3, characterized in that, The community summary vector library is constructed through the following process: running a community discovery algorithm on the knowledge graph to identify multiple semantically cohesive sub-graph clusters; generating a text summary summarizing the core theme for each sub-graph cluster; converting each text summary into a vector using a text encoding model; and establishing a vector index database.
9. A context organization system based on knowledge graphs, characterized in that, The system for performing the method as described in any one of claims 1 to 8 includes: a query generation module configured to generate standardized retrieval query statements; a graph retrieval module configured to perform entity relationship queries and community topic queries; an agent iteration module including a self-reflection unit and a self-evolution unit configured to perform integrity assessment of the retrieved information and trigger supplementary retrieval; and a context construction module configured to generate hierarchical context text.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1 to 8.