A data intelligent query method and system for a space division scene

By introducing feature completeness verification and dual correction mechanisms into the space separation unit, the problems of ambiguity in query intent and semantic gap in the space separation unit are solved, realizing high-security and high-precision data query, and improving query success rate and data security.

CN121681574BActive Publication Date: 2026-06-05ZHEJIANG UNIV +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
ZHEJIANG UNIV
Filing Date
2026-02-09
Publication Date
2026-06-05

Smart Images

  • Figure CN121681574B_ABST
    Figure CN121681574B_ABST
Patent Text Reader

Abstract

The application discloses a kind of data intelligent query method and system for air space scene, belong to computer data processing and artificial intelligence technical field.The method includes: receiving user natural language query instruction, based on the element set model of pre-set core element completeness verification is carried out;Structural prompt word containing few sample examples and authority constraint is constructed, and large language model is guided to generate preliminary SQL statement;Introduce rule-driven syntax repair and execution feedback-driven logic correction closed loop, type adaptation and authority injection are carried out to SQL statement.The application solves the query intention ambiguity and SQL generation illusion problem in industrial scene by digital element verification and multiple correction mechanism, realizes high safety, high precision end-to-end data query.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer data processing and artificial intelligence technology, specifically relating to a natural language to SQL intelligent query method that combines a large language model (LLM) and database technology, which is particularly suitable for data retrieval in vertical industrial fields such as air separation units. Background Technology

[0002] With the deepening of digital transformation in process industries, enterprises have accumulated massive amounts of operational data. To lower the barrier to data acquisition, intelligent data querying technology based on large models has become a research hotspot. However, in specialized fields such as air separation units, directly applying general-purpose large models for database queries faces the following significant challenges:

[0003] 1) The ambiguity and divergence of query intent: Industrial queries often implicitly contain specific contextual constraints (such as a specific time range or a specific factory unit). Without strict element validation, the model is prone to generating SQL statements that perform full table scans, leading to a sharp drop in database performance.

[0004] 2) Semantic gap between technical terms and table structure: Industrial database table structure is complex, and field names often use abbreviations (such as using FI_101 to represent "air flow rate into the tower"), which has a large semantic difference from the natural language expression of users. General large models lack domain knowledge and are difficult to accurately map.

[0005] 3) Lack of security and accuracy in generated results: SQL statements generated by general-purpose large models often contain syntax errors and lack awareness of enterprise data permissions. For example, the model might generate SQL queries for all factory data, leading to a serious risk of data leakage (unauthorized queries). Existing Text-to-SQL technologies focus primarily on accuracy, neglecting the necessary access control and static correction mechanisms required in industrial scenarios. Summary of the Invention

[0006] The purpose of this invention is to overcome the shortcomings of existing technologies and provide a data intelligent query method and system for spatial division scenarios. This invention achieves highly reliable intelligent data query by introducing mathematical element completeness verification, entity linking based on vector space, and a dual correction mechanism of "rules + model".

[0007] The specific technical solution adopted in this invention is as follows:

[0008] Firstly, this invention provides a data intelligent query method for spatial division scenarios, as detailed below:

[0009] S1: Receive natural language query commands Extracting using named entity recognition technology Entity set in Based on a predefined set of core elements in the space division domain right Perform a completeness check;

[0010] If the completeness check passes, execute S2; if the completeness check fails, block the subsequent generation process and return a missing element prompt to guide the user to complete the elements.

[0011] S2: Based on the above Semantic association is performed on database metadata to retrieve target table structure information relevant to the query intent. Combining the retrieved target table structure information, few sample examples, and the current user's permission scope, structured prompt words are constructed and input into a large language model to generate preliminary SQL statements. Then execute S3;

[0012] S3: Regarding the above Perform rule-based static repair and forced privilege injection to obtain secure SQL statements. and in the sandbox environment Perform pre-execution verification;

