Data query method and device and electronic equipment

By extracting the query intention and vectors of natural language problems, matching the data table information of multiple data sources, and generating SQL query statements, it solves the problem of SQL query in the multi-data source business scenario in the existing technology, and realizes efficient and accurate natural language to SQL query conversion.

CN119884169APending Publication Date: 2025-04-25CHINA TELECOM ARTIFICIAL INTELLIGENCE TECHNOLOGY (BEIJING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411944677.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

The existing technology is difficult to process SQL queries in multi-data source business scenarios through large models and cannot meet actual business needs.

Method used

By obtaining the query intent of natural language problems entered by the user, determining the vector and word segmentation results corresponding to the query intent, and matching with the data table vectors and word segmentation results of multiple data sources, determining the target data source and target data table, and generating corresponding SQL query statements.

Benefits of technology

It realizes efficient and accurate conversion of natural language queries into SQL queries in multi-data source business scenarios, and solves the problem of SQL queries in large-scale models processing multi-data source scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119884169A_ABST
    Figure CN119884169A_ABST
Patent Text Reader

Abstract

The invention discloses a data query method and device and electronic equipment. The method comprises the steps that a query intention, input by a target object, of a first question is obtained, and the query intention is obtained by extracting the first question; determining a first vector corresponding to the query intention, and performing word segmentation on the query intention to obtain a first word segmentation result; obtaining a second vector and a second word segmentation result corresponding to each data table in each data source in the plurality of data sources; determining a target data source and a target data table corresponding to the query intention according to the first vector, the second vector, the first word segmentation result and the second word segmentation result; and determining a database query statement corresponding to the first question according to the query intention, the data source type corresponding to the target data source and the target data table, and generating a query result according to the database query statement. The technical problem that SQL query in a multi-data-source business scene cannot be processed through a large model in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of natural language processing, and more specifically, to a method, device and electronic device for data query. Background Art

[0002] Text to SQL conversion is a challenging task in the natural language processing (NLP) and database communities. Its goal is to convert natural language questions on a given relational database into SQL queries. With the continuous development of large language models, this task has changed, and the current mainstream Text2SQL research is based on large language models or related technologies.

[0003] However, in the actual application and products of Text2SQL, it is often found that this technology cannot fully meet the actual business needs by simply relying on large models to generate SQL because it involves complex business data, especially in business scenarios that deal with multiple data sources, such as multiple types of data sources or multiple data sources under the same type of data source. According to current technology, it is usually necessary to manually limit it to a certain data source before querying the table under the data source. Therefore, the relevant technology cannot use large models to process SQL queries in business scenarios with multiple data sources.

[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0005] The embodiments of the present application provide a method, device and electronic device for data query, so as to at least solve the technical problem in the related art that SQL queries in multi-data source business scenarios cannot be processed through a large model.

[0006] According to one aspect of an embodiment of the present application, a method for data query is provided, including: obtaining a query intent of a first question input by a target object, wherein the query intent is obtained by extracting the first question; determining a first vector corresponding to the query intent, and segmenting the query intent to obtain a first segmentation result; obtaining a second vector and a second segmentation result corresponding to each data table in each data source of multiple data sources, wherein the multiple data sources are data sources to which a business associated with the first question belongs; determining a target data source and a target data table corresponding to the query intent based on the first vector, the second vector, the first segmentation result and the second segmentation result; determining a database query statement corresponding to the first question based on the query intent, the data source type corresponding to the target data source, and the target data table, and generating a query result based on the database query statement.

[0007] Optionally, determining a target data source and a target data table corresponding to the query intent includes: determining a first similarity result corresponding to the first vector and the second vector; determining a second similarity result corresponding to the first word segmentation result and the second word segmentation result; determining a target similarity result based on the first similarity result and the second similarity result; determining a target data source and a target data table based on the target similarity result.

[0008] Optionally, determining a first similarity result corresponding to the first vector and the second vector includes: acquiring the first vector and the second vector; determining the cosine similarity between the first vector and the second vector to obtain a first similarity; and normalizing the first similarity to obtain a first similarity result.

[0009] Optionally, determining a second similarity result corresponding to the first word segmentation result and the second word segmentation result includes: obtaining the first word segmentation result and the second word segmentation result; determining the text similarity between the first word segmentation result and the second word segmentation result to obtain a second similarity; and normalizing the second similarity to obtain a second similarity result.

[0010] Optionally, determining a target similarity result based on the first similarity result and the second similarity result includes: determining a first weight corresponding to the first similarity result, and determining a second weight corresponding to the second similarity result; determining a first numerical value based on the first similarity result and the first weight; determining a second numerical value based on the second similarity result and the second weight; and determining the target similarity result based on the sum of the first numerical value, the second numerical value, the first weight, and the second weight.

[0011] Optionally, based on the target similarity result, a target data source and a target data table are determined, including: in each data source, the data table corresponding to the similarity greater than a preset threshold in the target similarity result is determined as a first data table set, wherein each data source corresponds to a first data table set; the similarity scores of the first preset number of data tables in the first data table set corresponding to each data source are obtained, wherein each data table in the first data table set is sorted from high to low according to the similarity; based on the similarity score and the preset number, a target similarity score corresponding to each data source is determined; the data source corresponding to the maximum value in the target similarity score is determined as the target data source, and the first preset number of data tables in the target data source sorted from high to low according to the similarity are determined as the target data table.

[0012] Optionally, generating a query result based on a database query statement includes: obtaining a database query statement and obtaining a target data source; executing the database query statement at the target data source to generate a query result corresponding to the first question.

[0013] According to another aspect of an embodiment of the present application, a data query device is also provided, including: a first acquisition module, used to obtain the query intent of a first question input by a target object, wherein the query intent is obtained by extracting the first question; a first determination module, used to determine a first vector corresponding to the query intent, and to segment the query intent to obtain a first segmentation result; a second acquisition module, used to obtain a second vector and a second segmentation result corresponding to each data table in each data source of multiple data sources, wherein the multiple data sources are data sources to which the business associated with the first question belongs; a second determination module, used to determine a target data source and a target data table corresponding to the query intent based on the first vector, the second vector, the first segmentation result and the second segmentation result; a generation module, used to determine a database query statement corresponding to the first question based on the query intent, the data source type corresponding to the target data source, and the target data table, and generate a query result based on the database query statement.

[0014] According to another aspect of the embodiments of the present application, an electronic device is also provided, including: a memory for storing program instructions; a processor, connected to the memory, for executing program instructions to implement the following functions: obtaining a query intent of a first question input by a target object, wherein the query intent is obtained by performing a total extraction on the first question; determining a first vector corresponding to the query intent, and performing word segmentation on the query intent to obtain a first word segmentation result; obtaining a second vector and a second word segmentation result corresponding to each data table in each of a plurality of data sources, wherein the plurality of data sources are data sources to which a business associated with the first question belongs; determining a target data source and a target data table corresponding to the query intent based on the first vector, the second vector, the first word segmentation result and the second word segmentation result; determining a database query statement corresponding to the first question based on the query intent, the data source type corresponding to the target data source, and the target data table, and generating a query result based on the database query statement.

[0015] According to another aspect of the embodiments of the present application, a non-volatile storage medium is provided, which includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the above-mentioned data query method by running the computer program.

[0016] According to another aspect of the embodiments of the present application, a computer program product is provided, including computer instructions, which implement the above-mentioned data query method when executed by a processor.

[0017] In an embodiment of the present application, the query intent of the first question input by the target object is obtained, wherein the query intent is obtained by extracting the first question; a first vector corresponding to the query intent is determined, and the query intent is segmented to obtain a first segmentation result; a second vector and a second segmentation result corresponding to each data table in each data source in a plurality of data sources are obtained, wherein the plurality of data sources are data sources to which the business associated with the first question belongs; a target data source and a target data table corresponding to the query intent are determined based on the first vector, the second vector, the first segmentation result and the second segmentation result; a database query statement corresponding to the first question is determined based on the query intent, the data source type corresponding to the target data source, and the target data table, and a query result is generated based on the database query statement, thereby achieving the purpose of intelligently identifying and processing user natural language queries, thereby achieving the technical effect of efficiently and accurately converting natural language queries into SQL queries using a large model in a multi-data source business scenario, thereby solving the technical problem in the related art that the SQL query in the multi-data source business scenario cannot be processed by a large model. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0019] Figure 1 is a hardware structure block diagram of a computer terminal for implementing a method for data query according to an embodiment of the present application;

