City safety risk information retrieval method based on text2sql, electronic device and storage medium

By integrating multi-source data and performing natural language parsing and SQL generation through the text2sql intelligent retrieval system, the problems of scattered storage and insufficient semantic understanding of urban safety risk information have been solved. This has enabled efficient and accurate information retrieval and visualization, meeting the real-time and reliability requirements of urban safety management.

CN122364252APending Publication Date: 2026-07-10BEIJING COMPUTING CENT +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING COMPUTING CENT
Filing Date
2026-04-16
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

Urban safety risk information comes from scattered sources and comes in various formats. Traditional SQL queries require manual writing and rely on technical skills. Keyword retrieval is difficult to handle complex queries and lacks semantic understanding, resulting in high difficulty in information retrieval, many false positives and false negatives, and failing to meet the needs of urban safety management.

Method used

An intelligent retrieval system based on text2sql is adopted. Through an end-to-end process of multi-source data integration, natural language parsing and SQL generation, it enables users to directly query in natural language. Combined with vector databases and domain knowledge bases, semantic expansion and SQL optimization are performed to generate accurate SQL query statements and display them visually.

Benefits of technology

It enables non-professional users to efficiently and accurately obtain urban safety risk information, lowers the technical threshold, improves the accuracy of information retrieval and system stability, and meets the real-time and reliability requirements of urban safety management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122364252A_ABST
    Figure CN122364252A_ABST
Patent Text Reader

Abstract

The application provides a city safety risk information retrieval method based on text2sql, an electronic device and a storage medium. The process includes data integration and preprocessing, text2sql model construction and training, natural language query processing, SQL statement generation and execution, result processing and display. This method realizes the full automation of the operation of the user directly and accurately obtaining scattered risk information and obtaining intuitive visual results in natural language, to solve the three core problems of high technical threshold of non-professional user database retrieval, difficulty of multi-source heterogeneous data integration management, and insufficient accuracy of SQL generation caused by semantic gap and context loss in professional field query, which has important wisdom city theoretical innovation research significance and wide industrialization use value.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of smart city and data governance technology, and in particular to a method, electronic device and storage medium for retrieving urban security risk information based on text2sql. Background Technology

[0002] In the process of rapid urban development, urban safety faces increasingly complex and diverse challenges. Fires, natural disasters, public health emergencies, traffic accidents, and other safety risks constantly threaten the normal operation of cities and the lives and property of residents. To effectively prevent and respond to these risks, city managers need to quickly and accurately obtain various information related to urban safety risks in order to formulate scientific and reasonable decisions and emergency plans.

[0003] However, the management and retrieval of urban safety risk information currently faces numerous problems. On the one hand, urban safety risk information comes from a wide range of sources, including regulatory data from government departments, production and operation data from enterprises, feedback from the public, and data collected by various sensors. This data is scattered and stored in different systems and databases. For example, fire records, traffic accident data, and sensor data have different formats, lacking unified management and integration. Traditional SQL queries require manual writing and rely on technical skills, making information retrieval difficult. On the other hand, traditional information retrieval methods are mainly based on keyword matching. Keyword retrieval is difficult to handle complex queries, such as cases involving hazardous chemicals in downtown fires in the past month. For complex query requirements, especially those involving semantic understanding and logical relationships, it is difficult to accurately understand user intent. The retrieval results often contain a large number of false positives and false negatives, failing to meet the actual needs of urban safety management.

[0004] Therefore, there is an urgent need in this field for a technology that can overcome the above-mentioned shortcomings and efficiently and accurately retrieve urban safety risk information to address the deficiencies of existing technologies.

[0005] It should be noted that the above description of the technical background is only for the purpose of clearly and completely explaining the technical solutions of the present invention and facilitating understanding by those skilled in the art. It should not be assumed that these technical solutions are known to those skilled in the art simply because they have been described in the technical background section of the present invention. Summary of the Invention