[0013] If the pre-execution verification is successful, the final SQL statement will be output. If the pre-execution verification fails, the database error log is captured to construct structured feedback prompts, which are then returned to S2 to drive the large language model to dynamically self-correct the failed SQL until the pre-execution verification passes or the preset maximum number of iterations is reached.

[0014] Preferably, the completeness verification method in step S1 is as follows:

[0015] Define the core elements set of the space division domain ;in For time window, The main body of the device, For process indicators; extract entity sets from Q. and define the verification function. :

[0016] ;

[0017] If and only if If the integrity check passes, S2 can be executed; otherwise, the integrity check is considered to have failed.

[0018] Preferably, in step S2, the specific method for performing semantic association to recall target table structure information related to the query intent is as follows:

[0019] A vector index is constructed on the database metadata, which includes at least table names, field names, field types, field aliases, and / or descriptions of business meaning; the... Encoded as query vector ,calculate Similarity score between the data and the database metadata vector, and based on a threshold. Retrieve the structure information of the Top-K relevant tables and use it as the basis for generating the large language model. A concise context.

[0020] Preferably, in step S3, the rule-based static repair and forced permission injection method is as follows:

[0021] S31-1: Analysis of the above The abstract syntax tree and / or regular expression structure are used to detect the consistency between the field type and the literal type in the predicate condition; when the target field is detected to be a string type and the predicate is assigned a numeric literal, single quotes are automatically added to the literal to correct it to string format;

[0022] S31-2: Parse the current user's identity credentials to obtain the set of permission scopes. ,in It must contain at least one of the following: a set of permitted company codes, a set of regions, and / or a set of device ranges; Mapping to row-level filter clause generation function Construct permission filtering clauses ;in It must include at least the permissions field. For filtering conditions of predicates, This is one or an equivalent permission field in the identification information, including the company code;

[0023] S31-21: When the SQL statement already has a WHERE clause, Concatenate using AND; when the SQL statement does not have a WHERE clause, insert WHERE after the FROM and / or JOIN structure and append it. ;

[0024] S31-22: When the SQL contains subqueries and / or UNION, UNION ALL structures, execute S321 for each SELECT query block to perform structured injection, thereby forcing row-level permission restrictions. .

[0025] Preferably, the specific method for handling the failure of the pre-execution verification in step S3 is as follows:

[0026] S32-1: Execute the above in a sandbox environment. When the database execution fails, the exception object is captured, the error code and error information are extracted, and the error is classified into at least one type according to the preset error mapping rules: syntax parsing error, object not found error, field / alias mismatch error, function signature or data type mismatch error; then S32-2 is executed.

[0027] S32-2: Constructing Structured Feedback Prompts It includes at least: the failed SQL statement, the table structure entity definition for error message recall, the original natural language query intent, and a set of immutable constraints. ;in It must contain at least constraints that allow only the generation of SELECT query statements and require that permission filter clauses be retained or re-injected; then execute S2.

[0028] Preferably, in S3, when the maximum number of iterations is reached... If the verification still fails, the dynamic self-correction process is terminated and a standardized error response is returned; if the SQL text or error code generated in two consecutive iterations is the same and the SQL structure has not changed, the circuit breaker is triggered in advance to terminate the process.

[0029] Secondly, the present invention provides a data intelligent query system for spatial division scenarios, comprising:

[0030] The semantic parsing and element completeness verification module is used to receive natural language query commands. Extracting using named entity recognition technology Entity set in Based on a predefined set of core elements in the space division domain right Perform a completeness check; if the completeness check passes, execute the constraint-enhanced query statement generation module; if the completeness check fails, block the subsequent generation process and return a missing element prompt to guide the user to complete the elements;

[0031] The constraint-enhanced query generation module is used to generate queries based on the constraints. Semantic association is performed on database metadata to retrieve target table structure information relevant to the query intent. Combining the retrieved target table structure information, few sample examples, and the current user's permission scope, structured prompt words are constructed and input into a large language model to generate preliminary SQL statements. Then, a closed-loop correction process is implemented, combining rules and the model.