[0020] Figure 2 is a flow chart of a data query method according to an embodiment of the present application;

[0021] Figure 3 It is a structural diagram of a data query device according to an embodiment of the present application. DETAILED DESCRIPTION

[0022] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.

[0023] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0024] The information collected in the embodiments of the present application is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data comply with the relevant laws, regulations and standards of the relevant regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or reject automated decision-making results; if the user chooses to reject, the expert decision-making process will be entered.

[0025] First, some nouns or terms that appear in the process of explaining the embodiments of the present application are subject to the following explanations:

[0026] Prompt: It refers to the text or instructions that provide input to the large model to guide it to generate a specific type of output.

[0027] Data source: usually refers to the place or source where data is stored, such as a database, file, etc.

[0028] Table information: Table information generally includes table name, table description, field name, field description and field type, as well as primary and foreign keys and other table creation information.

[0029] Normalization: Aims to eliminate redundancy in data and ensure data consistency and integrity.

[0030] In order to solve the problems existing in the related art, the present application embodiment provides a data query method, which can be run on Figure 1 In the computer terminal shown, the computer terminal is explained below.

[0031] The data query method embodiment provided in the embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 FIG. 1 shows a hardware structure block diagram of a computer terminal for implementing a method for data query. Figure 1As shown, the computer terminal 10 may include one or more (102a, 102b, ..., 102n are used to illustrate) processors (the processor may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission module 106 for communication functions connected via a wired and / or wireless network. In addition, it may also include: a display, a keyboard, a cursor control device, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, and a BUS bus. Those skilled in the art can understand that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.

[0032] It should be noted that the one or more processors and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10. As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).