[0006] The purpose of this invention is to construct a Text2SQL-based intelligent retrieval system for the vertical field of urban safety risks by integrating natural language processing and database query technologies and designing an end-to-end process that includes multi-source data integration, natural language parsing and expansion, SQL generation, and RAG enhancement. This system enables users to directly and accurately obtain scattered risk information and obtain intuitive and visualized results using natural language, thus solving three core problems: high technical barriers for non-professional users to retrieve databases, difficulty in integrating and managing multi-source heterogeneous data, and insufficient accuracy of SQL generation due to semantic gaps and lack of context in professional field queries. This invention has significant theoretical innovation value for smart cities and broad industrial application value.

[0007] To achieve the above objectives, the present invention provides the following technical solution: A method for retrieving urban safety risk information based on text2sql includes the following steps; Step S1: Data Integration and Preprocessing: Collect urban safety risk-related data from multiple heterogeneous data sources, clean and standardize the collected data, and then store it in the target database. The multiple heterogeneous data sources include at least two of the following: authoritative regulatory databases, enterprise production safety databases, public interaction platform data, and IoT sensor monitoring data. The cleaning and standardization process includes: removing duplicate and erroneous data, and converting date and address information from different heterogeneous data sources into a unified standard format. Step S2: Text2SQL Model Construction and Training: Based on natural language query statements in the urban safety risk domain and their corresponding SQL statements, a training dataset is constructed. The deep learning-based text2SQL model is trained using this training dataset to obtain a trained text2SQL model. The text2SQL model is either a Seq2SQL model or a SyntaxSQLNet model. The construction of the training dataset includes: using NLTK or SpaCy tools to perform word segmentation and part-of-speech tagging on the natural language query statements, and using SQL parsing tools to standardize the corresponding SQL statements. Step S3: Natural Language Query Processing: Receive a natural language query input by the user, parse and identify the intent of the natural language query, and semantically expand the natural language query based on a knowledge graph of urban security risk domains; the semantic expansion of the natural language query based on the knowledge graph of urban security risk domains includes: Based on the query intent determined in the intent recognition, risk type, geographical environment, historical cases or domain specification text associated with the query entity are obtained from the knowledge graph; The obtained related information is used as an extended condition to supplement the semantics of the original natural language query; Step S4: SQL Statement Generation and Execution: Input the semantically expanded natural language query into the trained text2sql model to generate the corresponding SQL query statement; optimize and enhance the SQL query statement using retrieval enhancement generation technology, combined with domain knowledge context retrieved from the vector database; execute the optimized SQL query statement to obtain the query results from the target database; the optimization and enhancement of the SQL query statement using retrieval enhancement generation technology, combined with domain knowledge context retrieved from the vector database, includes: The natural language query is converted into a query vector, and semantically similar domain knowledge fragments are retrieved from the vector database. The domain knowledge fragments include domain specification documents, historical case descriptions, or standard SQL templates. The retrieved domain knowledge fragments are used as contextual hints and input into the text2sql model along with the natural language query to generate a more accurate SQL query statement; Step S5: Result Processing and Display: Filter and sort the query results, and display the processed query results to the user in a visual form.

[0008] Optionally, the visualization may take at least one of the following forms: Mark the locations of risk events or accidents on a map; Use time-series charts to show the changing trends of risk indicators or the number of events; It displays information in a structured table format and supports sorting by accident type, severity, or time.

[0009] An electronic device includes a memory, a processor, and a computer program stored in the memory, wherein the processor executes the program to implement the urban safety risk information retrieval method based on text2sql as described in any one of claims 1 to 2.

[0010] A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the above-described text2sql-based urban safety risk information retrieval method.

[0011] This invention provides a text-to-sql-based method for retrieving urban safety risk information. By innovatively integrating natural language processing and database technologies, it achieves efficient and accurate retrieval of urban safety risk information. First, it employs natural language-driven technology, allowing users to directly describe their query needs in natural language without requiring SQL skills. This accurately converts the user's natural language query into a corresponding SQL statement, ensuring the accuracy and completeness of semantic understanding. Second, it features end-to-end automation, optimizing the entire process from multi-source data integration to natural language parsing, SQL generation, and result visualization. This effectively integrates and manages scattered urban safety risk information to support rapid retrieval operations. Third, it utilizes RAG-enhanced retrieval to improve the performance and stability of the retrieval system. By combining vector databases and domain knowledge bases, it dynamically supplements policy, case, and other contextual information, improving the accuracy of SQL generation and meeting the stringent real-time and reliability requirements of urban safety management. Attached Figure Description