[0032] A rule-and-model collaborative correction closed-loop module is used to correct the aforementioned... Perform rule-based static repair and forced privilege injection to obtain secure SQL statements. and in the sandbox environment Perform pre-execution verification; if the pre-execution verification is successful, output the final SQL statement. If the pre-execution verification fails, the database error log is captured to construct structured feedback prompts, and the constraint-enhanced query statement generation module is returned to drive the large language model to dynamically self-correct the failed SQL until the pre-execution verification passes or the preset maximum number of iterations is reached.

[0033] Thirdly, the present invention provides a computer program product, including a computer program / instruction, which, when executed by a processor, can realize the intelligent data query method for spatial division scenarios as described in any of the first aspects.

[0034] Fourthly, the present invention provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the intelligent data query method for spatial division scenarios as described in any of the first aspects.

[0035] Fifthly, the present invention provides a computer electronic device, including a memory and a processor;

[0036] The memory is used to store computer programs;

[0037] The processor is configured to, when executing the computer program, implement the intelligent data query method for spatial division scenarios as described in any of the first aspects.

[0038] Compared with the prior art, the present invention has the following advantages:

[0039] 1) High query accuracy: Through steps such as element completeness verification, the semantic alignment problem between industry terms and database fields is effectively solved.

[0040] 2) Strong robustness: The dual correction loop enables the system to have debugging capabilities similar to those of human engineers, which greatly improves the success rate of complex queries.

[0041] 3) Security Guarantee: Mandatory element verification and permission injection mechanisms ensure that the data query process complies with enterprise-level security standards. Attached Figure Description

[0042] Figure 1 This is a flowchart illustrating the overall process architecture of the method of the present invention. Detailed Implementation

[0043] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Many specific details are set forth in the following description to provide a thorough understanding of the present invention. However, the present invention can be practiced in many other ways different from those described herein, and those skilled in the art can make similar modifications without departing from the spirit of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below. Technical features in various embodiments of the present invention can be combined accordingly without mutual conflict.

[0044] like Figure 1 As shown, this invention provides a data intelligent query method for spatial division scenarios. The method includes: receiving a user's natural language query command; performing a core element completeness check based on a preset element set model; constructing structured prompt words containing few sample examples and permission constraints to guide a large language model to generate a preliminary SQL statement; introducing a rule-driven syntax repair and execution feedback-driven logic correction closed loop to perform type adaptation and permission injection on the SQL statement.

[0045] The method of the present invention specifically includes the following steps:

[0046] S1, Semantic parsing and element completeness verification:

[0047] Receive natural language query commands Extracting using named entity recognition technology Entity set in Based on a predefined set of core elements in the space division domain right Perform a completeness check.

[0048] If the completeness check passes, execute S2;

[0049] If the completeness check fails, the subsequent generation process is blocked and a missing element prompt is returned to guide the user to complete the elements.

[0050] In other words, this step implements a core element completeness verification based on set theory, establishing a pre-verification mechanism based on set theory to prevent resource waste caused by fuzzy queries. Define the complete element set for spatially sparse data queries. It includes time dimension, subject dimension, and indicator dimension. Before SQL generation, natural language processing techniques are used to extract the entity set from the user command. The system determines... Is it The mechanism uses a subset of the data to determine whether to allow a request. This mathematically avoids the risk of unbounded queries.

[0051] In a preferred embodiment of the present invention, the completeness verification method in this step is as follows:

[0052] Define the core elements set of the space division domain ;in For time window, The main body of the device, For process parameters. Extract the entity set from Q. and define the verification function. :

[0053] ;

[0054] If and only if If the integrity check passes, S2 can be executed; otherwise, the integrity check is considered to have failed.

[0055] S2, Generation of query statements with enhanced constraints:

[0056] Based on the above Semantic association is performed on database metadata to retrieve target table structure information relevant to the query intent. Combining the retrieved target table structure information, few sample examples, and the current user's permission scope, structured prompt words are constructed and input into a large language model to generate preliminary SQL statements. Then execute S3.