[0033] The memory 104 can be used to store software programs and modules of application software, such as program instructions / data storage devices corresponding to the method for data query in the embodiment of the present application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, realizing the above-mentioned method for data query. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0034] The transmission module 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission module 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission module 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0035] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 .

[0036] It should be noted that, in some optional embodiments, the above Figure 1 The computer terminal shown may include hardware elements (including circuits), software elements (including computer code stored on a computer-readable medium), or a combination of hardware elements and software elements. It should be noted that Figure 1 This is merely one example of a particular embodiment and is intended to illustrate the types of components that may be present in the computer terminal described above.

[0037] In the above-mentioned operating environment, an embodiment of the present application provides an embodiment of a method for data query. 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, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0038] Figure 2 is a flow chart of a method for data query according to an embodiment of the present application. Figure 2 As shown, the method comprises the following steps:

[0039] Step S202: obtaining the query intent of the first question input by the target object, wherein the query intent is obtained by extracting the first question.

[0040] In the above step S202, the query intent is the key information and requirements extracted from the original natural language question through natural language processing (NLP) technology, especially through semantic analysis and text understanding of the question. Specifically, the process of obtaining the query intent may include the following steps: 1. Analyze the semantic structure of the first question to understand the entities, attributes, relationships, and contextual information such as time and place in the question; 2. Identify keywords or phrases from the first question, which are often directly related to the data or information that the user wants to query; 3. According to the keywords and semantic structure of the first question, identify the main purpose of the user's query, such as statistics, comparison, and finding specific data; 4. Considering the scenario of multiple rounds of conversations, understand the relationship between user questions and historical conversations to more accurately identify the query intent of the current question; 5. Integrate the above analysis results into a clear and accurate description of the query intent.

[0041] For example, if the first question asked by the user is "What was the sales volume in Beijing last year?" the system will extract "time" (last year), "location" (Beijing) and "query content" (sales volume), and summarize the query intent as "query the sales volume in Beijing last year". Through this process, the user's fuzzy query in natural language can be converted into a clear, specific and structured query intent, which provides accurate guidance for the subsequent steps to determine the relevant data source and table information, and generate SQL query statements. This intent extraction-based method can help the system accurately locate the specific data that the user wants to query in a multi-data source environment, so as to perform query operations on the correct data source and table.