[0012] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 This is a flowchart of the urban safety risk information retrieval method based on text2sql according to an embodiment of the present invention.

[0014] Figure 2 This is a flowchart of the urban safety risk information retrieval method based on text2sql according to an embodiment of the present invention.

[0015] Figure 3 This embodiment of the invention generates SQL language based on a vector database. Detailed Implementation

[0016] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be described in detail below. Obviously, the described embodiments are merely some embodiments of this invention, and not all embodiments. Based on the embodiments of this invention, all other implementation methods obtained by those skilled in the art without creative effort are within the scope of protection of this invention.

[0017] The management and retrieval of urban safety risk information currently faces numerous problems. On the one hand, urban safety risk information comes from a wide range of sources, including regulatory data from government departments, production and operation data from enterprises, feedback from the public, and data collected by various sensors. This data is scattered across different systems and databases, with varying formats, lacking unified management and integration. Traditional SQL queries require manual writing and rely heavily on technical skills, making information retrieval difficult. On the other hand, traditional information retrieval methods are primarily based on keyword matching, which struggles to handle complex queries. For complex query requirements, especially those involving semantic understanding and logical relationships, it is difficult to accurately understand user intent, often resulting in numerous false positives and false negatives, failing to meet the actual needs of urban safety management.

[0018] This invention provides a method for retrieving urban safety risk information based on text2sql, such as... Figure 1-3 As shown, it includes the following steps; Step S1: Data Integration and Preprocessing: Collect urban safety risk-related data from multiple heterogeneous data sources. After cleaning and standardizing the collected data, store it in the target database. The multiple heterogeneous data sources include at least two of the following: authoritative regulatory databases, enterprise production safety databases, public interaction platform data, and IoT sensor monitoring data. The cleaning and standardization process includes: removing duplicate and erroneous data, and converting date and address information from different heterogeneous data sources into a unified standard format. Step S2: Text2SQL Model Construction and Training: Based on the natural language query statements in the urban safety risk domain and the corresponding SQL statements, a training dataset is constructed. The deep learning-based text2SQL model is trained using the training dataset to obtain a trained text2SQL model. The text2SQL model is a Seq2SQL model or a SyntaxSQLNet model. The construction of the training dataset includes: using NLTK or SpaCy tools to perform word segmentation and part-of-speech tagging on the natural language query statements, and using SQL parsing tools to standardize the corresponding SQL statements. Step S3: Natural Language Query Processing: Receive the natural language query input by the user, parse and identify the intent of the natural language query, and semantically expand the natural language query based on the urban safety risk domain knowledge graph; the semantic expansion of the natural language query based on the urban safety risk domain knowledge graph includes: Based on the query intent determined in intent recognition, risk types, geographical environments, historical cases, or domain specification texts associated with the query entity are retrieved from the knowledge graph; The obtained related information is used as an extended condition to supplement the semantics of the original natural language query; Step S4: SQL Statement Generation and Execution: Input the semantically expanded natural language query into the trained text2sql model to generate the corresponding SQL query statement; use retrieval enhancement generation technology to optimize and enhance the SQL query statement by combining domain knowledge context retrieved from the vector database; execute the optimized SQL query statement to obtain the query results from the target database; the retrieval enhancement generation technology, combining domain knowledge context retrieved from the vector database to optimize and enhance the SQL query statement includes: The natural language query is converted into a query vector, and semantically similar domain knowledge fragments are retrieved from the vector database. These domain knowledge fragments include domain specification documents, historical case descriptions, or standard SQL templates. The retrieved domain knowledge fragments are used as contextual hints and input into the text2sql model along with the natural language query to generate more accurate SQL query statements; Step S5: Result Processing and Display: Filter and sort the query results, and display the processed query results to the user in a visual format.