[0057] In other words, this step implements a table structure retrieval mechanism based on vector space. Before SQL generation, the system vectorizes and encodes database metadata (including table names, field names, field types, aliases, and business definitions) to build a metadata vector index. The system then translates natural language query commands... Encode as a vector Through calculation Similarity scores between the data and metadata vectors are calculated, and the Top-K most relevant table structures are recalled based on a threshold τ. These recalled table structures are used as the basis for generating a large language model. The simplified context input at that time provides structural constraints for query generation.

[0058] In a preferred embodiment of the present invention, the specific method for performing semantic association to recall target table structure information related to the query intent in this step is as follows:

[0059] Build vector indexes on database metadata (including at least table names, field names, field types, field aliases, and / or business meaning descriptions); Encoded as query vector ,calculate Similarity score between the vector and the database metadata, and based on a threshold. Retrieve the structure information of the Top-K relevant tables and use it as the basis for generating the large language model. A concise context.

[0060] S3, a closed-loop correction mechanism combining rules and models:

[0061] Regarding the above Perform rule-based static repair and forced privilege injection to obtain secure SQL statements. and in the sandbox environment Perform pre-execution verification.

[0062] If the pre-execution verification is successful, the final SQL statement will be output. ;

[0063] If the pre-execution verification fails, the database error log is captured to construct structured feedback prompts, which are then returned to S2 to drive the large language model to dynamically self-correct the failed SQL until the pre-execution verification passes or the preset maximum number of iterations is reached.

[0064] In other words, this step implements a dual-correction closed loop of "static rules + dynamic feedback," innovatively constructing a layered correction architecture: 1) Static correction layer: It does not rely on the large model but parses the SQL abstract syntax tree based on code rules. It automatically corrects common data type errors (such as strings without quotes) and permission deficiencies (by forcibly injecting WHERE filtering conditions). 2) Dynamic correction layer: When the statically corrected SQL encounters an error during execution in the database sandbox, the system captures the error log returned by the database engine, feeding it back as a negative sample to the large model, triggering a "reflection-rewrite" process.

[0065] In a preferred embodiment of the present invention, the rule-based static repair and forced permission injection method in this step is specifically as follows:

[0066] S31-1, Type Compatibility:

[0067] Analysis The abstract syntax tree and / or regular expression structure are used to detect the consistency between the field type and the literal type in the predicate condition; when the target field is detected to be a string type and the predicate is assigned a numeric literal, single quotes are automatically added to the literal to correct it to string format;

[0068] S31-2, Forced Privilege Injection:

[0069] Parse the current user's identity credentials to obtain the set of permission scopes. ,in It must contain at least one of the following: a set of permitted company codes, a set of regions, and / or a set of device ranges; Mapping to row-level filter clause generation function Construct permission filtering clauses:

[0070] ;

[0071] in It must include at least the permissions field. For filtering conditions of predicates, This is one or an equivalent permission field in the identification information, including the company code;

[0072] Then, structured SQL injection is performed, as follows:

[0073] S31-21: When the SQL statement already has a WHERE clause, Concatenate using AND; when the SQL statement does not have a WHERE clause, insert WHERE after the FROM and / or JOIN structure and append it. ;

[0074] S31-22: When the SQL contains subqueries and / or UNION, UNION ALL structures, execute S321 for each SELECT query block to perform structured injection, thereby forcing row-level permission restrictions. .

[0075] In a preferred embodiment of the present invention, the specific method after the pre-execution verification fails is as follows:

[0076] S32-1, Error Capture and Classification:

[0077] Execute in a sandbox environment When the database execution fails, the exception object is captured, the error code and error information are extracted, and the error is classified into at least one type according to the preset error mapping rules: syntax parsing error, object not found error, field / alias mismatch error, function signature or data type mismatch error; then S32-2 is executed.