[0042] In some embodiments of the present application, if it is a new conversation, it is only necessary to obtain the current question (such as the first question mentioned above) to determine the query intent. If it is not a new conversation, it is necessary to input the current question (i.e., the first question), the intent summary result of the previous round of replies (last_intent, for example, which can be called historical query intent), and the historical conversation (history) into the big model, and generate the query intent corresponding to the current question through the intent summary prompt. For example: the historical query intent of the previous round of conversation is "query last year's sales volume", the current question is "Beijing", and the query intent after extracting the current question through the big model is "query last year's sales volume in Beijing".

[0043] Step S204, determining a first vector corresponding to the query intent, and performing word segmentation on the query intent to obtain a first word segmentation result.

[0044] In the above step S204, the query intent is vectorized using a vectorization model to obtain the above first vector, denoted as x2, and the query intent is segmented to obtain the above first segmentation result, denoted as y2. Segmentation is an important part of text preprocessing, which divides continuous text into meaningful vocabulary units for subsequent operations such as word frequency statistics and keyword extraction. In Chinese natural language processing, commonly used techniques include jieba segmentation or THULAC segmentation. The segmentation results can help the system understand the keywords contained in the query intent more carefully, and can better match the text information such as field names and descriptions in the data table when calculating text similarity. Through the two technologies of vectorization and segmentation, the system can understand and express the query intent from different angles, provide a data basis for subsequent similarity calculations and data source matching, so that it can intelligently identify the data source and table information most relevant to the user's query intent, and prepare for the generation of accurate SQL query statements.

[0045] Step S206, obtaining a second vector and a second word segmentation result corresponding to each data table in each data source in a plurality of data sources, wherein the plurality of data sources are data sources to which the business associated with the first question belongs.

[0046] In the above step S206, there is a mapping relationship between the data source and the data table, for example, {db1:[table1,table2...], db2:[table1,table2...]...db k :[table1,table2…]}, db indicates the data source, table indicates the data table. The types of each data source can be the same or different, and each table contains the table name and the corresponding table creation information, such as table description, field name, field description, and field type.

[0047] Use a vectorization model (such as BGE, Sentence-BERT, etc.) to process the description information of each data table, including the table name, field name, field description, etc., to generate a vector, namely the second vector, denoted as x1. The second vector can reflect the core semantic features and content structure of the data table, so as to perform similarity calculation with the first vector of the user's query intention in the mathematical space and identify the most relevant data table. For example, for the data table "sales record", it contains fields such as "sales date", "sales location", "sales amount", etc., and a vector representation, namely the second vector, can be generated through the vectorization model. The second vector contains the semantic information of these fields.

[0048] The word segmentation operation of a data table is to divide the data table information (such as table name, field name and description) into separate vocabulary units. Usually, a word segmentation tool such as Jieba is used to process the data table information to obtain the second word segmentation result, which is recorded as y1. The second word segmentation result is used for text similarity calculation to help the system identify the degree of direct match between the keywords in the query intent and the data table information. For example, for the data table "sales record", its field "sales location" is segmented to obtain two words "sales" and "location". These words can be used to compare with the words of the user's query intent to determine the text similarity between them.

[0049] Step S208, determining a target data source and a target data table corresponding to the query intent based on the first vector, the second vector, the first word segmentation result, and the second word segmentation result.

[0050] In the above step S208, the similarity between the first vector and the second vector is calculated, and the similarity between the first word segmentation result and the second word segmentation result is calculated. Based on the above two similarities, the target data source and the target data table corresponding to the query intent can be determined.

[0051] Step S210, determining a database query statement corresponding to the first question based on the query intent, the data source type corresponding to the target data source, and the target data table, and generating a query result based on the database query statement.

[0052] In the above step S210, after identifying and determining the user's query intention, the system will combine the type of the target data source (such as MySQL, PostgreSQL, etc.) and the specific information of the target data table to generate an SQL query statement that conforms to the syntax specification of the data source type. For example, if the query intention is "query the sales volume in Beijing last year", and the target data source is a MySQL database, the system will generate a SQL query statement as follows:

[0053] sql SELECT sales_volume FROM sales_records WHERE city='Beijing'AND year='last year';

