Data query method and system based on natural language text
By dynamic occlusion and multi-hop path expansion of natural language text, combined with heterogeneous feature fusion and iterative verification, the problems of insufficient semantic understanding and slow query response in the knowledge graph are solved, and efficient and accurate natural language query conversion and execution optimization are achieved.
Patent Information
- Application Number
- CN202510583553.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-07
- Publication Date
- 2025-08-15
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Natural language query processing technology faces challenges such as insufficient semantic understanding depth, low mining efficiency of multi-hop correlation paths, and difficulty in fusion of heterogeneous data in the application of knowledge graphs. The existing technology is difficult to dynamically adapt to text context semantic changes, resulting in insufficient semantic retention of low-frequency entities and slow query response speed.
By dynamically occluding preprocessing of the input natural language text, semantic vector sequences are generated, key entities and their association relationships are extracted, potential association paths are expanded, heterogeneous semantic graphs are generated, and syntax features are fused with text, query conditions are optimized, the consistency of response content is verified, and executable statements iteratively generate.
It realizes efficient and accurate natural language query conversion, improves query response speed, ensures the accuracy of semantic understanding and the coverage of multi-hop associations, and optimizes query execution efficiency.
Smart Images

Figure CN120492610A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of artificial intelligence and natural language processing, and in particular relates to a data query method and system based on natural language text. Background Art
[0002] Natural language query processing technology faces core challenges in knowledge graph applications, including insufficient semantic understanding, inefficient multi-hop association path mining, and difficulty integrating heterogeneous data. Traditional methods rely on static word embeddings (such as Word2Vec) and fixed rule templates, making them difficult to dynamically adapt to contextual changes in text. For example, in medical queries, the dynamic association between "chest pain" and "ST-segment elevation" can be easily overlooked. While existing dynamic masking techniques can mitigate overfitting by randomly replacing word fragments (e.g., a 15% masking rate), vector reconstruction of masked regions still relies on the aggregation of attention weights of adjacent words, resulting in insufficient semantic preservation of low-frequency entities (such as rare disease terms). In the knowledge graph expansion phase, a three-hop path expansion strategy based on bidirectional breadth-first search can cover 92% of common associations. However, for high-density graphs with over 200 nodes / hop, it is still necessary to dynamically adjust the threshold of the 768-dimensional vector similarity of the Sentence-BERT encoding (e.g., increasing it by 0.1 to suppress overload) and introduce a path structure complexity score (W3) to optimize top-N path screening. During the query optimization phase, the field access frequency matrix (Facc) and filter efficiency matrix (Efilt) constructed from historical execution logs are combined with a path hop attenuation factor (λ = 0.85) to dynamically adjust condition priorities, resulting in a 37% improvement in query response speed in e-commerce scenarios. In terms of semantic consistency verification, a multimodal encoder based on a pre-trained model can capture the joint semantic representation of text and unstructured data, locating 92% of semantically offset fields through attention alignment scores. The adversarial detection module achieves an 89% accuracy rate in identifying logical contradictions, significantly outperforming traditional dependency parsing methods. Current technological trends indicate that systems integrating dynamic masking, multi-hop reasoning (such as HR-GNN hybrid networks), and heterogeneous feature gating are driving natural language query processing towards adaptive and interpretable development. Summary of the Invention
[0003] Based on this, it is necessary to provide a data query method and system based on natural language text that can combine knowledge graphs to efficiently and accurately query and convert natural language to address the above technical problems.
[0004] In a first aspect, the present application provides a data query method and system based on natural language text, comprising:
[0005] Perform dynamic masking preprocessing on the input natural language text to generate a semantic vector sequence;
[0006] Extracting key entities and their association relationships in the semantic vector sequence based on the attention mechanism to obtain a structured entity relationship set;
[0007] Matching the structured entity relationship set with the knowledge graph nodes, expanding the potential association paths, and generating a heterogeneous semantic graph with multi-hop association paths and dynamic confidence weights;
[0008] Heterogeneously fusing the heterogeneous semantic graph with text syntactic features to generate an intent framework carrying logical constraints, and converting it into an intermediate query representation;
[0009] Based on the execution history log, the query condition sequence of the intermediate query representation is optimized to generate an executable statement carrying a semantic association identifier;
[0010] Verify the semantic consistency between the response content of the executable statement and the original input, and iteratively regenerate the executable statement if it fails.
[0011] In one embodiment, dynamic masking preprocessing is performed on the input natural language text to generate a semantic vector sequence, including: performing lemma processing on the input natural language text to obtain a lemma sequence;
[0012] Selecting continuous local subsequences in the continuous word sequence as word fragments, randomly selecting word fragments according to a preset ratio to replace them with special marks while retaining the position code;
[0013] Inputting the masked word sequence into a deep semantic encoding model to generate a semantic vector sequence;
[0014] The vector of the masked position is generated by aggregating the attention weights of adjacent words.
[0015] In one embodiment, heterogeneously fusing the heterogeneous semantic graph with text syntactic features to generate an intent framework carrying logical constraints, and converting the intent framework into an intermediate query representation includes:
[0016] The heterogeneous fusion of the heterogeneous semantic graph and the text syntactic features adopts a gating mechanism to dynamically adjust the contribution weights of the semantic and syntactic features;
[0017] The node association path of the intention framework carrying logical constraints is generated to inherit the confidence index in the semantic graph;
[0018] The conversion into an intermediate query representation supports the generation of executable query statements for relational and graph databases.
[0019] In one embodiment, matching the normalized relationship set with the knowledge graph nodes and expanding the potential association paths to generate a heterogeneous semantic graph includes:
[0020] For each entity e in the normalized relation set i , calculate its relationship with the knowledge graph node v j Semantic similarity of ∈V:
[0021]
[0022] in is the entity encoding function, ψ(·) is the node encoding function, and sim(e i ,v j )≥θ s im's node pair, θ s im∈[0.6,0.8];
[0023] Perform a three-hop traversal on the matching node vj and extract all associated paths P path =(v j →v j +1→v j +2→v j +3), calculate the path confidence:
[0024] conf(P path )=Π[w jk w k (k+1) / (1+log(1+deg(v k )))]
[0025] where w jk is the edge weight, deg(v k ) is the node degree;
[0026] Keep conf(P path )≥θ conf avg conf The path, θ conf ∈[1.2,1.5] is the dynamic adjustment coefficient, avg conf is the confidence of the current path;
[0027] Add the filtered path to the original semantic graph and update the edge weights between nodes as follows:
[0028] w new =γ·w old +(1-γ)·[conf(P path ) / max conf ]
[0029] Among them, w new is the updated edge weight, γ∈[0.3,0.6] is the weight inheritance factor, w old is the original edge weight, conf(P path ) is the path confidence, max confThe maximum path confidence of the current graph. By dynamically updating edge weights, screening high-confidence paths, and integrating multiple features, a heterogeneous semantic graph with semantic association identifiers is ultimately generated.
[0030] In one embodiment, query condition sequence optimization is performed on the intermediate query representation based on the execution history log to generate an executable statement carrying a semantic association identifier, including:
[0031] Extract the field access frequency matrix Facc and the conditional filtering efficiency matrix Efilt from the execution history log, where:
[0032] Facc[fi]=NtotalNaccess(fi)Efilt[cj]=∣D∣∣σcj(D)∣
[0033] Naccess is the number of times the field fi is accessed, σcj(D) is the data set after filtering by condition cj;
[0034] Based on the constraint condition set C = c1, ..., cn represented by the intermediate query, calculate the optimization weight of each condition:
[0035] wi=α·Efilt[ci]+β·∣ci∣∑f∈ciFacc[f]
[0036] Where α∈[0.5,0.8] is the filtering efficiency coefficient, and β∈[0.2,0.5] is the field correlation coefficient;
[0037] For the associated path set Ppath represented by the intermediate query, the path priority is adjusted according to the attenuation formula:
[0038] priority(p)=wpath·e-λ·h+μ·∣c∈p∣∑c∈pwc
[0039] Where h is the number of path hops, λ∈[0.1,0.3] is the attenuation factor, and μ∈[0.4,0.6] is the conditional weight fusion coefficient;
[0040] Generate the executable statement Qexec according to the optimized condition weight wi and path priority priority(p), and inject the semantic association identifier:
[0041] Qexec=conditional order ∪Sort(wi) ∪association path p ∣priority(p)>0.7 ∪semantic identity<fi,τ(fi)>
[0042] Where τ(fi) is the type label set of field fi in the semantic graph.
[0043] In one embodiment, expanding the potential association path to generate a heterogeneous semantic graph further includes:
[0044] Based on bidirectional breadth-first search, the knowledge graph is traversed, starting from the user entity and expanding along the relationship edge to all nodes within three hops. In the preprocessing stage, low-frequency relationships and invalid nodes are pruned, and the node importance scores are pre-calculated using graph embedding.
[0045] Use Sentence-BERT to encode user entity descriptions and adjacent node attributes into 768-dimensional vectors, calculate cosine similarity, and integrate graph embedding similarity for weighting;
[0046] Based on the historical similarity distribution of the sliding window statistics, the top 30% quantile is taken as the initial threshold. The threshold is dynamically adjusted according to the real-time data flow. If the node density exceeds 200 / hop, the threshold is increased by 0.1 to suppress overload.
[0047] Sort the extended paths in descending order according to the total score C = 0.5W1 + 0.3W2 + 0.2*W3, and retain the top-N paths, where W1 is the path confidence conf(Ppath)conf(P path )conf(Ppath) is the log-normalized value, W2 is the weighted sum of the cosine similarity encoded by Sentence-BERT and the graph embedding similarity, and W3 is the path structure complexity score;
[0048] Detect the conflict relationship between the new path and the original semantic graph, and calculate the contradiction score between the new path and the original semantic graph based on the knowledge graph embedding. If it is greater than 0.8, the system automatically freezes the conflicting path, dynamically lowers the similarity threshold and marks the audit log. After manual review, the instructions trigger the graph neural network completion or parameter correction, and finally generate a heterogeneous semantic graph with version identification.
[0049] In one embodiment, verifying the semantic consistency between the response content of the executable statement and the original input to obtain a verification result includes:
[0050] Use a pre-trained language model to encode the original input and generated response into high-dimensional semantic vectors, respectively. Dynamic pooling compression is used for long texts, or a multimodal encoder is used to process non-text inputs to ensure cross-modal alignment.
[0051] Calculate the cosine similarity between two vectors, dynamically adjust the threshold based on the text length, introduce the attention alignment score to assist in detecting local semantic shifts, and comprehensively determine whether the consistency meets the standards;
[0052] It locates low-similarity fields through dependency syntactic analysis, prioritizes replacing core semantic components, uses prompt constraints to generate directional corrections to the model, and adopts an iterative annealing strategy to gradually converge.
[0053] If the similarity of consecutive iterations drops by more than 15% or reaches the maximum number of iterations, the generation process is terminated and the retrieval enhancement generation is triggered to call the pre-stored answers from the knowledge base to ensure the output reliability;
[0054] The adversarial detection module identifies logical contradictions / factual errors, pushes low-similarity cases to the manual annotation platform, and reversely updates the encoder and generative model parameters.
[0055] In a second aspect, the present application further provides a data query device based on natural language text, comprising:
[0056] Dynamic masking and semantic encoding module, used to convert the natural language text input by the user into a semantic vector sequence through dynamic masking preprocessing;
[0057] The structured entity extraction module is used to extract key entities and inter-entity relationships from the semantic vector sequence to obtain a set of structured entity relationships;
[0058] The knowledge graph extension module is used to match structured entity relationship sets with knowledge graph nodes, expand potential association paths and generate semantic graphs;
[0059] A heterogeneous fusion and query generation module, which heterogeneously fuses the semantic graph with text syntactic features to generate an intermediate query representation;
[0060] Query optimization module, used to process intermediate query representation to generate executable statements;
[0061] The response generation and verification module is used to verify the semantic consistency between the response content of the executable statement and the original input. If it fails, the executable statement is iteratively regenerated.
[0062] In a third aspect, the present application further provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method described in any one of the first aspects of the present application when executing the computer program.
[0063] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in any one of the first aspects of the present application.
[0064] The above-mentioned data query method, system, and device based on natural language text, this solution systematically solves the problems of semantic fragmentation, update lag, and modal conflict raised in the background technology by combining the knowledge graph to perform dynamic masking preprocessing on the input text → multi-hop path expansion → heterogeneous feature fusion → iterative verification technology chain. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0066] Figure 1 This is a flow chart of a data query method based on natural language text of the present invention;
[0067] Figure 2 The present invention provides a data query device based on natural language text. DETAILED DESCRIPTION
[0068] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0069] In one embodiment, Figure 1 As shown, a method and system for data query based on natural language text are provided. This embodiment uses the method applied to a terminal as an example. It is understandable that the method can also be applied to a server, or to a system including a terminal and a server, and implemented through interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0070] Step S101 : performing dynamic masking preprocessing on the input natural language text to generate a semantic vector sequence.
[0071] For example, in medical text processing, the input is "The patient has chest pain with ST-segment elevation, and troponin I has risen to 5.2ng / mL." The system first performs dynamic masking preprocessing, randomly selects "ST-segment elevation" and "5.2ng / mL" and replaces them with the special marker [MASK]. After retaining the positional encoding, it inputs the BERT model to generate a semantic vector. The vector of the masked position is reconstructed by aggregating the attention weights of adjacent word units. For example, the semantic information of "ST-segment elevation" is generated through the contextual association of "chest pain" (weight 0.72) and "troponin I" (weight 0.28), ensuring the semantic integrity of the medical entity.
[0072] Step S102: extract key entities and their association relationships in the semantic vector sequence based on the attention mechanism to obtain a structured entity relationship set.
[0073] For example, a multi-head self-attention mechanism is used to extract entity relationships. Two attention heads identify the entity boundaries of "chest pain" (symptom) and "troponin I" (biomarker), respectively, while the other two heads capture the accompanying relationship of "with ST-segment elevation" and the numerical association of "increased to 5.2 ng / mL." The dual-affine attention model calculates the association strength score of "chest pain-acute myocardial infarction" as 0.93, and combines it with the knowledge graph to generate structured triples (chest pain, accompanying symptoms, ST-segment elevation) and (troponin I, abnormal indicator, 5.2 ng / mL).
[0074] Step S103: Match the structured entity relationship set with the knowledge graph nodes, expand the potential association path, and generate a heterogeneous semantic graph carrying multi-hop association paths and dynamic confidence weights.
[0075] For example, after matching the entity with the medical knowledge graph node, a three-hop path extension is triggered from the "acute myocardial infarction" node to supplement associations such as "treatment guidelines → PCI surgery" and "diagnostic threshold → 0.4ng / mL". When calculating the path confidence, the edge weight (such as the authority weight of the treatment guideline 0.9) and the node degree (such as the PCI surgery node degree 120) are combined, and the path with confidence > 0.75 is retained to generate a heterogeneous semantic graph with dynamic weights.
[0076] Step S104: heterogeneously fuse the heterogeneous semantic graph with the text syntactic features to generate an intent framework carrying logical constraints, and convert it into an intermediate query representation.
[0077] For example, the path weight (60%) of the heterogeneous semantic graph is integrated with the text syntactic features (such as "diagnosis" as the predicate verb governing the disease entity), and an intermediate query representation is generated through a gating mechanism and converted into a Cypher statement: match the process with the disease name "acute myocardial infarction" and the treatment effectiveness greater than 0.8, and return the surgery name and evidence level.
[0078] Step S105 : Based on the execution history log, the query condition sequence is optimized for the intermediate query representation to generate an executable statement carrying a semantic association identifier.
[0079] For example, based on the access frequency of the "Troponin I" field in the historical log (accounting for 42%) and the filtering efficiency of the "ST segment elevation" condition (data reduced to 18%), the query optimization weight is calculated, and the "WHERE troponin>5.0ANDst_elevation=TRUE" condition is executed first to generate an SQL statement with semantic tags: filter out records from the case table where the biomarker value is greater than 5.0 and there is ST segment elevation.
[0080] Step S106 , verifying the semantic consistency between the response content of the executable statement and the original input, and iteratively regenerating the executable statement if it fails.
[0081] For example, the semantic model is used to calculate the similarity (0.91) between the original text and the generated query. It is detected that "interventional treatment" in the knowledge graph must meet the "onset < 12 hours" condition, but the original text does not specify the time. The correction module is triggered to add the condition "AND onset_time < 12". After regeneration, the similarity is increased to 0.94, and the conflicting case is pushed to the review system to update the knowledge base.
[0082] In the above-mentioned data query method and system based on natural language text, the natural language text input by the user is processed, redundant information is removed, key content is extracted, and it is converted into a data format that can be recognized by the computer. The correlation between these key points is then analyzed and organized into a relationship table. Subsequently, the system matches the information in the relationship table with the existing knowledge in the database, expands more potential association paths, and forms a semantic network with credibility assessment. The network is then combined with the grammatical structure of the sentence to construct a logical query template and convert it into computer-executable instructions. The system will also optimize the order of query steps based on historical operation records to improve execution efficiency. Finally, it automatically checks whether the query results accurately reflect user needs. If deviations are found, the association paths are re-analyzed and new query instructions are generated to ensure that the final results are consistent with user expectations. Figure 1 It can achieve accurate semantic understanding, efficient information extraction, multi-hop association coverage, precise logical translation, and optimized execution efficiency.
[0083] In one embodiment, the step of performing dynamic masking preprocessing on the input natural language text to generate a semantic vector sequence includes:
[0084] S201: Perform lemma processing on the input natural language text to obtain a lemma sequence.
[0085] S202, selecting continuous local subsequences in the continuous word sequence as word segments, randomly selecting word segments according to a preset ratio to replace them with special marks and retaining position codes.
[0086] S203: Input the masked word sequence into a deep semantic coding model to generate a semantic vector sequence.
[0087] S204, generating a vector of the masked position by aggregating the attention weights of adjacent word units.
[0088] In a medical text processing scenario, given the natural language text "A patient experienced chest pain with ST-segment elevation, and troponin I rose to 5.2 ng / mL. This patient was diagnosed with acute myocardial infarction and required immediate treatment," the system first tokenized the text to produce the sequence ["patient," "appeared," "chest pain," "with," "ST-segment elevation," ","," "troponin I," "rose to," "5.2," "ng / mL," ","," diagnosed," "acute," "myocardial infarction," "required," "immediately," "treatment"]. The system then selected the continuous token fragment ["troponin I," "rose to," "5.2"] as the masking object and replaced it with a special marker ["[MASK]," "[MASK]," "[MASK]"] at a ratio of 15%, while retaining the original position code (e.g., position indexes 7-9). When the masked sequence is fed into the RoBERTa model to generate semantic vectors, the model outputs initial random vectors at positions 7-9. The masked word vectors are reconstructed by aggregating attention on the adjacent words "promoted" (position 6, attention weight 0.68) and "diagnosed" (position 10, weight 0.32). For example, the vector for "troponin I" at position 7 is weighted by 0.68 × the "promoted" vector + 0.32 × the "diagnosed" vector, achieving a cosine similarity of 0.89 with the original word vector. The final output semantic vector sequence contains complete contextual information, with an average similarity of 0.85 between the masked position vectors and the true word vectors, meeting the requirements of the subsequent entity extraction task.
[0089] In one embodiment, heterogeneously fusing the heterogeneous semantic graph with text syntactic features to generate an intent framework carrying logical constraints, and converting the intent framework into an intermediate query representation includes:
[0090] S301, performing heterogeneous fusion of the heterogeneous semantic graph and the text syntactic features, and adopting a gating mechanism to dynamically adjust the contribution weights of the semantic and syntactic features.
[0091] S302, generating a confidence index in a semantic graph of node association paths inheriting an intention framework carrying logical constraints.
[0092] S303, the conversion into an intermediate query representation supports the generation of executable query statements for relational and graph databases.
[0093] In a medical diagnosis scenario, the heterogeneous semantic graph generated from the input text "The patient has persistent chest pain with ST-segment elevation, and troponin I has risen to 5.2 ng / mL. PCI surgery needs to be performed within 12 hours of the onset of the disease" contains paths "Acute myocardial infarction → PCI surgery" (confidence 0.9) and "Acute myocardial infarction → Drug treatment" (confidence 0.7). At the same time, the core predicate verb "perform" and the time adverbial "within 12 hours" are extracted through dependency syntactic analysis. When fusing, a gating mechanism is used to dynamically allocate weights: the weight of the semantic graph features is set to 0.6 (weighted based on path confidence), and the weight of the syntactic features is 0.4 (due to the complex modification relationship of the time adverbial). When generating the intention framework, the confidence index 0.9 of the PCI surgery path is inherited as the logical constraint priority. When finally converted into an intermediate query representation, two executable statements are generated: the relational database query SELECT * FROM treatment WHERE diagnosis ='myocardial infarction' AND troponin > 5.0 AND procedure = 'PCI' AND onset_hours < 12 ORDER BY confidence DESC (sorted in descending order of confidence), and the graph database Cypher query MATCH (d:Disease)-[r:requires]->(p:Procedure) WHERE d.name = 'Acute myocardial infarction' AND p.efficacy > 0.85 AND r.onset_time < 12 RETURN p.name, r.evidence_level, where efficacy > 0.85 is directly mapped from the effectiveness attribute of the PCI surgery node in the semantic graph, and the time constraint is inherited from the adverbial modification structure of the syntactic analysis.
[0094] In one embodiment, the normalized relationship set is matched with the knowledge graph nodes to expand potential association paths to generate a heterogeneous semantic graph, including:
[0095] S401. For each entity e in the normalized relationship set i , calculate its semantic similarity with the knowledge graph node v j ∈ V:
[0096]
[0097] where is the entity encoding function, ψ(·) is the node encoding function, and retain the node pairs of sim(e i , v j ) ≥ θ s im, where θ s im ∈ [0.6, 0.8].
[0098] S402, matching node v j Perform three-hop traversal to extract all associated paths P path =(v j →v j +1→v j +2→v j +3), calculate the path confidence:
[0099] conf(P path )=Π[w jk w k (k+1) / (1+log(1+deg(v k )))]
[0100] where w jk is the edge weight, deg(v k ) is the node degree.
[0101] S403, retain conf(P path )≥θ conf avg conf The path, θ conf ∈[1.2,1.5] is the dynamic adjustment coefficient, avg conf The confidence of the current path.
[0102] S404: Add the filtered path to the original semantic graph and update the edge weights between nodes to:
[0103] w new =γ·w old +(1-γ)·[conf(P path ) / max conf ]
[0104] Among them, w new is the updated edge weight, γ∈[0.3,0.6] is the weight inheritance factor, w old is the original edge weight, conf(P path ) is the path confidence, max conf The maximum path confidence of the current graph. By dynamically updating edge weights, screening high-confidence paths, and integrating multiple features, a heterogeneous semantic graph with semantic association identifiers is ultimately generated.
[0105] In the medical knowledge graph construction scenario, the input structured entity relationship set contains triples (chest pain, associated symptoms, ST-segment elevation) and (troponin I, abnormal indicators, 5.2 ng / mL). The system first uses Sentence-BERT to encode "chest pain" into a 768-dimensional vector, and calculates the cosine similarity with the "chest pain symptoms" node vector in the knowledge graph to obtain 0.92. After exceeding the threshold of 0.85, the node matching pair is retained; and because "5.2 ng / mL" has no precise numerical node in the knowledge graph, it is associated with the "troponin abnormality" node through fuzzy matching (similarity 0.78). A three-hop traversal of the matching node "acute myocardial infarction" extracts two association paths: Path 1 (acute myocardial infarction → diagnostic evidence → ST-segment elevation → electrocardiogram features) has edge weights of 0.9 and 0.8, and node degrees of 50 and 120, respectively. Substituting this into the path confidence formula yields C_p = (0.9 + 0.8) / 2 × 120^(-0.2) = 0.76 (α = 0.2). Path 2 (acute myocardial infarction → complications → cardiogenic shock) has an edge weight of 0.7, a node degree of 30, and a confidence of 0.62. When the dynamic adjustment coefficient β = 0.6, paths 1 with confidence > 0.7 are selected and added to the original semantic graph. When updating edge weights, the weight inheritance factor γ was set to 0.7, and the current graph's maximum path confidence C_max was set to 0.9. Therefore, the updated weight for the diagnostic basis edge was W_new = 0.7 × 0.8 + (1 - 0.7) × (0.76 / 0.9) = 0.75. The system detected a conflict score of 0.83 between the newly added path "ECG Features → Ischemic Changes" and the node "Nonspecific ST Changes" in the original semantic graph. The system automatically froze the path and dynamically lowered the similarity threshold from 0.75 to 0.70, recording the conflict details in the audit log. After manual review and confirmation, the "ECG Dynamic Evolution" constraint was added via the graph neural network completion module. Finally, a heterogeneous semantic graph with version identifier V2.3 was generated, in which diagnostic basis edges were labeled as blue high-weight paths (0.75), and treatment path edges were labeled as green standard weight paths (0.68). Semantic type labels, such as "examination features" and "complications," were also added.
[0106] In one embodiment, query condition sequence optimization is performed on the intermediate query representation based on the execution history log to generate an executable statement carrying a semantic association identifier, including:
[0107] S501: Extract the field access frequency matrix Facc and the conditional filtering efficiency matrix Efilt from the execution history log, where:
[0108] Facc[fi]=NtotalNaccess(fi)Efilt[cj]=∣D∣∣σcj(D)∣
[0109] Naccess is the number of times the field fi is accessed, and σcj(D) is the data set after filtering by condition cj.
[0110] S502, based on the constraint condition set C=c1,...,cn represented by the intermediate query, calculate the optimization weight of each condition:
[0111] wi=α·Efilt[ci]+β·∣ci∣∑f∈ciFacc[f]
[0112] Where α∈[0.5,0.8] is the filtering efficiency coefficient, and β∈[0.2,0.5] is the field association coefficient.
[0113] S503: For the associated path set Ppath represented by the intermediate query, adjust the path priority according to the attenuation formula:
[0114] priority(p)=wpath·e-λ·h+μ·∣c∈p∣∑c∈pwc
[0115] Where h is the number of path hops, λ∈[0.1,0.3] is the attenuation factor, and μ∈[0.4,0.6] is the conditional weight fusion coefficient.
[0116] S504: Generate an executable statement Qexec according to the optimized condition weight wi and path priority priority(p), and inject a semantic association identifier.
[0117] Qexec=conditional order ∪Sort(wi) ∪association path p ∣priority(p)>0.7 ∪semantic identity<fi,τ(fi)>
[0118] Where τ(fi) is the type label set of field fi in the semantic graph.
[0119] In a medical data analysis scenario, the system extracts the "troponin (troponin I)" field access count (Facc) of 142 (the highest frequency) and the "st_elevation (ST-segment elevation)" filter efficiency (Efilt) of 0.18 (reducing the dataset by 18%) from the execution history log for a query request regarding acute myocardial infarction treatment plans. Based on the intermediate query condition set {troponin>5.0, st_elevation=True, procedure_type='PCI'}, the optimization weights for each condition are calculated: w1=0.6*(142 / 150)+0.4*(0.18 / 0.20)=0.92 (troponin I), w2=0.6*(85 / 150)+0.4*(0.15 / 0.20)=0.68 (ST-segment elevation). The association path set Ppath was prioritized. The path "diagnostic criteria → PCI surgical guidelines" (hop count h = 1) was scored as priority(p) = 0.85^1*(0.92+0.68) = 1.37, while the path "complications → cardiogenic shock" (h = 2) was scored as 0.85^2*(0.68) = 0.53. The resulting executable SQL statement was: SELECT * FROM treatment_plan WHERE @biomarker_troponin>5.0 AND @symptom_st_elevation=1 AND @procedure_type='PCI'. The semantic identifiers @biomarker_ and @symptom_ correspond to the biomarker and symptom type labels in the knowledge graph, ensuring precise alignment of the query conditions with the medical ontology concepts.
[0120] In one embodiment, expanding the potential association path to generate a heterogeneous semantic graph further includes:
[0121] S601, based on bidirectional breadth-first search, traverses the knowledge graph, starting from the user entity and expanding along the relationship edge to all nodes within three hops. In the preprocessing stage, low-frequency relationships and invalid nodes are pruned, and graph embedding is used to pre-calculate node importance scores.
[0122] S602: Use Sentence-BERT to encode the user entity description and adjacent node attributes into a 768-dimensional vector, calculate the cosine similarity, and integrate the graph embedding similarity for weighting.
[0123] S603: Based on the historical similarity distribution of the sliding window statistics, the top 30% quantile is taken as the initial threshold. The threshold is dynamically modified according to the real-time data flow. If the node density exceeds 200 / hop, the threshold is increased by 0.1 to suppress overload.
[0124] S604, sort the extended paths in descending order according to the total score C = 0.5W1 + 0.3W2 + 0.2*W3, and retain the top-N paths, where W1 is the path confidence conf(Ppath)conf(P path )conf(Ppath) is the log-normalized value, W2 is the weighted sum of the cosine similarity encoded by Sentence-BERT and the graph embedding similarity, and W3 is the path structure complexity score.
[0125] S605, detect the conflict relationship between the new path and the original semantic graph, and calculate the contradiction score between the new path and the original semantic graph based on the knowledge graph embedding. If it is greater than 0.8, the system automatically freezes the conflicting path, dynamically lowers the similarity threshold and marks the audit log. After manual review, the instructions trigger the graph neural network completion or parameter correction, and finally generate a heterogeneous semantic graph with version identification.
[0126] In a medical knowledge graph application, for a user query for the entity "acute myocardial infarction," the system initiates a potential association path expansion process. First, a bidirectional breadth-first search is performed to traverse all nodes within three hops from the entity. During preprocessing, edge relationships with a frequency of less than five occurrences (e.g., "complications → Kawasaki disease") are pruned. Node importance scores are precomputed using the Node2Vec graph embedding algorithm (e.g., "PCI surgery" has a score of 0.87, and "thrombolytic therapy" has a score of 0.68). Using Sentence-BERT, the entity description "ischemic necrosis caused by coronary artery occlusion" and adjacent node attributes (e.g., the indication description for "PCI surgery") are encoded into a 768-dimensional vector. The cosine similarity is calculated to be 0.85, and after fusing the graph embedding similarity to 0.78, the weighted score is 0.82. Based on sliding window statistics of historical query logs, the initial similarity threshold is set to 0.75, the top 30% quantile. When the density of "treatment method" branch nodes reaches 230 per hop, the threshold is dynamically increased to 0.85 to prevent overload. During the path ranking phase, the total path score W was calculated as 0.4W1 (log-normalized path confidence score of 0.92) + 0.3W2 (weighted sum of similarities of 0.82) + 0.3*W3 (structural complexity score of 0.75). The top 10 pathways, such as "acute myocardial infarction → PCI surgery → radial artery access" and "acute myocardial infarction → drug therapy → ticagrelor," were retained. The conflict detection module detected a 0.83 conflict between the newly added path "acute myocardial infarction → thrombolytic therapy → bleeding risk" and the "antiplatelet contraindications" in the original semantic graph. The system automatically froze the path, lowered the similarity threshold to 0.72, and recorded an audit log. After manual review confirmed the conflict, the graph neural network completion module was triggered to add the "bleeding risk assessment" constraint, ultimately generating a heterogeneous semantic graph with version ID V2.1, containing the core treatment pathways and their risk control nodes.
[0127] In one embodiment, verifying the semantic consistency between the response content of the executable statement and the original input to obtain a verification result includes:
[0128] S701 uses a pre-trained language model to encode the original input and generated response into high-dimensional semantic vectors respectively, uses dynamic pooling compression for long texts, or processes non-text inputs through a multimodal encoder to obtain a joint semantic representation.
[0129] S702, calculate the cosine similarity between the semantic vector of the original input text and the semantic vector of the generated response text, dynamically adjust the threshold based on the text length, introduce the attention alignment score to assist in detecting local semantic offsets, and comprehensively determine whether the consistency meets the standards.
[0130] S703 locates low-similarity fields through dependency syntactic analysis, prioritizes replacing core semantic components, uses prompt constraints to generate model-directed corrections, and adopts an iterative annealing strategy to gradually converge.
[0131] S704: If the similarity of consecutive iterations decreases by more than 15% or reaches the maximum number of iterations, the generation process is terminated and the search enhancement generation is triggered to call the pre-stored answer from the knowledge base.
[0132] S705, identify logical contradictions / factual errors through the adversarial detection module, push low-similarity cases to the manual annotation platform, and reversely update the encoder and generative model parameters.
[0133] In a medical report parsing scenario, the input text "A patient has persistent chest pain with ST-segment elevation, and troponin I has risen to 5.2 ng / mL. Acute myocardial infarction is confirmed, requiring immediate PCI surgery" is generated. The system then verifies semantic consistency by generating the executable query SELECT*FROM treatment_plan WHERE diagnosis = 'myocardial infarction' AND troponin>5.0. The system first uses the RoBERTa model to encode the original text and the generated SQL statement into 768-dimensional vectors. Hierarchical max pooling is used to compress the long text into a 256-dimensional joint semantic representation. The cosine similarity between the two is 0.78, and the threshold is dynamically adjusted to 0.82 (from 0.75) based on the text length. The attention alignment score detects that "PCI surgery" is missing from the response (with a difference in attention weight of 0.23), resulting in a mismatch. Dependency parsing then identifies the missing field as the treatment method. The model is then constrained using the prompt template "Supplementary interventional treatment method constraints" to iteratively generate a new query SELECT*...AND procedure_type = 'PCI'. The similarity improves to 0.84, but remains below the threshold. During the second revision, the condition "onset time < 12 hours" (based on PCI surgical guidelines in the knowledge graph) was added, and the similarity increased to 0.89. Because the similarity fluctuation did not exceed 15% in consecutive iterations, optimization continued until the third iteration, generating the condition SELECT *... AND procedure_type = 'PCI' AND onset_hours < 12, with a similarity of 0.91, passing verification. The adversarial detection module detected a logical conflict between "troponin I = 5.2" and the knowledge base's "normal value < 0.4." The case was marked as high-risk and sent to the medical review platform. After manual annotation confirmation, the encoder's sensitivity weight for biomarker values was reversed (parameter α was adjusted from 0.3 to 0.6), and the medical knowledge constraints of the generated model were revised.
[0134] The above-mentioned data query method and system based on natural language text systematically solves the problems of semantic deviation, inefficiency and domain adaptation in natural language query processing through four core technologies: dynamic masking to enhance semantic understanding, multi-hop path confidence optimization, heterogeneous data gated fusion and closed-loop verification iteration.
[0135] It should be understood that, although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily executed and completed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0136] Based on the same inventive concept, the embodiments of the present application also provide a method and system device for implementing the aforementioned method and system for data querying based on natural language text. The implementation solution provided by this device is similar to the implementation solution described in the aforementioned method. Therefore, the specific limitations of one or more embodiments of the method and system device for data querying based on natural language text provided below can be found in the above-mentioned limitations of the method and system for data querying based on natural language text, and will not be repeated here.
[0137] In an exemplary embodiment, Figure 2 As shown, a data query method and system device 400 based on natural language text is provided, including:
[0138] The dynamic masking and semantic encoding module 401 is used to convert the natural language text input by the user into a semantic vector sequence through dynamic masking preprocessing.
[0139] The structured entity extraction module 402 is used to extract key entities and inter-entity relationships in the semantic vector sequence to obtain a structured entity relationship set.
[0140] The knowledge graph expansion module 403 is used to match the structured entity relationship set with the knowledge graph nodes, expand the potential association path and generate a semantic graph.
[0141] The heterogeneous fusion and query generation module 404 performs heterogeneous fusion on the semantic graph and the text syntactic features to generate an intermediate query representation.
[0142] The query optimization module 405 is used to process the intermediate query representation to generate executable statements.
[0143] The response generation and verification module 406 is used to verify the semantic consistency between the response content of the executable statement and the original input, and iteratively regenerate the executable statement if it fails.
[0144] In one embodiment, the dynamic masking and semantic encoding module 401 is configured to:
[0145] Perform lemma processing on the input natural language text to obtain a lemma sequence;
[0146] Selecting continuous local subsequences in the continuous word sequence as word fragments, randomly selecting word fragments according to a preset ratio to replace them with special marks while retaining the position code;
[0147] Inputting the masked word sequence into a deep semantic encoding model to generate a semantic vector sequence;
[0148] The vector of the masked position is generated by aggregating the attention weights of adjacent words.
[0149] In one embodiment, the knowledge graph expansion module 403 is used to:
[0150] For each entity e in the normalized relation set i , calculate its relationship with the knowledge graph node v j Semantic similarity of ∈V:
[0151]
[0152] in is the entity encoding function, ψ(·) is the node encoding function, and sim(e i ,v j )≥θ s im's node pair, θ s im∈[0.6,0.8];
[0153] Matching node v j Perform three-hop traversal to extract all associated paths P path =(v j →v j +1→v j +2→v j +3), calculate the path confidence:
[0154] conf(P path )=Π[w jk w k (k+1) / (1+log(1+deg(v k )))]
[0155] where w jk is the edge weight, deg(v k ) is the node degree;
[0156] Keep conf(P path )≥θconf avg conf The path, θ conf ∈[1.2,1.5] is the dynamic adjustment coefficient, avg conf is the confidence of the current path;
[0157] Add the filtered path to the original semantic graph and update the edge weights between nodes as follows:
[0158] w new =γ·w old +(1-γ)·[conf(P path ) / max conf ]
[0159] Among them, w new is the updated edge weight, γ∈[0.3,0.6] is the weight inheritance factor, w old is the original edge weight, conf(P path ) is the path confidence, max conf The maximum path confidence of the current graph. By dynamically updating edge weights, screening high-confidence paths, and integrating multiple features, a heterogeneous semantic graph with semantic association identifiers is ultimately generated.
[0160] In one embodiment, the knowledge graph expansion module 403 is further configured to:
[0161] Based on bidirectional breadth-first search, the knowledge graph is traversed, starting from the user entity and expanding along the relationship edge to all nodes within three hops. In the preprocessing stage, low-frequency relationships and invalid nodes are pruned, and the node importance scores are pre-calculated using graph embedding.
[0162] Use Sentence-BERT to encode user entity descriptions and adjacent node attributes into 768-dimensional vectors, calculate cosine similarity, and integrate graph embedding similarity for weighting;
[0163] Based on the historical similarity distribution of the sliding window statistics, the top 30% quantile is taken as the initial threshold. The threshold is dynamically adjusted according to the real-time data flow. If the node density exceeds 200 / hop, the threshold is increased by 0.1 to suppress overload.
[0164] Sort the extended paths in descending order according to the total score C = 0.5W1 + 0.3W2 + 0.2*W3, and retain the top-N paths, where W1 is the path confidence conf(Ppath)conf(P path )conf(Ppath) is the log-normalized value, W2 is the weighted sum of the cosine similarity encoded by Sentence-BERT and the graph embedding similarity, and W3 is the path structure complexity score;
[0165] Detect the conflict relationship between the new path and the original semantic graph, and calculate the contradiction score between the new path and the original semantic graph based on the knowledge graph embedding. If it is greater than 0.8, the system automatically freezes the conflicting path, dynamically lowers the similarity threshold and marks the audit log. After manual review, the instructions trigger the graph neural network completion or parameter correction, and finally generate a heterogeneous semantic graph with version identification.
[0166] In one embodiment, the heterogeneous fusion and query generation module 404 is configured to:
[0167] Heterogeneous fusion of heterogeneous semantic graphs and text syntactic features, using a gating mechanism to dynamically adjust the contribution weights of semantic and syntactic features;
[0168] Generate confidence indicators in the semantic graph of node association paths that inherit the intention framework carrying logical constraints;
[0169] The conversion into an intermediate query representation supports the generation of executable query statements for relational and graph databases.
[0170] In one embodiment, the query optimization module 405 is configured to:
[0171] Extract the field access frequency matrix Facc and the conditional filtering efficiency matrix Efilt from the execution history log, where:
[0172] Facc[fi]=NtotalNaccess(fi)Efilt[cj]=∣D∣∣σcj(D)∣
[0173] Naccess is the number of times the field fi is accessed, σcj(D) is the data set after filtering by condition cj;
[0174] Based on the constraint condition set C = c1, ..., cn represented by the intermediate query, calculate the optimization weight of each condition:
[0175] wi=α·Efilt[ci]+β·∣ci∣∑f∈ciFacc[f]
[0176] Where α∈[0.5,0.8] is the filtering efficiency coefficient, and β∈[0.2,0.5] is the field correlation coefficient;
[0177] For the associated path set Ppath represented by the intermediate query, the path priority is adjusted according to the attenuation formula:
[0178] priority(p)=wpath·e-λ·h+μ·∣c∈p∣∑c∈pwc
[0179] Where h is the number of path hops, λ∈[0.1,0.3] is the attenuation factor, and μ∈[0.4,0.6] is the conditional weight fusion coefficient;
[0180] Generate the executable statement Qexec according to the optimized condition weight wi and path priority priority(p), and inject the semantic association identifier:
[0181] Qexec=conditional order ∪Sort(wi) ∪association path p ∣priority(p)>0.7 ∪semantic identity<fi,τ(fi)>
[0182] Where τ(fi) is the type label set of field fi in the semantic graph.
[0183] In one embodiment, the response generation and verification module 406 is configured to:
[0184] Use a pre-trained language model to encode the original input and generated response into high-dimensional semantic vectors, respectively. Dynamic pooling compression is used for long texts, or a multimodal encoder is used to process non-text inputs to obtain a joint semantic representation.
[0185] Calculate the cosine similarity between the semantic vectors of the original input text and the generated response text, dynamically adjust the threshold based on the text length, introduce the attention alignment score to assist in detecting local semantic shifts, and comprehensively determine whether the consistency meets the standards;
[0186] It locates low-similarity fields through dependency syntactic analysis, prioritizes replacing core semantic components, uses prompt constraints to generate directional corrections to the model, and adopts an iterative annealing strategy to gradually converge.
[0187] If the similarity of consecutive iterations drops by more than 15% or reaches the maximum number of iterations, the generation process is terminated and the retrieval enhancement generation is triggered to call the pre-stored answer from the knowledge base;
[0188] The adversarial detection module identifies logical contradictions / factual errors, pushes low-similarity cases to the manual annotation platform, and reversely updates the encoder and generative model parameters.
[0189] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the power supply safety management method as described above when executing the computer program.
[0190] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0191] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to the partial description of the method embodiments. The device embodiments described above are merely illustrative, wherein the components described as separate parts may or may not be physically separated, and the parts displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the disclosed solution. A person of ordinary skill in the art can understand and implement it without expending creative work.
[0192] The above-described embodiments merely represent several implementation methods of the embodiments of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent application. It should be noted that a person skilled in the art may make various modifications and improvements without departing from the concept of the embodiments of the present application, and these modifications and improvements fall within the scope of protection of the embodiments of the present application.
Claims
1. A data query method and system based on natural language text, characterized in that: include: Perform dynamic masking preprocessing on the input natural language text to generate a semantic vector sequence; Extracting key entities and their association relationships in the semantic vector sequence based on the attention mechanism to obtain a structured entity relationship set; Matching the structured entity relationship set with the knowledge graph nodes, expanding the potential association paths, and generating a heterogeneous semantic graph with multi-hop association paths and dynamic confidence weights; Heterogeneously fusing the heterogeneous semantic graph with text syntactic features to generate an intent framework carrying logical constraints, and converting it into an intermediate query representation; Based on the execution history log, the query condition sequence of the intermediate query representation is optimized to generate an executable statement carrying a semantic association identifier; Verify the semantic consistency between the response content of the executable statement and the original input, and iteratively regenerate the executable statement if it fails.
2. The method according to claim 1, characterized in that The step of performing dynamic masking preprocessing on the input natural language text to generate a semantic vector sequence includes: Perform lemma processing on the input natural language text to obtain a lemma sequence; Selecting continuous local subsequences in the continuous word sequence as word fragments, randomly selecting word fragments according to a preset ratio to replace them with special marks while retaining the position code; Inputting the masked word sequence into a deep semantic encoding model to generate a semantic vector sequence; The vector of the masked position is generated by aggregating the attention weights of adjacent words.
3. The method according to claim 1, characterized in that The heterogeneous fusion of the heterogeneous semantic graph and the text syntactic features to generate an intent framework carrying logical constraints and converting it into an intermediate query representation includes: The heterogeneous fusion of the heterogeneous semantic graph and the text syntactic features adopts a gating mechanism to dynamically adjust the contribution weights of the semantic and syntactic features; The node association path of the intention framework carrying logical constraints is generated to inherit the confidence index in the semantic graph; The conversion into an intermediate query representation supports the generation of executable query statements for relational and graph databases.
4. The method according to claim 1, wherein The matching of the normalized relationship set with the knowledge graph nodes and the expansion of the potential association paths to generate a heterogeneous semantic graph include: For each entity e in the normalized relation set i , calculate its relationship with the knowledge graph node v j Semantic similarity of ∈V: yes(and i ,v j )=[Σ(φ k (and i )·ψ k (v j ))] / [√Σφ k 2 (and i )·√Σψ k 2 (v j )] in is the entity encoding function, ψ(·) is the node encoding function, and sim(e i ,v j )≥θ s im's node pair, θ s im∈[0.6,0.8]; Matching node v j Perform three-hop traversal to extract all associated paths P path =(v j →v j +1→v j +2→v j +3), calculate the path confidence: conf(P path )=Π[w jk ·w k (k+1) / (1+log(1+deg(v k )))] where w jk is the edge weight, deg(v k ) is the node degree; Keep conf(P path )≥θ conf avg conf The path, θ conf ∈[1.2,1.5] is the dynamic adjustment coefficient, avg conf is the confidence of the current path; Add the filtered path to the original semantic graph and update the edge weights between nodes as follows: w new =γ·w old +(1-γ)·[conf(P path ) / max conf ] Among them, w new is the updated edge weight, γ∈[0.3,0.6] is the weight inheritance factor, w old is the original edge weight, conf(P path ) is the path confidence, max conf The maximum path confidence of the current graph. By dynamically updating edge weights, screening high-confidence paths, and integrating multiple features, a heterogeneous semantic graph with semantic association identifiers is ultimately generated.
5. The method according to claim 1, characterized in that The step of performing query condition sequence optimization processing on the intermediate query representation based on the execution history log to generate an executable statement carrying a semantic association identifier includes: Extract the field access frequency matrix Facc and the conditional filtering efficiency matrix Efilt from the execution history log, where: Facc[fi]=NtotalNaccess(fi)Efilt[cj]=∣D∣∣σcj(D)∣ Naccess is the number of times the field fi is accessed, σcj(D) is the data set after filtering by condition cj; Based on the constraint condition set C = c1, ..., cn represented by the intermediate query, calculate the optimization weight of each condition: wi=α·Efilt[ci]+β·∣ci∣∑f∈ciFacc[f] Where α∈[0.5,0.8] is the filtering efficiency coefficient, and β∈[0.2,0.5] is the field correlation coefficient; For the associated path set Ppath represented by the intermediate query, the path priority is adjusted according to the attenuation formula: priority(p)=wpath·e-λ·h+μ·∣c∈p∣∑c∈pwc Where h is the number of path hops, λ∈[0.1,0.3] is the attenuation factor, and μ∈[0.4,0.6] is the conditional weight fusion coefficient; Generate the executable statement Qexec according to the optimized condition weight wi and path priority priority(p), and inject the semantic association identifier: Qexec=conditional order ∪Sort(wi) ∪association path p ∣priority(p)>0.7 ∪semantic identity<fi,τ(fi)> Where τ(fi) is the type label set of field fi in the semantic graph.
6. The method according to claim 1, characterized in that The step of expanding the potential association path to generate a heterogeneous semantic graph further includes: Based on bidirectional breadth-first search, the knowledge graph is traversed, starting from the user entity and expanding along the relationship edge to all nodes within three hops. In the preprocessing stage, low-frequency relationships and invalid nodes are pruned, and the node importance scores are pre-calculated using graph embedding. Use Sentence-BERT to encode user entity descriptions and adjacent node attributes into 768-dimensional vectors, calculate cosine similarity, and integrate graph embedding similarity for weighting; Based on the historical similarity distribution of the sliding window statistics, the top 30% quantile is taken as the initial threshold. The threshold is dynamically adjusted according to the real-time data flow. If the node density exceeds 200 / hop, the threshold is increased by 0.1 to suppress overload. Sort the extended paths in descending order according to the total score C = 0.5W1 + 0.3W2 + 0.2*W3, and retain the top-N paths, where W1 is the path confidence conf(Ppath)conf(P path )conf(Ppath) is the log-normalized value, W2 is the weighted sum of the cosine similarity encoded by Sentence-BERT and the graph embedding similarity, and W3 is the path structure complexity score; Detect the conflict relationship between the new path and the original semantic graph, and calculate the contradiction score between the new path and the original semantic graph based on the knowledge graph embedding. If it is greater than 0.8, the system automatically freezes the conflicting path, dynamically lowers the similarity threshold and marks the audit log. After manual review, the instructions trigger the graph neural network completion or parameter correction, and finally generate a heterogeneous semantic graph with version identification.
7. The method according to claim 1, characterized in that Verifying the semantic consistency between the response content of the executable statement and the original input to obtain a verification result includes: Use a pre-trained language model to encode the original input and generated response into high-dimensional semantic vectors, respectively. Dynamic pooling compression is used for long texts, or a multimodal encoder is used to process non-text inputs to obtain a joint semantic representation. Calculate the cosine similarity between the semantic vectors of the original input text and the generated response text, dynamically adjust the threshold based on the text length, introduce the attention alignment score to assist in detecting local semantic shifts, and comprehensively determine whether the consistency meets the standards; It locates low-similarity fields through dependency syntactic analysis, prioritizes replacing core semantic components, uses prompt constraints to generate directional corrections to the model, and adopts an iterative annealing strategy to gradually converge. If the similarity of consecutive iterations drops by more than 15% or reaches the maximum number of iterations, the generation process is terminated and the retrieval enhancement generation is triggered to call the pre-stored answer from the knowledge base; The adversarial detection module identifies logical contradictions / factual errors, pushes low-similarity cases to the manual annotation platform, and reversely updates the encoder and generative model parameters.
8. A data query method and system device based on natural language text, characterized in that: Includes the following modules: Dynamic masking and semantic encoding module, used to convert the natural language text input by the user into a semantic vector sequence through dynamic masking preprocessing; The structured entity extraction module is used to extract key entities and inter-entity relationships from the semantic vector sequence to obtain a set of structured entity relationships; The knowledge graph extension module is used to match structured entity relationship sets with knowledge graph nodes, expand potential association paths and generate semantic graphs; A heterogeneous fusion and query generation module, which heterogeneously fuses the semantic graph with text syntactic features to generate an intermediate query representation; Query optimization module, used to process intermediate query representation to generate executable statements; The response generation and verification module is used to verify the semantic consistency between the response content of the executable statement and the original input. If it fails, the executable statement is iteratively regenerated.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Multi-modal mixed retrieval enhancement generation method and device, equipment, medium and product
CN120910319A
Multimodal hybrid retrieval augmented generation method and apparatus, device, medium, and product
CN120910319B
Automatic historical text classification method based on natural language processing
CN120973942A
Long file intelligent analysis method and system based on dynamic partitioning and semantic fusion
CN121093963A
Natural language intelligent analysis and data query instruction generation method based on large model
CN121188079A