[0078] S32-2, Correction of prompt word construction:

[0079] Build structured feedback prompts It includes at least: the failed SQL statement, the table structure entity definition for error message recall, the original natural language query intent, and a set of immutable constraints. ;in It must contain at least the constraints "only allow the generation of SELECT query statements" and "the permission filter clause must be retained or re-injected"; then execute S32-3.

[0080] S32-3, Iterative Generation, Static Review and Verification:

[0081] Set the maximum number of iterations. (For example, the default is 3 times), so that the query statement generated by the S2 constraint enhancement is the first one. The output of the large language model is For each round of output Executing static repair and forced permission injection in S31-1~S31-2 yielded the following results. Then re-execute the verification in the sandbox environment; if the verification passes, output the final result. If the verification fails, update the correction prompt (at least append the most recent failed SQL and the corresponding error message) and proceed to the next iteration;

[0082] S32-4, Infinite Loop Circuit Breaker: When the maximum number of iterations is reached... If the verification still fails, the dynamic self-correction process is terminated and a standardized error response is returned; if the SQL text or error code generated in two consecutive iterations is the same and the SQL structure has not changed, the circuit breaker is triggered in advance to terminate the process.

[0083] The methods and effects of the present invention will be specifically illustrated below through examples.

[0084] Example

[0085] like Figure 1 As shown, this embodiment provides a data intelligent query method for air separation scenarios. Specifically, it takes the data query of an air separation unit in a chemical plant as an example to demonstrate the complete closed loop from natural language to secure SQL.

[0086] Step 1: Semantic parsing and element completeness verification (S1)

[0087] Suppose a user inputs the query command Q: "Query yesterday's argon fraction data for air separation tower No. 2." The system performs semantic parsing on this query command and extracts the entity set. This includes at least time elements, device elements, and indicator elements, and can be represented as follows:

[0088] .

[0089] The system predefines the core element set of the space division domain. And based on this, define the verification function:

[0090] ;

[0091] If and only if If the verification is successful, proceed to the next step.

[0092] In another comparative scenario, if the user only enters a command that lacks key context, such as "query argon fraction", the system determines that the time element and / or device element are missing, and triggers an exception handling strategy: blocking the subsequent generation process and returning missing element guidance information on the interactive terminal (e.g., prompting the user to supplement the time range and device number in an interactive card manner) to avoid misunderstanding or high-risk queries.

[0093] Step 2: Generate query statements with enhanced constraints (S2)

[0094] After obtaining the simplified context, the system first constructs a vector index for the database metadata, encodes the natural language query instruction into a query vector, and recalls the Top-K relevant table structure information based on the similarity score threshold. The system combines the recalled table structure information, few sample examples, and the current user's permission scope to construct structured prompt words and input them into the large language model to generate candidate database query statements corresponding to the query intent.

[0095] Step 3: Closed-loop correction of rules and models (S3)

[0096] The system first performs rule-based static repair and security constraint injection on the candidate query statements, including but not limited to:

[0097] Business mapping repair: Map natural language indicators or descriptions to database-recognizable business tag numbers / standard codes (e.g., map descriptions related to "argon fraction" to corresponding measurement point tag numbers);

[0098] Type and syntax adaptation: Perform consistency checks and repairs on the data type and field validity of predicate conditions based on the target entity;

[0099] Forced permission injection: The access control conditions corresponding to the user's permission scope are injected into the query statement as forced filtering conditions to prevent unauthorized access.

[0100] After static repair is completed, the system performs pre-execution verification on the repaired query statement in a sandbox environment. If the database returns error information (e.g., field not found, column name mismatch), the system categorizes the errors according to their type (syntax parsing error, object not found, field / alias mismatch, function signature or data type mismatch, etc.), encapsulates the error log and failed SQL into structured correction prompts, re-inputs the large language model to generate the corrected SQL, and re-executes static repair and sandbox verification. If three consecutive iterations fail or duplicate SQL text is detected, a circuit breaker mechanism is triggered and a standardized error response is output. The system captures the error information and constructs feedback prompts containing "original instruction, current query statement, target entity, and error information," driving the large language model to self-reflect and rewrite, outputting the corrected query statement and entering the next round of sandbox pre-execution until pre-execution passes or the preset maximum number of iterations is reached.