[0054] It should be noted that the specific format and syntax of the SQL statements here will vary according to the type of the target data source to ensure that the query statements are correct and effective in the corresponding database system. Once the SQL query statement is determined, the system will execute this query statement on the corresponding target data source to obtain the data results required by the user's query. The query results will be returned according to the actual data in the database, which can be one or more records, depending on the query conditions and the matching situation of the data. For example, continuing with the above SQL query statement as an example, the system will search for all records in the "sales_records" table that meet the conditions of "city = 'Beijing' AND year = 'last year'", and return the values of the "sales_volume" field, that is, the sales volume data of Beijing last year.

[0055] In step S208 of the above method for data query, determining the target data source and the target data table corresponding to the query intention includes: determining the first similarity result corresponding to the first vector and the second vector; determining the second similarity result corresponding to the first word segmentation result and the second word segmentation result; determining the target similarity result based on the first similarity result and the second similarity result; and determining the target data source and the target data table based on the target similarity result.

[0056] In the above step, determining the first similarity result corresponding to the first vector and the second vector includes: obtaining the first vector and the second vector; determining the cosine similarity between the first vector and the second vector to obtain the first similarity; and performing a normalization process on the first similarity to obtain the first similarity result.

[0057] In some embodiments of the present application, obtaining the first vector x2 and the second vector x1; determining the cosine similarity cos(x1, x2) between the first vector and the second vector to obtain the first similarity; and performing a normalization process on the first similarity, such as Z-score normalization, to obtain the first similarity result sim(x1, x2).

[0058] In the above step, determining the second similarity result corresponding to the first word segmentation result and the second word segmentation result includes: obtaining the first word segmentation result and the second word segmentation result; determining the text similarity between the first word segmentation result and the second word segmentation result to obtain the second similarity; and performing a normalization process on the second similarity to obtain the second similarity result.

[0059] In some embodiments of the present application, a first word segmentation result y2 and a second word segmentation result y1 are obtained; stop words of y1 and y2 are removed, and the text similarity between the first word segmentation result and the second word segmentation result, such as tfidf similarity, is determined to obtain a second similarity tfidf(y1, y2); the second similarity is normalized, such as Z-score normalization, to obtain a second similarity result sim(y1, y2).

[0060] In the above steps, determining a target similarity result based on the first similarity result and the second similarity result includes: determining a first weight corresponding to the first similarity result, and determining a second weight corresponding to the second similarity result; determining a first value based on the first similarity result and the first weight; determining a second value based on the second similarity result and the second weight; and determining the target similarity result based on the sum of the first value, the second value, the first weight, and the second weight.

[0061] In some embodiments of the present application, for each data source, the semantic similarity and text similarity of the query intent and each data table information are calculated, and in order to solve the scale difference problem, each similarity score is normalized (such as Z-score normalization, Softmax normalization), and then the normalized score is linearly weighted to obtain the score after the fusion of the two methods. Specifically, the target similarity result after the linear weighting of the two similarities is:

[0062]

[0063] Among them, score1 represents the target similarity result, p1 represents the first weight, p2 represents the second weight, sim(x1,x2) represents the first similarity result, and sim(y1,y2) represents the second similarity result.

[0064] In the above steps, the target data source and the target data table are determined based on the target similarity result, including: in each data source, the data table corresponding to the similarity greater than the preset threshold in the target similarity result is determined as a first data table set, wherein each data source corresponds to a first data table set; the similarity scores of the first preset number of data tables in the first data table set corresponding to each data source are obtained, wherein each data table in the first data table set is sorted from high to low according to the similarity; the target similarity score corresponding to each data source is determined based on the similarity score and the preset number; the data source corresponding to the maximum value in the target similarity score is determined as the target data source, and the first preset number of data tables in the target data source sorted from high to low according to the similarity are determined as the target data table.

[0065] In some embodiments of the present application, for each data source, the data tables in the target similarity result that are greater than a preset threshold are recalled, that is, the first data table set mentioned above, and the corresponding similarity scores are recorded. For each data source, the average of the top n (preset number, n represents the preset number) scores of the recall is calculated, that is, the target similarity score mentioned above:

[0066]

[0067] Among them, score2 represents the target similarity score, score1 i Indicates the top n data tables in the order of score1. If the number of recalled result tables is less than n, all recalled data tables are taken. The data source with the highest score2 and the corresponding top n data tables are taken as the target data source and target data table related to this query intent.