[0019] In summary, the technical solution of this invention achieves efficient and accurate retrieval of urban safety risk information by innovatively integrating natural language processing and database technologies. Specifically, this invention aims to solve the following key problems: First, it adopts natural language-driven technology, allowing users to directly describe their query needs in natural language without requiring SQL skills, accurately converting the user's natural language query into the corresponding SQL statement, ensuring the accuracy and completeness of semantic understanding; second, it achieves end-to-end automation, optimizing the entire process from multi-source data integration → natural language parsing → SQL generation → result visualization, effectively integrating and managing the scattered urban safety risk information to support rapid retrieval operations; third, it employs RAG-enhanced retrieval to improve the performance and stability of the retrieval system, combining vector databases and domain knowledge bases to dynamically supplement policy, case, and other contextual information, improving the accuracy of SQL generation and meeting the stringent requirements of urban safety management for real-time performance and reliability.

[0020] It should be noted that regarding multi-source data collection: this mainly involves using data collection technology to obtain data from multiple data sources related to urban safety management, including government departments' safety supervision databases, such as fire accident records from fire departments and disaster early warning information from emergency management departments; enterprise production safety data, such as data on the storage and use of hazardous chemicals by chemical enterprises; data from public feedback platforms, such as safety hazards reported by citizens through hotlines or apps; and data collected by various sensors, such as traffic flow sensors and environmental monitoring sensors.

[0021] To improve accuracy, in specific embodiments of this invention, data cleaning algorithms are employed to remove noise, duplicate data, and erroneous data. For example, a deduplication algorithm is used to identify and delete duplicate safety incident records, and data verification rules are used to correct erroneous sensor data. Furthermore, a data standardization process is added to convert data of different formats into a unified standard format, facilitating subsequent storage and processing. For example, date formats are standardized to "YYYY-MM-DD", and address information is standardized according to a unified address encoding rule. Regarding data storage, this invention stores preprocessed data in a relational database or distributed database, establishing a reasonable data table structure and indexes to support rapid data query and update operations.

[0022] In specific embodiments of this invention, deep learning-based text2sql models, such as Seq2SQL and SyntaxSQLNet, are selected and optimized according to the characteristics of urban safety risk information. The training data preparation process mainly involves collecting a large number of natural language queries related to urban safety risks and their corresponding SQL statements to construct a training dataset. Preprocessing operations such as word segmentation and part-of-speech tagging are performed on the natural language queries in the dataset, and the SQL statements are parsed and normalized. The model training process involves training the text2sql model using the training dataset, adjusting the model's parameters to ensure it can accurately convert natural language queries into SQL statements. During training, techniques such as cross-validation and early stopping are used to prevent overfitting and improve the model's generalization ability.

[0023] In specific embodiments of the present invention, the natural language query processing includes query parsing, intent recognition, and query expansion. Query parsing involves: when a user inputs a natural language query, firstly, performing syntactic and semantic analysis to identify keywords, entities, relationships, and constraints within the query. For example, for the query "query of fire accidents that occurred in the city center within the past month," the keywords "fire accidents," the entity "city center," and the time constraint "within the past month" are parsed. Intent recognition utilizes semantic understanding technology, combined with a knowledge graph of urban safety risks, to accurately understand the user's query intent. For example, it determines whether the user's query is about risk accidents, potential risks, or safety measures. Query expansion expands and supplements the query based on the user's query intent and the knowledge graph to improve the accuracy and comprehensiveness of the retrieval. For example, if a user queries "traffic accidents in a certain area," the query can be expanded based on the knowledge graph to include information such as traffic facility conditions and weather conditions. SQL generation involves inputting the parsed and expanded natural language query into a trained Seq2SQL model to generate corresponding SQL statements. SQL syntax checking tools are used to check the generated SQL statements, and SQL optimization tools are used to optimize the SQL statements. Regarding SQL execution, the optimized SQL statement is sent to the database for execution, and the query results are obtained using database connection tools such as MySQL Connector / Python or HBasePython Client.

