Database semantic index construction method and device, medium and equipment
By reverse parsing the database definition language and historical SQL, adaptive segmentation of unstructured documents, and physical execution feedback verification, the accuracy problem of natural language query to SQL conversion in enterprise-level data analysis is solved, and efficient semantic indicator construction and consistency management are achieved.
Patent Information
- Application Number
- CN202611125587.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-28
- Publication Date
- 2026-11-20
Smart Images

Figure CN123138209A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of database construction technology, and more specifically, to a method, apparatus, medium, and device for constructing database semantic indicators. Background Technology
[0002] In recent years, with the rapid development of large language models, direct data querying and analysis via natural language has become an important development direction in the field of business intelligence. In typical enterprise business intelligence scenarios, users expect to ask questions in natural language, and the system will automatically generate SQL query statements and return the results, i.e., Text-to-SQL technology. However, the metrics in actual business operations usually have specific calculation methods, statistical dimensions, filtering conditions, and inter-table relationships, such as "average monthly active users" and "compound annual growth rate of revenue over the past three years." Simply relying on large language models to directly generate SQL, due to the lack of a unified description and structured modeling of the semantics of business metrics, is prone to problems such as semantic illusion, metric confusion, field matching errors, and uninterpretable query results, making it difficult to meet the accuracy and consistency requirements of enterprise-level data analysis.
[0003] To improve the accuracy of natural language queries, related technologies attempt to introduce database semantic layers or retrieval enhancement generation schemes. Semantic layer schemes aim to establish a structured description layer between business semantics and the physical database, unifying the meanings and calculation formulas of metrics, dimensions, fields, and so on. Retrieval enhancement generation schemes, on the other hand, use information such as database table structures, field descriptions, and business document fragments as contextual input to a large language model to assist in the generation of structured query language. However, these related technical solutions generally remain at the level of "retrieval context-assisted generation." When faced with complex business metrics, they frequently encounter problems such as inconsistent metric definitions, incorrect database field mappings, and incorrect table join path selections, failing to provide stable, reusable, and verifiable semantic support. Summary of the Invention
[0004] This disclosure provides at least one method, apparatus, medium, and device for constructing database semantic indicators. By integrating the reverse parsing of database definition language and historical SQL, as well as the adaptive segmentation and component-level deconstruction of unstructured documents, and introducing a closed-loop verification mechanism based on physical execution feedback, it achieves end-to-end automated construction of structured indicator assets from multi-source heterogeneous data to executable and reusable data.
[0005] This disclosure provides a method for constructing database semantic metrics, including: Obtain database semantic indicator construction information; wherein, the database semantic indicator construction information includes database definition language, historical structured query language logs, and unstructured business documents; The database definition language and the historical structured query language logs are reverse parsed to generate intermediate representations of indicators, and the intermediate representations of indicators are stored in the semantic indicator library. The unstructured business document is adaptively semantically segmented to obtain multiple semantic blocks, and each semantic block is deconstructed to obtain potential indicators. The potential indicators are matched based on the semantic indicator library, and the semantic alignment status is determined based on the matching results. When the semantic alignment state is a partial match, candidate query statements are generated based on the potential indicators that have been successfully matched. The candidate query statements are then verified by physical execution feedback, and the verified potential indicators are stored in the semantic indicator library.
[0006] This disclosure provides a database semantic index construction apparatus, including: The information acquisition module is used to acquire database semantic indicator construction information; wherein, the database semantic indicator construction information includes database definition language, historical structured query language logs, and unstructured business documents; The indicator library construction module is used to reverse parse the database definition language and the historical structured query language logs to generate intermediate indicator representations and store the intermediate indicator representations in the semantic indicator library. The indicator deconstruction module is used to adaptively segment the unstructured business document into multiple semantic blocks, and to deconstruct the indicator for each semantic block to obtain potential indicators. The indicator matching module is used to match the potential indicators based on the semantic indicator library and determine the semantic alignment state based on the matching results. The indicator verification module is used to generate candidate query statements based on the successfully matched potential indicators when the semantic alignment state is partial matching, perform physical execution feedback verification on the candidate query statements, and store the verified potential indicators into the semantic indicator library.
[0007] This disclosure provides a computer device, including a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the computer device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, a database semantic index construction method as described in any of the above possible embodiments is performed.
[0008] This disclosure provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the database semantic index construction method as described in any of the possible embodiments above.
[0009] The database semantic indicator construction method, apparatus, medium, and device provided in this disclosure achieve structured extraction and representation of semantic indicators by integrating the reverse parsing of database definition language and historical structured query language logs, as well as adaptive semantic segmentation and indicator deconstruction of unstructured business documents. Based on the semantic indicator library, potential indicators are matched to reduce the cost of manual verification. For some matching states, physical execution feedback verification of candidate query statements is introduced, which can automatically filter out the indicator definitions that can be actually executed, improve the accuracy and usability of semantic indicator construction, and at the same time ensure the consistency and computability between new indicators and existing indicators.
[0010] This improves the automation level and semantic alignment accuracy of database semantic indicator construction, and realizes end-to-end automated construction from multi-source heterogeneous data to executable and reusable structured indicator assets. It effectively reduces the human cost of semantic layer initialization and maintenance, and provides highly reliable and interpretable indicator knowledge support for Text-to-SQL systems.
[0011] To make the above-mentioned objects, features and advantages of this disclosure more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0012] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings referenced in the embodiments will be briefly described below. These drawings are incorporated in and constitute a part of this specification. They illustrate embodiments conforming to this disclosure and, together with the specification, serve to explain the technical solutions of this disclosure. It should be understood that the following drawings only show some embodiments of this disclosure and should not be considered as limiting the scope. Those skilled in the art can obtain other related drawings based on these drawings without creative effort.
[0013] Figure 1 A flowchart of a database semantic index construction method provided by an embodiment of this disclosure is shown; Figure 2 A flowchart of a semantic index library construction method provided by an embodiment of this disclosure is shown; Figure 3 A flowchart of an index deconstruction method provided by an embodiment of this disclosure is shown; Figure 4 A flowchart of a closed-loop verification method based on physical execution feedback provided in an embodiment of this disclosure is shown; Figure 5 This diagram illustrates the structure of a database semantic index construction apparatus provided in an embodiment of the present disclosure. Figure 6A schematic diagram of the structure of a computer device provided in an embodiment of this disclosure is shown. Detailed Implementation
[0014] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of the embodiments of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.
[0015] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0016] In this document, the term "and / or" merely describes a relationship, indicating that three relationships can exist. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. Furthermore, the term "at least one" in this document means any combination of at least two of any one or more elements. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0017] In recent years, Large Language Models (LLMs) have demonstrated outstanding performance in natural language understanding and generation tasks, making data querying and analysis via natural language possible. In business intelligence scenarios, users typically want to directly pose natural language questions, with the system automatically generating SQL queries—a text-to-SQL task. However, in real-world enterprise applications, complex business metrics often have specific calculation methods, statistical dimensions, and filtering conditions. Relying solely on LLMs to directly generate SQL can easily lead to semantic illusions, ambiguity, field matching errors, and uninterpretable query results.
[0018] To improve the accuracy of natural language queries, existing technologies typically introduce a database semantic layer—a structured description layer located between business semantics and the underlying database. This layer unifies the definition of metrics, dimensions, field meanings, inter-table relationships, calculation formulas, and filtering conditions. Through the semantic layer, the system can first understand the business metrics and statistical definitions corresponding to the user's question, and then generate SQL based on the defined semantic information, thereby improving the consistency and reliability of query results.
[0019] However, in actual business scenarios, the definition of indicators and calculation logic required by the semantic layer often do not exist directly in database fields, but are scattered in multi-source heterogeneous data, including unstructured business documents such as business reports, financial statements, system documents and indicator definitions, tabular business data such as statistical tables, indicator comparison tables and their table titles and notes, semi-structured historical SQL query logs such as historical report SQL, reference SQL and commonly used query templates, as well as database metadata such as DDL, table structure, field comments and inter-table relationships.
[0020] Research has revealed that a common approach is to directly translate user queries into SQL using natural language processing models or large language models—the traditional Text-to-SQL approach. The system receives the natural language query, inputs the database table structure, field names, field types, and some sample data as context to the model, which then directly generates SQL and sends it to the database for execution. Some improved approaches introduce enhanced retrieval generation, providing the model with database DDL, field descriptions, historical query examples, or business document fragments as supplementary context to enhance its understanding of database schemas and business terminology. Other approaches build auxiliary knowledge based on historical SQL query logs, collecting historical query statements, analyzing frequently used tables and fields, and extracting common join paths or query templates to assist in subsequent SQL generation.
[0021] However, most of these solutions remain at the level of "retrieval context-assisted generation," and at least have the following problems: First, they lack a unified and reusable database semantic layer. Traditional Text-to-SQL directly maps from natural language to database tables and fields. When user questions involve business metrics, statistical definitions, computational logic, or dimensional constraints, the model struggles to obtain a stable and unified semantic foundation. Second, they struggle to handle implicitly complex business metrics—a business metric is often not equivalent to a single field in the database, but rather a computational definition composed of multiple parts such as aggregate functions, filtering conditions, time granularity, dimensional constraints, and table joins. Existing solutions easily misjudge complex metrics as simple field mappings, leading to logical gaps. Third, they struggle to accurately extract metric definitions from multi-source heterogeneous data, because metric definitions may be scattered across unstructured text, tables, reports, policy documents, and historical SQL logs. Traditional solutions lack a unified mechanism for segmenting, understanding, and extracting components from plain text and tabular data. Fourth, database schema matching is prone to semantic bias. In large databases, business metrics typically involve multiple tables, multiple fields, and complex join paths. Existing solutions rely solely on field names or model semantic inference, making it difficult to determine valid table join paths and easily leading to issues such as name homonyms, incorrect table matching, and incorrect field matching. Finally, there is a lack of verification mechanisms based on physical execution feedback. Existing solutions focus more on the syntactic or textual similarity of the generated SQL, neglecting closed-loop verification of the semantic correctness and physical executability of metrics. This is especially true in vertical domains, where it is difficult to effectively verify name homonyms, mapping of technical terms, and the consistency between query results and document facts.
[0022] Based on the above research, this disclosure provides a method, apparatus, medium, and device for constructing database semantic indicators. By integrating the reverse parsing of database definition language and historical structured query language logs, as well as the adaptive semantic segmentation and indicator deconstruction of unstructured business documents, the structured extraction and representation of semantic indicators are achieved. Based on the semantic indicator library, potential indicators are matched to reduce the cost of manual verification. For some matching states, physical execution feedback verification of candidate query statements is introduced, which can automatically filter out the indicator definitions that can be actually executed, improve the accuracy and usability of semantic indicator construction, and at the same time ensure the consistency and computability between new indicators and existing indicators.
[0023] This disclosure improves the automation level and semantic alignment accuracy of database semantic indicator construction, realizes end-to-end automated construction from multi-source heterogeneous data to executable and reusable structured indicator assets, effectively reduces the human cost of semantic layer initialization and maintenance, and provides highly reliable and interpretable indicator knowledge support for Text-to-SQL systems.
[0024] To facilitate understanding of this embodiment, the executing entity of the database semantic index construction method provided in this disclosure will first be described in detail. The executing entity of the database semantic index construction method provided in this disclosure is a computer device. This computer device can be a terminal device or a server. The terminal device can also be a mobile device, user terminal, terminal, handheld device, computing device, vehicle-mounted device, wearable device, etc. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud storage, big data, and artificial intelligence platforms. Optionally, this method can also be applied to an implementation environment composed of computer devices and servers.
[0025] The database semantic index construction method provided in this application embodiment will be described in detail below with reference to the accompanying drawings. See also Figure 1 The diagram shows a flowchart of a database semantic index construction method provided in this embodiment of the disclosure. The method includes the following steps S101 to S105: S101, Obtain database semantic indicator construction information.
[0026] It is understandable that database semantic metric construction information refers to the multi-source input data required for defining, extracting, or validating database semantic metrics; it is a set of information that serves as the original basis during the construction of the database semantic layer. This information may include database definition language, historical structured query language logs, and unstructured business documents, among other things.
[0027] Specifically, Database Definition Language (DBML) refers to a standardized set of instructions used to define database structure, tables, fields, data types, constraints, and relationships between tables. It is the metadata description of the database physical schema and can include metadata information such as table names, field names, field types, primary and foreign key definitions, and index declarations in table creation statements. Historical Structured Query Language (SCL) logs refer to a collection of historically executed SCL statements and their execution context information recorded in the database system. They can be used to represent query patterns, calculation logic, table join paths, and aggregation operations that have been validated in business practice. They can include historical report query statements, commonly used statistical query templates, data extraction scripts, and corresponding auxiliary information such as execution frequency and execution time. For example, in a sales report generation scenario, the corresponding historical SCL logs could include query statements for monthly sales statistics for each region and query statements for calculating average prices by product category. Unstructured business documents refer to data carriers that exist in the form of natural language text, tables, charts, etc. and do not follow a fixed data pattern. They can represent the business meaning, calculation method, statistical dimension, filtering conditions, and business relationship between indicators. They are the original materials that carry business semantics, such as indicator description paragraphs in business reports, calculation formula descriptions in financial system documents, and table titles and notes in statistical reports.
[0028] Here, the aforementioned database semantic indicator construction information can be obtained by connecting to the database management system to acquire the database definition language, by obtaining historical structured query language logs through database audit logs or query history interfaces, and by importing unstructured business documents through the file system or document management platform. During the acquisition process, data from different sources can be formatted, denoised, and normalized to form a unified and usable input set, thereby providing a more complete and accurate basis for semantic construction in subsequent steps.
[0029] S102, reverse-parse the database definition language and the historical structured query language log to generate an intermediate representation of the indicator, and store the intermediate representation of the indicator in the semantic indicator library.
[0030] Specifically, after obtaining the database definition language and historical structured query language logs, since the database definition language only describes the metadata of the database physical structure and lacks business semantics, and the historical structured query language logs contain the calculation paradigm of the actual business query but are in the form of statements related to the specific database dialect, they may not be able to directly correspond to the indicator caliber described in natural language when performing cross-document indicator matching in the future. Therefore, the database definition language and historical structured query language logs can be reverse-analyzed to transform the physical layer information and the verified calculation logic into a structured expression that is independent of the specific database dialect and oriented towards business semantics. The calculation formula, statistical dimensions and filtering conditions of the indicators are determined to generate a structured intermediate representation of the indicators, which is then stored in the semantic indicator library.
[0031] The intermediate representation of an indicator refers to a standardized expression that is independent of any specific database dialect and uses a declarative data structure to describe the core logic of an indicator. It can include elements such as the indicator name, calculation formula, dependent dimensions, filtering conditions, and table join relationships. It represents a reusable indicator definition extracted from historical SQL and validated by business operations. The semantic indicator library is a knowledge base that supports vectorized storage and hybrid retrieval. It stores the intermediate representation of indicators and their corresponding natural language description text, vector embeddings, and other data. It can include metadata such as the structured definition of the indicator, the business explanation of the indicator, and the derivation relationships between indicators. This metadata can be used in subsequent steps to perform semantic matching and reuse determination of potential indicators extracted from documents.
[0032] For example, in order to automatically extract reusable semantic indicator assets from database definition language and historical structured query language logs, a basic semantic model can be gradually built and the query structure extracted using reverse engineering, referring to... Figure 2 As shown, the process of generating database semantic metrics based on reference SQL documents may include the following steps S201~S204: S201, Input the database definition language into the natural language processing model to generate a basic semantic model.
[0033] Here, a natural language processing (NLP) model refers to a deep learning-based algorithmic model capable of understanding and generating natural language text. It can identify table names, field names, field comments, and primary / foreign key relationships between tables from database definition language, and infer the business meaning and potential metric and dimensional roles of the fields. Open-source models such as BERT and the GPT series, or fine-tuned domain models, can be used for semantic understanding and structured output. By inputting the database definition language into the NLP model, the model performs semantic parsing and entity recognition, thereby generating a basic semantic model. This basic semantic model is a lightweight ontology model oriented towards a business perspective, used to describe the core business entities in the database and their attribute classifications. Specifically, it can include metadata such as metric information, dimensional information, and inter-table relationship information.
[0034] Specifically, metric information refers to the business meaning of numerical fields that can be aggregated. It forms the basis of quantitative evaluation indicators in business analysis. Aggregation calculations can include methods such as summation, counting, and averaging. For example, metric information can be represented as the sales amount field in a sales table or the order quantity field in an order table. Dimension information can be used to represent attribute fields for grouping, filtering, or drill-down analysis of metrics. It is a categorical variable used in business analysis to observe data cross-sections, providing different perspectives on the data, such as the year in the time dimension or the province name in the region dimension. Inter-table relationship information refers to the association paths established between different data tables through foreign keys or business keys. It is metadata in the database schema that describes the connection methods between entities. For example, the customer identifier in the order table and the customer identifier in the customer table form a one-to-many relationship.
[0035] In some other embodiments, the basic semantic model described above may also include metadata such as data type constraints of fields, default aggregation methods of fields, and business hierarchy relationships of fields, which can provide richer context for subsequent metric matching. No specific limitations are made here.
[0036] S202, convert each historical structured query language in the historical structured query language log into an abstract syntax tree, and extract the data table identifier, calculation operation, grouping operation, and data table relationship from the syntax tree structure.
[0037] Understandably, each historical structured query language entry in the historical query language log has a different syntax and dependent table objects, corresponding to different business query scenarios and calculation methods. Therefore, to ensure consistent extraction of metric definitions without being affected by specific syntax differences, it can first be converted into a structured abstract syntax tree. Then, the nodes of the syntax tree can be traversed to extract key operation elements, thus extracting the core components that constitute the metrics. Furthermore, through abstract syntax tree analysis, structured information such as data table identifiers, calculation operations, grouping operations, and data table relationships can be extracted for alignment and mapping with the basic semantic model.
[0038] In this context, the data table identifier refers to the name or alias of the physical table being queried, which can be used to determine the data source upon which the indicator depends. Calculation operations refer to aggregate functions, arithmetic expressions, or scalar function calls in Structured Query Language (SCL), which can represent the calculation formula for the indicator, such as summation functions, counting functions, averaging functions, and addition, subtraction, multiplication, and division operations. Grouping operations are the set of fields specified by the grouping clause in SCL, which can be used to represent the dimensional division of indicator statistics, such as grouping by month or by product category. Data table relationships refer to the inter-table join conditions specified by the join clause in SCL, which can be used to represent the join path required to retrieve data from multiple tables, such as two tables in an inner join being linked through the same order number field.
[0039] S203, the extracted data table identifier, calculation operation, grouping operation, and data table association relationship are aligned and mapped with the measurement information, dimension information, and inter-table relationship information in the basic semantic model to generate an intermediate representation of the indicator.
[0040] Specifically, by aligning and mapping data table identifiers, calculation operations, grouping operations, and data table relationships with the metrics, dimensions, and inter-table relationships in the basic semantic model, expressions in historical SQL related to specific database dialects can be bound to business entities in the semantic model. This eliminates ambiguity in field aliases, determines the business meaning of each operation, identifies the calculation logic, statistical dimensions, and filtering conditions of metrics, and generates intermediate representations of metrics.
[0041] Here, the intermediate representation of an indicator can specifically include calculation logic, dimensions, and filtering conditions. It can be organized using declarative data formats such as YAML or JSON, independent of the specific database type, facilitating subsequent natural language description generation and vectorized storage. For example, in a sales statistics scenario, a historical structured query might include a summation operation on the sales amount field and a grouping operation by month. The corresponding intermediate representation of this indicator could be: Indicator Name: Total Monthly Sales Amount, Calculation Formula: Sum of Sales Amount, Statistical Dimension: Month. Alternatively, in a user activity analysis scenario, the corresponding intermediate representation of this indicator could be: Indicator Name: Daily Active Users, Calculation Formula: Count User Identifier, Filter Condition: Last Login Date Equals Current Date.
[0042] S204, the intermediate representation of the indicator is input into the natural language processing model, the natural language processing model is used to generate a corresponding natural language description text for each intermediate representation of the indicator, and the semantic indicator library is constructed based on each intermediate representation of the indicator and the natural language description text corresponding to the intermediate representation of the indicator.
[0043] Furthermore, after obtaining the structured intermediate representations of the indicators, to enhance their interpretability and facilitate subsequent semantic retrieval, these intermediate representations can be input into a natural language processing (NLP) model. The NLP model can then generate a corresponding natural language description for each intermediate representation, explaining its business meaning, calculation method, and usage scenarios. For example, if the calculation logic of an intermediate representation involves summing the sales amount field with a month dimension, the NLP model can generate a natural language description for that intermediate representation, indicating that the indicator calculates the total sales amount for each month, used to analyze monthly sales trends.
[0044] In this way, after obtaining the intermediate representation of the indicator and the corresponding natural language description text, a semantic indicator library can be constructed based on the structured definition of the intermediate representation of the indicator and the natural language description text. This indicator library can include machine-readable definitions of the indicators, human-readable explanations, and vector embeddings for subsequent similarity matching.
[0045] In this embodiment of the disclosure, by combining the basic semantic model generated by the database definition language with the query components parsed from the historical structured query language logs, and performing alignment mapping to generate intermediate representations of indicators, and then supplementing them with natural language descriptions before storing them in the semantic indicator library, a reusable and searchable structured semantic indicator base library is automatically built based on existing database assets, effectively alleviating the cold start problem of semantic layer construction.
[0046] S103, perform adaptive semantic segmentation on the unstructured business document to obtain multiple semantic segments, and deconstruct the indicators of each semantic segment to obtain potential indicators.
[0047] Understandably, unstructured business documents, due to their diverse formats, inconsistent content layouts, and mix of text and tables, often suffer from issues such as ambiguous semantic boundaries, complex contextual dependencies, and missing structural information. Therefore, an adaptive semantic segmentation approach can be adopted. Based on the structural characteristics of different data types within the document, a differentiated segmentation strategy is employed to decompose the original document into multiple semantically complete and contextually coherent segments, resulting in multiple semantic blocks. Each semantic block is a text unit with a clear business theme and complete contextual information. Here, each semantic block represents a relatively independent semantic unit extracted from the original document and serves as the basic processing unit for subsequent metric deconstruction operations.
[0048] Specifically, when performing adaptive semantic segmentation on unstructured business documents, the data type in the unstructured business document can be identified first, that is, whether its content fragments belong to plain text data described in natural language or data table data organized in rows and columns. When the data type is plain text data, it means that the content consists of continuous paragraphs, headings, and narrative text, and its semantic structure depends on the document's chapter hierarchy. At this time, a text hierarchy logical structure tree can be constructed based on the document heading hierarchy in the unstructured business document. The headings at all levels of the document are organized into a tree structure according to the hierarchical relationship from the root node to the leaf node. Then, the unstructured business document is segmented hierarchically based on the text hierarchy logical structure tree, with each heading and its subordinate content as an independent text block. At the same time, in order to retain the business affiliation and context of each text block in subsequent processing, the complete hierarchical path information of each text block in the text hierarchy logical structure tree can be retained. For example, the names of the first-level heading, second-level heading, and third-level heading can be concatenated as the context prefix of the text block, thus obtaining the plain text block. Here, plain text blocks refer to natural language text fragments that retain the original document's hierarchical structure information, have complete content, and have a clear business theme, thus avoiding semantic breaks and context loss caused by simple segmentation based on character length.
[0049] On the other hand, when the data type is table data, it means that this part of the content is presented in tabular form. The table header, table body, and table notes together constitute the carrier of the indicator data. The semantics of the table often depends on the explanatory text in the table title and table notes. In this case, the table title, table content, and table notes of the table data in the unstructured business document can be extracted as contextual anchors. The indicator names described in the table title and the calculation methods explained in the table notes are used as the business interpretation of the table data, serving as the semantic background for subsequent parsing of the table content. This allows the table data to be reconstructed into a structured table format, that is, converted into a row and column structure represented by comma-separated values, removing the interference caused by complex formatting such as merged cells and row spanning, thus obtaining table data blocks. Here, table data blocks can be used to convert two-dimensional tables embedded in documents into a machine-readable standardized data format, which is the basic input for subsequently extracting indicator formulas and dimension values from the table.
[0050] In this way, by adopting hierarchical segmentation and table reconstruction strategies for plain text data and data table data respectively, the most effective semantic context can be preserved for the characteristics of different types of data, providing input fragments with clear structure and complete semantics for subsequent indicator deconstruction.
[0051] Furthermore, after obtaining multiple semantic blocks (i.e., plain text blocks and / or tabular data blocks) corresponding to the unstructured business document, metric deconstruction can be performed. A semantic understanding model can be used to analyze the content of each semantic block, identifying and extracting components related to the business metrics from its natural language description and tabular structure to obtain structured potential metrics. Here, potential metrics refer to candidate metric definitions identified from the business document that have not yet been validated by the database schema. These can include component information such as potential calculation logic, potential dimensions, and potential filtering conditions.
[0052] Specifically, the potential calculation logic is represented by arithmetic operations, aggregation operations, or ratio calculations performed on one or more fields. This can be a formula extracted from the document, such as total revenue minus total cost, or aggregation operations such as counting, summing, and averaging. Potential dimensions refer to the business attribute fields used when grouping or filtering indicators, such as monthly or annual time periods, or regional or product category attributes. Potential filtering conditions are constraint expressions that limit the data records participating in the indicator calculation, restricting the data range for indicator statistics, such as limiting the sales status to "completed" in sales records or limiting the statistical period to the previous natural quarter.
[0053] In some possible embodiments, considering that different paragraphs in an unstructured business document may belong to different business domains, and that the descriptions of metrics in different domains have different professional terms and expression habits, domain recognition and context enhancement mechanisms can be introduced when extracting metric components from semantic blocks, referring to... Figure 3 As shown, the following steps S301~S303 may be included when performing indicator deconstruction: S301, each of the semantic blocks is input into the first semantic understanding model, and the first semantic understanding model performs domain recognition on each of the input semantic blocks.
[0054] Here, the first semantic understanding model is a lightweight natural language processing model or classifier that can be used to classify input text fragments into different domains. By analyzing keywords, terminology distribution, and sentence structure features in the text, it can determine the domain to which the semantic blocks belong. Here, "domain" refers to the scope of business knowledge, which can include business categories such as sales, finance, supply chain, and human resources.
[0055] S302, for each semantic block, determine the domain prompt word template corresponding to the domain of the semantic block and the industry terminology corresponding to the domain of the semantic block, and generate enhanced prompt words corresponding to the semantic block based on the domain prompt word template and the industry terminology.
[0056] Specifically, after obtaining the domain classification of each semantic block, the corresponding domain prompt word template can be found from a pre-built template library or knowledge base based on that domain, and the set of professional terms under that domain can be retrieved from the industry terminology knowledge base. Here, the domain prompt word template refers to the structured instruction text designed for a specific business domain to guide the semantic understanding model in extracting indicators. It can also be used to constrain the output format and extraction focus of the model. For example, for the prompt word template in the financial domain, the model can be required to extract specific types of indicator formulas such as profit margin and growth rate from the text. By using the domain prompt word template, the model can be constrained to focus on indicator elements related to that domain, thereby improving the targeting of extraction. Industry terms are professional terms or abbreviations within a specific business domain. They are basic concepts in the knowledge system of that domain and can help the semantic understanding model accurately identify industry-specific expressions appearing in documents, avoiding misjudging professional terms as ordinary words. For example, in the financial domain, industry terms may include operating profit, net profit margin, year-on-year growth rate, month-on-month change, pre-tax profit, and EBITDA.
[0057] For example, the aforementioned domain-specific prompt templates can be determined through manual design or by summarizing from historical successful cases. A standardized set of prompt instructions can be maintained for each domain to ensure consistency in the extraction methods of similar metrics across different documents. The aforementioned industry terms can be retrieved from external knowledge bases using retrieval-enhanced generation technology. This technology combines information retrieval with text generation, allowing background knowledge related to the current semantic segment to be retrieved from a vector database before the semantic understanding model processes the input, injecting it as additional input context into the model.
[0058] Furthermore, after obtaining the domain prompt template and industry terms, the domain prompt template can be used as a basic instruction to incorporate the retrieved industry terms as supplementary explanations, generating enhanced prompts corresponding to the semantic blocks. This is used to guide the second semantic understanding model to more accurately extract indicator components in subsequent steps. Taking a semantic block in a financial report as an example, its content, after analysis by the first semantic understanding model, corresponds to the domain of financial analysis. By searching for the prompt template of the financial domain and retrieving financial-related industry terms such as operating profit, period expenses, year-on-year comparison, and month-on-month comparison, it can be determined that its corresponding domain prompt template can be represented as identifying the calculation formula, statistical dimensions, and screening conditions of the indicators from the following text and outputting them according to a specified format. Industry terms can be operating profit, net profit margin, year-on-year growth rate, etc., and then its corresponding enhanced prompts can be represented as combining the financial domain terms operating profit and year-on-year growth rate to extract indicator components from the text and output structured results.
[0059] In some other embodiments, the aforementioned domain prompt word templates and industry terms can also be determined and obtained through other methods such as rule matching and manual annotation, as long as they can provide effective semantic guidance for the target domain, and no specific limitations are made here.
[0060] S303, for each semantic block, the semantic block and the corresponding enhanced prompt words are input into the second semantic understanding model, and the second semantic understanding model performs component-level deconstruction on the semantic block to extract the potential indicators corresponding to the semantic block.
[0061] Here, the second semantic understanding model refers to a large-scale natural language processing model with text generation and information extraction capabilities. It can be used to deconstruct input text under the guidance of enhanced prompts. By analyzing verb phrases, numerical expressions, and conditional adverbs in the text, it can identify the calculation method of indicators, grouping criteria, and data filtering range, and output this information in the form of predefined fields.
[0062] Specifically, component-level deconstruction is an extraction method that breaks down business metrics described in natural language into atomic elements. It can separate complex metric definitions into independent computational logic, dimension references, and filtering conditions, thereby determining the triplet structure of each potential metric—that is, what the calculation formula is, what dimensions are used for statistics, and what filtering constraints are attached—resulting in structured potential metrics. For example, for a semantic block containing text describing the calculation of the total sales revenue of each product line in North China in 2024, the second semantic understanding model can deconstruct it into the potential computational logic of summing sales revenue, the potential dimension of product line, and the potential filtering conditions of region equal to North China and year equal to 2024.
[0063] In some possible embodiments, the first semantic understanding model and the second semantic understanding model described above can be set as the same model instance as the natural language processing model in the above steps, or they can be selected and configured as different large language model instances according to task complexity, response latency requirements or computing resource constraints, without specific limitations here.
[0064] S104, Match the potential indicators based on the semantic indicator library, and determine the semantic alignment state based on the matching results.
[0065] Here, after obtaining the potential metrics extracted from the business documents, they can be matched with the existing intermediate representations of metrics in the semantic metric library and the metadata in the basic semantic model. This determines whether the potential metric already has a corresponding metric definition in the semantic metric library, and the degree of alignment between its components and the database physical schema. Based on the matching results, the semantic alignment status of the potential metric is determined. The semantic alignment status includes one of three: complete match, partial match, or semantic missing. A complete match indicates that the potential metric is highly consistent with an existing metric in the semantic metric library in terms of semantic description and component composition, and the metric definition can be directly reused. A partial match indicates that some components of the potential metric (such as calculation logic or dimensions) can be found in the semantic metric library or the basic semantic model, but some components cannot be aligned. Semantic missing indicates that the core components of the potential metric cannot establish an effective correspondence with existing semantic assets.
[0066] Specifically, a progressive two-stage strategy can be adopted to match potential indicators. First, the natural language description in the semantic block of the potential indicator is compared with the natural language description of the intermediate representation of each indicator in the semantic indicator library. The distance or cosine similarity between the two in the vector space is calculated to determine whether the potential indicator matches the existing indicators in the semantic indicator library at the business semantic level. That is, it is determined whether the potential indicator is an approximate expression, synonymous variant, or synonymous heteromorphic description of the existing indicator.
[0067] For example, when the feature similarity comparison result can determine the semantic matching status between the potential indicator and the existing indicator, it means that the business meaning of the potential indicator is highly overlapping with the existing indicator. The structured definition and database mapping relationship of the existing indicator can be directly inherited. At this time, the semantic alignment status of the potential indicator can be determined as a complete match based on the feature similarity comparison result, without having to enter a more granular component-level matching process.
[0068] For example, when the feature similarity comparison result indicates that it is impossible to determine whether a potential indicator semantically matches an existing indicator, it means that the semantic description similarity between the potential indicator and the existing indicator is in a fuzzy range, or that there is no highly similar existing indicator in the semantic indicator library, thus making it impossible to determine the matching relationship based solely on the overall semantic description. In this case, the three components of the potential indicator—potential calculation logic, potential dimensions, and potential screening conditions—can be matched and semantically aligned with the measurement information, dimension information, and inter-table relationship information in the basic semantic model to determine the corresponding fields or relationships of each component in the database physical schema.
[0069] Here, fine-grained feature matching refers to comparing each component of a potential metric—such as the potential calculation logic for summing sales figures, the potential dimensions for grouping by month, and the potential filtering conditions limiting the region to North China—with the metadata in the basic semantic model, including field business meanings, field annotations, and field data types. Using methods such as vector similarity calculation or rule matching, the most matching database column or table join path is found for each component to determine the physical field name and the data table to which the component belongs. Semantic alignment is the process of establishing a mapping relationship between the various components of the potential metric and the database metadata. It is used to confirm which field the calculation described by the potential metric should be based on, which dimension should be used for grouping, and what filtering conditions should be added, ensuring that the conversion from business terms to the database physical schema is accurate and executable. For example, for a potential metric that includes summing contract amounts, grouping by signing year, and limiting the signing status to effective, fine-grained feature matching will match the summation operation to the amount field in the contract table, match the signing year to the year part of the signing date field in the contract table, and match the effective status to the status field in the contract table. Semantic alignment will confirm that the calculation of the metric should be based on the amount field in the contract table, grouped by the year dimension of the signing date, and add a filter condition that the status is equal to effective.
[0070] Furthermore, after completing fine-grained feature matching, the semantic alignment status of potential indicators can be determined by comprehensively evaluating the feature similarity comparison results and the fine-grained matching results. This process can include: if all components of a potential indicator—the computational logic, dimensions, and filtering conditions—can find high-confidence counterparts in the basic semantic model, the semantic alignment status of the potential indicator can be determined as a complete match; if only some components can find counterparts, or if all components can find counterparts but some components come from multiple different and incompatible data tables lacking effective connection paths, it can be determined as a partial match; if core components such as the computational logic cannot find any reasonable field correspondences, it can be determined as semantic missing. For example, a potential indicator may include the logic for summing contract amounts and a dimension grouped by the year of signing. If the contract amount field and the year of signing dimension both exist in the basic semantic model, and they belong to the same contract fact table and have a relationship, then the semantic alignment of this potential indicator can be determined as a complete match. If the contract amount field exists but the year of signing dimension only exists in the customer dimension table and there is no explicit join key between the two tables, then it can be determined as a partial match. If the contract amount field does not exist in any known table, then it is determined as semantically missing.
[0071] In this way, by adopting a progressive strategy of first performing global semantic description matching and then component-level fine-grained matching, an efficient diversion mechanism can be established between the reuse of existing indicators and the construction of new indicators, while ensuring that accurate matching results can still be obtained in cases of semantic ambiguity or component complexity.
[0072] S105, when the semantic alignment state is partial matching, a candidate query statement is generated based on the potential indicators that have been successfully matched, the candidate query statement is verified by physical execution feedback, and the verified potential indicators are stored in the semantic indicator library.
[0073] Understandably, when the semantic alignment of a potential indicator is partially matched, it means that some components of the potential indicator can be found in the semantic indicator library or basic semantic model, but some components are still missing or have unclear mappings. If the potential indicator is directly defined as a new semantic indicator and stored in the library, subsequent query execution may fail or return incorrect results due to incorrect field mapping, missing table join paths, or inaccurate filtering conditions. Therefore, to verify whether a partially matched potential indicator truly has the ability to be physically executed on the target database and to ensure that its query results are consistent with the business document facts, candidate structured query statements can be generated based on the successfully matched components and candidate mappings of unmatched components in the potential indicator. This transforms the business statement into executable database query logic, serving as a preliminary test of the executability of the potential indicator. Then, by physically executing the candidate query statements, their syntactic correctness, execution security, and result consistency are verified, determining whether the potential indicator can be reliably transformed into a database semantic asset. If the candidate query statements pass all verifications, the corresponding potential indicator can be transformed into a structured definition and stored in the semantic indicator library, achieving a closed-loop construction from vague business statements to reusable indicator assets.
[0074] For example, in the physical execution feedback verification process, refer to Figure 4 As shown, it can specifically include the following steps S401~S404: S401, Obtain environmental detection information from the target database.
[0075] Here, the target database refers to the physical database system that will ultimately execute the metric query. It is the actual storage environment that carries the business data. The corresponding environment detection information is represented by the database runtime metadata obtained by calling the database system interface or executing the system view query. It can provide contextual information for predicting the physical characteristics of the tables involved in the metric calculation, the distribution of field values, and the feasibility of inter-table connections.
[0076] The environmental detection information can include physical model data such as the cardinality and distribution information of the target dimension, table-level time granularity information, column-level data storage mode information, and multi-table join path information, providing a basis for constructing accurate and efficient candidate query statements. The cardinality and distribution information of the target dimension describes the number of different values in the column of that dimension and the proportion of records for each value, which can be used to determine whether the dimension is suitable as a grouping criterion. Table-level time granularity information describes the smallest storage unit of the time field in the data table, such as day, month, or year, used to align the time dimension in the indicator. Column-level data storage mode information describes the data type of the field, whether it can be nullable, and whether it has a default value. Multi-table join path information can be used to represent the connection method between two or more tables related by foreign keys or business keys, such as an inner join between the order table and the customer table using the customer identifier field.
[0077] For example, the aforementioned environmental detection information can be obtained by executing metadata query statements provided by the database system, such as querying information pattern views or using the data analysis function of database management tools, thereby obtaining various physical pattern parameters.
[0078] S402, based on the potential indicators of partial matching in the semantic alignment state and the environmental detection information, construct candidate structured query statements; and use the target database to perform syntax verification and execution feasibility testing on the candidate structured query statements.
[0079] Furthermore, after obtaining environmental detection information, for potential indicators with partial semantic alignment, the system can combine successfully matched components such as the database fields corresponding to the calculation logic, the columns corresponding to the dimensions, and the expressions corresponding to the filtering conditions. It can also refer to the connection paths provided in the environmental detection information, such as which tables can be connected through which fields, and the granularity of physical storage features such as the time field, to assemble and generate candidate structured query statements. These query statements fully express the logic required to calculate the indicator from the target database in the form of standard structured query language, including the aggregate expression in the select clause, the table name and join type from the select clause, the dimension columns in the grouping clause, and the filtering expression in the condition clause.
[0080] Specifically, during the process of performing syntax verification and execution feasibility testing on candidate structured query statements, one can first use the interpretation commands provided by the target database, such as execution plan analysis commands, to submit an interpretation request for the candidate query statement to the database. The database parser will return the syntax check results and execution path analysis of the query, including whether it references non-existent tables or fields, whether the join conditions are reasonable, and whether a full table scan will occur. This determines whether the query statement conforms to the database's syntax rules and whether the referenced database objects exist without actually consuming a large amount of computing resources. Then, the execution feasibility of the candidate query statement can be further tested using the target database. A clause limiting the number of rows returned can be added to the query statement, such as limiting the return to one record and performing a forced trial run, to more reliably verify whether the query can return valid results in a real physical environment, avoiding execution failures caused by insufficient permissions, extreme data distribution, or table locking.
[0081] In some possible implementations, to more comprehensively evaluate the stability and execution efficiency of candidate query statements, the database query cost estimation can be incorporated during the verification process to determine whether the query involves inefficient operations such as Cartesian products across multiple large tables or full table scans. This allows for optimization and adjustment of the candidate query statements, such as adding more precise join conditions or using index hints. Additionally, a LIMIT 1 mechanism can be introduced, where a LIMIT 1 clause is added to the end of the candidate query statement, forcing the database to return only the first record that meets the conditions. This allows for rapid verification of whether the query statement can execute successfully and return valid results without consuming significant database resources. If the query returns a single row of data after adding LIMIT 1, it indicates that the query syntax, table names, field names, join conditions, and filtering conditions are basically correct and physically executable. If an error or an empty set is returned, further correction is needed.
[0082] S403, after the candidate structured query statement passes the syntax verification and the execution feasibility test, the indicator query task corresponding to the candidate structured query statement is executed, and the query result is compared with the natural language description in the semantic block that generates the potential indicator.
[0083] Specifically, once a candidate structured query statement passes syntax validation and execution feasibility testing, it indicates that the query statement possesses basic physical executability at the database level and will not fail directly due to syntax errors, non-existent objects, or invalid connection paths. At this point, a complete metric query task can be executed, i.e., the candidate structured query statement is run in the target database to obtain the actual metric values or statistical result set. The query results returned by the database are then compared with the natural language description in the original semantic block that generated the potential metric to determine whether the calculated result of the metric conforms to the business facts described in the business document. For example, if a semantic block describes the sales revenue of a product line in the fourth quarter of last year as approximately five million yuan, and the database query returns a value of four million nine hundred and fifty thousand yuan, it can be considered basically consistent; if the returned value is negative, zero, or differs from the five million yuan level by more than one order of magnitude, it is considered inconsistent.
[0084] The scope of comparison can include the degree of approximation of numerical values, i.e., whether the relative error is within an acceptable threshold; the trend direction, such as whether the growth or decline described in the document is consistent with the actual trend of the query results; the statistical time range, such as whether the time interval in the document matches the time boundary in the query conditions; the dimensional conditions, such as whether the classification mentioned in the document corresponds to the grouping value in the query results; and the sorting relationship, such as whether the ranking or sorting described in the document is consistent with the order of the query results.
[0085] S404, if the comparison result of the query result and the natural language description in the semantic block that generates the potential index does not meet the preset conditions, the potential index is corrected based on the preset correction rules; and after regenerating the candidate structured query statement based on the corrected potential index, physical execution feedback verification is performed again until the candidate structured query statement passes the syntax verification, the execution feasibility test and the comparison result meets the preset conditions.
[0086] Here, if the database query results do not match the natural language descriptions in the business documents, it indicates that the calculation logic, field mapping, dimension binding, filtering conditions, or table join paths defined by the current potential indicator deviate from the business facts described in the document, and therefore cannot be directly stored in the database as semantic indicators. In this case, the potential indicator can be corrected according to the preset correction rules.
[0087] Specifically, the preset correction rules are a knowledge set storing various common correction strategies. These pre-stored rules can include: field mapping replacement rules (using the field with the second highest semantic similarity when a field fails to match); alternative connection paths rules (attempting indirect connections through intermediate tables when the main connection path does not exist); filter condition adjustment rules (adjusting filter values to actual values based on the distribution of dimension values in the environmental detection information); and aggregation level adjustment rules (adjusting monthly aggregation to daily or quarterly aggregation based on time granularity information). These different correction operations can serve as the basis for adjusting unmatched or low-confidence components, selecting the appropriate rule based on the specific reason for the verification failure.
[0088] Furthermore, after correcting the potential indicators according to the preset correction rules, candidate structured query statements can be regenerated based on the corrected potential indicators. Then, return to steps S402-S403 to re-perform syntax verification, feasibility testing, and factual consistency comparison until the candidate query statements pass all verifications and the comparison results meet the preset conditions. The preset conditions are a set of pre-defined criteria for determining whether the database query results and the natural language description meet the factual consistency requirements. These criteria may include multi-dimensional factual consistency judgment standards such as numerical error tolerance, trend direction consistency requirements, statistical time range matching degree, dimension value correspondence, sorting relationship consistency, unit and magnitude consistency, and the reasonableness of null or zero values. For example, the preset conditions can be set such that the relative error between the query returned value and the document description value does not exceed 5%, the trend direction of the query result is the same as the growth or decline trend of the document description, the time range covered by the query result must completely fall within the statistical interval specified in the document, and the grouping values of each dimension should correspond one-to-one with the categories listed in the document. The specific thresholds for each of the above dimensions can be flexibly set according to the requirements of indicator accuracy and reliability in different business scenarios, and are not specifically limited here.
[0089] In some possible embodiments, if the candidate query still fails all verifications after a preset number of automatic corrections, such as three corrections, the potential indicator, along with its current matching results and verification failure logs, can be sent to a human review terminal for offline analysis and correction by human experts. The human reviewer can view the original document, database metadata, and failure logs to determine whether the document description is ambiguous or the database schema lacks necessary fields. The corrected indicator definition or mapping relationship is then fed back, and the verification process is retried until the indicator passes verification or is marked as an invalid candidate that cannot be automatically constructed.
[0090] Furthermore, after the candidate query statement passes syntax validation, performs feasibility testing, and the comparison results meet preset conditions, the validated potential indicators can be stored in the semantic indicator library.
[0091] In some possible implementations, to ensure the structured nature, cross-platform compatibility, and searchability of the metrics being stored, validated potential metrics can first be converted into declarative configuration files. This involves using a declarative format independent of specific database dialects, such as YAML or JSON, to describe the metric's name, calculation formula, dependent dimensions, filtering conditions, and table join relationships. The declarative configuration file is then input into a natural language processing (NLP) model, which generates corresponding natural language description text for it. For example, for a metric that includes summation of sales revenue, grouping by month and product line, and filtering by region (North China), the NLP model can generate the description text: "This metric calculates the total monthly sales of each product line in North China, used to analyze the monthly sales performance of each product line in the North China region." Finally, the declarative configuration file and its corresponding natural language description text can be stored together in a semantic metric library. Simultaneously, an embedding model is called to convert the natural language description text into a high-dimensional vector and store it in a vector index to support subsequent semantic similarity retrieval. This enriches the asset content of the semantic metric library and provides a reusable and interpretable metric knowledge kernel for subsequent Text-to-SQL natural language query generation tasks.
[0092] It's understandable that semantic alignment states include both exact matches and semantic missing states. When the semantic alignment state is an exact match, it means the potential indicator is highly consistent with the definitions of existing indicators in the semantic indicator library. In this case, the definition and database mapping of the existing indicator can be directly reused without re-performing physical execution verification. The potential indicator only needs to be marked as a match, or it can be added to the library as an alias or synonym of an existing indicator to expand the query coverage of the semantic indicator library. When the semantic alignment state is semantic missing, the potential indicator lacks sufficient matching information to support the construction of candidate query statements, thus preventing physical execution verification. In this case, the potential indicator can be marked as an item that cannot be automatically constructed and requires manual processing, or it can be used as reference material for manually defining new indicators, avoiding further physical execution verification and thus preventing ineffective query construction and resource consumption.
[0093] The database semantic indicator construction method, apparatus, medium, and device provided in this disclosure improve the automation level and semantic alignment accuracy of database semantic indicator construction, realize end-to-end automated construction from multi-source heterogeneous data to executable and reusable structured indicator assets, effectively reduce the human cost of semantic layer initialization and maintenance, and provide highly reliable and interpretable indicator knowledge support for Text-to-SQL systems.
[0094] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0095] Based on the same inventive concept, this disclosure also provides a database semantic index construction device corresponding to the database semantic index construction method. Since the principle of the device in this disclosure for solving the problem is similar to the database semantic index construction method described above in this disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0096] Reference Figure 5 The diagram shown is a schematic of a database semantic index construction apparatus 500 provided in an embodiment of this disclosure. The apparatus includes: The information acquisition module 501 is used to acquire database semantic indicator construction information; wherein, the database semantic indicator construction information includes database definition language, historical structured query language logs, and unstructured business documents; The indicator library construction module 502 is used to reverse parse the database definition language and the historical structured query language logs, generate intermediate indicator representations, and store the intermediate indicator representations in the semantic indicator library. The indicator deconstruction module 503 is used to adaptively segment the unstructured business document into multiple semantic blocks, and to deconstruct each semantic block into potential indicators. The indicator matching module 504 is used to match the potential indicators based on the semantic indicator library and determine the semantic alignment state based on the matching result. The indicator verification module 505 is used to generate candidate query statements based on the successfully matched potential indicators when the semantic alignment state is partial matching, perform physical execution feedback verification on the candidate query statements, and store the verified potential indicators into the semantic indicator library.
[0097] In some possible embodiments, the indicator library construction module 502 is specifically used for: The database definition language is input into a natural language processing model to generate a basic semantic model; wherein, the basic semantic model includes metric information, dimension information, and inter-table relationship information; Each historical structured query language entry in the historical structured query language log is converted into an abstract syntax tree, and data table identifiers, calculation operations, grouping operations, and data table relationships are extracted from the syntax tree structure. The extracted data table identifiers, calculation operations, grouping operations, and data table relationships are aligned and mapped with the metric information, dimension information, and inter-table relationship information in the basic semantic model to generate an intermediate representation of the indicator; wherein, the intermediate representation of the indicator includes calculation logic, dimensions, and filtering conditions; The intermediate representation of the indicator is input into a natural language processing model, and the natural language processing model is used to generate a corresponding natural language description text for each intermediate representation of the indicator. The semantic indicator library is constructed based on each intermediate representation of the indicator and the natural language description text corresponding to the intermediate representation of the indicator.
[0098] In some possible embodiments, the index deconstruction module 503 is specifically used for: Identify the data types in the unstructured business documents; When the data type is plain text data, a text hierarchy logical structure tree is constructed based on the document title hierarchy in the unstructured business document, and the unstructured business document is hierarchically divided into blocks based on the text hierarchy logical structure tree. The complete hierarchical path information of each text block in the text hierarchy logical structure tree is retained to obtain plain text blocks. When the data type is table data, the table title, table content, and table notes of the table data in the unstructured business document are extracted as context anchors, and the table data is reconstructed into a structured table format to obtain table data blocks.
[0099] In some possible embodiments, the index deconstruction module 503 is specifically used for: Each of the semantic blocks is input into the first semantic understanding model, and the first semantic understanding model performs domain identification on each of the input semantic blocks respectively; For each semantic block, a domain prompt word template corresponding to the domain of the semantic block and an industry term corresponding to the domain of the semantic block are determined, and an enhanced prompt word corresponding to the semantic block is generated based on the domain prompt word template and the industry term. For each semantic block, the semantic block and the corresponding enhanced prompt words are input into the second semantic understanding model. The second semantic understanding model performs component-level deconstruction on the semantic block and extracts the potential indicators corresponding to the semantic block. The potential indicators include potential computational logic, potential dimensions, and potential filtering conditions.
[0100] In some possible embodiments, the indicator matching module 504 is specifically used for: The natural language description in the semantic block of the potential indicator is generated is compared with the natural language description of the intermediate representation of each indicator in the semantic indicator library to determine whether the potential indicator is semantically matched with the existing indicators in the semantic indicator library. When the feature similarity comparison result can determine the semantic matching status between the potential indicator and the existing indicator, the semantic alignment status of the potential indicator is determined according to the feature similarity comparison result; wherein, the semantic alignment status includes one of complete matching, partial matching or semantic missing. When the feature similarity comparison result indicates that it is impossible to determine whether the potential indicator is semantically matched with the existing indicator, the potential calculation logic, potential dimensions and potential screening conditions in the potential indicator are respectively matched and semantically aligned with the measurement information, dimension information and data table relationship information in the basic semantic model; and the semantic alignment status of the potential indicator is determined according to the feature similarity comparison result and the fine-grained matching result.
[0101] In some possible embodiments, the indicator verification module 505 is specifically used for: Obtain environmental detection information of the target database; wherein, the environmental detection information includes cardinality and distribution information of the target dimension, table-level time granularity information, column-level data storage mode information, and multi-table join path information; Based on the potential indicators of partial matching in the semantic alignment state and the environmental detection information, candidate structured query statements are constructed; and the target database is used to perform syntax verification and execution feasibility testing on the candidate structured query statements. After the candidate structured query statement passes the syntax verification and the execution feasibility test, the indicator query task corresponding to the candidate structured query statement is executed, and the query result is compared with the natural language description in the semantic block that generates the potential indicator. If the comparison result of the query result and the natural language description in the semantic block that generates the potential indicator does not meet the preset conditions, the potential indicator is corrected based on the preset correction rules; and after regenerating the candidate structured query statement based on the corrected potential indicator, physical execution feedback verification is performed again until the candidate structured query statement passes the syntax verification, the execution feasibility test and the comparison result meets the preset conditions.
[0102] In some possible embodiments, the indicator verification module 505 is specifically used for: Transform the validated potential metrics into declarative configuration files; The declarative configuration file is input into a natural language processing model, and the natural language processing model is used to generate a corresponding natural language description text for the declarative configuration file. The declarative configuration file and the corresponding natural language description text are stored in the semantic index library.
[0103] Based on the same technical concept, this disclosure also provides a computer device. (See also...) Figure 6 The diagram shows the structure of a computer device 600 provided in this embodiment of the present disclosure, including a processor 601, a memory 602, and a bus 603. The memory 602 stores execution instructions and includes a main memory 6021 and an external memory 6022. The main memory 6021, also called internal memory, is used to temporarily store computational data in the processor 601 and data exchanged with external memory 6022 such as a hard disk. The processor 601 exchanges data with the external memory 6022 through the main memory 6021.
[0104] In this embodiment, the memory 602 is specifically used to store application code that executes the solution of this application, and its execution is controlled by the processor 601. That is, when the computer device 600 is running, the processor 601 communicates with the memory 602 through the bus 603, so that the processor 601 executes the application code stored in the memory 602, and then executes the method described in any of the foregoing embodiments.
[0105] The memory 602 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0106] Processor 601 may be an integrated circuit chip with signal processing capabilities. The aforementioned processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor can be a microprocessor or any conventional processor.
[0107] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the computer device 600. In other embodiments of this application, the computer device 600 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0108] This disclosure also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the database semantic index construction method described in the above method embodiments. The storage medium can be a volatile or non-volatile computer-readable storage medium.
[0109] This disclosure also provides a computer program product carrying program code. The program code includes instructions that can be used to execute the steps of the database semantic index construction method described in the above method embodiments. For details, please refer to the above method embodiments, which will not be repeated here.
[0110] The aforementioned computer program product can be implemented through hardware, software, or a combination thereof. In one optional embodiment, the computer program product is specifically embodied in a computer storage medium; in another optional embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.
[0111] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. In the several embodiments provided in this disclosure, it should be understood that the disclosed systems and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.
[0112] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0113] In addition, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0114] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0115] Finally, it should be noted that the above-described embodiments are merely specific implementations of this disclosure, used to illustrate the technical solutions of this disclosure, and not to limit it. The protection scope of this disclosure is not limited thereto. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this disclosure. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure, and should all be covered within the protection scope of this disclosure. Therefore, the protection scope of this disclosure should be determined by the protection scope of the claims.
Claims
1. A method for constructing semantic indicators for a database, characterized in that, include: Obtain database semantic indicator construction information; wherein, the database semantic indicator construction information includes database definition language, historical structured query language logs, and unstructured business documents; The database definition language and the historical structured query language logs are reverse parsed to generate intermediate representations of indicators, and the intermediate representations of indicators are stored in the semantic indicator library. The unstructured business document is adaptively semantically segmented to obtain multiple semantic blocks, and each semantic block is deconstructed to obtain potential indicators. The potential indicators are matched based on the semantic indicator library, and the semantic alignment status is determined based on the matching results. When the semantic alignment state is a partial match, candidate query statements are generated based on the potential indicators that have been successfully matched. The candidate query statements are then verified by physical execution feedback, and the verified potential indicators are stored in the semantic indicator library.
2. The method according to claim 1, characterized in that, The process of reverse parsing the database definition language and the historical structured query language logs to generate an intermediate representation of the indicators, and storing the intermediate representation of the indicators in the semantic indicator library, includes: The database definition language is input into a natural language processing model to generate a basic semantic model; wherein, the basic semantic model includes metric information, dimension information, and inter-table relationship information; Each historical structured query language entry in the historical structured query language log is converted into an abstract syntax tree, and data table identifiers, calculation operations, grouping operations, and data table relationships are extracted from the syntax tree structure. The extracted data table identifiers, calculation operations, grouping operations, and data table relationships are aligned and mapped with the metric information, dimension information, and inter-table relationship information in the basic semantic model to generate an intermediate representation of the indicator; wherein, the intermediate representation of the indicator includes calculation logic, dimensions, and filtering conditions; The intermediate representation of the indicator is input into a natural language processing model, and the natural language processing model is used to generate a corresponding natural language description text for each intermediate representation of the indicator. The semantic indicator library is constructed based on each intermediate representation of the indicator and the natural language description text corresponding to the intermediate representation of the indicator.
3. The method according to claim 1, characterized in that, The adaptive semantic segmentation of the unstructured business document includes: Identify the data types in the unstructured business documents; When the data type is plain text data, a text hierarchy logical structure tree is constructed based on the document title hierarchy in the unstructured business document, and the unstructured business document is hierarchically divided into blocks based on the text hierarchy logical structure tree. The complete hierarchical path information of each text block in the text hierarchy logical structure tree is retained to obtain plain text blocks. When the data type is table data, the table title, table content, and table notes of the table data in the unstructured business document are extracted as context anchors, and the table data is reconstructed into a structured table format to obtain table data blocks.
4. The method according to claim 2, characterized in that, The step of deconstructing the metrics for each semantic block includes: Each of the semantic blocks is input into the first semantic understanding model, and the first semantic understanding model performs domain identification on each of the input semantic blocks respectively; For each semantic block, a domain prompt word template corresponding to the domain of the semantic block and an industry term corresponding to the domain of the semantic block are determined, and an enhanced prompt word corresponding to the semantic block is generated based on the domain prompt word template and the industry term. For each semantic block, the semantic block and the corresponding enhanced prompt words are input into the second semantic understanding model. The second semantic understanding model performs component-level deconstruction on the semantic block and extracts the potential indicators corresponding to the semantic block. The potential indicators include potential computational logic, potential dimensions, and potential filtering conditions.
5. The method according to claim 4, characterized in that, The step of matching the potential indicators based on the semantic indicator library and determining the semantic alignment state based on the matching results includes: The natural language description in the semantic block of the potential indicator is generated is compared with the natural language description of the intermediate representation of each indicator in the semantic indicator library to determine whether the potential indicator is semantically matched with the existing indicators in the semantic indicator library. When the feature similarity comparison result can determine the semantic matching status between the potential indicator and the existing indicator, the semantic alignment status of the potential indicator is determined according to the feature similarity comparison result; wherein, the semantic alignment status includes one of complete matching, partial matching or semantic missing. When the feature similarity comparison result indicates that it is impossible to determine whether the potential indicator is semantically matched with the existing indicator, the potential calculation logic, potential dimensions and potential screening conditions in the potential indicator are respectively matched and semantically aligned with the measurement information, dimension information and data table relationship information in the basic semantic model; and the semantic alignment status of the potential indicator is determined according to the feature similarity comparison result and the fine-grained matching result.
6. The method according to claim 1, characterized in that, The physical execution feedback verification of the candidate query statements includes: Obtain environmental detection information of the target database; wherein, the environmental detection information includes cardinality and distribution information of the target dimension, table-level time granularity information, column-level data storage mode information, and multi-table join path information; Based on the potential indicators of partial matching in the semantic alignment state and the environmental detection information, candidate structured query statements are constructed; and the target database is used to perform syntax verification and execution feasibility testing on the candidate structured query statements. After the candidate structured query statement passes the syntax verification and the execution feasibility test, the indicator query task corresponding to the candidate structured query statement is executed, and the query result is compared with the natural language description in the semantic block that generates the potential indicator. If the comparison result of the query result and the natural language description in the semantic block that generates the potential indicator does not meet the preset conditions, the potential indicator is corrected based on the preset correction rules; and after regenerating the candidate structured query statement based on the corrected potential indicator, physical execution feedback verification is performed again until the candidate structured query statement passes the syntax verification, the execution feasibility test and the comparison result meets the preset conditions.
7. The method according to claim 1, characterized in that, The step of storing the verified potential metrics into the semantic metric library includes: Transform the validated potential metrics into declarative configuration files; The declarative configuration file is input into a natural language processing model, and the natural language processing model is used to generate a corresponding natural language description text for the declarative configuration file. The declarative configuration file and the corresponding natural language description text are stored in the semantic index library.
8. A database semantic index construction device, characterized in that, include: The information acquisition module is used to acquire database semantic indicator construction information; wherein, the database semantic indicator construction information includes database definition language, historical structured query language logs, and unstructured business documents; The indicator library construction module is used to reverse parse the database definition language and the historical structured query language logs to generate intermediate indicator representations and store the intermediate indicator representations in the semantic indicator library. The indicator deconstruction module is used to adaptively segment the unstructured business document into multiple semantic blocks, and to deconstruct the indicator for each semantic block to obtain potential indicators. The indicator matching module is used to match the potential indicators based on the semantic indicator library and determine the semantic alignment state based on the matching results. The indicator verification module is used to generate candidate query statements based on the successfully matched potential indicators when the semantic alignment state is partial matching, perform physical execution feedback verification on the candidate query statements, and store the verified potential indicators into the semantic indicator library.
9. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 7.
10. A computer device, comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 7.
