Intelligent agent-based securities field natural language question and answer method and device, and medium
By employing an agent-based natural language question answering method for the securities domain, and utilizing quintuple transformation and implicit verification, the problem of semantically similar but unequal intents in securities data queries is solved, thereby improving the accuracy and speed of question answering.
Patent Information
- Application Number
- CN202611665913.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-27
- Publication Date
- 2026-11-27
AI Technical Summary
In securities data queries, existing technologies cannot identify implicit conditions that lead to incorrect answers due to semantic similarity threshold judgments. Furthermore, when generating SQL from large models, errors in table field mapping and inconsistent calculation methods for relative indicators can easily occur, resulting in inaccurate answers.
We adopt an agent-based natural language question answering method for the securities field. We use a five-tuple transformation to represent natural language questions in a structured way, and perform comparison and implicit verification to ensure the consistency of query intent and the accuracy of the answer.
It improves the accuracy and speed of natural language question answering, and solves the problem of semantically similar but unequal query intents by using quintuple comparison and implicit verification, thereby reducing latency and computing power overhead.
Smart Images

Figure CN123178581A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language data processing technology, and in particular to a natural language question-answering method, apparatus, and medium based on intelligent agents in the securities field. Background Technology
[0002] As the scale of business data in enterprise databases continues to grow, securities business databases are also becoming increasingly large. In the field of securities data querying, intelligent question-answering systems typically use direct matching and reuse of historical question-answer pairs to respond to users' natural language questions. Regarding historical question-answer pair matching, existing technologies generally use vector similarity thresholds, which calculate the semantic similarity between the user's question and a standard question in the knowledge base. If the similarity exceeds a preset threshold, it is considered a match, and the standard answer is returned directly. However, semantic similarity does not equate to equivalent query intent. Two questions may be highly similar at the text level, but due to differences in implicit conditions such as numerical values, dates, and units, completely different query results may be required. Simply relying on similarity thresholds cannot identify these differences and can easily lead to incorrect answers.
[0003] Furthermore, the securities business database has many tables and highly specialized field naming. User questions include both factual queries and business analysis. When the existing large model is directly generated into SQL, it is easy to encounter table field mapping errors, inconsistent calculation methods for relative indicators, and incomplete consistency between the answer content and the data results, resulting in inaccurate answers to the questions.
[0004] Therefore, a new natural language question answering method is needed in the securities field to address the problems of poor accuracy and slow speed in natural language question answering, thereby improving the accuracy and speed of natural language question answering. Summary of the Invention
[0005] This invention provides a natural language question answering method, device, and medium based on intelligent agents in the securities field, which improves the accuracy and speed of natural language question answering.
[0006] The first aspect of this invention discloses a natural language question answering method for the securities field based on intelligent agents, the method comprising: In response to natural language processing issues in the securities field, the natural language processing issue is retrieved based on a preset private knowledge base to obtain a target issue; the natural language processing issue and the target issue are transformed into a quintuple to obtain a first quintuple and a second quintuple; the first quintuple and the second quintuple are aligned and compared to obtain a comparison result; the quintuple transformation is to represent the issue in a structured way. When it is determined that the comparison result meets the preset comparison requirements, implicit verification is performed on the first question answer corresponding to the target question in the private knowledge base to obtain an implicit verification result; when it is determined that the implicit verification result meets the preset verification requirements, the first question answer is input into the agent to obtain a first output result. When it is determined that the comparison result does not meet the preset comparison requirements, or when it is determined that the implicit verification result does not meet the preset verification requirements, the natural language question is processed through a bidirectional retrieval path to obtain a metadata string; based on the metadata string, the answer to the second question corresponding to the natural language question is obtained; the answer to the second question is input into the agent to obtain a second output result. Determine either the first output result or the second output result to obtain the target output result.
[0007] As an optional implementation, in the first aspect of the present invention, the step of processing the natural language problem through a bidirectional retrieval path to obtain a metadata string includes: The natural language question is processed through a first retrieval path to obtain a first metadata list. The first retrieval path is used to filter physical table names and field names related to the natural language question in a preset securities metadata knowledge base. The natural language question is processed through a second retrieval path to obtain a second metadata list. The second retrieval path is used to filter the business meanings and definitions related to the natural language question in a preset securities metadata knowledge base. Based on the first quintuple, the first metadata list is validated to obtain a first validation set; based on the first quintuple, the second metadata list is validated to obtain a second validation set. Based on the first verification set and the second verification set, a metadata string is obtained.
[0008] As an optional implementation, in the first aspect of the present invention, obtaining the metadata string based on the first verification set and the second verification set includes: When it is determined that the first structural anchor in the first quintuple can match the data of both the first validation set and the second validation set, a first complete block corresponding to the data of the first structural anchor is obtained based on the first validation set, and a second complete block corresponding to the data of the first structural anchor is obtained based on the second validation set. When it is determined that the second structural anchor in the first quintuple only matches the data of the first verification set or the second verification set, the first unidirectional block corresponding to the data tag of the second structural anchor is obtained according to the first verification set, or the second unidirectional block corresponding to the data tag of the second structural anchor is obtained according to the second verification set. When it is determined that the third structural anchor point in the first quintuple cannot match the data of the first validation set and the second validation set, a data missing block is obtained based on the third structural anchor point. The first complete block, the second complete block, the first unidirectional block or the second unidirectional block, and the missing data block are filled into a preset metadata concatenation table to obtain a metadata string.
[0009] As an optional implementation, in the first aspect of the present invention, the step of retrieving the natural language question based on a preset private knowledge base to obtain the target question includes: The natural language problem is broken down according to its structure to obtain a first subject part, a second object part, and a third body part; the first subject part includes the target object of the natural language problem, the second object part includes the specific content of the natural language problem, and the third body part includes the time constraint and aggregation dimension of the natural language problem; The first subject part, the second object part, and the third subject part are matched with the question data in the private knowledge base to obtain the first subject matching score, the second object matching score, and the third subject matching score; A first confidence level is obtained based on the first subject matching score and the second object matching score; a second confidence level is obtained based on the second object matching score and the third subject matching score; a third confidence level is obtained based on the first subject matching score and the third subject matching score; the first confidence level is a score used to reflect whether the query target is consistent, the second confidence level is a score used to reflect whether the query content and limiting conditions are consistent, and the third confidence level is a score used to reflect whether the query scope is consistent. The question selection score is obtained based on the first confidence level, the second confidence level, and the third confidence level. Based on the scores of the questions, the target questions are obtained.
[0010] As an optional implementation, in the first aspect of the present invention, obtaining the answer to the second question corresponding to the natural language question based on the metadata string includes: Based on the metadata string, a first SQL statement is obtained; the first SQL statement is parsed using a syntax analysis algorithm to obtain a statement syntax tree; the statement syntax tree is subjected to error checking to obtain a set of error-activated nodes; based on a preset semantic violation topology graph, the set of error-activated nodes is matched to obtain a matching result; the semantic violation topology graph includes a function selection subgraph, a data aggregation subgraph, and an indicator caliber subgraph; When the matching result is determined to be a modification statement suggestion, the first SQL statement is corrected based on the modification statement suggestion to obtain a second SQL statement; based on the second SQL statement, the answer to the second question is obtained; the modification statement suggestion includes combined error review suggestions and independent error review suggestions; When the matching result is determined to be a normal statement opinion, the answer to the second question is obtained based on the first SQL statement.
[0011] As an optional implementation, in the first aspect of the present invention, obtaining the first SQL statement based on the metadata string includes: The SQL statement structure is determined based on the first complete block and / or the first unidirectional block in the metadata string; Based on the SQL statement structure, the initial SQL statement is obtained according to the second complete block and / or the second unidirectional block; Based on the initial SQL statement, the first SQL statement is obtained by checking the missing data blocks.
[0012] As an optional implementation, in the first aspect of the present invention, the semantic violation topology graph is constructed in the following specific manner: Obtain the SQL validation rule set for error checking of the statement syntax tree in the securities field. The SQL validation rule set includes at least a first validation rule, a second validation rule, a third validation rule, a fourth validation rule, and a fifth validation rule. The first validation rule is used to detect whether there is data source structure distortion in the SQL statement due to the incorrect use of the UNION ALL operation. The second validation rule is used to detect whether the SQL statement mistakenly uses the basic sorting function instead of the standard quantile window function in the quantile or percentage ranking scenario. The third validation rule is used to detect whether the median aggregation function is omitted in the SQL statement. The fourth validation rule is used to detect whether the SQL statement incorrectly uses the AVG or MAX aggregation function instead of SUM summation in the relative indicator calculation scenario. The fifth validation rule is used to detect whether the SQL statement directly performs a percentage formatting operation of multiplying by 100 during data processing. Based on the second and fifth verification rules, a function selection subgraph is obtained; based on the first, third, and fourth verification rules, a data aggregation subgraph is obtained; based on the fourth and fifth verification rules, an indicator caliber subgraph is obtained. Based on the function selection subgraph, the data aggregation subgraph, and the indicator caliber subgraph, a semantic violation topology graph is obtained.
[0013] A second aspect of this invention discloses a natural language question-answering device for the securities field based on intelligent agents, the device comprising: The language conversion and comparison module is used to respond to natural language problems in the securities field; it retrieves the natural language problem based on a preset private knowledge base to obtain the target problem; it performs a quintuple conversion on the natural language problem and the target problem to obtain a first quintuple and a second quintuple; it aligns and compares the first quintuple and the second quintuple to obtain a comparison result; the quintuple conversion is to represent the problem in a structured way. The local data retrieval module is used to perform implicit verification on the first question answer corresponding to the target question in the private knowledge base when it is determined that the comparison result meets the preset comparison requirements, and obtain implicit verification result; when it is determined that the implicit verification result meets the preset verification requirements, the first question answer is input into the intelligent agent to obtain the first output result; The data retrieval module is used to process the natural language question through a bidirectional retrieval path to obtain a metadata string when it is determined that the comparison result does not meet the preset comparison requirements or the implicit verification result does not meet the preset verification requirements; based on the metadata string, it obtains the second question answer corresponding to the natural language question; and inputs the second question answer into the intelligent agent to obtain a second output result. The target result output module is used to determine the first output result or the second output result to obtain the target output result.
[0014] A third aspect of the present invention discloses an apparatus comprising a memory and a processor, the apparatus comprising: Memory containing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory to execute some or all of the steps in the agent-based natural language question answering method for the securities field according to any one of the first aspects of the present invention.
[0015] The fourth aspect of the present invention discloses a computer storage medium storing computer instructions, which, when invoked, are used to execute some or all of the steps in the agent-based natural language question answering method for the securities field as described in any of the first aspects of the present invention.
[0016] Compared with the prior art, the present invention has the following beneficial effects: By responding to natural language questions in the securities field, the natural language question is retrieved based on a private knowledge base to obtain the target question. The natural language question and the target question are then transformed into five-tuples to obtain the first five-tuple and the second five-tuple. The first five-tuple and the second five-tuple are aligned and compared to obtain the comparison result. By transforming the fuzzy natural language question into a five-tuple structured query intent representation consisting of entity type, entity value, indicator, time constraint, and aggregation dimension, and comparing it, the problem of semantically similar but unequal query intents can be solved.
[0017] When the comparison result is determined to meet the preset comparison requirements, implicit verification is performed on the first question answer corresponding to the target question in the private knowledge base to obtain the implicit verification result. By checking one by one whether there is a conflict with the implicit unit constraints and time sensitivity requirements in the user question, the problem of incorrect answer caliber caused by different currencies and units of measurement in the securities field can be solved. Question matching is determined by comparing five tuples, and result matching is determined by implicit verification, forming a complete closed loop of two-way confirmation between "question and answer", which improves the accuracy of natural language question answering in the securities field. At the same time, through the path question-and-answer answer of the private knowledge base, questions with high repetition and fixed conclusion caliber can bypass the two-way path retrieval access and complex calculation process, thereby significantly reducing latency and computing power overhead and improving the question-and-answer speed.
[0018] When the comparison result is determined not to meet the preset comparison requirements, or when the implicit verification result is determined to meet the non-preset verification requirements, the natural language question is processed through a bidirectional retrieval path to obtain a metadata string; based on the metadata string, the answer to the second question corresponding to the natural language question is obtained; the answer to the second question is input into the agent to obtain a second output result; finally, it is determined whether the output result is obtained from the private knowledge base or the result obtained from the bidirectional retrieval path processing, and the target output result is determined. By first matching with the private knowledge base to see if the answer can be quickly found in the private knowledge base, and if the answer cannot be found in the private knowledge base, the answer to the natural language question is obtained through bidirectional retrieval path processing, thus improving the accuracy of question answering. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a flowchart illustrating a natural language question-answering method for the securities field based on intelligent agents, as disclosed in an embodiment of the present invention. Figure 2 This is a schematic diagram of the structure of a natural language question-answering device for the securities field based on an intelligent agent, as disclosed in an embodiment of the present invention. Figure 3 This is a schematic diagram of the structure of a device including a memory and a processor disclosed in an embodiment of the present invention. Detailed Implementation
[0021] To enable those skilled in the art to better understand the present invention, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0022] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this invention are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, product, or end that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or ends.
[0023] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0024] This invention discloses a natural language question answering method, apparatus, and medium based on intelligent agents in the securities field, which are used to improve the accuracy and speed of natural language question answering. These will be described in detail below.
[0025] Example 1 Please see Figure 1 , Figure 1 This is a flowchart illustrating a natural language question-answering method for the securities field based on intelligent agents, as disclosed in an embodiment of the present invention. Figure 1 The described agent-based natural language question answering method for the securities field can be applied to agent-based natural language question answering devices for the securities field. These devices can be integrated into cloud servers or local servers; however, this invention does not impose limitations. Figure 1 As shown, this agent-based natural language question answering method for the securities field can include the following operations: Step 101: Responding to natural language questions in the securities field; retrieving the natural language question based on a preset private knowledge base to obtain the target question; converting the natural language question and the target question into a quintuple to obtain the first quintuple and the second quintuple; aligning and comparing the first quintuple and the second quintuple to obtain the comparison result.
[0026] In this embodiment of the invention, in response to a natural language problem in the securities field, the natural language problem is retrieved based on a preset private knowledge base to obtain a target problem; the natural language problem is transformed into a quintuple to obtain a first quintuple; the target problem is transformed into a quintuple to obtain a second quintuple; the first quintuple and the second quintuple are aligned and compared to obtain a comparison result; the quintuple transformation is to represent the database query intent of the natural language problem in a structured way.
[0027] In this embodiment of the invention, the natural language question can be a query request made by the end user to the system in an unstructured manner based on their daily communication habits, aiming to obtain data or knowledge related to securities business; for example, "What is the current price of something?", "What sector is the hottest recently?", "Which product has a higher PE ratio, product A or product B?", etc.
[0028] In this embodiment of the invention, the construction of the private knowledge base can be achieved by organizing historical standard questions and answers into a private knowledge base. Specifically, historical questions and answers with fixed conclusions accumulated in securities business are compiled, with each entry representing a pairing of a "question" and its corresponding "standard answer." Then, all standard questions are pre-converted into vectors. This vector encoding process is completed by an embedding model. After encoding, each standard question becomes a string of numbers that a computer can efficiently calculate similarity for. Finally, the information of the standard question text, the standard question vector encoding, the intent quintuple, the standard answer text, and the structured fact tuple of the answer is stored in the private knowledge base. The standard question text can be the original question description that a user might ask; the vector encoding of the standard question can be used for retrieval in a private knowledge base; the intent quintuple can be pre-calculated historical question data stored in the database, such as the quintuple of <stock, a certain bank (xxxxxx), net profit, 2024Q1, none>; the standard answer text can be the verified and reliable answer content; the structured fact tuple of the answer can be the structured data pre-extracted from the standard answer, which includes specific values, units, data expiration dates, etc., and can be directly read during verification, which is both accurate and efficient.
[0029] In this embodiment of the invention, the process of obtaining the target question can be as follows: different questions in the private knowledge base are scored, and the top-ranked questions are selected as the target questions based on the scores. Alternatively, vector similarity retrieval and BM25 keyword retrieval can be performed simultaneously on the user question to recall the Top-5 candidate standard questions from the private knowledge base.
[0030] In this embodiment of the invention, the quintuple transformation is the structured representation of the database query intent of a problem. The quintuple transformation can be an abstraction of a natural language problem into a query intent skeleton that the database can execute, uniquely determining the result set. The structure of the quintuple transformation can be: quintuple = {entity type, entity value, indicator, time constraint, aggregation dimension}. Here, the entity type can be the category of the object to be queried, because the same name may belong to different types; for example, the entity type of "What happened to a certain listed liquor company?" is stock, the entity type of "What is the outlook for the pharmaceutical industry?" is industry sector, the entity type of "How is a certain fund selection?" is fund, and the entity type of "Has a certain index 300 risen?" is index. The entity value can be the specific name or standard code of the object to be queried; for example, the entity value of type (stock) + value is a certain bank, code XXXXXX.SH; the entity value of type (index) + value is the Shanghai Composite Index, code XXXXXX.SH. The metrics can be the data fields you want to query. For example, if a user asks "how much money did you make?" or "what is the profit?", the metric is net profit attributable to the parent company. If a user asks "what is the PE ratio?" or "what is the price-to-earnings ratio?", the metric is the rolling price-to-earnings ratio. The time constraint can be the point-in-time data you want to query. If a user says "the first quarter of 2024", the time constraint is 2024Q1; if a user says "the whole year of last year", the time constraint is 2023 (assuming the current year is 2024); if a user says "last month", the time constraint is 2026-07 (assuming the current year is August 2026); if the user doesn't specify a time constraint, there is none, or you can retrieve the latest date data. The aggregation dimension can be whether the results should be grouped and by what group. For example, if a user asks "what is the net profit of a certain bank?", the aggregation dimension is none because they want a single number; if a user asks "the net profit of a certain bank for each year over the past 5 years", the aggregation dimension is by year; if a user asks "the revenue of each branch", the aggregation dimension is by branch; if a user asks "the average price-to-earnings ratio of each industry", the aggregation dimension is by industry.
[0031] For example, a complete quintuple could be: User question: "How much money did a certain bank earn last quarter?", quintuple: Entity type = stock, Entity value = XXXXXX.SH, Metric = Net profit attributable to parent company, Time constraint = 2026Q1 (assuming the current month is August 2026, "last quarter" is resolved to 2026Q1), Aggregation dimension = None. User question: "What were the revenue and net profit of listed company A and listed company B over the past three years?", quintuple: Entity type = stock, Entity value = XXXXXX.SH, XXXXXX.SZ (multiple entity values), Metric = Operating revenue, Net profit attributable to parent company, Time constraint = 2023 to 2025 (assuming this year is 2026), Aggregation dimension = By year, By entity.
[0032] The quintuple transformation is a key module of the system, aiming to extract structured quintuples from natural language processing problems: entity type, entity value, indicator, time constraint, and aggregation dimension. The specific transformation process can be as follows: Preprocessing is performed on natural language problems, including word segmentation, part-of-speech tagging, and dependency parsing; a named entity recognition (NER) model for the financial domain, which has been trained on a large amount of general or financial text and has basic language understanding and entity recognition capabilities, is used to identify entities and map them to entity types and entity values; an indicator thesaurus and rule matching are used to identify indicators; a time parsing module is used to parse time constraints; and an aggregation dimension recognition module is used to determine whether grouping is needed and the grouping dimension based on syntactic structure and trigger words.
[0033] Specifically, entity types include, but are not limited to: stocks, industry sectors, funds, indices, bonds, etc. Entity values can be specific names or standard codes. A securities entity dictionary is constructed, containing stock names, codes, industry names, fund names, index names, etc., and labeled with their corresponding entity types. Pre-trained NER models such as BERT-BiLSTM-CRF are used to identify entities in the problem, outputting entity text and their type labels. The identified entity text is then fuzzily matched with the entity dictionary (e.g., pinyin, abbreviation, full name) to obtain the standard code. If multiple entities appear in the problem, a list of entity value slots is stored, for example, "XXXXXX.SH,XXXXXX.SZ".
[0034] Construct a thesaurus of securities indicators, including the standard name of the indicator, synonyms, English abbreviations, and corresponding database field names. For example: Net Profit Attributable to Shareholders: Net Profit, Net Profit Attributable to Shareholders, Profit Attributable to Shareholders; Rolling Price-to-Earnings Ratio: PE(TTM), Price-to-Earnings Ratio, PE, TTM Price-to-Earnings Ratio; Operating Revenue: Revenue, Total Operating Revenue, Revenue. The extraction method could be: perform maximum length matching between the question text and the synonyms in the dictionary. If multiple candidate indicators are matched, disambiguation is performed based on context and syntactic position. For example, indicators appearing after "how much" or "how much" are usually the primary indicators. If multiple indicator terms are explicitly present in the question (e.g., "revenue and net profit"), multiple indicators are stored in the indicator slots.
[0035] The time constraint parsing module receives the question text and outputs standardized time constraint expressions, such as "2024Q1", "2023-2025", or "latest". It constructs time expression rules, such as regular expression matching for "last year", "last quarter", "most recent year", "last three years", "first quarter of 2024", etc.; it maintains a time parsing function library, for example: "last quarter" → calculates the previous quarter based on the current date; "last year" → the previous year; "latest" → no explicit time, indicating the latest data is taken, and in subsequent SQL generation, it sorts by the data update time field and takes the first record; if the question contains no time words, the time constraint slot is set to "none", meaning the latest available data is taken; the time constraint parsing result also affects the data cutoff time determination in subsequent implicit validations.
[0036] The aggregation dimension indicates whether the answer needs to be grouped, and by which field. Identification methods include: constructing a list of grouping trigger words, such as "each year," "every year," "each industry," "each branch," "by XX," "separately," etc.; performing dependency parsing on the question to find noun phrases associated with the trigger words and mapping them to database dimension fields; if there are no grouping trigger words in the question, the aggregation dimension = none, indicating that a single summary value is returned.
[0037] The results from the above modules are assembled into quintuples. For uncertain slots, the system can generate multiple candidate quintuples and use a pre-trained quintuple extraction model (such as a sequence-to-sequence model based on T5 or mT5) to jointly extract the entire sentence, outputting the quintuple with the highest confidence. If the confidence is lower than the threshold, the system switches to a bidirectional retrieval path to avoid misjudgment from the private knowledge base path.
[0038] In this embodiment of the invention, the alignment comparison process can be performed directly by comparing the five-tuples, since both the target problem and the natural language problem have been transformed by the five-tuples. There are two types of comparison results: one is that if the five-tuples are completely identical (entity values are the same after code mapping, and metrics are consistent after normalization), and there are no conflicts in the time constraints, the comparison result is marked as "structured intent hit"; the other is that if the key fields of the five-tuples conflict (such as different metrics), the comparison result is marked as "directly removing this candidate".
[0039] By performing a five-tuple transformation and comparison of queries, ambiguous natural language queries can be transformed into a structured query intent representation consisting of five slots: entity type, entity value, metric, time constraint, and aggregation dimension. Traditional vector matching can only determine whether two queries are semantically similar, failing to distinguish between key factual differences such as "net profit in 2023" and "net profit in 2024." Five-tuple comparison, by comparing the five-tuples of the user's query and the target query slot by slot, determines whether the two queries point to the same database query result set. Through five-tuple transformation, semantic equivalence determination is elevated from text similarity calculation to query result set equivalence determination, resolving the misjudgment problem of "semantic similarity but unequal query intent" in traditional vector matching. Five-tuple transformation ensures that the determination is based entirely on standardized domain knowledge rather than ambiguous text similarity. Furthermore, the results of five-tuple slot-by-slot comparison are fully interpretable: when a match fails, the specific slot and rule can be directly located, facilitating problem investigation and rule iteration optimization compared to black-box similarity scoring or large model judgment. Meanwhile, the quintuple alignment is based entirely on deterministic rules and does not require calling large models, further reducing the computational cost of the confirmation process.
[0040] Step 102: When it is determined that the comparison result meets the preset comparison requirements, perform implicit verification on the first question answer corresponding to the target question in the private knowledge base to obtain the implicit verification result; when it is determined that the implicit verification result meets the preset verification requirements, input the first question answer into the agent to obtain the first output result.
[0041] In this embodiment of the invention, implicit verification includes data cutoff time verification and data unit verification.
[0042] In this embodiment of the invention, the preset comparison requirement may be that the comparison result of the first quintuple corresponding to the natural language question and the second quintuple corresponding to the target question is "structured intent hit" as the comparison requirement; if this comparison requirement is met, the following implicit verification will continue; if not, the process will jump to bidirectional path retrieval to find the answer to the natural language question.
[0043] In this embodiment of the invention, implicit validation can be achieved by recognizing that the intent equivalence of a quintuple does not guarantee the availability of the answer. Quintuple alignment only ensures that the user's question and the standard question are consistent in their query intent, meaning both will request the same data from the database. However, the quintuple cannot cover whether the requested data itself is still correct or meets the implicit requirements not explicitly stated by the user. Therefore, implicit validation is needed for the first question answer corresponding to the target question in the private knowledge base.
[0044] Implicit validation can verify the validity period and specific data units. Because data is highly time-sensitive, the quintuple structure designed in this embodiment is unaware of the passage of time. Furthermore, user questions may contain implicit units of measurement, but the quintuple does not include unit information. For example, if a user asks for the "latest" net profit, the quintuple can interpret "latest" as the current latest financial reporting period (e.g., 2026Q1) and find a standard answer also labeled 2026Q1. However, the problem is that this standard answer might have been generated in April 2026, while it is currently August 2026, and the second-quarter report has already been released; the truly "latest" data has changed. The quintuple only compares whether the time tags are consistent and does not check whether the answer is currently expired. Only by comparing the data cutoff date in the answer to the first question with the current system date and determining the validity period based on the financial reporting cycle can such expired data be intercepted.
[0045] For example, during data cutoff date verification, the system reads the data cutoff date and reporting period type from the structured fact tuple corresponding to the answer to the first question. For instance, the structured fact tuple corresponding to the answer to the first question might contain "Data cutoff date: 2026-03-31" and "Reporting period type: 2026Q1". The system presets data validity rules for the reporting period: Q1 data is valid until August 31st of the current year; Q2 data is valid until October 31st of the current year; Q3 data is valid until April 30th of the following year; and annual report data is valid until August 31st of the following year. The system obtains the current system date and compares it with the data validity cutoff date. If the current system date is later than the data validity cutoff date, the data is considered expired, and the implicit verification fails; otherwise, the data cutoff date verification passes. As shown in the example below, the user's question is "What is the latest net profit attributable to the parent company of a certain bank?" The time constraint in the first quintuple is parsed as "latest". The answer data for the target question in the private knowledge base has a cutoff date of March 31, 2026, and the reporting period type is 2026Q1. The current system date is September 5, 2026. Since the validity period of the 2026Q1 quarterly report data expires on August 31, 2026, and the current system date is later than this cutoff date, the data cutoff time validation is determined to fail. The implicit validation result is also a failure, and the system switches to bidirectional retrieval path processing.
[0046] The data unit check may be implemented as follows: the system parses unit constraint words in the user question, such as "hundred million yuan", "ten thousand US dollars", "hundred million US dollars", "yuan", "%", etc. If no unit constraint word appears in the user question, the data unit check is directly determined to be passed; if a unit constraint word appears in the user question, the answer value unit is read from the structured fact tuple of the first question answer, and this unit is compared with the unit constraint word in the user question. If the two are consistent, the data unit check is determined to be passed; if the two are inconsistent, the data unit check is determined to be failed. As shown in the following example, if the user question is "What is the latest net profit of a certain bank in hundred million US dollars?", the system parses the unit constraint as "hundred million US dollars". The structured fact tuple of the first question answer records the net profit value as 3500 with the unit "hundred million yuan". Since the two units are inconsistent, the data unit check is determined to be failed, the implicit check result is failed, and the system switches to the bidirectional retrieval path for processing. If the user question is "What is the latest net profit of a certain bank in hundred million yuan?", the unit constraint in the user question is "hundred million yuan", which is consistent with the answer unit, so the data unit check is passed. The above-mentioned reporting period data validity rule and unit constraint word list can both be stored in the system configuration file and read by the implicit check module during operation. Those skilled in the art can adjust the data validity cutoff date or expand the unit constraint word list according to actual securities business rules.
[0047] The "indicator" slot of the quintuple only records "net profit" and does not record "what unit it is measured in". If "hundred million US dollars" appears in the user question, this is a hard constraint on the answer unit, but it is not within the five limiting conditions of the quintuple. If the unit check of implicit verification is not performed, the system may directly reuse a standard answer denominated in RMB for a user requiring US dollar denomination, which is a serious compliance and accuracy accident in the securities field.
[0048] Through implicit verification, after the intent equivalence comparison and verification are passed, the first question answer itself can be independently verified based on factual data. By parsing factual tuples such as specific values, units, and data cutoff dates in the answer, and comparing them one by one with the implicit unit qualifiers and time-sensitive words in the user question, it is confirmed that the answer meets the current user's needs in both measurement caliber and timeliness dimensions.
[0049] Through the data timeliness check in implicit verification, historical answers that become invalid due to the update of the financial report cycle are automatically intercepted, ensuring that "latest" type questions always return truly latest data and avoiding misleading user decisions due to information lag. Through the implicit unit qualifier check in implicit verification, factual errors in answers caused by inconsistent currencies and dimensions are prevented, and the security of private knowledge base reuse is improved from "matching intent" to "usable answer content". Figure 1
[0050] Five-tuple alignment verifies whether "questions are equivalent," while implicit verification verifies whether "answers are still correct." These two complementary methods form a complete safety net; if either step fails, the query will not be reused. This solves the problems of semantically similar queries with unequal query intents and the reliability of answers derived from query intents, thus ensuring the reliability of private paths and improving the accuracy of natural language question answers. The verification process is based on pre-defined rules and structured fact tuple comparisons, eliminating the need to call large models and removing the manual review step while maintaining low latency, thereby increasing the speed of question answering.
[0051] In this embodiment of the invention, the intelligent agent can be an AI system capable of autonomously perceiving the environment, making decisions, and executing actions. The intelligent agent in this embodiment is used to rewrite the standard answer in a contextualized or summary manner; when the question is an analytical question, the intelligent agent uses an analysis report template, requiring the model to output in the form of a formal business summary, emphasizing conclusions first and the traceability of viewpoints and tables; when the question is a factual query, the intelligent agent uses a factual answer template, requiring a direct answer based on the result table.
[0052] The agent can be implemented using a large language model (LLM) commonly used in this field, such as a pre-trained language model based on the Transformer architecture, and fine-tuned on a corpus in the securities domain. Alternatively, an open-source or commercial large language model with 7B to 70B parameters can be selected, and domain adaptation can be achieved through the following methods: Continue pre-training or fine-tuning using corpora such as securities industry Q&A pairs, research reports, and announcement summaries; format the model input, using a unified prompt word template to ensure consistent output style and structure.
[0053] The agent's input consists of two parts: the user's original natural language question, and the answer data provided by the system (the answer to the first question or the answer to the second question) and its structured metadata. The structured metadata may include: data source (private knowledge base or database query), data expiration date, unit of measurement, generation time, etc. The output is a user-oriented natural language answer. The agent uses different output templates depending on the question type (fact-based query or analytical report).
[0054] When the system determines that the user's question is a factual query (such as querying specific values or indicator sizes), the agent uses a factual answer template; when the system determines that the user's question is an analytical query (such as comparisons, trends, proportions, etc.), the agent uses an analytical report template.
[0055] The factual response template may include: [Direct Response] {Core Conclusion or Value}; [Data Description] Data Source: {Source Identifier}; Data Cutoff Date: {Cutoff Date}; Unit: {Unit of Measurement}; [Supplementary Explanation] {Provide a brief explanation if necessary}.
[0056] An analysis report template may include: [Conclusion First] {A one-sentence core judgment}; [Key Data] {List 2-3 key data points or tables supporting the conclusion}; [Risk Warning] {Explanation of data timeliness or limitations in scope}.
[0057] Step 103: When it is determined that the comparison result does not meet the preset comparison requirements, or when it is determined that the implicit verification result does not meet the preset verification requirements, the natural language question is processed through a bidirectional retrieval path to obtain the metadata string; based on the metadata string, the answer to the second question corresponding to the natural language question is obtained; the answer to the second question is input into the agent to obtain the second output result.
[0058] In this embodiment of the invention, the bidirectional retrieval path can be processed using two different retrieval paths. The bidirectional retrieval can be performed through two directions. The first retrieval direction can be to perform similarity retrieval on all metadata blocks in the vector index and prioritize the selection of schema-type documents. Those skilled in the art will understand that schema-type documents are essentially "data format specifications," and different fields have different schema languages, but they all essentially define the structure and constraints of data. The second retrieval direction can be to obtain global candidate documents based on a hybrid retrieval tool that combines vector retrieval and BM25 sparse retrieval. Those skilled in the art will understand that BM25 is a classic text retrieval algorithm belonging to the "bag-of-words model," which does not consider the order of words, but only the words themselves.
[0059] In this embodiment of the invention, the metadata string can be a context string formed by deduplicating and merging the search results from two directions to address the current problem. This context string retains information such as physical table names, field names, business meanings, granularity, and update times for strict reference during the SQL generation stage.
[0060] In this embodiment of the invention, obtaining the answer to the second question can be achieved by generating an SQL statement based on the metadata string, then sending the SQL statement to the OceanBase database for execution to obtain the answer to the second question corresponding to the SQL statement. Those skilled in the art will understand that the OceanBase database is a distributed relational database.
[0061] Step 104: Determine the first output result or the second output result to obtain the target output result.
[0062] In this embodiment of the invention, the final target output result is determined by determining whether the natural language problem is the output result obtained through a private knowledge base path or the output result obtained through a bidirectional retrieval path.
[0063] As can be seen, in this embodiment of the invention, by responding to natural language questions in the securities field, the natural language question is retrieved based on a private knowledge base to obtain the target question; the natural language question and the target question are respectively transformed into five-tuples to obtain the first five-tuple and the second five-tuple; the first five-tuple and the second five-tuple are aligned and compared to obtain the comparison result; by transforming the fuzzy natural language question into a five-tuple structured query intent representation consisting of entity type, entity value, indicator, time constraint, and aggregation dimension, and comparing them, the problem of semantically similar but unequal query intents can be solved.
[0064] When the comparison result is determined to meet the preset comparison requirements, implicit verification is performed on the first question answer corresponding to the target question in the private knowledge base to obtain the implicit verification result. By checking one by one whether there is a conflict with the implicit unit constraints and time sensitivity requirements in the user question, the problem of incorrect answer caliber caused by different currencies and units of measurement in the securities field can be solved. Question matching is determined by comparing five tuples, and result matching is determined by implicit verification, forming a complete closed loop of two-way confirmation between "question and answer", which improves the accuracy of natural language question answering in the securities field. At the same time, through the path question-and-answer answer of the private knowledge base, questions with high repetition and fixed conclusion caliber can bypass the two-way path retrieval access and complex calculation process, thereby significantly reducing latency and computing power overhead and improving the question-and-answer speed.
[0065] When the comparison result is determined not to meet the preset comparison requirements, or when the implicit verification result is determined to meet the non-preset verification requirements, the natural language question is processed through a bidirectional retrieval path to obtain a metadata string; based on the metadata string, the answer to the second question corresponding to the natural language question is obtained; the answer to the second question is input into the agent to obtain a second output result; finally, it is determined whether the output result is obtained from the private knowledge base or the result obtained from the bidirectional retrieval path processing, and the target output result is determined. By first matching with the private knowledge base to see if the answer can be quickly found in the private knowledge base, and if the answer cannot be found in the private knowledge base, the answer to the natural language question is obtained through bidirectional retrieval path processing, thus improving the accuracy of question answering.
[0066] In an optional embodiment, the natural language question is processed through a bidirectional retrieval path to obtain a metadata string, including: The natural language question is processed through the first retrieval path to obtain the first metadata list. The first retrieval path is used to filter the physical table names and field names related to the natural language question in the preset securities metadata knowledge base. The natural language question is processed through the second retrieval path to obtain the second metadata list. The second retrieval path is used to filter the business meaning and definition of the natural language question in the preset securities metadata knowledge base. Based on the first quintuple, the first metadata list is validated to obtain the first validation set; based on the first quintuple, the second metadata list is validated to obtain the second validation set. Based on the first and second validation sets, the metadata string is obtained.
[0067] In this optional embodiment, the first retrieval path processing may involve performing a similarity search on all metadata blocks corresponding to all metadata documents involved in securities business, filtering the physical table names and field names of the data to obtain a first metadata list. The preset securities metadata knowledge base may be formed by cutting all metadata documents involved in securities business into small fragments according to record boundaries, then vectorizing each fragment and storing it in a vector index to form the corresponding all metadata blocks. The metadata documents include the table name and purpose description of each table, the name and type definition of each field, the business definition and calculation formula of each indicator, and the data update frequency and granularity description.
[0068] The process can be as follows: First, retrieve physical table names and field names directly related to the user's query intent from the securities metadata knowledge base. The retrieved data returns metadata blocks filtered by vector similarity retrieval. Each block contains the structural definitions of physical table names and field names, forming a first metadata list. Then, based on the five precise structural anchors in the first quintuple, the first metadata list is checked and verified one by one, filtering out data blocks that match the anchors. The matching data blocks are then retained, resulting in the first verification set.
[0069] For example, each block in the first metadata list is examined one by one using the five anchors in the first quintuple. Blocks that match the metric anchor "net profit" are retained and marked as matching metric anchor fields; blocks that match the entity type anchor "stock" are retained and marked as matching entity type anchor table structure; blocks that match the time constraint anchor "2024Q1" are retained and marked as matching time constraint anchor fields; blocks that are not related to any of the five anchors are removed; the retained blocks form the first validation set.
[0070] In this optional embodiment, the second retrieval path processing may involve using a hybrid retrieval tool combining vector retrieval and BM25 sparse retrieval to perform semantic information retrieval and filtering of the preset securities metadata knowledge base to obtain a second metadata list; then, based on the five precise structural anchors in the first quintuple, checking and verifying the second metadata list one by one, and filtering out data blocks that match the anchors; and finally, retaining the matching data blocks to obtain the second verification set.
[0071] In this optional embodiment, if only a single-path retrieval is used to generate the metadata string for the natural language question, the returned data is a mixed set, with structural and semantic information intertwined. Therefore, the quality of both structural and semantic information cannot be guaranteed simultaneously, and they can easily drag each other down. The resulting metadata string needs to distinguish between "field names" and "business explanations." Misidentification could lead to explanations being used as fields or missing actual fields, resulting in incorrect SQL and inaccurate SQL statements. Therefore, by setting up a two-path retrieval, structural and semantic information are retrieved and generated separately. Simultaneously, the first quintuple generated in the private knowledge base path is used to verify the structural and semantic information obtained from both retrieval paths. The resulting metadata string improves the accuracy of the generated SQL statement.
[0072] Furthermore, the first quintuple is decomposed into five independent semantic anchors: entity type anchor, entity value anchor, metric anchor, time constraint anchor, and aggregation dimension anchor. These five anchors are used to verify the relevance of the first metadata list generated by the first retrieval path and the second metadata list generated by the second retrieval path, respectively. Blocks irrelevant to any anchor are removed, and the verified blocks are retained and labeled with their corresponding anchor types, forming the first and second verification sets. At this point, the first verification set contains structural blocks relevant to the current query intent, and the second verification set contains relevant business description blocks. This removes irrelevant blocks mixed in with the original data, preventing irrelevant information from being fed to the large model during subsequent context assembly, reducing interference and eliminating noise. When generating SQL, it deals with pre-filtered, highly relevant categorical data, eliminating the need to manually determine which information is useful and which is not, reducing the probability of illusions and generation errors. Subsequently, all five anchors are traversed to form a structured metadata context oriented towards the current problem, i.e., a metadata string.
[0073] In the partitioning of structural and semantic information, the first path emphasizes structural information such as physical table names and field names, while the second path emphasizes semantic information such as business meaning and definitions. After cross-validation, the two types of blocks are assigned to the structural definition area and the business description area respectively based on anchor point coverage, rather than being flatly pieced together. This partitioning organization method makes the subsequent SQL generation process more orderly and efficient.
[0074] By validating the two-way recall results using quintuple anchors, only chunks explicitly related to at least one dimension of the current query intent are retained, while irrelevant chunks are removed. This reduces interference from useless information, improving the accuracy and relevance of metadata in the final context and reducing information interference during subsequent SQL generation. This is because directly performing vector similarity and keyword matching retrieval operations on natural language problems might retrieve and retain semantically similar but irrelevant metadata chunks. For example, if a user queries "net profit," vector retrieval might include the "operating revenue" field definition as a candidate, leading to inaccurate query results in the generated SQL statement. By setting up two-way retrieval, generating structural and semantic information separately, and validating them using quintuple structural anchors to eliminate interference from irrelevant data, this problem can be effectively solved.
[0075] The quintuple structure was originally used for problem equivalence determination in the fast path of a private knowledge base. This optional implementation reuses it as a verification anchor for retrieved metadata, allowing the same structured intent representation to play different roles in two different stages of the system. This design reuse reduces additional feature extraction overhead, maintains consistency in information representation within the system, and facilitates maintenance and expansion.
[0076] As can be seen, in this optional embodiment, by splitting the natural language problem into two parts, the first path ensures structural rigor, and the second path ensures semantic completeness, reducing the impact of data contamination on SQL generation. Validation using quintuple structural anchors can reduce interference from irrelevant data. After cross-validation, an organizational context is generated to obtain the metadata string. This segmented retrieval and validation allows the large model to prioritize the structural definition area and supplement it with the business description area during SQL generation, improving the accuracy and utilization of information retrieval, thereby enhancing the accuracy of the generated SQL statements.
[0077] In another optional embodiment, the metadata string obtained based on the first verification set and the second verification set may include: When it is determined that the first structural anchor in the first quintuple can match the data of the first validation set and the second validation set, the first complete block corresponding to the data of the first structural anchor is obtained according to the first validation set, and the second complete block corresponding to the data of the first structural anchor is obtained according to the second validation set. When it is determined that the second structural anchor in the first quintuple only matches the data of the first validation set or the second validation set, the first unidirectional block corresponding to the data tag of the second structural anchor is obtained according to the first validation set, or the second unidirectional block corresponding to the data tag of the second structural anchor is obtained according to the second validation set. When it is determined that the third structural anchor in the first quintuple cannot match the data in the first and second validation sets, the missing data block is obtained based on the third structural anchor. The first complete block, the second complete block, the first unidirectional block or the second unidirectional block, and the missing data block are filled into the preset metadata concatenation table to obtain the metadata string.
[0078] In this optional embodiment, the first structural anchor point may be one where there are five structural anchor points in the first quintuple. The structural anchor point that can simultaneously match data in both the first and second validation sets is considered the first structural anchor point. In this case, the data corresponding to the first structural anchor point in the first validation set is defined as the first complete block, and the data corresponding to the first structural anchor point in the second validation set is defined as the second complete block. The first complete block corresponds to the complete structural information that can be associated with the business description information, and the second complete block corresponds to the complete business description information that can be associated with the structural information; the two are mutually corresponding complete information.
[0079] In this optional embodiment, the second structural anchor point can be one where there are five structural anchor points in the first quintuple. The structural anchor point that only matches one type of data in either the first or second validation set is considered the second structural anchor point. In this case, the data corresponding to the second structural anchor point in the first validation set is defined as the first-way unidirectional block, or the data corresponding to the second structural anchor point in the second validation set is defined as the second-way unidirectional block. This unidirectional block indicates that the tagging information corresponding to the structural anchor point only contains structural information or only business descriptions, reminding the model that the anchor point's information is incomplete. If only one path is covered in either the first or second validation set, it means half is missing—either there's a field definition but no business definition, or there's a business description but no physical field name. This information about "which half is missing" must be explicitly marked so that the large model can handle it carefully and specifically during subsequent generation, rather than using it directly as complete information, which would cause ambiguity when generating SQL statements.
[0080] In this optional embodiment, the third structural anchor point can be any of the five structural anchor points in the first quintuple that cannot be matched to any data in either the first or second validation set. This is considered the third structural anchor point. Then, based on the information of the third structural anchor point, information about missing data blocks is generated. The information in the missing data block indicates that the aggregation dimension anchor point is not covered, and metadata related to industry groupings is missing; please do not fabricate such data. This missing data block clearly informs the large model that metadata for this dimension is missing, and fields must not be fabricated.
[0081] In this optional embodiment, the preset metadata concatenation table can be a pre-assembled metadata concatenation table arranged in the order of structure definition area, business description area, and uncovered warning area. Then, the first complete block and the first unidirectional block are filled into the structure definition area, the second complete block and the second unidirectional block are filled into the business description area, and the missing data block is filled into the uncovered warning area, finally forming the metadata string. The resulting complete text is the final metadata context used for SQL generation. It is not a random stack of blocks, but a refined input that is structurally and semantically segmented and with missing information explicitly marked.
[0082] By traversing five anchor points to check coverage, the system can explicitly identify which query intent dimensions lack corresponding structural definitions or business descriptions in the securities metadata knowledge base. Anchor points not covered by any block are injected into the context as warning markers, clearly informing the large model that metadata for that dimension is missing and that fields or definitions should not be fabricated. Compared to traditional methods where models tend to guess when faced with missing information, this fundamentally reduces the conditions for illusions to occur.
[0083] As can be seen, in this optional embodiment, the structural anchors in the first quintuple are matched with the first and second verification sets to obtain three matching cases. The information corresponding to different matching cases is marked respectively, so that the subsequent large model can only read the structural definition area in the SQL skeleton generation stage, only read the business description area in the business logic injection stage, and prohibit the fabrication of data in the structural anchors without data. Each stage only processes a single type of information, which will not cause confusion, improve the accuracy of SQL statement generation, and reduce the occurrence of illusions.
[0084] In another optional embodiment, retrieving the natural language question based on a preset private knowledge base to obtain the target question may include: The natural language problem is broken down according to its structure, resulting in a first subject part, a second object part, and a third aspect part; The first subject part, the second object part, and the third subject part are matched with the problem data in the private knowledge base to obtain the first subject matching score, the second object matching score, and the third subject matching score. The first confidence level is obtained based on the first subject matching score and the second object matching score; the second confidence level is obtained based on the second object matching score and the third object matching score; and the third confidence level is obtained based on the first subject matching score and the third object matching score. The question selection score is obtained based on the first confidence level, the second confidence level, and the third confidence level. Based on the scores of the questions, the target questions are obtained.
[0085] In this optional embodiment, the first subject portion, the second object portion, and the third subject portion can be divided according to a quintuple.
[0086] In this optional embodiment, the first subject part can be the target object of the query, i.e., the entity the user wants to query. For example, "a certain bank" or "a certain stock index 300". It can also be the entity type and entity value corresponding to the quintuple. The second object part can be the specific content of the query, i.e., the data indicator the user wants to obtain. For example, "net profit" or "price-to-earnings ratio". It can also be an indicator corresponding to the quintuple. The third subject part can be the query constraints, i.e., time constraints and aggregation dimensions. For example, "last quarter" or "each year of the past five years". It can also be the time constraints and aggregation dimensions corresponding to the quintuple.
[0087] In this optional embodiment, the first subject part is matched with the question data in the private knowledge base to obtain a first subject matching score. This process can involve determining the degree of matching between the first subject part and the subject of each standard question in the private knowledge base. The matching logic includes whether the entity code is consistent and whether the entity types are the same. If they are completely consistent, the first subject matching score S1 = 1.0; if they are partially consistent (e.g., the first subject part asks for "a certain line," and the question data in the private knowledge base is "a certain bank," and the code is consistent after entity mapping), then S1 = 1.0; if they are completely different, then S1 = 0.
[0088] In this optional embodiment, the second object part is matched with the question data in the private knowledge base to obtain a second object matching score. This process can involve calculating the degree of matching between the second object part and the object of each standard question in the private knowledge base. The matching logic can be based on an indicator synonym dictionary: if the indicator codes are consistent, the second object matching score S2 = 1.0; if there is a hierarchical relationship (e.g., the second object part asks for "profitability," while the question in the private knowledge base is for "net profit"), the score is calculated based on a preset indicator hierarchy distance; if they are completely unrelated, S2 = 0. This preset indicator hierarchy distance can be understood as a knowledge graph of indicators. It organizes various indicators in the securities field according to hierarchical, synonym, and other relationships. For example, "profitability" is a broad concept that includes specific indicators such as "net profit," "gross profit margin," and "return on equity." When a user asks the broad term "profitability," the standard question asks for the specific "net profit." The system identifies "Net Profit" as a subordinate indicator of "Profitability" on the graph. While they have a hierarchical relationship, they are not closely related, so the system assigns a discount, giving it a score of 0.8. This indicates a relationship, and the 0.8 score is calculated based on the distance between them. For example, the graph distance for profitability within the indicator hierarchy could be: Profitability (primary category), Net Profit (secondary indicator) including: Net Profit Attributable to Parent Company, Net Profit Excluding Non-Recurring Items, Revenue (secondary indicator) including: Operating Revenue, Gross Profit Margin (secondary indicator) including: Sales Gross Profit Margin. A primary category can be scored 1.0, a secondary indicator 0.8, indicators within the secondary category 0.5, and indicators outside the indicator hierarchy 0.
[0089] In this optional embodiment, the third body part is matched with the question data in the private knowledge base to obtain a third body matching score. This process can involve calculating the degree of matching between the third body part and the object of each standard question in the private knowledge base. The matching logic includes whether the time constraints are consistent or inferable (e.g., "latest" matches "most recent reporting period," "last quarter" matches "2026Q2"), and whether the aggregation dimensions are consistent. If they are completely consistent, the third body matching score S3 = 1.0; if an inferable relationship exists, the score is calculated based on the time distance or dimensional differences.
[0090] For example, the time distance can be used to calculate the score. Time distance: day, week, month, quarter, half a year, year; 1 level difference (e.g., from day to week, from month to quarter): 0.9 points; 2 levels difference (e.g., from day to month, from week to quarter): 0.7 points; 3 levels difference (e.g., from day to quarter, from month to half a year): 0.5 points; 4 levels difference and above: 0.2 points; and the rest are not in the time distance category, so 0 points are given.
[0091] The score for dimensional difference can be calculated as follows: Dimensional difference: single dimension (e.g., "by year"), two dimensions (e.g., "by industry, by year"), three dimensions (e.g., "by industry, by year, by branch"); Completely consistent: 1.0 point, 1 level difference (e.g., "none" vs. "by year"): 0.8 points, 2 levels difference (e.g., "none" vs. "by industry, by year"): 0.5 points, 3 levels or more difference: 0.2 points, Completely unrelated (e.g., one requires grouping, the other explicitly does not require grouping and cannot be inferred): 0 points.
[0092] If both dimensions match well, their consistency is more reliable, and the overall score should be higher than if they are weighted individually. If one dimension matches poorly but the other two dimensions match well, the overall score should be lowered because the candidate is inconsistent on a key dimension. In this case, the confidence score can be used to reflect the degree of matching between different dimensions.
[0093] In this optional embodiment, the first confidence level is used to reflect whether the query targets are consistent. If the object and indicator the user wants to query both match, it means that the query targets are clearly consistent. Specifically, the first subject matching score is multiplied by the second object matching score. The second confidence level is used to reflect whether the query content and limiting conditions are consistent. If the indicator and time constraint the user wants to query both match, it means that the query content and limiting conditions are consistent. Specifically, the second object matching score is multiplied by the third subject matching score. The third confidence level is used to reflect whether the query scope is consistent. If the object and time constraint the user wants to query both match, it means that the query scope is consistent. Specifically, the first subject matching score is multiplied by the third subject matching score.
[0094] Calculating the screening score directly using the triple product (S1×S2×S3) is too strict; if any dimension scores 0, the overall score is 0, which would excessively eliminate candidates. Therefore, we choose to average the pairwise products. When the matching in one dimension is weak, the other two pairs of confidence scores can still contribute to the score, thus preserving the strength of cross-validation while also providing some tolerance for error.
[0095] In this optional embodiment, the question selection score can be calculated by averaging the first confidence level, the second confidence level, and the third confidence level. All standard questions in the private knowledge base are then sorted in descending order of their final scores, and the top 5 are selected as the candidate set to obtain the target question.
[0096] Furthermore, after calculating the question screening score for all standard questions in the private knowledge base, they are sorted in descending order of score; the candidate ranked first can be taken as the target question for subsequent quintuple transformation and alignment comparison; if the score of the candidate ranked first is lower than the preset threshold (e.g., 0.75), it is considered that there are not enough matching standard questions in the private knowledge base, and the comparison result is directly determined not to meet the preset comparison requirements, and the process is switched to bidirectional retrieval path processing; if the score of the candidate ranked first is higher than or equal to the threshold, the quintuple alignment comparison is continued.
[0097] Furthermore, if the scores of the first and second ranked candidates differ by no more than 0.05, to avoid misselection due to fluctuations in scores across individual dimensions, the top two candidates can be transformed into five-tuples and aligned for comparison, followed by implicit validation. If any candidate passes all validations, the answer to the first question corresponding to that candidate can be adopted. If all candidates fail, the process switches to a bidirectional retrieval path.
[0098] By structurally breaking down natural language problems into three parts—the first subject, the second object, and the third—the problem of semantic focus being obscured during overall matching is avoided. When entities, metrics, and time conditions are mixed together in vector matching for user questions, the model might capture the semantics but overlook crucial details. After decomposition, each dimension is scored independently; an incorrect entity or a mismatched metric is a clear indication of a mismatch, preventing simplification based on overall semantic similarity. Matching results become interpretable; the overall score is not a black-box output but a combination of the individual scores of the three dimensions and pairwise confidence scores. A low score directly pinpoints whether the entity didn't match, the metric didn't match, or the time condition was inconsistent. There's a clear direction for troubleshooting and optimization. Both fault tolerance and rigor are balanced; the fusion method of averaging the products of pairwise confidence scores is more fault-tolerant than a three-way product, preventing a complete rejection due to a zero score in one dimension; it's also more rigorous than simple weighted summation, as a low score in one dimension will simultaneously lower the overall score through both pairs of confidence scores. Boundary cases will not be misjudged with a one-size-fits-all approach, nor will a high score in one dimension mask a low score in another.
[0099] As can be seen, in this optional embodiment, the matching status of each dimension can be clarified by calculating the first subject matching score, the second object matching score, and the third subject matching score. To reflect the selection of the target question corresponding to the natural language question in the private knowledge base, the first confidence level, the second confidence level, and the third confidence level are calculated, and the three confidence levels are averaged to obtain the question selection score; thus, the target question is obtained. By calculating the confidence level, the fault tolerance and rigor of the target question selection can be combined, thereby improving the accuracy of obtaining the answer to the first question from the private knowledge base.
[0100] In yet another optional embodiment, the answer to the second question corresponding to the natural language question is obtained based on the metadata string, including: Based on the metadata string, the first SQL statement is obtained; the first SQL statement is parsed using a syntax analysis algorithm to obtain a statement syntax tree; the statement syntax tree is subjected to error checking to obtain a set of error-activated nodes; based on a preset semantic violation topology graph, the set of error-activated nodes is matched to obtain a matching result; When the matching result is determined to be a modification statement suggestion, the first SQL statement is corrected based on the modification statement suggestion to obtain the second SQL statement; based on the second SQL statement, the answer to the second question is obtained. When the matching result is determined to be a normal statement opinion, the answer to the second question is obtained based on the first SQL statement.
[0101] In this optional embodiment, the specific process of obtaining the first SQL statement based on the metadata string may be: determining the SQL statement structure based on the first complete block and / or the first unidirectional block in the metadata string; Based on the SQL statement structure, the initial SQL statement is obtained according to the second complete block and / or the second unidirectional block; Based on the initial SQL statement, the first SQL statement is obtained by checking for missing data blocks.
[0102] The pre-defined metadata concatenation table can be a pre-assembled metadata concatenation table following the order of the structure definition area, business description area, and uncovered warning area. The process of obtaining the first SQL statement can be as follows: Because the generated metadata string divides the data into first-way complete blocks and first-way unidirectional block-marked data, the generated SQL statement structure uses the structure definition area as its skeleton, filling in the first-way complete blocks and first-way unidirectional block-marked data to generate the SQL statement structure. Then, based on the SQL statement structure, the data corresponding to the second-way complete blocks and / or second-way unidirectional blocks in the business description area are filled into the SQL statement structure to obtain the initial SQL statement. However, this initial SQL statement has not been validated. Therefore, the generated initial SQL statement is checked using missing data blocks to prevent the system from automatically modifying the initial SQL statement with information not present in the missing data blocks. Finally, after the check and processing, the first SQL statement is obtained.
[0103] Further, the overall process involves extracting the physical table names, field names, and data types from the structure definition area to generate an SQL skeleton containing only FROM, JOIN, and SELECT field lists. The large model then reads the business description area and the user's intent quintuple from the question, adding the following to the SQL skeleton one by one: WHERE filtering conditions (based on the business meaning of entity values and time), GROUP BY grouping fields (based on aggregation dimensions), and aggregate functions and calculation expressions in the SELECT statement (based on the metric's definition). At this stage, the large model no longer needs to guess the table structure; it focuses solely on translating business requirements into correct SQL logic. Finally, the large model reads warning markers from the uncovered warning area and checks them one by one. If the anchor point involved in the warning has sufficient information to infer from the business description area or structure definition area, the warning is eliminated and the reasoning basis is noted; if it cannot be inferred, the corresponding part is wrapped in a pending confirmation comment block in the SQL and added to the business description area, without fabricating fields or definitions.
[0104] The three-stage control for SQL generation could be: Stage 1: Generate SQL skeleton (using only the structure definition area). Input: Structure definition area content, the first 5-tuple of the user's question (used to determine the query intent); prompt: "You are an SQL generation expert." Please generate the SQL skeleton strictly according to the table names and field names in the following structure definition area, including only FROM and JOIN clauses, and do not add any WHERE, GROUP BY, SELECT fields, or aggregate functions. Structure definition area: {structure definition area text}. Query intent 5-tuple: {5-tuple}. Please output the SQL skeleton.
[0105] Phase Two: Inject Business Logic (using the Business Description Area and the Five-Tuple). Input: The SQL skeleton from Phase One, the content of the Business Description Area, the user question, and the first five-tuple. Hints may include: Based on the following SQL skeleton: {Skeleton SQL}, add necessary SELECT fields, WHERE conditions, GROUP BY, and aggregate functions according to the definitions in the Business Description Area and the user intent five-tuple. Only fields and calculation methods explicitly mentioned in the Business Description Area can be used; no new table names or field names are allowed. Business Description Area: {Business Description Area Text}. Please output the complete SQL statement.
[0106] Phase 3: Missing Warning Check. Input: Initial SQL generated in Phase 2, content of the uncovered warning area; The prompt can be, "Please check if the following SQL uses fields or dimensions marked as missing in the uncovered warning area." If missing fields exist, please mark that part as "Pending Confirmation" with a comment and retain the original logic. Uncovered Warning Area: {Uncovered Warning Area Text}. SQL: {Initial SQL}. Please output the checked SQL.
[0107] If the warning area indicates "Aggregation dimension anchor not covered, missing industry grouping metadata," and the initial SQL does not indeed contain industry groups, then leave it as is. If the initial SQL contains a fabricated industry field, replace it with a comment block. Through these three stages, we can strictly control the large model to only generate SQL within the given metadata scope, avoiding illusions.
[0108] The structure definition area, business description area, and missing information warning area are separated in terms of content; physical table names are not mixed with business descriptions. Each of the three stages of SQL generation reads only one of these areas. This is not simply splitting prompts, but ensuring that the large model faces a single type of information at each stage: the first stage only sees the structure, the second stage only sees the business meaning, and the third stage only sees missing information warnings. In existing technologies, whether in a single generation or multiple rounds, the model needs to process both structural constraints and business semantics at each step. This solution physically isolates these two types of information at the input end, significantly reducing the cognitive load at each step, and clearly separating the sources of structural and business errors. The SQL skeleton (FROM, JOIN) generated in the first stage of this solution is not modified in subsequent stages. The business logic injection in the second stage can only add WHERE, GROUP BY, aggregate functions, etc., to the skeleton, without changing the skeleton structure. This means that structural correctness is not guaranteed by post-processing validation, but by the hard constraints of the generation process itself. The third phase of this solution does not require the large model to fill in the missing information itself, but forces it to output SQL with confirmation markers. Fields that cannot be inferred are marked with annotations, and no fabrication is allowed, thereby improving the accuracy of SQL statement generation.
[0109] The SQL statement structure is determined by analyzing the structure definition area corresponding to the first complete block and / or the first unidirectional block in the metadata string. Based on the SQL statement structure, the initial SQL statement is obtained by analyzing the business description area corresponding to the second complete block and / or the second unidirectional block. The first SQL statement is then obtained by checking the uncovered warning area corresponding to the missing data block. This three-stage constraint, with the structure definition area serving as the skeleton and the business description provided separately, ensures that the two types of information are not mixed. The uncovered warning area further reduces the logical error rate during SQL statement generation.
[0110] The structure definition area, serving as the unique and immutable data source foundation, eliminates the possibility of large models fabricating table and field names out of thin air, resolving the illusion problem caused by SQL and improving the physical reliability of SQL. The business description area provides standardized guidelines, ensuring that large models do not simply "guess" business meanings but strictly adhere to domain specifications in writing computational logic, avoiding business errors such as misuse of aggregate functions and confusion of indicator definitions, thus guaranteeing the accuracy of business logic. The uncovered warning area transforms information gaps from a hidden state to explicit markings, directly embedded in the SQL code. This not only prevents large models from acting arbitrarily when uncertain but also provides clear checkpoints for subsequent automatic verification or manual review, making SQL quality auditable and traceable, achieving explicit and traceable risk. The responsibilities of the three areas are clearly defined and independent. When problems occur, it is possible to quickly pinpoint whether the issue stems from inaccurate structural information, incorrect business guidance, or improper handling of missing information, greatly improving the efficiency of system debugging and iteration, and optimizing the maintainability of the generation process.
[0111] In this optional embodiment, the syntax analysis algorithm can be the LL algorithm or the LR algorithm; those skilled in the art will understand that the LL algorithm and the LR algorithm can perform syntax analysis on SQL statements to generate a tree structure, that is, an abstract syntax tree.
[0112] In this optional embodiment, error checking is performed on the statement syntax tree to obtain a set of error-activated nodes. Based on a preset semantic violation topology graph, the set of error-activated nodes is matched to obtain the matching result. Specifically, the system presets five commonly used syntax error rules in the securities field. Each of the five rules traverses the statement syntax tree to check if its violation condition is triggered. If triggered, the nodes corresponding to the five syntax error rules are activated. After completion, a set of activated nodes is obtained, which is the error-activated node set. This error-activated node set is then matched with the function selection subgraph, data aggregation subgraph, and indicator caliber subgraph in the semantic violation topology graph to obtain the matching result. The five commonly used error checking rules may be multi-branch splicing check rules, sorting function misuse check rules, median function missing check rules, aggregation function misuse check rules, and caliber multiplication by 100 check rules.
[0113] The rule for checking multiple branch office concatenation can be to check if the SQL query contains instances where the same table is filtered by different branch office conditions and then concatenated using UNION ALL. If a match is found, the data source organization is deemed incorrect. Specifically, when performing multi-entity comparison queries (such as comparing data from multiple branch offices), the correct SQL should use GROUP BY (a keyword used for grouping and aggregation in SQL) for unified processing. If the AST (Abstract Syntax Tree) contains multiple subqueries with the same structure but different filtering conditions concatenated using UNION ALL, it indicates an incorrect data source organization. Subsequent aggregation calculations across subqueries will inevitably fail, resulting in a direct violation and blocking.
[0114] The rule for checking for misuse of sorting functions could be that when a user's question involves quantile or percentage ranking, the SQL query is checked to see if the ROW_NUMBER function is used but the PERCENT_RANK function is missing. If a match is found, the quantile calculation method is considered incorrect. Specifically, when a user's question is marked as a quantile or percentage-related question, the correct approach is to use standard window functions such as PERCENT_RANK. If the ROW_NUMBER function appears in the AST (Abstract Syntax Tree) but the corresponding PERCENT_RANK function does not exist, it indicates that the large model is simulating quantile calculation using manual sorting methods, which may result in inaccurate results or overly complex logic. This is considered a violation and the query is blocked.
[0115] The median function missing check rule can be implemented by checking if the SQL statement contains the `MEDIAN` function when the user explicitly requests median calculation. If it doesn't, the median aggregation method is considered incorrect. Specifically, when the user explicitly requests median calculation, all aggregation function nodes in the AST are traversed. If the `MEDIAN` function is not found, it indicates that the larger model may have used `AVG` or other functions to replace median calculation, leading to a completely incorrect result in terms of business logic. This is then considered a violation and the process is blocked.
[0116] The rule for checking for misuse of aggregate functions could be as follows: when a user question involves percentages or relative metrics, check if the aggregate functions used in the SQL for calculating the numerator or denominator are AVG or MAX instead of SUM. If found, it indicates an incorrect aggregation method. Specifically, when a user question is marked as a percentage or relative metric question, the correct business approach is to calculate the ratio based on SUM aggregation. If AVG or MAX functions appear in the calculated fields of the numerator or denominator in the AST, it means the aggregation method was chosen incorrectly, and the calculated ratio is meaningless in business terms, thus triggering a violation and blocking the process.
[0117] The rule for multiplying the caliber by 100 can be to check if the calculated field in the SQL SELECT statement exists. An arithmetic expression containing 100, if it matches, is determined to have performed percentage formatting at the data layer, which should have been handled by the display layer. Specifically, the standard practice is to keep the underlying data in decimal format (e.g., 0.35), and multiplying by 100 to convert it to a percentage should be handled during data output and display; traversing the expression nodes of the AST (Abstract Syntax Tree), if found in the calculated fields of the SELECT statement... The 100 pattern indicates that the large model was formatted at the data layer, which would pollute the original data scope and cause errors in the magnitude of values during subsequent secondary calculations, resulting in a violation and interception.
[0118] Furthermore, the specific method for constructing the semantic violation topology graph is as follows: This document describes a set of SQL validation rules for error checking of statement syntax trees in the securities field. The SQL validation rule set includes at least the following: a multi-branch concatenation check rule (first validation rule), a sorting function misuse check rule (second validation rule), a median function missing check rule (third validation rule), an aggregation function misuse check rule (fourth validation rule), and a caliber multiplication by 100 check rule (fifth validation rule). The first validation rule detects whether the SQL statement contains data source structure distortion caused by the incorrect use of the UNION ALL operation. The second validation rule detects whether the SQL statement misuses the basic sorting function instead of the standard quantile window function in quantile or percentage ranking scenarios. The third validation rule detects whether the SQL statement omits the median aggregation function. The fourth validation rule detects whether the SQL statement incorrectly uses the AVG or MAX aggregation function instead of SUM summation in relative indicator calculation scenarios. The fifth validation rule detects whether the SQL statement directly performs a 100 multiplication by percentage formatting operation during data processing (data layer). Based on the second and fifth verification rules, the function selection subgraph is obtained; based on the first, third, and fourth verification rules, the data aggregation subgraph is obtained; based on the fourth and fifth verification rules, the indicator caliber subgraph is obtained. Based on the function selection subgraph, data aggregation subgraph, and indicator caliber subgraph, a semantic violation topology graph is obtained.
[0119] In this optional embodiment, the first verification rule could be that the system checks whether the SQL statement uses UNION ALL to split the data of the same table into several segments based on different conditions and then reassembles them. If so, it is determined that the data source structure has been incorrectly torn and forcibly spliced, which falls under the category of error. The correct approach should be to use a single SQL statement with GROUP BY to directly query and maintain the integrity of the data source. Those skilled in the art will understand that UNION ALL is a keyword in SQL used to combine the results of two or more queries into a single table; GROUP BY can be a keyword in SQL used to group data rows according to the values of one or more columns, usually used with aggregate functions (such as SUM, AVG, COUNT) to perform statistical calculations on each group.
[0120] The second validation rule could be that the system checks whether the SQL generated by the large model uses a common sorting function like ROW_NUMBER to perform a calculation that should be done by a specialized window function like PERCENT_RANK. This isn't a syntax error, but rather using the wrong tool, leading to complex logic and inaccurate results. The common sorting function (the misused tool) could be ROW_NUMBER, which assigns a unique, consecutive numerical number (1, 2, 3, ...) to each row of the result set. It doesn't care about the numerical value, only the order. The standard quantile window function (the correct tool to use) could be PERCENT_RANK or CUME_DIST. These are specifically designed for calculating percentile rankings and quantiles, directly returning a relative position between 0 and 1 (e.g., 0.35, representing the top 35%), with the calculation logic and boundary handling built into the database. Quantiles can be ranking orders, for example, the 20th quantile, which represents the value in the top 20%.
[0121] The third verification rule could be that the system checks whether the generated SQL statement actually uses a function like MEDIAN, specifically for calculating the median, when the user explicitly requests it. If not, it's considered an omission. The median aggregate function is one that sorts a set of data from smallest to largest and returns the middle value; MEDIAN is a database function specifically used to calculate the median, and it's a type of aggregate function. The median and the mean are two completely different things; the mean is the sum of all numbers divided by the number of elements, and is easily skewed by extreme values. The median is the middle value after sorting, and is not affected by extreme values. In securities analysis, their business meanings are entirely different. If the user explicitly requests the median, but the SQL doesn't use the corresponding function, the calculated result will definitely not be what the user wants, so it must be rejected and rewritten.
[0122] The fourth verification rule could be that when a user wants to calculate relative indicators such as "percentage" or "ratio," the system checks whether the SQL incorrectly uses AVG (average) or MAX (maximum) instead of SUM (summary). SQL generated by large models often uses AVG (average) and MAX (maximum) instead of SUM when calculating the numerator or denominator.
[0123] The fifth verification rule could be whether the system directly writes the SQL calculation logic when checking the SQL. The issue stems from converting decimals to percentages. The data layer, where SQL queries and data storage occur, should contain clean, standard-formatted data. For ratios, the standard format is a decimal (e.g., 0.35). The database stores a number magnified 100 times. If another program or a subsequent query needs to perform calculations based on this "net profit margin" (e.g., industry average), it will receive 35 instead of 0.35, polluting the underlying data. Some metrics are stored as decimals, while others are multiplied by 100, leading to inconsistent data interpretation across the entire database and hindering unified processing. Mixing data calculations and formatting violates system architecture standards; a SQL query returning a decimal like 0.35 requires the front-end application to process it into 35% for the user.
[0124] In this optional embodiment, when both the second and fifth validation rules are triggered simultaneously, the subgraph corresponding to this pattern is named the function selection subgraph. This is because the second validation rule uses ROW_NUMBER to simulate quantiles, and the fifth validation rule multiplies by 100 at the SQL layer. The simultaneous occurrence of these two errors is not a coincidence, but rather two symptoms of the same underlying problem: the large model fundamentally misunderstands the standard notation of quantiles and uses a completely incorrect approach: first sorting by ROW_NUMBER, then calculating the position, and finally multiplying by 100 to obtain a percentage. Therefore, {the second and fifth validation rules} are defined as a high-risk pattern, and the diagnosis is "overall error in quantile calculation logic." Without setting this subgraph, the large model might receive two instructions and change UNION ALL without modifying the aggregate function, or vice versa; worse, it might not understand the relationship between these two instructions, causing new problems with a single change. The second validation rule is misuse of ROW_NUMBER, and the fifth validation rule is multiplying by 100. These two errors occur simultaneously not because the overall model made two separate mistakes, but because it misunderstood the concept of "percentiles." It used ROW_NUMBER to simulate sorting position and then multiplied by 100 to obtain a percentage. If you only tell it to "change the function" or "don't multiply by 100," it might change the function but still multiply by 100, or remove the multiplication by 100 but still use ROW_NUMBER. Therefore, these two errors are bundled into a pattern function selection subgraph. When triggered, the overall solution modification suggestion is given: "Change the function and keep it within the 0-1 range," instead of converting the data into percentages, such as multiplying 0.35 by 100 to become 35%.
[0125] When the first validation rule is triggered simultaneously with the third and / or fourth validation rules, the subgraph corresponding to this pattern is named the data aggregation subgraph. The first validation rule uses UNION ALL to split the data into multiple subqueries and then combines them. The third validation rule is a missing median function, and the fourth validation rule is misuse of AVG / MAX. The first validation rule is the root cause, while the third and fourth validation rules are the direct consequences. After the data is split by UNION ALL, performing median or summation across subqueries will inevitably result in errors. Therefore, {the first validation rule plus the third or fourth validation rule} is defined as a pattern, and the diagnostic result is "UNION ALL causes aggregation failure". The first validation rule is UNION ALL splitting the data source, while the third and fourth validation rules are due to problems with the aggregation function. These two types of errors have a causal chain: because the data is broken up by UNION ALL, the aggregation calculation across subqueries will inevitably fail; if only the aggregate function is fixed, UNION ALL will still exist, the data will still be scattered, and the aggregation result will still be wrong; if only UNION ALL is fixed and the aggregate function is forgotten, it may also leave hidden dangers; therefore, when the data is bundled into a data aggregation subgraph, the diagnostic result after triggering it is "the root cause is UNION ALL, the solution is to start by merging the data source, and then correct the aggregation logic." The overall modification instruction can be, "first delete the UNION ALL logic, merge the data source into a complete table using GROUP BY; on this basis, then correctly apply aggregate functions such as MEDIAN or SUM." When both the fourth and fifth validation rules are triggered simultaneously, the subgraph corresponding to this pattern is named the "Indicator Calibration Subgraph." The fourth validation rule replaces SUM with AVG / MAX in the aggregation function, and the fifth validation rule multiplies by 100 at the SQL layer. The simultaneous occurrence of these two errors indicates that the large model is flawed in both the aggregation method and the numerical format when calculating relative indicators, representing a fundamental error in the overall caliber design. Therefore, {the fourth and fifth validation rules} are defined as a single pattern, with the diagnostic result being "Relative Indicator Calibration Error." The fourth validation rule is an incorrect aggregation method (AVG / MAX replacing SUM), and the fifth validation rule is an incorrect numerical format (multiplying by 100 at the SQL layer). Their simultaneous occurrence indicates a methodological error in how the large model calculates relative indicators; the aggregation method for the numerator and denominator is incorrect, and the numerical format of the result is also incorrect. Since both dimensions are flawed, a single overall caliber correction instruction should be provided, rather than correcting them separately. Therefore, they are bundled into an "Indicator Calibration Subgraph." The overall modification instruction could be, "The numerator and denominator are both calculated based on the SUM function, and the final result is kept in the decimal format before multiplying by 100." By solidifying common compound errors into identifiable patterns, when multiple violations are triggered simultaneously, the system does not simply list the problems, but can identify the underlying fundamental logical fallacies based on the "pattern" they form.
[0126] While error activation node sets can only point out "the wrong function was used here" or "an extra 100 was multiplied there," the semantic violation topology graph can determine "your overall approach to quantile calculation is wrong" or "this aggregation error is caused by an incorrect data source split." It diagnoses the "root cause," not just the "symptoms," achieving deeper diagnosis rather than superficial fixes. It avoids multiple independent modification suggestions that can throw the large model into chaos or lead to piecemeal modifications. Linked diagnosis can generate a holistic repair plan containing the correct approach (e.g., directly requesting a refactoring of the quantile logic), guiding the model towards a more thorough, one-step code refactoring. This results in more focused and unified correction instructions in the output. While triggering error activation node sets may sometimes be harmless code in a specific context, the semantic violation topology graph, by requiring multiple intrinsically related nodes to be activated simultaneously, greatly reduces the probability of the entire process being interrupted by a single harmless code error. It ensures intervention only when a logical fallacy is confirmed, making feedback more accurate and valuable, reducing false alarms, and improving the quality of feedback.
[0127] Each pattern definition is not a random pairing, but rather extracted from the causal relationships of errors that actually occur during the generation of securities SQL. The root cause of the function selection subgraph is a lack of understanding of quantile semantics; the root cause of the data aggregation subgraph is that UNIONALL corrupts data integrity; and the root cause of the indicator caliber subgraph is a general misunderstanding of relative indicator calibers.
[0128] There are two types of matching results: one is the modified statement comment, and the other is the normal statement comment.
[0129] The feedback on the modified statements includes combined error review feedback and independent error review feedback. Among them, the combined error review feedback can be a unified diagnosis and modification suggestion given by the system when multiple non-compliant nodes are activated at the same time in the set of erroneous activation nodes, and they belong to the same subgraph in the semantic violation topology graph. Instead of reporting each error individually, it outputs a whole feedback for this combined pattern. For example, when a function selection subgraph in the semantic violation topology is triggered, the combined error audit opinion will directly output: "A quantile calculation logic error has been detected. It is recommended to abandon the ROW_NUMBER logic and rewrite it with the standard PERCENT_RANK function, and confirm that the numerical range is 0-1." An independent error review opinion can be a targeted modification suggestion given after a rule is triggered. It only addresses the one violating node in the set of erroneous activation nodes, does not involve other rules, and does not match any subgraph in the semantic violation topology. For example, when ROW_NUMBER is misused and triggered alone, and the other four rules do not detect the error and do not match any subgraph in the semantic violation topology, the independent error review opinion would be: "The ROW_NUMBER function has been detected in the quantile scenario. Please replace it with PERCENT_RANK." A normal statement could be that if none of the five verification rules are triggered, meaning there is no data in the set of error activation nodes, then a normal statement would be output directly.
[0130] In this optional embodiment, when the matching result is determined to be a modification statement opinion, the first SQL statement is corrected based on the modification statement opinion to obtain a second SQL statement; the answer to the second question is obtained based on the second SQL statement; alternatively, when the matching result is a modification statement opinion, it is determined whether it is a combined error audit opinion or an independent error review opinion, and then the first SQL statement is modified accordingly based on the content of the combined error audit opinion or the independent error review opinion to obtain the second SQL statement; then the second SQL statement is input into the target database for querying to obtain the answer to the second question. The target database can be the OceanBase database, but this embodiment of the invention does not limit it.
[0131] Furthermore, for errors with clear correspondences, string or AST replacements are performed directly on the SQL text. For example, in the independent error review comment "Replace ROW_NUMBER with PERCENT_RANK", the system locates the ROW_NUMBER function node in the AST, replaces its function name with PERCENT_RANK, and adjusts the sort field in the OVER clause; in the independent error review comment "Delete data layer",... When the value is 100, the system locates the arithmetic expression node in the SELECT statement and deletes the operation multiplied by 100. When the combined error review opinion is "abandon the ROW_NUMBER logic, rewrite it as the standard PERCENT_RANK function, and confirm that the value range is 0-1", the system not only replaces the function name but also deletes any existing errors. Use a 100 expression and ensure that the final result is not amplified.
[0132] For more complex semantic errors, such as "UNION ALL causes aggregation failure" triggered by a data aggregation subgraph, rule replacement is difficult to complete automatically. In this case, the system inputs the modified statement, the original SQL, and the corresponding partition of the metadata string into the large model, requiring it to rewrite the SQL according to the modified statement. The prompt template could be: The original SQL has the following problem: {Modified statement}. Please rewrite the SQL based on the metadata information to correct the above problem. Requirements: The original query intent must not be changed, and fields or functions that do not exist in the metadata must not be introduced. Metadata information: {Relevant partition content}. Original SQL: {First SQL}. Please output the corrected SQL.
[0133] After the large model is output, the system performs another syntax tree error check to ensure that the modified SQL no longer triggers the violation rules; if it still triggers, it performs a maximum of 3 iterations of correction; if it still fails, the problem is marked as "requiring manual intervention" and logged.
[0134] The corrected second SQL or the initial first SQL (when the matching result is a normal statement opinion) is sent to the target database (such as OceanBase) for execution. The execution result is returned in tabular form, which is the raw data for the answer to the second question. This raw data, along with metadata, is then input into the agent to generate the second output result.
[0135] Once the matching result is determined to be a normal statement opinion, the first SQL statement is directly input into the large model database to obtain the answer to the second question.
[0136] As can be seen, in this optional embodiment, the SQL statement generated from the three parts of the metadata string makes the SQL statement quality auditable and traceable, improving the efficiency of system debugging and iteration. The SQL statement is checked for errors using the system's preset error checking rules, resulting in a set of error-activated nodes. Then, it is matched against the semantic violation topology graph to obtain the matching results. The SQL statement is modified using the matching results to finally obtain the answer to the second question. The error-activated node set is responsible for low-level detection, while the semantic violation topology graph is responsible for high-level decision-making. When new business constraints need to be added, only new nodes and edges need to be defined in the graph to form a new high-risk subgraph, without modifying the triggering logic of individual rules or the code for generating combined opinions, thus reducing the maintenance complexity of the rule engine. By outputting modification opinions, information redundancy can be reduced, avoiding multiple independent modification suggestions from causing chaos in the large model. Unified correction instructions reduce false alarms, improve the quality of feedback information, and thus improve the accuracy of natural language question answering.
[0137] Example 2 Please see Figure 2 , Figure 2 This invention discloses an agent-based natural language question-answering device for the securities field, which may include: The language conversion and comparison module 201 is used to respond to natural language problems in the securities field; it retrieves the natural language problem based on a preset private knowledge base to obtain the target problem; it performs a quintuple conversion between the natural language problem and the target problem to obtain the first quintuple and the second quintuple; it aligns and compares the first quintuple and the second quintuple to obtain the comparison result; the quintuple conversion is to represent the problem in a structured way. The local data retrieval module 202 is used to perform implicit verification on the answer to the first question corresponding to the target question in the private knowledge base when it is determined that the comparison result meets the preset comparison requirements, and obtain the implicit verification result; when it is determined that the implicit verification result meets the preset verification requirements, the answer to the first question is input into the intelligent agent to obtain the first output result. The Unicom data retrieval module 203 is used to process the natural language question through a bidirectional retrieval path to obtain a metadata string when it is determined that the comparison result does not meet the preset comparison requirements or the implicit verification result does not meet the preset verification requirements; based on the metadata string, obtain the answer to the second question corresponding to the natural language question; and input the answer to the second question into the intelligent agent to obtain the second output result. The target result output module 204 is used to determine the first output result or the second output result to obtain the target output result.
[0138] As can be seen, this embodiment of the invention, in response to natural language questions in the securities field, retrieves the target question based on a private knowledge base; transforms the natural language question and the target question into five-tuples respectively, obtaining a first five-tuple and a second five-tuple; aligns and compares the first five-tuple and the second five-tuple to obtain a comparison result; by transforming the fuzzy natural language question into a structured query intent representation of five-tuples consisting of entity type, entity value, indicator, time constraint, and aggregation dimension, and then comparing them, it can solve the problem of semantically similar but unequal query intents.
[0139] When the comparison result is determined to meet the preset comparison requirements, implicit verification is performed on the first question answer corresponding to the target question in the private knowledge base to obtain the implicit verification result. By checking one by one whether there is a conflict with the implicit unit constraints and time sensitivity requirements in the user question, the problem of incorrect answer caliber caused by different currencies and units of measurement in the securities field can be solved. Question matching is determined by comparing five tuples, and result matching is determined by implicit verification, forming a complete closed loop of two-way confirmation between "question and answer", which improves the accuracy of natural language question answering in the securities field. At the same time, through the path question-and-answer answer of the private knowledge base, questions with high repetition and fixed conclusion caliber can bypass the two-way path retrieval access and complex calculation process, thereby significantly reducing latency and computing power overhead and improving the question-and-answer speed.
[0140] When the comparison result is determined not to meet the preset comparison requirements, or when the implicit verification result is determined to meet the non-preset verification requirements, the natural language question is processed through a bidirectional retrieval path to obtain a metadata string; based on the metadata string, the answer to the second question corresponding to the natural language question is obtained; the answer to the second question is input into the agent to obtain a second output result; finally, it is determined whether the output result is obtained from the private knowledge base or the result obtained from the bidirectional retrieval path processing, and the target output result is determined. By first matching with the private knowledge base to see if the answer can be quickly found in the private knowledge base, and if the answer cannot be found in the private knowledge base, the answer to the natural language question is obtained through bidirectional retrieval path processing, thus improving the accuracy of question answering.
[0141] Example 3 Please see Figure 3 , Figure 3 This is a schematic diagram of the structure of a device including a memory and a processor, as disclosed in an embodiment of the present invention. Figure 3 As shown, the device including memory and processor may include: Memory 301 storing executable program code; Processor 302 coupled to memory 301; The processor 302 calls the executable program code stored in the memory 301 to execute some or all of the steps in any of the agent-based natural language question answering methods in the securities field according to Embodiment 1 of the present invention.
[0142] Example 4 This invention discloses a computer storage medium storing computer instructions. When these computer instructions are invoked, they are used to execute some or all of the steps in any of the agent-based natural language question answering methods for the securities field disclosed in Embodiment 1 of this invention.
[0143] The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0144] Through the detailed description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, including read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-Erasable Programmable Read-Only Memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0145] Finally, it should be noted that the above embodiments are merely preferred embodiments of the present invention and are only used to illustrate the technical solutions of the present invention, not to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications 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 the present invention.
Claims
1. A natural language question answering method for the securities field based on intelligent agents, characterized in that, The method includes: In response to natural language processing issues in the securities field, the natural language processing issue is retrieved based on a preset private knowledge base to obtain a target issue; the natural language processing issue and the target issue are transformed into a quintuple to obtain a first quintuple and a second quintuple; the first quintuple and the second quintuple are aligned and compared to obtain a comparison result; the quintuple transformation is to represent the issue in a structured way. When it is determined that the comparison result meets the preset comparison requirements, implicit verification is performed on the first question answer corresponding to the target question in the private knowledge base to obtain an implicit verification result; when it is determined that the implicit verification result meets the preset verification requirements, the first question answer is input into the agent to obtain a first output result. When it is determined that the comparison result does not meet the preset comparison requirements, or when it is determined that the implicit verification result does not meet the preset verification requirements, the natural language question is processed through a bidirectional retrieval path to obtain a metadata string; based on the metadata string, the answer to the second question corresponding to the natural language question is obtained; the answer to the second question is input into the agent to obtain a second output result. Determine either the first output result or the second output result to obtain the target output result.
2. The agent-based natural language question answering method for the securities field according to claim 1, characterized in that, The process of processing the natural language problem through a bidirectional retrieval path to obtain the metadata string includes: The natural language question is processed through a first retrieval path to obtain a first metadata list. The first retrieval path is used to filter physical table names and field names related to the natural language question in a preset securities metadata knowledge base. The natural language question is processed through a second retrieval path to obtain a second metadata list. The second retrieval path is used to filter the business meanings and definitions related to the natural language question in a preset securities metadata knowledge base. Based on the first quintuple, the first metadata list is validated to obtain a first validation set; based on the first quintuple, the second metadata list is validated to obtain a second validation set. Based on the first verification set and the second verification set, a metadata string is obtained.
3. The agent-based natural language question answering method for the securities field according to claim 2, characterized in that, The step of obtaining the metadata string based on the first verification set and the second verification set includes: When it is determined that the first structural anchor in the first quintuple can match the data of both the first validation set and the second validation set, a first complete block corresponding to the data of the first structural anchor is obtained based on the first validation set, and a second complete block corresponding to the data of the first structural anchor is obtained based on the second validation set. When it is determined that the second structural anchor in the first quintuple only matches the data of the first verification set or the second verification set, the first unidirectional block corresponding to the data tag of the second structural anchor is obtained according to the first verification set, or the second unidirectional block corresponding to the data tag of the second structural anchor is obtained according to the second verification set. When it is determined that the third structural anchor point in the first quintuple cannot match the data of the first validation set and the second validation set, a data missing block is obtained based on the third structural anchor point. The first complete block, the second complete block, the first unidirectional block or the second unidirectional block, and the missing data block are filled into a preset metadata concatenation table to obtain a metadata string.
4. The agent-based natural language question answering method for the securities field according to claim 1, characterized in that, The step of retrieving the target question from the natural language question based on a preset private knowledge base includes: The natural language problem is broken down according to its structure to obtain a first subject part, a second object part, and a third body part; the first subject part includes the target object of the natural language problem, the second object part includes the specific content of the natural language problem, and the third body part includes the time constraint and aggregation dimension of the natural language problem; The first subject part, the second object part, and the third subject part are matched with the question data in the private knowledge base to obtain the first subject matching score, the second object matching score, and the third subject matching score; A first confidence level is obtained based on the first subject matching score and the second object matching score; a second confidence level is obtained based on the second object matching score and the third subject matching score; a third confidence level is obtained based on the first subject matching score and the third subject matching score; the first confidence level is a score used to reflect whether the query target is consistent, the second confidence level is a score used to reflect whether the query content and limiting conditions are consistent, and the third confidence level is a score used to reflect whether the query scope is consistent. The question selection score is obtained based on the first confidence level, the second confidence level, and the third confidence level. Based on the scores of the questions, the target questions are obtained.
5. The agent-based natural language question answering method for the securities field according to claim 3, characterized in that, The step of obtaining the answer to the second question corresponding to the natural language question based on the metadata string includes: Based on the metadata string, a first SQL statement is obtained; the first SQL statement is parsed using a syntax analysis algorithm to obtain a statement syntax tree; the statement syntax tree is subjected to error checking to obtain a set of error-activated nodes; based on a preset semantic violation topology graph, the set of error-activated nodes is matched to obtain a matching result; the semantic violation topology graph includes a function selection subgraph, a data aggregation subgraph, and an indicator caliber subgraph; When the matching result is determined to be a modification statement suggestion, the first SQL statement is corrected based on the modification statement suggestion to obtain a second SQL statement; based on the second SQL statement, the answer to the second question is obtained; the modification statement suggestion includes combined error review suggestions and independent error review suggestions; When the matching result is determined to be a normal statement opinion, the answer to the second question is obtained based on the first SQL statement.
6. The agent-based natural language question answering method for the securities field according to claim 5, characterized in that, The step of obtaining the first SQL statement based on the metadata string includes: The SQL statement structure is determined based on the first complete block and / or the first unidirectional block in the metadata string; Based on the SQL statement structure, the initial SQL statement is obtained according to the second complete block and / or the second unidirectional block; Based on the initial SQL statement, the first SQL statement is obtained by checking the missing data blocks.
7. The agent-based natural language question answering method for the securities field according to claim 5, characterized in that, The specific method for constructing the semantic violation topology graph is as follows: Obtain the SQL validation rule set for error checking of the statement syntax tree in the securities field. The SQL validation rule set includes at least a first validation rule, a second validation rule, a third validation rule, a fourth validation rule, and a fifth validation rule. The first validation rule is used to detect whether there is data source structure distortion in the SQL statement due to the incorrect use of the UNION ALL operation. The second validation rule is used to detect whether the SQL statement mistakenly uses the basic sorting function instead of the standard quantile window function in the quantile or percentage ranking scenario. The third validation rule is used to detect whether the median aggregation function is omitted in the SQL statement. The fourth validation rule is used to detect whether the SQL statement incorrectly uses the AVG or MAX aggregation function instead of SUM summation in the relative indicator calculation scenario. The fifth validation rule is used to detect whether the SQL statement directly performs a percentage formatting operation of multiplying by 100 during data processing. Based on the second and fifth verification rules, a function selection subgraph is obtained; based on the first, third, and fourth verification rules, a data aggregation subgraph is obtained; based on the fourth and fifth verification rules, an indicator caliber subgraph is obtained. Based on the function selection subgraph, the data aggregation subgraph, and the indicator caliber subgraph, a semantic violation topology graph is obtained.
8. A natural language question-answering device for the securities field based on intelligent agents, characterized in that, The device includes: The language conversion and comparison module is used to respond to natural language problems in the securities field; it retrieves the natural language problem based on a preset private knowledge base to obtain the target problem; it performs a quintuple conversion on the natural language problem and the target problem to obtain a first quintuple and a second quintuple; it aligns and compares the first quintuple and the second quintuple to obtain a comparison result; the quintuple conversion is to represent the problem in a structured way. The local data retrieval module is used to perform implicit verification on the first question answer corresponding to the target question in the private knowledge base when it is determined that the comparison result meets the preset comparison requirements, and obtain implicit verification result; when it is determined that the implicit verification result meets the preset verification requirements, the first question answer is input into the intelligent agent to obtain the first output result; The data retrieval module is used to process the natural language question through a bidirectional retrieval path to obtain a metadata string when it is determined that the comparison result does not meet the preset comparison requirements or the implicit verification result does not meet the preset verification requirements; based on the metadata string, it obtains the second question answer corresponding to the natural language question; and inputs the second question answer into the intelligent agent to obtain a second output result. The target result output module is used to determine the first output result or the second output result to obtain the target output result.
9. An apparatus comprising a memory and a processor, characterized in that, The device includes: Memory containing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the agent-based natural language question answering method for the securities field as described in any one of claims 1-7.
10. A computer storage medium, characterized in that, The computer storage medium stores computer instructions, which, when invoked by a processor, are used to execute the agent-based natural language question answering method for the securities field as described in any one of claims 1-7.