[0068] In step S210 of the above data query method, query results are generated based on a database query statement, including: obtaining a database query statement and obtaining a target data source; executing the database query statement at the target data source to generate a query result corresponding to the first question.

[0069] In some embodiments of the present application, the query intent, the data source type (db_type) corresponding to the target data source, and the target data table are input into a prefabricated text query prompt, and the query SQL corresponding to the question is generated based on the large language model, that is, the above-mentioned database query statement.

[0070] Get the database query statement and the target data source. Connect to the target data source through the database connection API or database driver. When connecting, you need to provide the correct database address, port, user name, password and other information to ensure secure access to the data source. After establishing the connection, execute the generated SQL query statement on the target data source. For example, use the database query API or directly call the SQL execution function to send the SQL statement to the database server, which parses and executes the SQL statement to access the underlying data storage. After executing the SQL query statement, the database will return a query result set, which contains data records that meet the query conditions. The system needs to receive and parse these results from the database and convert them into a format that is easy to understand and use, such as JSON, XML or data frame. Finally, the system returns the processed query results to the user, completing a closed loop from natural language questions to data queries. The returned results may also contain some additional information, such as query time, number of returned records, or any error information encountered during execution, to help users better understand and use the query results.

[0071] Through the above steps S202 to S210, the purpose of intelligently identifying and processing user natural language queries is achieved, thereby achieving the technical effect of efficiently and accurately converting natural language queries into SQL queries in multi-data source business scenarios using a large model, thereby solving the technical problem in related technologies that SQL queries in multi-data source business scenarios cannot be processed by a large model.

[0072] The data query method provided in the embodiment of the present application supports the access of multiple data sources in the data query task, including multiple databases of different types of data sources and multiple databases of the same type of data sources; and intelligently associates the question with the data source, and then realizes the text query task through the large language model, which solves the current defect that it is necessary to artificially limit it to a certain data source before querying the table under the data source. When recommending data sources and data tables, the most relevant data source information and corresponding table information are obtained based on two different recall methods. First, for each data source, a linear weighted recall greater than a threshold value is used using semantic and text methods. Then, in order to avoid the influence of the long-tail distribution of similarity on the next recall result, the similarity mean of the top n tables of similarity is taken as the similarity of the data source, and the source type of the top1 similar (i.e., the most similar) data source and the corresponding top n table information are input into the pre-made text query prompt.

[0073] Figure 3 is a structural diagram of a data query device according to an embodiment of the present application, such as Figure 3 As shown, the device comprises:

[0074] A first acquisition module 30 is used to acquire the query intent of the first question input by the target object, wherein the query intent is obtained by extracting the first question;

[0075] A first determination module 32, configured to determine a first vector corresponding to a query intent, and segment the query intent to obtain a first segmentation result;

[0076] A second acquisition module 34 is used to acquire a second vector and a second word segmentation result corresponding to each data table in each data source in a plurality of data sources, wherein the plurality of data sources are data sources to which the business associated with the first question belongs;

[0077] A second determination module 36, configured to determine a target data source and a target data table corresponding to the query intent based on the first vector, the second vector, the first word segmentation result, and the second word segmentation result;

[0078] The generation module 38 is used to determine the database query statement corresponding to the first question according to the query intent, the data source type corresponding to the target data source and the target data table, and generate the query result according to the database query statement.

[0079] In the second determination module in the above-mentioned data query device, the second determination module is also used to determine the first similarity result corresponding to the first vector and the second vector; determine the second similarity result corresponding to the first word segmentation result and the second word segmentation result; determine the target similarity result based on the first similarity result and the second similarity result; determine the target data source and the target data table based on the target similarity result.

[0080] In the second determination module in the above data query device, the second determination module is also used to obtain the first vector and the second vector; determine the cosine similarity between the first vector and the second vector to obtain the first similarity; normalize the first similarity to obtain the first similarity result.

[0081] In the second determination module in the above-mentioned data query device, the second determination module is also used to obtain the first word segmentation result and the second word segmentation result; determine the text similarity between the first word segmentation result and the second word segmentation result to obtain the second similarity; normalize the second similarity to obtain the second similarity result.