[0024] To improve the presentation, specific embodiments of the present invention include a results visualization process. Specifically, data visualization tools, such as Matplotlib, Seaborn, or Echarts, are used to display the query results to the user in the form of tables, bar charts, line charts, maps, etc. For example, Echarts' map component can be used to mark the locations of safety incidents on a map.

[0025] In a specific embodiment of the present invention, the urban safety risk information retrieval method based on text2sql involves text segmentation in multi-source data processing. This involves processing data from different sources in the knowledge base, such as web page data, document data, and image data, ensuring a unified data format. The data is cleaned and preprocessed, such as removing noise, HTML tags, and special characters. The text is segmented into meaningful fragments, typically continuous words or sentences that constitute a unit syntactically and semantically, or segmented according to a predetermined length. Regarding vectorization in multi-source data processing: the text is converted into a vector representation, usually using pre-trained word embedding or sentence embedding models, and stored in a vector database. Regarding query retrieval: the text is converted into a vector representation, and semantic similarity is calculated using a vector space model. The distance between the query vector and the document vector is compared to find the most relevant result, achieving more accurate retrieval. If necessary, the results are re-ranked based on the initial retrieval results to improve search relevance and accuracy. Regarding context construction and prompt word context construction technology: the retrieved information is combined with user input to form a rich context, providing a more comprehensive and accurate information foundation for the generative model. By optimizing prompts and context window sizes, prompt words are used to guide the large model in reasoning and generation, enhancing its robustness in the presence of noise or irrelevant context, and improving the quality and accuracy of generated content. User input queries and retrieved information are embedded into pre-defined templates to guide the large model in generating responses according to user needs, guiding it through each specific generation step. Cases without retrieved information are handled, guiding the large model in generating responses. Regarding evaluation, the performance of the RAG system is monitored to ensure its quality and accuracy, focusing on AI illusion issues and taking measures to detect, measure, and mitigate them.

[0026] In specific embodiments of the present invention, the visualization may take at least one of the following forms: Mark the locations of risk events or accidents on a map; Use time-series charts to show the changing trends of risk indicators or the number of events; It displays information in a structured table format and supports sorting by accident type, severity, or time.

[0027] Example 1: Dynamic risk assessment of hazardous chemical areas. This example is a complex scenario that requires the integration of real-time sensor data and historical knowledge.

[0028] User input and background, query: "Evaluate all safety incidents in the past 24 hours within a 3-kilometer radius of Chemical Plant A (coordinates: 121.123, 31.456), with special emphasis on chlorine-related incidents."

