Data query method and device, nonvolatile storage medium and computer equipment
By identifying named entities and matching query templates in a pre-defined vector database, the system generates target query statements, solving the problem of low query flexibility for bank accounting teams. This enables dynamic adjustment of query logic, improving query efficiency and system stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-26
- Publication Date
- 2026-04-10
AI Technical Summary
In existing technologies, there is a conflict between the diversity of query needs and the stability of the query system when bank accounting teams query financial accounting data. Business personnel need to have data analysis skills, and new query scenarios are likely to require manual processing, resulting in low query flexibility and huge manpower consumption.
By receiving an initial query statement, identifying named entities, querying a matching query template in a pre-defined vector database, generating a target query statement, and dynamically adjusting the query logic using a named entity recognition model and a natural language processing model to generate query results that meet the user's needs.
It enables the parsing of query targets and conditions from user input, dynamically adjusts query logic, improves query flexibility, reduces the need for manual processing, and enhances query efficiency and system stability.
Smart Images

Figure CN121833752A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of big data technology, and more specifically, to data query methods, apparatus, non-volatile storage media, and computer equipment. Background Technology
[0002] As banks become increasingly digitalized, their accounting teams rely more and more on online systems to query and analyze accounting data. However, there is often a conflict between the diversity of query needs and the stability of the query system. How to intelligently analyze user needs and adaptively query financial accounting data has always been an important issue.
[0003] The current industry practice is to handle non-urgent requests by submitting requirements and initiating projects, then connecting with technical staff to add or optimize queries to meet business needs. For urgent requests, business personnel download all data to their local machines and use Excel or other data analysis methods to filter and calculate the target data. However, in practice, business personnel often need to manually download and process the data before submitting a request to technical staff, requiring them to iterate the system to continuously improve its functionality and adapt to new changes. In other words, business personnel must possess data analysis skills, and new query scenarios are highly likely to require manual processing. Relying on system updates cannot meet business needs, resulting in significant manpower costs and low query flexibility.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] The present invention provides a data query method, apparatus, non-volatile storage medium, and computer device to at least solve the technical problem that current data queries are usually limited to queries based on specified conditions, resulting in low query flexibility.
[0006] According to one aspect of the present invention, a data query method is provided, comprising: receiving an initial query statement input based on a target account; identifying named entities in the initial query statement; querying a preset vector database to determine whether a query template matching the initial query statement exists, wherein the preset vector database includes N candidate query templates, where N is a positive integer; if a query template matching the initial query statement exists, filling the query template with named entities to generate a first target query statement; and performing a query in an entity database based on the first target query statement to obtain a first query result.
[0007] Optionally, identifying named entities in the initial query statement includes: performing word segmentation on the initial query statement to obtain multiple words; inputting the multiple words into the target named entity recognition model to determine the named entities in the initial query statement, wherein the target named entity recognition model is obtained by training the original recognition model using sample words labeled with multiple entity types.
[0008] Optionally, querying a preset vector database to see if a query template matching the initial query statement exists includes: inputting the initial query statement into a preset natural language processing model to obtain the vector features corresponding to the initial query statement; calculating the similarity between the vector features corresponding to the initial query statement and the vector features corresponding to each of the N candidate query templates; and querying whether a query template matching the initial query statement exists based on a preset similarity threshold and the similarity between the N candidate query templates.
[0009] Optionally, querying the preset vector database to see if a query template matching the initial query statement exists further includes: if no query target matching the initial query statement exists, querying the target field in the entity database corresponding to the named entity; determining the relationship of the target field based on the field relationship in the entity database; constructing a second target query statement based on the relationship between the named entity and the target field; and querying the entity database based on the second target query statement to obtain a second query result.
[0010] Optionally, based on the relationship between named entities and target fields, a second target query statement is constructed, including: constructing candidate query statements based on the relationship between named entities and target fields; performing syntax validation on the candidate query statements to obtain validation results, wherein the syntax validation includes at least one of the following: statement structure validation, spelling validation, and data type validation; if the validation result is a validation failure, generating prompt words based on the validation result; repeating the steps of constructing a new query statement based on the relationship between prompt words, named entities, and target fields and performing syntax validation on the new query statement until the validation result is a validation success, at which point the new query statement is determined as the second target query statement.
[0011] Optionally, constructing a second target query statement based on the relationship between named entities and target fields further includes: sending the second query result back to the target account; receiving feedback information from the target account based on the second query result, wherein the feedback information represents the target account's satisfaction with the second query result; generating a target query template based on the second target query statement when the feedback information meets preset conditions; inputting the target query template into a preset natural language processing model to obtain the vector features corresponding to the target query template; and storing the vector features corresponding to the target query template in a preset vector database.
[0012] According to another aspect of the present invention, a data query apparatus is also provided, comprising: a receiving module for receiving an initial query statement input based on a target account; an identification module for identifying named entities in the initial query statement; a first query module for querying in a preset vector database whether a query template matching the initial query statement exists, wherein the preset vector database includes N candidate query templates, where N is a positive integer; a generating module for filling named entities into the query template to generate a first target query statement if a query template matching the initial query statement exists; and a second query module for querying in an entity database based on the first target query statement to obtain a first query result.
[0013] According to another aspect of the present invention, a non-volatile storage medium is also provided, the non-volatile storage medium including a stored program, wherein, when the program is running, it controls the device where the non-volatile storage medium is located to execute any of the above-described data query methods.
[0014] According to another aspect of the present invention, a computer device is also provided, the computer device including a processor, the processor being configured to run a program, wherein the program executes any of the above-described data query methods during runtime.
[0015] According to another aspect of the present invention, a computer program product is also provided, including a computer program that, when executed by a processor, implements any of the above-described data query methods.
[0016] In this embodiment of the invention, a data query method is employed. This involves receiving an initial query statement based on target account input; identifying named entities in the initial query statement; querying a preset vector database to determine if a query template matching the initial query statement exists (the preset vector database includes N candidate query templates, where N is a positive integer); if a query template matching the initial query statement exists, the named entity is filled into the query template to generate a first target query statement; and a query is performed in the entity database based on the first target query statement to obtain a first query result. This method ensures that the query target and conditions can be parsed from the user input, achieving dynamic adjustment of the query logic and thus improving query flexibility. It also solves the current technical problem that data queries typically only allow queries based on specified conditions, resulting in low query flexibility. Attached Figure Description
[0017] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0018] Figure 1 A hardware structure block diagram of a computer terminal for implementing a data query method is shown.
[0019] Figure 2 This is a schematic diagram of a data query method provided according to an embodiment of the present invention;
[0020] Figure 3 This is a schematic diagram of the entity extraction process provided by an optional embodiment of the present invention;
[0021] Figure 4 This is a schematic diagram of the query logic flow provided by an optional embodiment of the present invention;
[0022] Figure 5 This is a schematic diagram of a user feedback process provided by an optional embodiment of the present invention;
[0023] Figure 6 This is a structural block diagram of a data query device provided according to an embodiment of the present invention. Detailed Implementation
[0024] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. 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 should fall within the scope of protection of the present invention.
[0025] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0026] According to an embodiment of the present invention, a method embodiment of a data query method is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0027] The method embodiment provided in Embodiment 1 of this application can be executed on a mobile terminal, computer terminal, or similar computing device. Figure 1 A hardware block diagram of a computer terminal for implementing a data query method is shown. Figure 1 As shown, the computer terminal 10 may include one or more processors (shown as 102a, 102b, ..., 102n in the figure) (the processor may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 10 may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0028] It should be noted that the aforementioned one or more processors and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10. As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).
[0029] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the data query method in this embodiment of the invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby realizing the data query method of the application described above. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0030] The display can be, for example, a touchscreen liquid crystal display (LCD) that allows the user to interact with the user interface of the computer terminal 10.
[0031] Figure 2 This is a flowchart illustrating the data query method provided according to an embodiment of the present invention, such as... Figure 2 As shown, the method includes the following steps:
[0032] Step S202: Receive the initial query statement based on the target account input.
[0033] In this step, when a user wants to query data in the system, they typically enter an initial query statement based on the target account. Specifically, this may include the following steps:
[0034] Step S202.1 involves verifying the user's identity to ensure that only authorized users can perform query operations. This is typically achieved through a login interface, where the user must enter their username and password. The system compares this information with pre-stored account information, and only after successful verification is the user allowed to perform subsequent query operations based on the corresponding target account.
[0035] In step S202.2, users or business personnel can input their specific questions or needs in the human-computer interaction interface. This interface can be a graphical user interface (GUI) that allows users to input text via keyboard, or a voice input system that can convert the user's spoken commands into text.
[0036] Step S202.3 involves performing integrity and correctness checks on the user-input text, i.e., the initial query statement, such as checking for garbled characters. Once the integrity and correctness of the input text are confirmed, the text data can be transmitted to the entity extraction device. The entity extraction device is responsible for identifying key entity information from the user-input text. It typically uses natural language processing techniques and machine learning models to identify valid information in the text, such as dates, account names, and amount types.
[0037] Step S204: Identify named entities in the initial query statement.
[0038] In this step, the initial query statement can be segmented into individual words or phrases to facilitate subsequent named entity recognition. Then, natural language processing techniques are used to tag each word with its part of speech, helping to determine which words might be candidates for dates, account names, or amount types. Furthermore, pre-existing named entities in the system can be compared with the identified named entities, or other recognition algorithms can be used to initially capture named entities in the statement. Pre-existing keywords include, but are not limited to, words related to dates, account names, and amount types.
[0039] Named entity recognition typically involves natural language processing (NLP) techniques, particularly the use of named entity recognition (NER) models, which can be used to identify entities with specific meanings in text, such as names of people, places, organizations, times, amounts, etc., and classify them into predefined categories.
[0040] Specifically, to identify and classify named entities in query statements, pre-trained machine learning models such as BiLSTM (Bidirectional Long Short-Term Memory), CNN (Convolutional Neural Network), or BERT (Bidirectional Encoder Representer) models can be used. Deep learning techniques, including but not limited to the Transformer model with attention mechanisms, can also be used for more accurate identification and classification of named entities.
[0041] Figure 3 This is a schematic diagram of the entity extraction process provided by an optional embodiment of the present invention, such as... Figure 3 As shown, the process involves receiving an initial query statement, which can be natural language input by the user based on the target account. This initial query statement can be segmented into a series of basic words or phrases. Matching is performed based on entity templates and relevant prompt words to retrieve named entities. The identified named entities are then matched with corresponding entities in the database; for example, matching an account name to a specific account ID. Date information from the natural language is converted into the date format required for the database query, such as converting "this year" into a specific date range. Based on the amount type mentioned in the statement (such as operating revenue, net profit, etc.), relevant codes are found for use in the query logic generation stage. Specifically, entity types can include data date, financial transaction type, transaction entity, amount dimension, and statistical dimension. The identified and matched named entities are integrated into the prompt words, providing the agent with detailed query background and target. In addition to named entities, other contextual information, such as query context and potential query relationships, can be added to enhance the agent's understanding. The list of identified named entities can also be displayed to the user, allowing the user to confirm whether the required information has been correctly identified. Users have the opportunity to correct the named entity recognition results. The system learns from user feedback and improves the accuracy of future recognitions. This reduces query errors caused by input ambiguity or system misinterpretation. If the user confirms that the results are correct, the system will continue with subsequent steps; if there is an error, the system will ask the user to provide more detailed instructions or re-enter the query.
[0042] Step S206: Query the preset vector database to see if there is a query template that matches the initial query statement. The preset vector database includes N candidate query templates, where N is a positive integer.
[0043] A pre-trained vector database is a storage system containing N candidate query templates, where N is a positive integer representing the number of query templates in the database. These templates cover the diversity and complexity of past user queries, aiming to provide fast and accurate matching for new query requests. Specifically, the pre-trained vector database can include several components, such as: a question case vector library: storing vectorized representations of historical user queries, including but not limited to queries submitted by users in natural language, corresponding valid SQL statements, API call instructions and their execution results, and user feedback. These vectors can be used to quickly match newly submitted user queries, find the most similar query cases, and thus guide the generation of new query logic. An API vector library: containing vectorized descriptions of all available API interfaces within the system. Each API entry includes its functional description, parameter list, parameter types, and example query conditions. The API vector library helps the agent quickly identify and match existing functions during the query logic generation phase, reducing redundant work and query latency. An entity encoding vector library: covering vector representations of various named entities in the accounting field, such as account names, dates, currencies, accounting code codes, etc., as well as their internal system encodings. The use of entity encoding vector libraries ensures that agents accurately understand and transform named entities in user queries, thereby improving query accuracy and efficiency. Database relationship graph vector libraries store information about database structure and relationships, including table structure, field names, field types, and relationships between tables (such as primary and foreign keys). This vectorized representation helps agents more accurately understand and construct relationships between tables when generating SQL queries, avoiding errors and redundancy. A prompt word vector library contains a set of prompt words to guide agents in entity extraction and query logic generation. These prompt words are vectorized and can be flexibly adjusted and combined according to different query scenarios and user needs, providing agents with more accurate input information.
[0044] Upon receiving the initial query, the system immediately initiates the query template matching process. This process involves converting the text into a vector representation so that the machine can understand and compare the meaning of the text. The conversion process may involve natural language processing techniques, such as word embeddings, sentence embeddings, or deep learning models, such as BERT (Bidirectional Encoder Representations from Transformers) or its variant SBERT (Sentence-BERT).
[0045] Specifically, the matching of the query statement can be verified by calculating the similarity between the vector features of the initial query statement and the vector features of all N candidate query templates in a preset vector database. Similarity calculation methods can include cosine similarity, Jaccard similarity, and Euclidean distance.
[0046] Step S208: If a query template that matches the initial query statement exists, the named entity is filled into the query template to generate the first target query statement.
[0047] When a query template that highly matches the initial query statement does exist in the preset vector database, named entities (such as date, account name, amount type, etc.) identified from the initial query statement can be further filled into the corresponding positions in this matching query template. Because of the existence of query templates, even if the user's input query statement has a variety of formats, a suitable execution mode can be found through matching.
[0048] Specifically, a query template with the highest similarity to the initial query statement can be selected from a pre-defined vector database. The selected query template is then analyzed to identify the positions of all variables. These variables typically correspond to named entities in the query statement, such as date, account name, and amount type. The specific values of these named entities are then filled into the corresponding variable positions in the template; for example, specific dates, account IDs, and amount codes are filled into the SQL or API template. The generated first target query statement can be checked to ensure it conforms to SQL syntax or API call syntax rules. After confirming its correctness, a complete and specific first target query statement or API call command is obtained, i.e., the first target query statement.
[0049] By following the steps above, a primary target query statement that meets the user's needs can be quickly generated, significantly shortening the time from user input to query result output, and improving system response speed and user experience. Simultaneously, through template matching and entity replacement, the system can maintain the consistency and accuracy of query logic, avoiding potential errors caused by manually writing SQL statements, and enhancing system stability and reliability.
[0050] Step S210: Perform a query in the entity database based on the first target query statement to obtain the first query result.
[0051] In this step, after the first target query statement is generated, it is sent to the entity database for actual data retrieval. The entity database stores all entity data related to the business, such as various account information, transaction records, and financial statements. This data is typically stored in a structured manner, such as using a SQL (Structured Query Language) database. Based on the first target query statement, the database management system parses the SQL statement, determines the tables, fields, conditions, and other information to be queried, and then executes the corresponding data retrieval operations. This process may involve single-table queries or multi-table joins, and may also require data aggregation, sorting, and other operations, depending on the logic of the first target query statement.
[0052] The above steps achieve the goal of dynamically adjusting the query logic, thereby improving the technical effect of query flexibility and solving the technical problem that current data queries are usually limited to queries based on specified conditions, resulting in low query flexibility.
[0053] As an optional embodiment, identifying named entities in the initial query statement includes: performing word segmentation on the initial query statement to obtain multiple words; inputting the multiple words into a target named entity recognition model to determine the named entities in the initial query statement, wherein the target named entity recognition model is obtained by training the original recognition model using sample words labeled with multiple entity types.
[0054] Optionally, the word segmentation algorithms employed include, but are not limited to, maximum matching, HMM (Hidden Markov Model) segmentation, and CRF (Conditional Random Field)-based segmentation. Named entity recognition models are typically based on deep learning techniques, such as BiLSTM-CRF and BERT. These models can learn complex relationships and patterns between words to identify specific entity categories. During training, sample words of various entity types can be input into the model, and through supervised learning, the model gradually learns to recognize entities based on context.
[0055] Specifically, the initial query is input into a word segmentation algorithm, which decomposes it into a series of meaningful lexical units to prepare for subsequent named entity recognition. Then, a target named entity recognition model is loaded. This target model can be trained on the original recognition model using a large number of sample words labeled with entity types. A large number of text samples from the accounting field can be collected, containing different types of named entities such as dates, account names, and amount types. The samples are manually labeled, marking the entity type to which each word belongs. These labeled samples are then used to train the original named entity recognition model (such as BERT, BiLSTM-CRF, etc.), enabling it to learn to recognize and classify these entity types in new text. Through iterative training and evaluation, the model parameters are optimized to improve the accuracy and recall of named entity recognition. The segmented words are then input into the trained target named entity recognition model, which outputs the possible named entity types and their confidence scores for each word. Based on the model's prediction results, the named entity labels with the highest confidence scores are extracted to determine the specific entity types and instances in the query. The identified named entities and their types can be organized into a list, such as date, account name, amount type, etc., for use in subsequent processing and query logic generation stages.
[0056] It can also display a list of identified named entities to users, allowing them to confirm whether all key information in their query has been correctly identified. If users point out errors or omissions, this feedback can be collected for subsequent model training and optimization, thereby gradually improving the accuracy of named entity recognition.
[0057] Through the above steps, named entities in user queries can be accurately and efficiently identified, providing a solid foundation for subsequent query logic generation. Furthermore, the original recognition model is trained using sample words labeled with multiple entity types. This model training method enables the agent to more accurately extract specific entity information from the user's natural language input, such as accounting dates, query statements, and amount types. In this way, the system can accurately understand the user's query intent, providing crucial information for subsequent query logic generation and ensuring the accuracy and efficiency of the query.
[0058] As an optional embodiment, querying a preset vector database to see if a query template matching the initial query statement exists includes: inputting the initial query statement into a preset natural language processing model to obtain the vector features corresponding to the initial query statement; calculating the similarity between the vector features corresponding to the initial query statement and the vector features corresponding to each of the N candidate query templates; and querying whether a query template matching the initial query statement exists based on a preset similarity threshold and the similarity between the N candidate query templates.
[0059] Optionally, a pre-trained natural language processing model, such as Sentence-BERT, can be used, which can convert natural language text into fixed-length vector representations. The user's initial query is input into this model to generate vector features representing the semantics of the query. The similarity between the vector features of the initial query and the vector features of each candidate query template in the database is then calculated. A commonly used similarity calculation method is cosine similarity, which effectively compares the directional similarity between two vectors.
[0060] To filter out irrelevant or low-quality matches, a preset similarity threshold can be set. Only when the initial query's similarity to a candidate template exceeds this threshold is it considered a valid match. Based on the calculated similarity, all candidate query templates in the database are retrieved, and those that meet the preset similarity threshold are identified. If multiple templates have similarities exceeding the threshold, the system should select one or more of the best-matching templates based on a specific strategy (such as the highest similarity, the most recently updated template, etc.).
[0061] Once a matching template is found, the identified named entities (such as date, account name, amount type, etc.) can be filled into the corresponding positions in the template to generate the first target query statement or API call command. Based on the context and the relationships between entities, the query logic can be supplemented or adjusted to ensure that the generated query statement accurately reflects the user's query intent.
[0062] Specifically, the pre-defined vector database can be constructed based on the following steps:
[0063] Step 1: Obtain high-frequency query question documents and query API documents, which may contain frequently queried questions from historical periods. Perform SBERT (Sentence-BERT) sentence embedding on the original question fields of the high-frequency query question documents and the API description fields of the query API documents to obtain the corresponding feature vectors.
[0064] Step 2: For entity-encoded documents, feature extraction of entity names can be performed using open-source pre-trained word vectors obtained through Word2Vec. Accounting system named entities are characterized by short names, simple semantics, and large data volume. Using word vector embedding is not only sufficiently accurate but also computationally simple and efficient. Specifically, the names can first be segmented into simple words, and then the following formula can be used for feature extraction, where... V 实体 The vector representation of the entity, i.e., the feature vector to be calculated. n The number of words obtained after word segmentation. W i The word vector representing the i-th word:
[0065] ;
[0066] Step 3: The processed content from Steps 1 and 2 can be stored in a preset vector database. During querying, the similarity is calculated using the cosine distance between vectors, with the specific formula as follows:
[0067] ;
[0068] in, SIM(A, B) For the corresponding similarity, A The vector features corresponding to the initial query statement. B These are the vector features corresponding to each candidate query template.
[0069] As an optional embodiment, querying the preset vector database to see if a query template matching the initial query statement exists further includes: if no query target matching the initial query statement exists, querying the target field corresponding to the named entity in the entity database; determining the relationship of the target field based on the field relationship in the entity database; constructing a second target query statement based on the relationship between the named entity and the target field; and querying the entity database based on the second target query statement to obtain a second query result.
[0070] Optionally, when existing query templates cannot directly respond to a user's accounting data query needs, the system can proactively search the entity database for target fields that match the named entities in the user's query. Then, based on the field relationship graph in the database, the relationships between the target fields are determined. Based on these relationships and named entities, a second set of query statements is automatically generated. This newly generated query statement is used for deep searching in the entity database to obtain query results that meet the user's specific needs. Through these steps, the system's query scope is expanded, query accuracy is improved, and it can adapt to more complex query scenarios. This ensures that even when faced with unpredictable accounting data query requests, a reasonable solution can be found, enabling efficient data retrieval and analysis without manual intervention. This significantly enhances the system's adaptability and user convenience.
[0071] Specifically, the second query result is generated by SQL. Based on the entity list, the query involves inferring the fields, databases, and relationships from the database relationship graph. The user's original query and the entity list are combined as input prompts, and the agent generates SQL, which is then checked for syntax and efficiency. If syntax errors or significant execution inefficiency are found, the errors are incorporated as part of the prompts, and the SQL is regenerated, ultimately ensuring that an executable and efficient SQL command is generated.
[0072] Figure 4This is a schematic diagram of the query logic flow provided by an optional embodiment of the present invention, such as... Figure 4 As shown, this process includes: converting extracted named entities from natural language form into a system-recognizable encoding format for easy matching with database fields and API parameters. Specifically, it identifies all relevant named entities from user input, such as date, account name, and amount type. Using an entity encoding vector library, the identified entity names are converted into corresponding system codes, for example, "RMB" is encoded as "CNY," and "loan" is encoded as a specific business code. A set of encoded named entities is obtained, ready for use in query logic generation. Authentication is also required, ensuring that the user's requested data query is within the authorized scope to maintain data security and compliance. Based on the encoded entities (such as account ID, organizational unit, etc.), it can be checked whether the user has permission to access the relevant data. If the permission check passes, the process continues; if permissions are insufficient, an insufficient permission error message is returned to the user, preventing further data retrieval. Then, it attempts to directly utilize existing API functions to meet the user's query needs, avoiding unnecessary SQL statement generation. Based on the encoded entities and query conditions, a matching API can be searched from the API vector library. If a matching API is found, the extracted entity information is used to fill in the API parameters, generating the API call command. If a matching API exists, an API call instruction is generated; otherwise, an executable SQL query is generated based on user input and entity information. Table and field information can be extracted from the database relationship graph to understand the relationships between tables and the meaning of fields. Specialized prompts are constructed based on the user question and the entity list to guide the agent in generating the SQL statement. Using these prompts, the agent attempts to generate an SQL query. The generated SQL statement is checked for syntax correctness and its estimated execution efficiency meets requirements, resulting in a syntactically correct and efficient SQL query.
[0073] If the initially generated SQL statement has syntax errors or efficiency issues, a better query logic is generated through multiple rounds of suggestion word optimization and agent attempts, finally resulting in the second target query statement.
[0074] As an optional embodiment, constructing a second target query statement based on the relationship between named entities and target fields includes: constructing candidate query statements based on the relationship between named entities and target fields; performing syntax validation on the candidate query statements to obtain validation results, wherein the syntax validation includes at least one of the following: statement structure validation, spelling validation, and data type validation; if the validation result is a validation failure, generating prompt words based on the validation result; repeating the steps of constructing a new query statement based on the relationship between prompt words, named entities, and target fields and performing syntax validation on the new query statement until the validation result is a validation success, at which point the new query statement is determined as the second target query statement.
[0075] Specifically, syntax validation includes checking the completeness of the statement structure to ensure there are no syntax errors; checking the spelling of keywords in the query statement to avoid query failures due to spelling errors; and data type validation to confirm that the data types in the query statement match the data types of the database fields, ensuring the correctness and efficiency of the query. The correctness and completeness of the syntax can be verified by constructing an Abstract Syntax Tree (AST) of the SQL statement and traversing the entire tree structure. If a validation error occurs, the system will generate corresponding prompts based on the specific reason for the failure. These prompts are to guide the system or user to make necessary corrections to improve the success rate of the next query generation. Based on the relationship between the generated prompts, named entities, and target fields, the system will attempt to construct a new query statement again and perform syntax validation on this new query statement. This process will be repeated until the generated query statement passes all syntax checks, i.e., the validation result is successful. This ensures that the final query statement is not only syntactically correct but also properly constructed based on the named entities and target fields input by the user, effectively retrieving the required information from the entity database.
[0076] As an optional embodiment, constructing a second target query statement based on the relationship between named entities and target fields further includes: sending the second query result back to the target account; receiving feedback information from the target account based on the second query result, wherein the feedback information represents the target account's satisfaction with the second query result; generating a target query template based on the second target query statement when the feedback information meets preset conditions; inputting the target query template into a preset natural language processing model to obtain the vector features corresponding to the target query template; and storing the vector features corresponding to the target query template in a preset vector database.
[0077] Optionally, the query results can be sent to the user who submitted the query (i.e., the target account) so that the user can directly view and use the data. Then, user feedback on the query results is collected to evaluate the effectiveness and satisfaction of the query statement. Specifically, a feedback interface or mechanism can be provided so that the target account can easily express its satisfaction with the second query results. The collected feedback information is analyzed to understand the user's specific opinions and suggestions regarding the query results. If the user feedback indicates satisfaction with the query results, the second target query statement is transformed into a standardized query template for use in future similar queries. Based on the user-satisfied second target query statement, a new query template is created, which should contain the key structure and logic of the query. Specific entity parameters in the query statement are transformed into variables or placeholders so that the template can be applied to queries under different input conditions. The created target query template can be converted into a vector representation for easy storage and retrieval. The generated vector features are then stored together with the corresponding query template in a pre-defined vector database.
[0078] Figure 5 This is a schematic diagram of a user feedback process provided by an optional embodiment of the present invention, such as... Figure 5 As shown, after the system generates query results (second query results) based on the second target query statement and displays them to the target account, the user can view the results and provide feedback based on how well they meet their needs. Feedback can include the user's satisfaction rating of the query results, whether the required information was found, and whether the query results are complete. Further, the system determines whether this feedback meets preset update conditions. These preset conditions might be a user feedback satisfaction threshold, the error type of the query results (such as incomplete data, logical errors, etc.), or a certain number of feedback collections. If the feedback meets these preset conditions, the system proceeds to the next step; otherwise, it stops or waits for more user feedback. When the feedback meets the update conditions, the system generates a new query template based on the user feedback and the second target query statement. This process may include adjusting the structure of the query statement, optimizing the syntax of the query statement, and adding or modifying named entity recognition rules to ensure that the new query template more accurately meets the target account's query needs. The generated target query template is input into a preset natural language processing model, such as BERT or SBERT, to generate vector features for the query template and store them in the problem case vector library, i.e., the preset vector library.
[0079] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.
[0080] Through the above description of the embodiments, those skilled in the art can clearly understand the general-purpose hardware platform required to implement the data query method according to the above embodiments. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of the present invention.
[0081] According to an embodiment of the present invention, a data query apparatus for implementing the above-described data query method is also provided. Figure 6 This is a structural block diagram of a data query device provided according to an embodiment of the present invention, such as... Figure 6 As shown, the data query device includes: a receiving module 602, an identification module 604, a first query module 606, a generating module 608, and a second query module 610. The data query device will be described below.
[0082] The receiving module 602 is used to receive the initial query statement based on the target account input.
[0083] The identification module 604 is used to identify named entities in the initial query statement.
[0084] The first query module 606 is used to query in a preset vector database whether there is a query template that matches the initial query statement. The preset vector database includes N candidate query templates, where N is a positive integer.
[0085] The generation module 608 is used to fill the named entity into the query template and generate the first target query statement when a query template that matches the initial query statement exists.
[0086] The second query module 610 is used to perform a query in the entity database based on the first target query statement to obtain the first query result.
[0087] It should be noted that the receiving module 602, the identification module 604, the first query module 606, the generating module 608, and the second query module 610 mentioned above correspond to steps S202 to S210 in the embodiments. Multiple modules and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in the above embodiments. It should also be noted that the above modules, as part of the device, can run in the computer terminal 10 provided in the embodiments.
[0088] Embodiments of the present invention may provide a computer device. Optionally, in this embodiment, the computer device may be located in at least one of a plurality of network devices in a computer network. The computer device includes a memory and a processor.
[0089] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the data query method and apparatus in this embodiment of the invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby realizing the aforementioned data query method. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to a computer terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0090] The processor can invoke information and application programs stored in the memory via a transmission device to perform the following steps: receiving an initial query statement based on the target account input; identifying named entities in the initial query statement; querying a preset vector database to see if a query template matching the initial query statement exists, wherein the preset vector database includes N candidate query templates, where N is a positive integer; if a query template matching the initial query statement exists, filling the query template with the named entities to generate a first target query statement; and querying the entity database based on the first target query statement to obtain a first query result.
[0091] Optionally, the processor may also execute program code for the following steps: identifying named entities in the initial query statement, including: performing word segmentation on the initial query statement to obtain multiple words; inputting the multiple words into the target named entity recognition model to determine the named entities in the initial query statement, wherein the target named entity recognition model is obtained by training the original recognition model using sample words labeled with multiple entity types.
[0092] Optionally, the processor may also execute program code that performs the following steps: querying a preset vector database to see if a query template matches the initial query statement, including: inputting the initial query statement into a preset natural language processing model to obtain the vector features corresponding to the initial query statement; calculating the similarity between the vector features corresponding to the initial query statement and the vector features corresponding to each of the N candidate query templates; and querying whether a query template matches the initial query statement based on a preset similarity threshold and the similarity between the N candidate query templates.
[0093] Optionally, the processor may also execute program code that performs the following steps: querying a preset vector database to see if a query template matches the initial query statement, and further including: if no query target matches the initial query statement, querying the entity database for the target field corresponding to the named entity; determining the relationship of the target field based on the field relationship in the entity database; constructing a second target query statement based on the relationship between the named entity and the target field; and querying the entity database based on the second target query statement to obtain a second query result.
[0094] Optionally, the processor may also execute program code that performs the following steps: constructing a second target query statement based on the relationship between named entities and target fields, including: constructing candidate query statements based on the relationship between named entities and target fields; performing syntax validation on the candidate query statements to obtain validation results, wherein the syntax validation includes at least one of the following: statement structure validation, spelling validation, and data type validation; generating prompt words based on the validation results if the validation result is a validation failure; repeating the steps of constructing a new query statement based on the relationship between prompt words, named entities, and target fields and performing syntax validation on the new query statement until the validation result is a validation success, and then determining the new query statement as the second target query statement.
[0095] Optionally, the processor may also execute program code that performs the following steps: constructing a second target query statement based on the relationship between named entities and target fields, further including: feeding back the second query result to the target account; receiving feedback information from the target account based on the second query result, wherein the feedback information represents the target account's satisfaction with the second query result; generating a target query template based on the second target query statement when the feedback information meets preset conditions; inputting the target query template into a preset natural language processing model to obtain the vector features corresponding to the target query template; and storing the vector features corresponding to the target query template into a preset vector database.
[0096] This invention provides a data query method. It involves receiving an initial query statement based on a target account input; identifying named entities in the initial query statement; querying a preset vector database to determine if a query template matching the initial query statement exists, wherein the preset vector database includes N candidate query templates, where N is a positive integer; if a query template matching the initial query statement exists, filling the query template with the named entities to generate a first target query statement; and querying the entity database based on the first target query statement to obtain a first query result. This method achieves dynamic adjustment of the query logic, thereby improving query flexibility and solving the current technical problem that data queries are typically limited to specific conditions, resulting in low query flexibility.
[0097] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a non-volatile storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0098] Embodiments of the present invention also provide a non-volatile storage medium. Optionally, in this embodiment, the aforementioned non-volatile storage medium can be used to store the program code executed by the data query method provided in the above embodiments.
[0099] Optionally, in this embodiment, the non-volatile storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.
[0100] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: receiving an initial query statement based on target account input; identifying named entities in the initial query statement; querying a preset vector database to see if a query template matching the initial query statement exists, wherein the preset vector database includes N candidate query templates, where N is a positive integer; if a query template matching the initial query statement exists, filling the query template with named entities to generate a first target query statement; and querying the entity database based on the first target query statement to obtain a first query result.
[0101] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: identifying named entities in an initial query statement, including: performing word segmentation on the initial query statement to obtain multiple words; inputting the multiple words into a target named entity recognition model to determine the named entities in the initial query statement, wherein the target named entity recognition model is obtained by training the original recognition model using sample words labeled with multiple entity types.
[0102] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: querying a preset vector database to see if a query template matches the initial query statement, including: inputting the initial query statement into a preset natural language processing model to obtain vector features corresponding to the initial query statement; calculating the similarity between the vector features corresponding to the initial query statement and the vector features corresponding to each of the N candidate query templates; and querying whether a query template matches the initial query statement based on a preset similarity threshold and the similarity between the N candidate query templates.
[0103] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: querying a preset vector database to see if a query template matching the initial query statement exists, further including: if no query target matching the initial query statement exists, querying the entity database for the target field corresponding to the named entity; determining the relationship of the target field based on the field relationship in the entity database; constructing a second target query statement based on the relationship between the named entity and the target field; and querying the entity database based on the second target query statement to obtain a second query result.
[0104] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: constructing a second target query statement based on the relationship between named entities and target fields, including: constructing candidate query statements based on the relationship between named entities and target fields; performing syntax verification on the candidate query statements to obtain a verification result, wherein the syntax verification includes at least one of the following: statement structure verification, spelling verification, and data type verification; if the verification result is a verification failure, generating a prompt word based on the verification result; repeating the steps of constructing a new query statement based on the relationship between the prompt word, named entities, and target fields and performing syntax verification on the new query statement until the verification result is a verification success, and then determining the new query statement as the second target query statement.
[0105] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for performing the following steps: constructing a second target query statement based on the relationship between named entities and target fields, and further including: feeding back the second query result to the target account; receiving feedback information from the target account based on the second query result, wherein the feedback information represents the target account's satisfaction with the second query result; generating a target query template based on the second target query statement when the feedback information meets preset conditions; inputting the target query template into a preset natural language processing model to obtain the vector features corresponding to the target query template; and storing the vector features corresponding to the target query template in a preset vector database.
[0106] Embodiments of the present invention also provide a computer program product, including a computer program. Optionally, in this embodiment, when the computer program is executed by a processor, it can: receive an initial query statement input based on a target account; identify named entities in the initial query statement; query a preset vector database to see if there is a query template matching the initial query statement, wherein the preset vector database includes N candidate query templates, where N is a positive integer; if there is a query template matching the initial query statement, fill the named entity into the query template to generate a first target query statement; and perform a query in the entity database based on the first target query statement to obtain a first query result.
[0107] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0108] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0109] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0110] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0111] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0112] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a non-volatile storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0113] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A data query method, characterized in that, include: Receive the initial query statement based on the target account input; Identify named entities in the initial query statement; The system queries a preset vector database to see if there is a query template that matches the initial query statement. The preset vector database includes N candidate query templates, where N is a positive integer. If a query template matching the initial query statement exists, the named entity is filled into the query template to generate the first target query statement; Based on the first target query statement, a query is performed in the entity database to obtain the first query result.
2. The method according to claim 1, characterized in that, The process of identifying named entities in the initial query statement includes: The initial query statement is segmented into multiple words. The multiple words are input into the target named entity recognition model to determine the named entities in the initial query statement. The target named entity recognition model is obtained by training the original recognition model with sample words labeled with multiple entity types.
3. The method according to claim 1, characterized in that, The step of querying the preset vector database to see if a query template matching the initial query statement exists includes: The initial query statement is input into a preset natural language processing model to obtain the vector features corresponding to the initial query statement; Calculate the similarity between the vector features corresponding to the initial query statement and the vector features corresponding to each of the N candidate query templates; Based on a preset similarity threshold and the similarity of each of the N candidate query templates, a query is performed to determine whether there exists a query template that matches the initial query statement.
4. The method according to any one of claims 1 to 3, characterized in that, Also includes: If no query target matches the initial query statement, query the target field corresponding to the named entity in the entity database; Based on the field relationships in the entity database, determine the relationship of the target field; Based on the relationship between the named entity and the target field, construct a second target query statement; The second query result is obtained by querying the entity database based on the second target query statement.
5. The method according to claim 4, characterized in that, The construction of the second target query statement based on the relationship between the named entity and the target field includes: Based on the relationship between the named entity and the target field, construct candidate query statements; The candidate query statement is subjected to syntax validation to obtain a validation result, wherein the syntax validation includes at least one of the following: statement structure validation, spelling validation and data type validation; If the verification result is a verification failure, a prompt word is generated based on the verification result; Repeat the steps of constructing a new query statement based on the relationship between the prompt words, the named entities, and the target fields, and performing syntax validation on the new query statement until the validation result is successful, then determine the new query statement as the second target query statement.
6. The method according to claim 4, characterized in that, Also includes: The second query result is then sent back to the target account. Receive feedback information from the target account based on the second query result, wherein the feedback information represents the target account's level of satisfaction with the second query result; If the feedback information meets the preset conditions, a target query template is generated based on the second target query statement; The target query template is input into a preset natural language processing model to obtain the vector features corresponding to the target query template; The vector features corresponding to the target query template are stored in the preset vector database.
7. A data query device, characterized in that, include: The receiving module is used to receive the initial query statement based on the target account input; The identification module is used to identify named entities in the initial query statement; The first query module is used to query in a preset vector database whether there is a query template that matches the initial query statement, wherein the preset vector database includes N candidate query templates, where N is a positive integer; The generation module is used to fill the named entity into the query template and generate the first target query statement when a query template matching the initial query statement exists. The second query module is used to perform a query in the entity database based on the first target query statement to obtain the first query result.
8. A non-volatile storage medium, characterized in that, The non-volatile storage medium includes a stored program, wherein, when the program is executed, it controls the device where the non-volatile storage medium is located to execute the data query method according to any one of claims 1 to 6.
9. A computer device, characterized in that, include: Memory and processor The memory stores computer programs; The processor is configured to execute a computer program stored in the memory, wherein when the computer program is executed, the processor performs the data query method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the data query method according to any one of claims 1 to 6.