[0082] In the second determination module in the above-mentioned data query device, the second determination module is also used to determine the first weight corresponding to the first similarity result, and to determine the second weight corresponding to the second similarity result; determine the first numerical value based on the first similarity result and the first weight; determine the second numerical value based on the second similarity result and the second weight; determine the target similarity result based on the sum of the first numerical value, the second numerical value, the first weight and the second weight.

[0083] In the second determination module in the above-mentioned data query device, the second determination module is also used to determine, in each data source, the data table corresponding to the similarity greater than the preset threshold in the target similarity result as a first data table set, wherein each data source corresponds to a first data table set; obtain the similarity scores of the first preset number of data tables in the first data table set corresponding to each data source, wherein each data table in the first data table set is sorted from high to low according to the similarity; determine the target similarity score corresponding to each data source based on the similarity score and the preset number; determine the data source corresponding to the maximum value in the target similarity score as the target data source, and determine the first preset number of data tables in the target data source sorted from high to low according to the similarity as the target data table.

[0084] In the generation module in the above-mentioned data query device, the generation module is also used to obtain a database query statement and a target data source; execute the database query statement at the target data source to generate a query result corresponding to the first question.

[0085] It should be noted that Figure 3The data query device shown is used to perform Figure 2 The data query method shown in the figure, therefore the relevant explanations in the above data query method are also applicable to the data query device, and will not be repeated here.

[0086] An embodiment of the present application also provides an electronic device, which includes a memory and a processor, wherein the memory is used to store program instructions; the processor is connected to the memory and is used to execute program instructions to implement the following functions: obtain the query intent of a first question input by a target object, wherein the query intent is obtained by performing a total extraction on the first question; determine a first vector corresponding to the query intent, and segment the query intent to obtain a first segmentation result; obtain a second vector and a second segmentation result corresponding to each data table in each data source of multiple data sources, wherein the multiple data sources are data sources to which the business associated with the first question belongs; determine a target data source and a target data table corresponding to the query intent based on the first vector, the second vector, the first segmentation result and the second segmentation result; determine a database query statement corresponding to the first question based on the query intent, the data source type corresponding to the target data source, and the target data table, and generate a query result based on the database query statement.

[0087] It should be noted that the above electronic equipment is used to execute Figure 2 The data query method shown in the figure, therefore the relevant explanations and instructions in the above data query method are also applicable to the electronic device and will not be repeated here.

[0088] An embodiment of the present application also provides a non-volatile storage medium, which includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the following data query method by running the computer program: obtaining the query intent of a first question input by a target object, wherein the query intent is obtained by performing a total extraction on the first question; determining a first vector corresponding to the query intent, and segmenting the query intent to obtain a first segmentation result; obtaining a second vector and a second segmentation result corresponding to each data table in each of a plurality of data sources, wherein the plurality of data sources are data sources to which a business associated with the first question belongs; determining a target data source and a target data table corresponding to the query intent based on the first vector, the second vector, the first segmentation result, and the second segmentation result; determining a database query statement corresponding to the first question based on the query intent, the data source type corresponding to the target data source, and the target data table, and generating a query result based on the database query statement.

[0089] It should be noted that the above non-volatile storage medium is used to execute Figure 2 The data query method shown in the figure, therefore the relevant explanations in the above data query method are also applicable to the non-volatile storage medium, and will not be repeated here.

[0090] The embodiments of the present application also provide a computer program product, including computer instructions, which, when executed by a processor, implement the steps of the data query method in each embodiment of the present application.

[0091] The embodiments of the present application also provide a computer program, which, when executed by a processor, implements the steps of the data query method in each embodiment of the present application.

[0092] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0093] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0094] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0095] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0096] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0097] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, 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, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.

[0098] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A data query method, characterized in that: include: Acquire a query intent of a first question input by a target object, wherein the query intent is obtained by extracting the first question; Determine a first vector corresponding to the query intent, and segment the query intent to obtain a first segmentation result; Obtaining a second vector and a second word segmentation result corresponding to each data table in each data source in a plurality of data sources, wherein the plurality of data sources are data sources to which the business associated with the first question belongs; Determine a target data source and a target data table corresponding to the query intent according to the first vector, the second vector, the first word segmentation result, and the second word segmentation result; According to the query intent, the data source type corresponding to the target data source and the target data table, a database query statement corresponding to the first question is determined, and a query result is generated according to the database query statement.