[0029] Step 1: Data Integration, Sensor API: Access real-time JSON data streams from four air quality monitoring points around the factory area, containing the fields: {"sensor_id": "S01", "timestamp": "2023-10-27 14:30:00", "CL2_ppm": 0.05, "location": [121.122, 31.455]}. A scheduled task queries the safety production supervision platform database every 5 minutes to retrieve newly reported records. Write a Pandas cleaning function with the following rules: delete records with negative CL2_ppm values; retain only the first record of duplicate reports from the same sensor within one second; convert the address text "XX Road XX Number" to latitude and longitude using a geocoding service, such as the Gaode API. Step 2: Query processing and expansion. The knowledge graph is stored in Neo4j. Examples of some nodes and relationships are shown below: (Chemical Plant A:Factory)-[:STORES]->(Chlorine:Chemical) (Chlorine)-[:HAS_ALIAS]->(:Alias ​​{name:'Liquid Chlorine'}) (Chlorine leak:IncidentType)-[:TRIGGERED_BY]->(Chlorine) (Chlorine leak) - [:HAS_STANDARD]->(:Standard {name:'GB 16297-1996', limit:'0.1mg / m3'}) After identifying "chlorine," the system retrieves its aliases, related accident types, and national standard limits from the spectrum, expanding the query to: "...safety events that meet the following conditions: the event type is 'leak' or 'alarm'; or the event description contains 'chlorine' or 'liquid chlorine'; or the sensor chlorine reading exceeds 0.1 mg / m³." Step 3: SQL generation and RAG enhancement: Convert the expanded query into a vector and retrieve it from a vector database (such as Chroma). Similar case: "On August 1, 2023, a small amount of chlorine gas leaked due to a valve malfunction at Chemical Plant B. The system triggered an alarm on sensor No. 3, with the threshold set at 0.08 ppm." The emergency response document states: "First step of the chlorine leak emergency response procedure: Notify personnel within 3 kilometers downwind to evacuate to safety." A verifiable SQL snippet is generated: The model, combined with the context, generates SQL WHERE conditions that may include: ... WHERE(event_type IN ('Leak', 'Alarm') OR description REGEXP 'Chlorine|Liquid Chlorine' OR (sensor_data.CL2_ppm > 0.08 AND ST_Distance(location, POINT(121.123, 31.456)) <3000)) ... Step 4: Results Display. Main Map: Different icons distinguish between "Historical Incidents" and "Real-time Sensor Alarm Points". Clicking the sensor icon will pop up a card displaying the concentration change curve. Timeline: A 24-hour timeline is set below; dragging it allows you to view the event distribution over different time periods. Report Summary: The system automatically generates a text summary: "In the past 24 hours, a total of 3 related events occurred: 1 historical leak record, and 2 instances of sensor readings exceeding limits (the highest being 0.12 ppm, occurring at 14:30)." Example 2: Multi-dimensional Fire Safety Situation Quantitative Analysis Report. User Input and Background: Generate a comparative report on fire safety in all administrative districts of the city in the third quarter, including: fire incidence rate (number of fires per 10,000 people), average property loss, and rescue compliance rate (the proportion of responses with a time of less than 10 minutes). This involves the correlation and complex statistics of population data, loss data, and time data.

[0030] Step 1: Data Integration and Multi-Table Joining: Three core tables need to be joined: fire_incidents (fire record table: district, loss_amount), response_logs (police dispatch record table: incident_id, call_time, arrival_time), and district_population (administrative district population table: district, population). Data Preprocessing: Calculate the derived field: response_time = arrival_time - call_time; Cleaning Logic: Remove abnormal records where response_time is greater than 120 minutes or less than 1 minute.

[0031] In steps two and three, querying and generating, the model recognizes that the "Comparison Report" requires grouping and aggregation, and understands that "rate" and "proportion" need to be calculated. The generated SQL will include: SELECT district, COUNT(*) as incident_count, AVG(loss_amount) as avg_loss, SUM(CASE WHEN response_time < 600 THEN 1 ELSE 0 END) * 1.0 / COUNT(*)as compliance rate FROM ... JOIN ... GROUP BY district RAG Enhancement: The "Fire Safety Evaluation Index Description Document" was retrieved from the vector database, confirming the formula for "Fire Occurrence Rate". Based on this, the model corrected the SQL, adding JOIN district_population and a calculation column.

[0032] Step 4, Results Display: a) Horizontal comparison bar chart, with the three indicators for each district arranged in parallel. b) Scatter plot: X-axis represents "incidence rate," Y-axis represents "average loss," and bubble size represents "compliance rate," visually displaying high-risk areas. Structured table: A "drill down" function is provided at the bottom of the table; clicking on a district will expand to display a detailed list of all fires in that district during the third quarter. Text conclusion: The system automatically outputs: "In the third quarter, District X had the highest fire incidence rate, reaching 0.42 fires per 10,000 people; District Y had the highest average property loss, at 123,000 yuan per fire; District Z had the highest rescue compliance rate, at 98.5%." The applicant constructed a test environment using historical safety data (containing over 100,000 records) from a certain city over the past three years. Tests were conducted using queries from Examples 1 and 2. Results showed: Semantic understanding accuracy: For 100 natural language queries containing complex domain terminology, the method generated SQL with a syntactic accuracy of 99% and a query intent matching accuracy of 95%, significantly higher than the 78% achieved by simply using the basic Seq2SQL model. RAG enhancement effect: In 30 queries involving professional knowledge such as "hazardous chemical standards" and "rescue procedures," enabling RAG enhancement improved the accuracy of the generated SQL results (consistency between the execution result and expert expectations) from 70% to 92%. Query efficiency: The average end-to-end query response time was less than 2 seconds, meeting the real-time requirements of urban safety management.