[0101] Finally, after satisfying security policies and executability verification, the system executes the final query on the target data source and returns the query results in the form of tables or charts.

[0102] This invention solves the problems of ambiguous query intent and SQL generation illusion in industrial scenarios by using digital element verification and multiple correction mechanisms, and achieves high-security and high-precision end-to-end data query.

[0103] The embodiments described above are merely preferred embodiments of the present invention and are not intended to limit the invention. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of the invention. Therefore, all technical solutions obtained through equivalent substitution or transformation fall within the protection scope of the present invention.

Claims

1. A data intelligent query method for spatial division scenarios, characterized in that, Specifically as follows: S1: Receive natural language query commands Extracting using named entity recognition technology Entity set in Based on a predefined set of core elements in the space division domain right Perform a completeness check; If the completeness check passes, execute S2; if the completeness check fails, block the subsequent generation process and return a missing element prompt to guide the user to complete the elements. S2: Based on the above Semantic association is performed on database metadata to retrieve target table structure information relevant to the query intent. Combining the retrieved target table structure information, few sample examples, and the current user's permission scope, structured prompt words are constructed and input into a large language model to generate preliminary SQL statements. Then execute S3; S3: Regarding the above Perform rule-based static repair and forced privilege injection to obtain secure SQL statements. and in the sandbox environment Perform pre-execution verification; If the pre-execution verification is successful, the final SQL statement will be output. ; If the pre-execution verification fails, the database error log is captured to construct structured feedback prompts, which are then returned to S2 to drive the large language model to dynamically self-correct the failed SQL until the pre-execution verification passes or the preset maximum number of iterations is reached. In S3, the rule-based static repair and forced permission injection method is as follows: S31-1: Analysis of the above Abstract syntax trees and / or regular expression structures are used to detect the consistency between field types and literal types in predicate conditions; When it is detected that the target field is a string type and the predicate is assigned a numeric literal, single quotes are automatically added to the literal to correct it to string format; S31-2: Parse the current user's identity credentials to obtain the set of permission scopes. ,in It must contain at least one of the following: a set of permitted company codes, a set of regions, and / or a set of device ranges; Mapping to row-level filter clause generation function Construct permission filtering clauses ;in It must include at least the permissions field. For filtering conditions of predicates, This includes identification information such as company code; S31-21: When the SQL statement already has a WHERE clause, Concatenate using AND; when the SQL statement does not have a WHERE clause, insert WHERE after the FROM and / or JOIN structure and append it. ; S31-22: When the SQL contains subqueries and / or UNION or UNION ALL structures, execute S31-21 separately for each SELECT query block to inject permission filtering conditions, thereby forcing row-level permission restrictions. .

2. The intelligent data query method for spatial division scenarios according to claim 1, characterized in that, In S1, the completeness verification method is as follows: Define the core elements set of the space division domain ;in For time window, The main body of the device, For process indicators; extract entity sets from Q. And define the verification function. : ; If and only if If the integrity check passes, S2 can be executed; otherwise, the integrity check is considered to have failed.

3. The intelligent data query method for spatial division scenarios according to claim 1, characterized in that, In step S2, the specific method for performing semantic association to recall target table structure information related to the query intent is as follows: A vector index is constructed on the database metadata, which includes at least table names, field names, field types, field aliases, and / or descriptions of business meaning; the... Encoded as query vector ,calculate Similarity score between the data and the database metadata vector, and based on a threshold. Retrieve the structure information of the Top-K relevant tables and use it as the basis for generating the large language model. A concise context.