2. The method according to claim 1, characterized in that: Determining a target data source and a target data table corresponding to the query intent includes: Determine a first similarity result corresponding to the first vector and the second vector; Determine a second similarity result corresponding to the first word segmentation result and the second word segmentation result; Determining a target similarity result according to the first similarity result and the second similarity result; The target data source and the target data table are determined according to the target similarity result.

3. The method according to claim 2, characterized in that Determining a first similarity result corresponding to the first vector and the second vector includes: Obtaining the first vector and the second vector; Determine a cosine similarity between the first vector and the second vector to obtain a first similarity; Normalizing the first similarity to obtain the first similarity result.

4. The method according to claim 2, characterized in that: Determining a second similarity result corresponding to the first word segmentation result and the second word segmentation result includes: Obtaining the first word segmentation result and the second word segmentation result; Determine the text similarity between the first word segmentation result and the second word segmentation result to obtain a second similarity; Normalizing the second similarity to obtain the second similarity result.

5. The method according to claim 2, characterized in that: Determining a target similarity result according to the first similarity result and the second similarity result includes: Determining a first weight corresponding to the first similarity result, and determining a second weight corresponding to the second similarity result; Determine a first value according to the first similarity result and the first weight; Determine a second value according to the second similarity result and the second weight; The target similarity result is determined according to the sum of the first value, the second value, the first weight, and the second weight.

6. The method according to claim 2, characterized in that Determining the target data source and the target data table according to the target similarity result includes: In each data source, the data tables corresponding to the similarities in the target similarity results that are greater than a preset threshold are determined as a first data table set, wherein each data source corresponds to one first data table set; Obtain similarity scores of a preset number of data tables in the first data table set corresponding to each data source, wherein each data table in the first data table set is sorted from high to low according to similarity; Determine a target similarity score corresponding to each data source according to the similarity score and the preset number; The data source corresponding to the maximum value in the target similarity score is determined as the target data source, and the first preset number of data tables in the target data source sorted from high to low according to similarity are determined as the target data tables.

7. The method according to claim 1, characterized in that Generating query results according to the database query statement includes: Obtaining the database query statement and the target data source; The database query statement is executed on the target data source to generate a query result corresponding to the first question.

8. A data query device, characterized in that: include: A first acquisition module, used to acquire the query intent of a first question input by a target object, wherein the query intent is obtained by extracting the first question; A first determination module, used to determine a first vector corresponding to the query intent, and segment the query intent to obtain a first segmentation result; A second acquisition module, configured to acquire a second vector and a second word segmentation result corresponding to each data table in each data source in a plurality of data sources, wherein the plurality of data sources are data sources to which the business associated with the first question belongs; A second determination module, configured to determine a target data source and a target data table corresponding to the query intent based on the first vector, the second vector, the first word segmentation result, and the second word segmentation result; A generation module is used to determine a database query statement corresponding to the first question based on the query intent, the data source type corresponding to the target data source and the target data table, and generate a query result based on the database query statement.

9. An electronic device, characterized in that: include: A memory for storing program instructions; A processor is connected to the memory and is used to execute program instructions to implement the following functions: obtain a query intent of a first question input by a target object, wherein the query intent is obtained by performing a total extraction on the first question; determine a first vector corresponding to the query intent, and perform word segmentation on the query intent to obtain a first word segmentation result; obtain a second vector and a second word segmentation result corresponding to each data table in each data source of a plurality of data sources, wherein the plurality of data sources are data sources to which the business associated with the first question belongs; determine a target data source and a target data table corresponding to the query intent based on the first vector, the second vector, the first word segmentation result, and the second word segmentation result; determine a database query statement corresponding to the first question based on the query intent, the data source type corresponding to the target data source, and the target data table, and generate a query result based on the database query statement.

10. A non-volatile storage medium, characterized in that: The non-volatile storage medium includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the data query method described in any one of claims 1 to 7 by running the computer program.

11. A computer program product comprising computer instructions, characterized in that: When the computer instructions are executed by a processor, the data query method described in any one of claims 1 to 7 is implemented.