[0033] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the program to implement any of the above-mentioned text2sql-based urban safety risk information retrieval methods.

[0034] The present invention also provides a computer-readable storage medium storing computer instructions thereon, which, when executed by a processor, implement the above-described text2sql-based urban safety risk information retrieval method.

[0035] Text2SQL technology, an important research direction in the field of natural language processing, can convert natural language queries into executable SQL statements for databases, enabling natural interaction between users and the database. This technology can effectively address the shortcomings of traditional information retrieval methods in semantic understanding and complex query processing, improving the accuracy and efficiency of information retrieval. Therefore, applying text2SQL technology to urban safety risk information retrieval has significant practical implications and application value.

[0036] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for retrieving urban safety risk information based on text2sql, characterized in that, Includes the following steps; Step S1: Data Integration and Preprocessing: Collect urban safety risk-related data from multiple heterogeneous data sources, clean and standardize the collected data, and then store it in the target database. The multiple heterogeneous data sources include at least two of the following: authoritative regulatory databases, enterprise production safety databases, public interaction platform data, and IoT sensor monitoring data. The cleaning and standardization process includes: removing duplicate and erroneous data, and converting date and address information from different heterogeneous data sources into a unified standard format. Step S2: Text2SQL Model Construction and Training: Based on natural language query statements in the urban safety risk domain and their corresponding SQL statements, a training dataset is constructed. The deep learning-based text2SQL model is trained using this training dataset to obtain a trained text2SQL model. The text2SQL model is either a Seq2SQL model or a SyntaxSQLNet model. The construction of the training dataset includes: using NLTK or SpaCy tools to perform word segmentation and part-of-speech tagging on the natural language query statements, and using SQL parsing tools to standardize the corresponding SQL statements. Step S3: Natural Language Query Processing: Receive a natural language query input by the user, parse and identify the intent of the natural language query, and semantically expand the natural language query based on a knowledge graph of urban security risk domains; the semantic expansion of the natural language query based on the knowledge graph of urban security risk domains includes: Based on the query intent determined in the intent recognition, risk type, geographical environment, historical cases or domain specification text associated with the query entity are obtained from the knowledge graph; The acquired related information is used as an extended condition to supplement the semantics of the original natural language query; Step S4: SQL Statement Generation and Execution: Input the semantically expanded natural language query into the trained text2sql model to generate the corresponding SQL query statement; optimize and enhance the SQL query statement using retrieval enhancement generation technology, combined with domain knowledge context retrieved from the vector database; execute the optimized SQL query statement to obtain the query results from the target database; the optimization and enhancement of the SQL query statement using retrieval enhancement generation technology, combined with domain knowledge context retrieved from the vector database, includes: The natural language query is converted into a query vector, and semantically similar domain knowledge fragments are retrieved from the vector database. The domain knowledge fragments include domain specification documents, historical case descriptions, or standard SQL templates. The retrieved domain knowledge fragments are used as contextual hints and input into the text2sql model along with the natural language query to generate a more accurate SQL query statement; Step S5: Result Processing and Display: Filter and sort the query results, and display the processed query results to the user in a visual form.

2. The urban safety risk information retrieval method based on text2sql according to claim 1, characterized in that, The visualization may take at least one of the following forms: Mark the locations of risk events or accidents on a map; Use time-series charts to show the changing trends of risk indicators or the number of events; It displays information in a structured table format and supports sorting by accident type, severity, or time.

3. An electronic device, comprising a memory, a processor, and a computer program stored in the memory, characterized in that, When the processor executes the program, it implements the urban safety risk information retrieval method based on text2sql as described in any one of claims 1 to 2.

4. A computer-readable storage medium storing computer instructions thereon, characterized in that, When the instruction is executed by the processor, it implements the urban safety risk information retrieval method based on text2sql as described in any one of claims 1 to 2.