4. The intelligent data query method for spatial division scenarios according to claim 1, characterized in that, In S3, the specific method after the pre-execution verification fails is as follows: S32-1: Execute the above in a sandbox environment. When the database fails, the exception object is captured, and the error code and error information are extracted. The error is then categorized into at least one type based on the preset error mapping rules: syntax parsing error, object not found error, field / alias mismatch error, function signature or data type mismatch error; then S32-2 is executed. S32-2: Constructing Structured Feedback Prompts It includes at least: the failed SQL statement, the table structure entity definition for error message recall, the original natural language query intent, and a set of immutable constraints. ;in It must include at least the constraints that allow only the generation of SELECT query statements and that require the retention or re-injection of permission filtering clauses; Then S2 is executed.

5. The intelligent data query method for spatial division scenarios according to claim 1, characterized in that, In S3, when the maximum number of iterations is reached... If the verification still fails, the dynamic self-correction process will be terminated. If the SQL text or error code generated in two consecutive iterations is the same and the SQL structure has not changed, the circuit breaker will be triggered prematurely to terminate the process.

6. A data intelligent query system for space division scenarios, characterized in that, include: The semantic parsing and element completeness verification module is used to receive natural language query commands. Extracting using named entity recognition technology Entity set in Based on a predefined set of core elements in the space division domain right Perform a completeness check; if the completeness check passes, execute the constraint-enhanced query statement generation module. If the completeness check fails, the subsequent generation process is blocked and a missing element prompt is returned to guide the user to complete the elements. The constraint-enhanced query generation module is used to generate queries based on the constraints. Semantic association is performed on database metadata to retrieve target table structure information relevant to the query intent. Combining the retrieved target table structure information, few sample examples, and the current user's permission scope, structured prompt words are constructed and input into a large language model to generate preliminary SQL statements. Then, a closed-loop correction process is implemented, combining rules and the model. A rule-and-model collaborative correction closed-loop module is used to correct the aforementioned... Perform rule-based static repair and forced privilege injection to obtain secure SQL statements. and in the sandbox environment Perform pre-execution verification; If the pre-execution verification is successful, the final SQL statement will be output. ; If the pre-execution verification fails, the database error log is captured to construct structured feedback prompts and return to the constraint-enhanced query statement generation module to drive the large language model to dynamically self-correct the failed SQL until the pre-execution verification passes or the preset maximum number of iterations is reached. The rule-based static repair and forced permission injection method is as follows: S31-1: Analysis of the above Abstract syntax trees and / or regular expression structures are used to detect the consistency between field types and literal types in predicate conditions; When it is detected that the target field is a string type and the predicate is assigned a numeric literal, single quotes are automatically added to the literal to correct it to string format; S31-2: Parse the current user's identity credentials to obtain the set of permission scopes. ,in It must contain at least one of the following: a set of permitted company codes, a set of regions, and / or a set of device ranges; Mapping to row-level filter clause generation function Construct permission filtering clauses ;in It must include at least the permissions field. For filtering conditions of predicates, This is one or an equivalent permission field in the identification information, including the company code; S31-21: When the SQL statement already has a WHERE clause, Concatenate using AND; when the SQL statement does not have a WHERE clause, insert WHERE after the FROM and / or JOIN structure and append it. ; S31-22: When the SQL contains subqueries and / or UNION or UNION ALL structures, execute S31-21 separately for each SELECT query block to inject permission filtering conditions, thereby forcing row-level permission restrictions. .

7. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it can realize the intelligent data query method for spatial division scenarios as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the intelligent data query method for spatial division scenarios as described in any one of claims 1 to 5.

9. A computer electronic device, characterized in that, Including memory and processor; The memory is used to store computer programs; The processor is configured to implement the intelligent data query method for spatial division scenarios as described in any one of claims 1 to 5 when executing the computer program.

Citation Information

Patent Citations

  • Method for correcting nonstandard SQL (Structured Query Language) statement based on large language model

    CN119003563A

  • Data query method, device and system based on large model and medium

    CN119848080A