Intelligent number asking method and device and readable storage medium

By using external vector databases to find similar problems and terms in the intelligent numbering system, and reorganizing user input problems in combination with database table structure information, and using big models to generate SQL, the existing intelligent numbering method has solved the problems of poor and high cost caused by relying on big models or RAG retrieval, achieving more efficient, accurate and economical intelligent numbering effect.

CN119739730APending Publication Date: 2025-04-01CHINA UNITED NETWORK COMM GRP CO LTD +1
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411804448.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-09
Publication Date
2025-04-01

AI Technical Summary

Technical Problem

The existing intelligent number-question method relies entirely on the ability to generate SQL, or rely too much on RAG vector retrieval, or the intelligent number-question system is complex and relies too much on the previous semantic modeling, resulting in poor results and excessive use cost.

Method used

Find the target similarity problems and/or the explanations of related professional terms/keywords similar to the user input problems in the pre-established external vector database, and reorganize them with the user input problems. Combining the database table structure information, use the big model to generate target SQL statements.

Benefits of technology

By introducing an external vector database, it provides a reliable basis for generating SQL, reduces the possibility of illusion in large models, significantly improves the generation accuracy and system efficiency of Text2SQL tasks, and reduces the cost of use.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119739730A_ABST
    Figure CN119739730A_ABST
Patent Text Reader

Abstract

The invention provides an intelligent question asking method and device and a readable storage medium. The method comprises the steps of obtaining a question input by a user; in a pre-established external vector database, searching for explanations of target similarity questions similar to the questions input by the user and / or related terminologies / keywords; the questions input by the user are recombined; setting a first role for the large model in a system cue word of the large model, and assembling database table structure information needing intelligent question into the system cue word of the large model; and utilizing the large model to generate a target SQL statement based on the first role, the database table structure information and the recombined user input question. According to the method, the device and the medium, the problems that an existing intelligent number asking method is poor in effect and high in use cost due to the fact that the existing intelligent number asking method completely depends on large model capacity to generate SQL or excessively depends on RAG vector retrieval, or an intelligent number asking system is complex in design and excessively depends on early-stage semantic modeling can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an intelligent number-asking method, device and readable storage medium. Background Art

[0002] Intelligent questioning is an important application of artificial intelligence technology in the field of data analysis. It enables users to interact with the system in natural language through natural language processing and machine learning technology to achieve data query and analysis. Text2SQL (Text-to-SQL) is a key technology for realizing intelligent questioning systems. It aims to convert natural language questions into structured query language (SQL) for interaction and query with databases. In recent years, with the rapid development of deep learning and large language models (LLMs), Text2SQL technology has made significant progress. The application of large language models in the field of Text2SQL has greatly promoted the automation and intelligence of natural language to SQL queries, bringing revolutionary changes to data query and analysis. Although intelligent questioning systems have made significant progress in many aspects in the era of large models, they still need to be continuously optimized and innovated to meet the challenges and needs in practical applications.

[0003] When answering questions, RAG (Retrieval-Augmented Generation) prioritizes retrieving relevant information from external knowledge bases and inputs the retrieved information into the large model as the context for answering user questions. By combining the parameterized knowledge of the large language model with the non-parametric external knowledge base, RAG effectively improves the speed of knowledge iteration and the utilization of private domain knowledge, while also improving the accuracy of the large language model in answering questions.

[0004] However, existing implementation solutions usually have the following problems: First, they rely on large models to generate SQL from natural language, resulting in poor results; second, they rely too much on RAG retrieval. If the retrieval effect is not good, the overall effect of intelligent question answering will also deteriorate; third, the intelligent question answering system is complex in design and overly dependent on early semantic modeling, resulting in problems such as high usage costs. Summary of the invention

[0005] The technical problem to be solved by the present invention is to provide an intelligent number-asking method, device and readable storage medium in view of the above-mentioned deficiencies in the prior art, so as to solve the problems that the existing intelligent number-asking methods completely rely on the ability of large models to generate SQL, or rely too much on RAG vector retrieval, or the intelligent number-asking system is relatively complex in design and relies too much on early semantic modeling, resulting in poor results and high usage costs.

[0006] In a first aspect, the present invention provides an intelligent number-asking method, the method comprising:

[0007] Get user input questions;

[0008] Searching for target similarity questions and / or explanations of related professional terms / keywords similar to the question input by the user in a pre-established external vector database; wherein the external vector database stores a plurality of similarity questions and their corresponding structured query languages ​​SQL, as well as explanations of a plurality of professional terms / keywords;

[0009] Reorganizing the user input question, wherein the reorganized user input question includes the original user input question and at least one of the following: a target similarity question similar to the user input question and its corresponding SQL, and an explanation of professional terms / keywords related to the user input question;

[0010] Setting a first role for the large model in the system prompt words of the large model, and assembling the database table structure information that needs to be intelligently queried into the system prompt words of the large model;

[0011] The large model is used to generate a target SQL statement based on the first role, database table structure information, and the reorganized user input question.

[0012] Furthermore, before searching the pre-established external vector database for target similarity questions similar to the user input question and / or explanations of related professional terms / keywords, the method further includes:

[0013] Receive input similarity questions and their corresponding SQL;

[0014] Receive interpretation of input professional terms / keywords;

[0015] The SQL corresponding to the input similarity question is stored separately, and the id of the SQL storage is recorded in the metadata; wherein the similarity question and its corresponding SQL are associated through the id of the SQL storage;

[0016] Construct the input similarity questions and explanations of professional terms / keywords into document chunks;

[0017] The document block is converted into a vector form through a preset embedding model, and the vectorized data of the document block is stored in the external vector database.

[0018] Furthermore, searching a pre-established external vector database for target similarity questions and / or explanations of related professional terms / keywords similar to the question input by the user specifically includes:

[0019] Convert the user input question into an embedding vector;

[0020] The embedded vector is used to perform a similarity search in the external vector database to find target similarity questions similar to the user input question and / or explanations of related professional terms / keywords.

[0021] Furthermore, after generating a target SQL statement using the large model based on the first role, database table structure information, and the reorganized user input question, the method further includes:

[0022] Parse and execute the target SQL statement to obtain the data returned after execution;

[0023] Visualize the data returned after the execution.

[0024] Furthermore, the parsing and executing of the target SQL statement to obtain the data returned after the execution specifically includes:

[0025] Parsing the target SQL statement generated by the large model through a pre-designed parser to obtain an SQL command;

[0026] The SQL command obtained by parsing is converted into an operation executable by the database through a pre-designed SQL executor, and when the operation is verified to be a query operation, the operation is executed to obtain the data returned after the execution.

[0027] Furthermore, the visualization of the data returned after the execution specifically includes:

[0028] Obtaining a chart type specified by a user, or, if the user does not specify a chart type, determining and selecting an appropriate chart type based on the characteristics of the data returned after the execution and the user input question;

[0029] Setting a second role for the large model in the system prompt words of the large model, and assembling a chart code template corresponding to the chart type into the system prompt words of the large model;

[0030] The large model is used to generate a chart of the chart type based on the second role, the chart code template, and the data returned after the execution.

[0031] Furthermore, after generating a target SQL statement using the large model based on the first role, database table structure information, and the reorganized user input question, the method further includes:

[0032] Display the target SQL statement;

[0033] Receiving an editing operation of the target SQL statement by a user through an SQL editor;

[0034] Run the edited target SQL statement according to the user's instruction, and display the query result of the edited target SQL statement;

[0035] The user input question and the edited target SQL statement are saved in the external vector database.

[0036] In a second aspect, the present invention provides an intelligent number-asking device, the device comprising:

[0037] Input question acquisition module, used to obtain questions input by users;

[0038] A similar content search module is connected to the input question acquisition module and is used to search for target similarity questions similar to the user input question and / or explanations of related professional terms / keywords in a pre-established external vector database; wherein the external vector database stores a plurality of similarity questions and their corresponding structured query languages ​​SQL, as well as explanations of a plurality of professional terms / keywords;

[0039] An input question reorganization module, connected to the similar content search module, for reorganizing the user input question, wherein the reorganized user input question includes the original user input question and at least one of the following: a target similarity question similar to the user input question and its corresponding SQL, and an explanation of professional terms / keywords related to the user input question;

[0040] A first prompt word assembly module, connected to the input question reorganization module, is used to set a first role for the large model in the system prompt words of the large model, and assemble the database table structure information required for intelligent questioning into the system prompt words of the large model;

[0041] A target SQL statement generating module is connected to the first prompt word assembling module and is used to generate a target SQL statement based on the first role, database table structure information, and the reorganized user input question by using the large model.

[0042] In a third aspect, the present invention provides an intelligent number-asking device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to implement the intelligent number-asking method described in the first aspect.

[0043] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the intelligent number-asking method described in the first aspect is implemented.

[0044] The intelligent questioning method, device and readable storage medium provided by the present invention first obtain the question input by the user; and search for target similarity questions similar to the user input question and / or explanations of related professional terms / keywords in a pre-established external vector database; wherein the external vector database stores multiple similarity questions and their corresponding structured query languages ​​SQL, as well as explanations of multiple professional terms / keywords; then the user input question is reorganized, and the reorganized user input question includes the original user input question, and at least one of the following: target similarity questions similar to the user input question and their corresponding SQL, and explanations of professional terms / keywords related to the user input question; then a first role is set for the large model in the system prompt words of the large model, and the database table structure information that needs to be intelligently questioned is assembled into the system prompt words of the large model; finally, the large model is used to generate a target SQL statement based on the first role, the database table structure information, and the reorganized user input question. The present invention introduces an external vector database to store historical similarity problems and their corresponding SQL statements or explanations of professional terms / keywords, providing a reliable basis for generating SQL. This design can not only reduce the possibility of hallucinations caused by large models, but also significantly improve the generation accuracy and system efficiency of Text2SQL tasks. In addition, by dynamically assembling database table structure information into the system prompt words of the large model in real time, compared with the traditional method (i.e. storing all database table structures in the vector database), it effectively avoids the problem of being unable to retrieve the corresponding database table structure due to inaccurate user description, thereby improving the effect of intelligent questioning. In summary, the present invention achieves comprehensive improvement in effect, cost, efficiency and accuracy, and solves the problems of poor effect and high cost of use of existing intelligent questioning methods due to complete reliance on large model capabilities to generate SQL, or over-reliance on RAG vector retrieval, or relatively complex intelligent questioning system design, and over-reliance on early semantic modeling. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 This is a flow chart of an intelligent number-asking method according to Embodiment 1 of the present invention;

[0046] Figure 2 is a diagram of the architecture of an intelligent number-asking system according to an embodiment of the present invention;

[0047] Figure 3 A flowchart of the vectorized storage phase of similarity problems and corresponding SQL and professional terms / keywords in an embodiment of the present invention;

[0048] Figure 4 This is a flow chart of the SQL generation and execution phase of an embodiment of the present invention;

[0049] Figure 5 It is a flow chart of the data visualization chart code generation and data analysis phase of an embodiment of the present invention;

[0050] Figure 6 is a flow chart of the feedback phase of an embodiment of the present invention;

[0051] Figure 7 This is a schematic diagram of the structure of an intelligent number-asking device according to Embodiment 2 of the present invention;

[0052] Figure 8 FIG. 4 is a schematic diagram of the structure of an intelligent number-asking device according to Embodiment 3 of the present invention. DETAILED DESCRIPTION

[0053] In order to enable those skilled in the art to better understand the technical solution of the present invention, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.

[0054] It can be understood that, in the absence of conflict, the various embodiments of the present invention and the various features in the embodiments can be combined with each other.

[0055] It can be understood that, for the convenience of description, the drawings of the present invention only show the parts related to the present invention, while the parts irrelevant to the present invention are not shown in the drawings.

[0056] It can be understood that each unit and module involved in the embodiments of the present invention may correspond to only one physical structure, or may be composed of multiple physical structures, or multiple units and modules may be integrated into one physical structure.

[0057] It can be understood that the terms "first", "second", etc. in the embodiments of the present invention are used to distinguish different objects, or to distinguish different processing of the same object, rather than to describe a specific order of objects.

[0058] It can be understood that, without conflict, the functions and steps marked in the flowcharts and block diagrams of the present invention may occur in an order different from that marked in the drawings.

[0059] It is understood that the flowcharts and block diagrams of the present invention illustrate the possible architectures, functions, and operations of the systems, devices, equipment, and methods according to the various embodiments of the present invention. Each box in the flowchart or block diagram may represent a unit, module, program segment, or code, which contains executable instructions for implementing the specified functions. Moreover, each box or combination of boxes in the block diagram and flowchart may be implemented by a hardware-based system that implements the specified functions, or may be implemented by a combination of hardware and computer instructions.

[0060] It can be understood that the units and modules involved in the embodiments of the present invention can be implemented by software or hardware. For example, the units and modules can be located in a processor.

[0061] Embodiment 1:

[0062] This embodiment provides an intelligent number-asking method, such as Figure 1 As shown, the method includes:

[0063] Step S101: Obtaining a question input by a user;

[0064] In this embodiment, the user inputs the question he wants to query (that is, inputs the query content), and the intelligent question system obtains the question input by the user.

[0065] Step S102: searching a pre-established external vector database for target similarity questions and / or explanations of related professional terms / keywords that are similar to the question input by the user; wherein the external vector database stores a plurality of similarity questions and their corresponding structured query languages ​​SQL, as well as explanations of a plurality of professional terms / keywords.

[0066] It should be noted that the intelligent questioning system is an advanced data analysis tool based on Text2SQL technology. Its core advantage lies in its ability to understand and process complex natural language queries, automatically convert them into corresponding data query languages ​​(such as SQL), and retrieve information from the database. It supports multiple types of questions, including simple indicator queries, time screening, regional analysis, record count statistics, and more complex sorting, fuzzy matching, and time type aggregation. However, the existing intelligent questioning solutions have certain limitations to varying degrees, such as over-reliance on large models or RAG retrieval resulting in poor performance. The present invention refers to RAG technology and reduces the possibility of hallucinations in large models by introducing external knowledge bases. Specifically, an external vector database is added to the intelligent questioning system to store historical similarity questions and corresponding SQL statements as well as related professional terms / keyword explanations. This design will provide a reliable basis for subsequent large models to generate SQL based on user descriptions and table structures, significantly improving the ability of large models in Text2SQL tasks.

[0067] It should be noted that the "external" in "external vector database" means that the database is relatively independent of the core intelligent question system or large model. It is an independent knowledge base or data storage system designed to provide additional information support for the large model.

[0068] Optionally, before searching a pre-established external vector database for target similarity questions and / or explanations of related professional terms / keywords similar to the question input by the user, the method further comprises:

[0069] Receive input similarity questions and their corresponding SQL;

[0070] Receive interpretation of input professional terms / keywords;

[0071] The SQL corresponding to the input similarity question is stored separately, and the id of the SQL storage is recorded in the metadata; wherein the similarity question and its corresponding SQL are associated through the id of the SQL storage;

[0072] Construct the input similarity questions and explanations of professional terms / keywords into document chunks;

[0073] The document block is converted into a vector form through a preset embedding model, and the vectorized data of the document block is stored in the external vector database.

[0074] In this embodiment, when a similarity question is entered, the corresponding correct SQL must be entered, such as: {'question':'How many people in each department participate in attendance? ','SQL':'SELECT department_id,COUNT(*)AS attendance_count FROM attendance GROUP BY department_id;'}; if the explanation of professional terms / keywords is entered, there is no need to enter SQL, such as: {'question':'The volume refers to the person with the longest cumulative working hours','SQL':"}.

[0075] It should be noted that questions that the large model answers incorrectly or may answer incorrectly can be avoided in advance by inputting similarity questions and SQL. Similarity questions can include several different expressions of the same question, corresponding to one SQL, such as 1) Help me count the number of people who take attendance in each department? 2) How many people take attendance in each department? These two questions can correspond to one SQL.

[0076] In this embodiment, similarity questions and their corresponding SQL, professional terms / keywords related explanations, when they are stored in the document block, the storage content of the metadata is different. If the stored content is the explanation of professional terms / keywords, the storage id of SQL does not need to be stored in the metadata. If the stored content is similarity questions and SQL, the SQL needs to be stored first, and the SQL storage id is recorded in the metadata. The method of storing similarity questions and corresponding SQL separately can effectively improve the accuracy of similarity question retrieval.

[0077] In this embodiment, the similarity problems that need to be vectorized and the explanations of professional terms / keywords and other key information that need to be recorded are constructed as Document document block objects for subsequent vectorized storage. Then the document block is embedded, i.e., vectorized, and the document block is converted into a vector form through a preset embedding model (such as text2vec-large-chinese, sentence-transformer, OpenAIEmbedding, etc.), and then the vectorized data of the document block is stored in an external vector database, so that efficient retrieval operations can be performed based on the similarity of the vector space. The process of building an index after text vectorization, writing to an external vector database and saving it in disk persistent storage is called vectorized storage of text, among which commonly used vector databases include: faiss, Chroma, Milvus, etc.

[0078] Optionally, searching a pre-established external vector database for target similarity questions and / or explanations of related professional terms / keywords similar to the question input by the user specifically includes:

[0079] Convert the user input question into an embedding vector;

[0080] The embedded vector is used to perform a similarity search in the external vector database to find target similarity questions similar to the user input question and / or explanations of related professional terms / keywords.

[0081] In this embodiment, the questions input by the user are converted into embedded vectors. These vectors are points in a high-dimensional space and can capture the semantic features of the input text. Their main functions are: semantic understanding. Through the embedded vectors, the system can better understand the semantics of the user input, which helps to improve the relevance and accuracy of the retrieval results; efficient retrieval: after the text is converted into an embedded vector, an efficient vector search algorithm can be used to quickly find the most semantically relevant documents or information in a large-scale data set; similarity calculation. The embedded vector allows the system to evaluate the similarity between different texts by calculating the distance or similarity between vectors, so as to find the content most relevant to the user input question.

[0082] In this embodiment, similar questions or related professional terms / keywords are searched for the question input by the user, which mainly includes two steps:

[0083] 1) Vector database loading: Loading an external vector database enables the system to access and manage all pre-processed and stored vectorized data. This allows the system to use its built-in index structure and optimization algorithm to quickly find vectors similar to the query vector in a large amount of vector data;

[0084] 2) Similarity retrieval: Use the embedded vector of the question to perform similarity retrieval in an external vector database. This process usually uses methods such as cosine similarity, Euclidean distance, Manhattan distance, and maximum marginal correlation to calculate similarity. The present invention appropriately increases the number of returned correlation samples in the similarity retrieval step to enhance the diversity of samples.

[0085] Step S103: reorganize the user input question, wherein the reorganized user input question includes the original user input question and at least one of the following: a target similarity question similar to the user input question and its corresponding SQL, and an explanation of professional terms / keywords related to the user input question.

[0086] In this embodiment, the user input question is reorganized using the retrieved similarity questions and the corresponding SQL and the explanation of professional terms / keywords. The reorganized user input question includes three parts: the user input question, the similarity question and its corresponding SQL, and the relevant explanation of professional terms / keywords. By assembling the historical similarity questions and their corresponding correct SQL and the explanation of professional terms / keywords in the form of user input, it can provide a reference for the large model when generating SQL according to the user question and table structure, which effectively improves the accuracy of SQL generation of the intelligent question-answering system.

[0087] In an optional implementation, the three parts of user questions, similarity questions and their corresponding SQL, and related explanations of professional terms / keywords can be spliced ​​into the following form:

[0088] Question input by the user: How many people in each department take attendance?

[0089] Historical similarity question question and correct SQL: {'question':'Count the number of people who take attendance in each department? ','SQL':'SELECT*FROM question_vector_db'}

[0090] {'question':'How many people in each department take attendance? ','SQL':'SELECT*FROMquestion_vector_db'}

[0091] Explanation of relevant terms: necessary explanation of terms.

[0092] Step S104: setting a first role for the large model in the system prompt words of the large model, and assembling the database table structure information required for intelligent questioning into the system prompt words of the large model.

[0093] In this embodiment, the system prompt words of the large model are set. First, the first role needs to be defined for the large model in the system prompt words to specify the tasks of the large model; secondly, the database table structure information that needs to be intelligently asked is obtained from the database; finally, the dynamically obtained database table structure information is assembled into the system prompt words, which provides a basis for the large model to generate SQL for user queries. The first role, such as "database expert" or "SQL expert", is used to indicate the generation of corresponding SQL statements based on the database table structure information and the reorganized user input questions.

[0094] Step S105: Generate a target SQL statement using the large model based on the first role, database table structure information, and the reorganized user input question.

[0095] In this embodiment, a large model is used to generate a target SQL statement based on the first role, database table structure information, the above similarity questions and their corresponding SQL, and interpretation of professional terms / keywords.

[0096] Optionally, after generating a target SQL statement using the large model based on the first role, database table structure information, and the reorganized user input question, the method further includes:

[0097] Parse and execute the target SQL statement to obtain the data returned after execution;

[0098] Visualize the data returned after the execution.

[0099] In this embodiment, by parsing the target SQL statement generated by the large model and executing it, the data returned after the execution can be obtained, and by visualizing the data returned after the execution, it is convenient for the user to view the results.

[0100] Optionally, parsing and executing the target SQL statement to obtain data returned after execution specifically includes:

[0101] Parsing the target SQL statement generated by the large model through a pre-designed parser to obtain an SQL command;

[0102] The SQL command obtained by parsing is converted into an operation executable by the database through a pre-designed SQL executor, and when the operation is verified to be a query operation, the operation is executed to obtain the data returned after the execution.

[0103] In this embodiment, the pre-designed parser can accurately process and analyze the data returned by the large model. It can not only interpret the SQL statements generated by the large model to ensure its grammatical correctness and logical rationality, but also process other types of content returned by the large model. The working mechanism of the parser includes the following key steps: data reception, first, the parser receives the data output from the large model, these outputs may include SQL statements, text descriptions (such as the thinking process of the large model to generate SQL, the interpretation of SQL), etc.; format recognition, the parser uses the preset format recognition rules to determine the type and structure of the data, providing a basis for subsequent parsing work; error detection, during the parsing process, the parser will detect possible errors or inconsistencies in the data and give relevant error information; result output, after the parsing is completed, the parser will output the processed data in a structured form for use in subsequent processes. These data may include revised SQL statements, extracted key information, etc.

[0104] In this embodiment, the task of the SQL executor is to convert the parsed SQL commands into operations that can be executed by the database. The SQL executor usually includes the following key components:

[0105] 1. Security verification: Before executing any SQL statement, the executor will check whether the SQL statement to be executed is a query statement. For security reasons, the intelligent query system does not allow automatic modification of data in the database.

[0106] 2. Data access: According to the execution plan, the executor will access the data in the database. This may involve reading tables, indexes or temporary tables, and performing operations such as joins, sorts and aggregations.

[0107] 3. Error handling: During the execution process, if any errors are encountered, the executor will capture these errors and return appropriate error information so that the user can take appropriate measures.

[0108] 4. Result return: For query operations, the executor returns the result set to the user. This may include formatting output, paging processing, or applying any user-defined transformations.

[0109] 5. Resource cleanup: After execution is completed, the executor will release all resources occupied during the execution process, such as memory, locks, etc., to ensure the stability and performance of the database.

[0110] Through these steps, the SQL executor ensures that SQL statements can be executed safely and efficiently while providing accurate results to users.

[0111] Optionally, the visualizing the data returned after the execution specifically includes:

[0112] Obtaining a chart type specified by a user, or, if the user does not specify a chart type, determining and selecting an appropriate chart type based on the characteristics of the data returned after the execution and the user input question;

[0113] Setting a second role for the large model in the system prompt words of the large model, and assembling a chart code template corresponding to the chart type into the system prompt words of the large model;

[0114] The large model is used to generate a chart of the chart type based on the second role, the chart code template, and the data returned after the execution.

[0115] In this embodiment, if the user inputs data that specifies the chart type for data display, such as specifying the bar type for data display, then the instruction "Display the data I gave you in a bar chart." needs to be assembled after the input data. If the user does not specify a specific chart type for data display, the big model will select the appropriate chart type for display based on the characteristics of the data and the question input by the user.

[0116] In this embodiment, the second role is, for example, "data analysis expert", and the selected chart code template is assembled into the system prompt word, such as the chart code templates for data visualization display such as bar charts, pie charts, and line charts in echarts, for the big model to learn. And specify the format of the big model data response, so that the big model can generate chart codes that conform to the current input data based on the input data and the learning chart code template, and realize the analysis of the data at the same time.

[0117] Optionally, after generating a target SQL statement using the large model based on the first role, database table structure information, and the reorganized user input question, the method further includes:

[0118] Display the target SQL statement;

[0119] Receiving an editing operation of the target SQL statement by a user through an SQL editor;

[0120] Run the edited target SQL statement according to the user's instruction, and display the query result of the edited target SQL statement;

[0121] The user input question and the edited target SQL statement are saved in the external vector database.

[0122] In this embodiment, the data display page is an important part of the intelligent question system, which displays the questions raised by the user and the SQL statements generated by the intelligent question system based on the questions. The user can intuitively see the specific content of the SQL statement through the page and understand the process of its execution. After the SQL is executed, the page will display the data results returned by the query, and support detailed data display in the form of a table. At the same time, the system will also visualize the query results and generate various charts (such as bar charts, line charts, pie charts, etc.) to help users understand the data more intuitively.

[0123] In this embodiment, the user determines whether the intelligent question system's answer to the user's question is correct based on the SQL and data returned by the data display page. For incorrect SQL, the intelligent question system has specially set up a SQL editor for modifying and testing SQL. In this step, the user needs to judge whether the intelligent question system's answer to the user's question is accurate based on the SQL returned by the data display page and its corresponding data. If the SQL and query results generated by the system do not meet expectations, the user can manually modify and adjust the generated SQL statement through the SQL editor. At the same time, the user can run the modified SQL immediately for testing to see its impact on the data and verify the accuracy of the results. Once the user modifies and runs the SQL, the system will display the updated query results for the user to compare the data output to ensure that the final answer is consistent with the user's expectations. This process effectively improves the flexibility and usability of the intelligent question system.

[0124] The intelligent questioning method provided in the embodiment of the present invention draws on the RAG technology to reduce the illusion of a large model by using an external knowledge base, and adds an external vector database to the intelligent questioning system to store historical similarity questions and SQL and explanations of related professional terms / keywords. This provides a reliable reference for the large model to generate SQL based on user descriptions and table structures, and helps to significantly improve the ability of the large model Text2SQL. In addition, the present invention carefully designs the construction process of Prompt (prompt words), so that the database table structure can be assembled in real time and dynamically in System Prompt (system prompt words), rather than storing the entire database table structure in the vector database in the early stage, and searching the database first when needed. This effectively avoids inaccurate user descriptions, resulting in the inability to retrieve the corresponding database table structure, thereby affecting the final intelligent questioning effect. The present invention also designs a parser and SQL executor for the large model response results to parse and execute the SQL generated by the large model. In response to the problem of data display, the present invention relies on the learning ability of the big model and the ECharts front-end code sample to construct an Agent for data chart display, which can analyze the data and generate ECharts code according to the characteristics of the data and the user's questions. It can mainly generate ECharts code for bar charts, pie charts, and line charts to achieve visual display of data.

[0125] In a specific embodiment, Figure 2 As shown, an architecture diagram of an intelligent question-and-answer system integrating knowledge retrieval provided by an embodiment of the present invention is shown. Based on the architecture diagram, the overall implementation process of the corresponding intelligent question-and-answer method is divided into four stages, namely, the vectorized storage stage of similarity questions and corresponding SQL and professional terms / keywords, the SQL generation and execution stage, the data visualization chart code generation and data analysis stage, and the feedback stage.

[0126] (I) Similarity Problem and Vectorized Storage of Corresponding SQL and Professional Terms / Keywords

[0127] like Figure 3 As shown in the figure, the specific implementation steps of the vectorized storage phase of the similarity problem and the corresponding SQL and professional terms / keywords are as follows:

[0128] Step 1: Input

[0129] In this step, similarity questions and SQL input or related explanations of professional terms and keywords are input. If similarity questions are input, the corresponding correct SQL must be input. The input similarity questions and correct SQL, professional terms / keyword explanations can be used as a reference when the big model generates SQL based on the table structure and user questions.

[0130] It should be noted that when entering a similarity question, you must enter the corresponding correct SQL, such as: {'question':'How many people in each department take attendance? ','SQL':'SELECT department_id,COUNT(*)AS attendance_count FROM attendance GROUP BY department_id;'}; If you enter the explanation of professional terms / keywords, you do not need to enter SQL, such as: {'question':'The volume refers to the person with the longest cumulative working hours','SQL':"}.

[0131] It should be noted that questions that the large model answers incorrectly or may answer incorrectly can be avoided in advance by inputting similarity questions and SQL. Similarity questions can include several different expressions of the same question, corresponding to one SQL, such as 1) Help me count the number of people who take attendance in each department? 2) How many people take attendance in each department? These two questions can correspond to one SQL.

[0132] Step 2: Classification

[0133] Classify the input content. In the previous step, similarity questions and related explanations of SQL or professional terms and keywords were input, but when they were built into document blocks for storage, the metadata storage content was different. If the stored content is the explanation of professional terms / keywords, there is no need to store the SQL storage id in the metadata. If the stored content is similarity questions and SQL, the SQL needs to be stored first, and the SQL storage id needs to be recorded in the metadata. Separate storage of similarity questions and corresponding SQL can effectively improve the accuracy of similarity question retrieval.

[0134] Step 3: Documentation Block Construction

[0135] The similarity problems that need to be stored in vectors, the explanations of professional terms / keywords, and other key information that need to be recorded are constructed into Document block objects to facilitate subsequent vectorized storage.

[0136] It should be noted that SQL is stored separately and does not need to be vectorized. There is no need to add SQL to the document block for storage. If SQL needs to be stored, it needs to be stored before building the document block and the SQL storage id needs to be returned. Because the question and SQL are associated with the SQL through the SQL storage id, the SQL storage id needs to be stored in the metadata of the document block when building the document block.

[0137] Step 4: Document Block Embedding

[0138] Document block embedding, also known as vectorization, is the process of converting text data into a vector matrix. This step has a direct impact on the subsequent retrieval effect. Commonly used embedding models include text2vec-large-chinese, sentence-transformer, OpenAIEmbedding, etc. The choice of embedding model is crucial in this process. Choosing a suitable vector embedding model can effectively improve the quality of retrieval.

[0139] Step 5: Vector storage

[0140] The previous step converts the document block into a vector form through the embedding model. In this step, the vectorized data of the document block is stored in an external vector database, so that efficient retrieval operations can be performed based on the similarity of the vector space. The process of building an index after text vectorization, writing it to an external vector database and saving it in disk persistent storage is called vectorized storage of text. Commonly used vector databases include: faiss, Chroma, Milvus, etc.

[0141] (II) SQL generation and execution phase

[0142] like Figure 4 As shown in the figure, the specific implementation steps of the SQL generation and execution phase are as follows:

[0143] Step 1: Question or query input

[0144] This step is the starting stage of the SQL generation and execution process. At this stage, the user enters the content or question they want to query. Clear and accurate question input can help the big model fully understand the user's intention. This step is crucial, as it determines the effect of similarity questions and SQL generation. The system will first perform a similarity question query in the vector database based on the content entered by the user, so as to provide a reference for the subsequent big model to generate SQL for intent recognition, which can effectively improve the accuracy of the system Text2SQL.

[0145] Step 2: Question / Query Content Embed

[0146] The role of question / query content embedding is to convert the user's input questions or the content to be retrieved into an embedding vector. These vectors are points in a high-dimensional space that can capture the semantic features of the input text. Their main functions are: semantic understanding, through the embedding vector, the system can better understand the semantics of the user input, which helps to improve the relevance and accuracy of the retrieval results; efficient retrieval: after converting the text into an embedding vector, an efficient vector search algorithm can be used to quickly find the most semantically relevant documents or information in a large-scale data set; similarity calculation, the embedding vector allows the system to evaluate the similarity between different texts by calculating the distance or similarity between vectors, which is crucial for finding the content most relevant to the user's question.

[0147] Step 3: Similarity Question Retrieval

[0148] This step uses the embedding vector of the query content to retrieve similar questions or professional terms / keyword explanations for the user's questions. It mainly has two steps:

[0149] Vector database loading: Loading the vector database enables the system to access and manage all pre-processed and stored vectorized data. This allows the system to use its built-in index structure and optimization algorithm to quickly find vectors similar to the query vector in a large amount of vector data.

[0150] Similarity retrieval: Use the embedded vector of the question to perform similarity retrieval in the vector database. This process usually uses methods such as cosine similarity, Euclidean distance, Manhattan distance, and maximum marginal correlation to calculate similarity. The present invention appropriately increases the number of returned correlation samples in the similarity retrieval step to enhance the diversity of samples.

[0151] It should be noted that when searching for similarity questions, multiple similar results may be returned; for example, if the threshold is 3, then no more than 3 similarity results can be returned.

[0152] Step 4: Reframe your question or query

[0153] The user's query content (i.e., the question input by the user) is reorganized using the similarity questions retrieved in step 3 and the corresponding SQL and related explanations of professional terms. The reorganized user input includes three parts: the user input question, the similarity question and its corresponding SQL, and the related explanations of professional terms / keywords. By assembling historical similarity questions and their corresponding correct SQL and the explanations of professional terms / keywords in the form of user input, it can provide a reference for the large model when generating SQL based on user questions and table structures, which effectively improves the accuracy of SQL generation of the intelligent question-answering system.

[0154] In an optional implementation, the three parts of user questions, similarity questions and their corresponding SQL, and related explanations of professional terms / keywords can be spliced ​​into the following form:

[0155] Question input by the user: How many people in each department take attendance?

[0156] Historical similarity question question and correct SQL: {'question':'Count the number of people who take attendance in each department? ','SQL':'SELECT*FROM question_vector_db'}

[0157] {'question':'How many people in each department take attendance? ','SQL':'SELECT*FROMquestion_vector_db'}

[0158] Explanation of relevant terms: necessary explanation of terms.

[0159] It should be noted that if there is no historical similarity problem or explanation of professional terms / keywords, all will be empty: e.g.

[0160] Question input by the user: How many people in each department take attendance?

[0161] Historical similarity question with the correct SQL:

[0162] Explanation of relevant terms:

[0163] Step 5: Initialize the large model and set the system prompt words for the large model

[0164] This step will initialize the large model and set the system prompt words for the large model. First, you need to define the role (i.e., the first role) for the large model in the system prompt words and specify the tasks of the large model; secondly, obtain the database table structure information that needs to be intelligently queried in the database; finally, assemble the dynamically obtained database table structure information into the system prompt words, which provides a basis for the large model to generate SQL for user queries. Unlike other intelligent query solutions, the database table structure of this invention is obtained in real time and dynamically, which is more accurate than relying on vector databases to retrieve database table structures.

[0165] The roles defined are as follows: You are a database and SQL expert. The tasks specified are as follows: Your task is to generate the corresponding SQL based on the provided database table structure and the questions raised by the user.

[0166] It should be noted that the system prompt words of the big model include the roles and database table structure information of the big model. The big model can then generate target SQL statements based on the roles, database table structure information, the above similarity questions and their corresponding SQL, and professional terms / keywords.

[0167] Step 6: Response parsing

[0168] Response parsing is a crucial part of the entire data processing process. In this process, we designed an efficient parser that can accurately process and analyze the data returned by the big model. This parser can not only interpret the SQL statements generated by the big model to ensure their grammatical correctness and logical rationality, but also process other types of content returned by the big model.

[0169] The working mechanism of the parser includes the following key steps: data reception, first, the parser receives the data output from the big model, which may include SQL statements, text descriptions (such as the thinking process of the big model to generate SQL, SQL interpretation), etc.; format recognition, the parser determines the type and structure of the data through the preset format recognition rules, providing a basis for subsequent parsing work; error detection, during the parsing process, the parser will detect possible errors or inconsistencies in the data and give relevant error information; result output, after the parsing is completed, the parser will output the processed data in a structured form for use in subsequent processes. These data may include revised SQL statements, extracted key information, etc.

[0170] This step can ensure that the output data of the large model is effectively processed and utilized, providing accurate information support for subsequent data processing and decision-making.

[0171] Step 7: SQL Execution

[0172] After the SQL statement is parsed, the execution phase begins. The core of this step is a carefully designed SQL executor, whose task is to convert the parsed SQL commands into operations that can be executed by the database. The SQL executor usually includes the following key components:

[0173] 1. Security verification: Before executing any SQL statement, the executor will check whether the SQL statement to be executed is a query statement. For security reasons, the intelligent query system does not allow automatic modification of data in the database.

[0174] 2. Data access: According to the execution plan, the executor will access the data in the database. This may involve reading tables, indexes or temporary tables, and performing operations such as joins, sorts and aggregations.

[0175] 3. Error handling: During the execution process, if any errors are encountered, the executor will capture these errors and return appropriate error information so that the user can take appropriate measures.

[0176] 4. Result return: For query operations, the executor returns the result set to the user. This may include formatting output, paging processing, or applying any user-defined transformations.

[0177] 5. Resource cleanup: After execution is completed, the executor will release all resources occupied during the execution process, such as memory, locks, etc., to ensure the stability and performance of the database.

[0178] Through these steps, the SQL executor ensures that SQL statements can be executed safely and efficiently, while providing accurate results to users. This process is a very critical part of the database management system, which directly affects the performance of the database and the user experience.

[0179] (III) Data visualization chart code generation and data analysis stage

[0180] like Figure 5 As shown in the figure, the specific implementation process of the data visualization chart code generation and data analysis stage is as follows:

[0181] Step 1: Data Input

[0182] The process first needs to input the data returned after the SQL execution of the previous process. The big model will perform data analysis and generate data visualization code based on this data.

[0183] Step 2: Data Preprocessing

[0184] After the data is entered, it is necessary to pre-process the data. If the user specifies the chart type for data display in the data input, such as specifying the bar type to display the data, you need to assemble the instruction 'Display the data I gave you in a bar chart.' after the input data. If the user does not specify a specific chart type for data display, let the big model judge and select the appropriate chart type for display based on the characteristics of the data and the questions entered by the user.

[0185] Step 3: Initialize the large model and set the system prompt words for the large model

[0186] First, you need to set a role for the big model, set the big model to the role of "data analysis expert" (i.e. the second role), and assemble the selected chart code template into the system prompt words, such as the chart code templates for data visualization display such as bar charts, pie charts, and line charts in echarts, for the big model to learn. And specify the format of the big model data response, so that the big model can generate chart codes that match the current input data based on the input data and the learning chart code template, and realize the analysis of the data at the same time.

[0187] It should be noted that here the big model needs to be transformed into another role, which is used to convert the data obtained by executing SQL queries into the code displayed on the front end. For example, you are a data analysis expert. Your task is to generate bar charts, line charts, pie charts and other chart code samples according to the provided bar charts, line charts, pie charts and other chart code samples and the given data, and analyze the data.

[0188] Step 4: Response parsing

[0189] In this step, a parsing tool is designed to parse the response output of the large model. According to the output format of the large model, the data visualization chart code returned by the large model and the analysis of the data by the large model are parsed, and the parsed content is further processed for front-end display.

[0190] (IV) Feedback stage

[0191] like Figure 6 As shown in the figure, the specific implementation process of the feedback phase is as follows:

[0192] Step 1: Data display page

[0193] The data display page is an important part of the intelligent question system. It displays the questions raised by users and the SQL statements generated by the intelligent question system based on the questions. Users can intuitively see the specific content of the SQL statement through the page and understand its execution process. After the SQL is executed, the page will display the data results returned by the query, supporting detailed data display in the form of a table. At the same time, the system will also visualize the query results and generate various charts (such as bar charts, line charts, pie charts, etc.) to help users understand the data more intuitively.

[0194] In addition, the data display page not only displays static query results, but the system also further analyzes the data to provide summary conclusions and key findings. Users can obtain valuable information and insights from the analysis results to support decision-making or further business operations.

[0195] Step 2: SQL editing and testing

[0196] The user can judge whether the intelligent question system's answer to the user's question is correct based on the SQL and data returned by the data display page. For incorrect SQL, the intelligent question system has set up a SQL editor for modifying and testing SQL.

[0197] In this step, users need to judge whether the intelligent question system's answer to the user's question is accurate based on the SQL returned by the data display page and its corresponding data. If the SQL generated by the system and the query results do not meet expectations, users can manually modify and adjust the generated SQL statements through the SQL editor. At the same time, users can immediately run the modified SQL for testing to see its impact on the data and verify the accuracy of the results.

[0198] Once the user modifies the SQL and runs it, the system will display the updated query results for the user to compare the data output to ensure that the final answer is consistent with the user's expectations. This process effectively improves the flexibility and usability of the intelligent question system, allowing users to participate in the optimization process of SQL queries and improve the overall performance and accuracy of the system.

[0199] Step 3: Problem and corresponding SQL vectorized storage

[0200] This step will repeat the specific implementation steps of the vectorized storage phase of similarity questions and corresponding SQL and professional terms / keywords, including the input of questions and their corresponding SQL, receiving user-input questions, and SQL query statements corresponding to the questions; classification, classifying the input content. If the stored content is similarity questions and SQL, the SQL needs to be stored first, and the SQL storage id is recorded in the metadata; document block construction, constructing the similarity questions and professional terms / keywords explanations that need to be vectorized and other key information that needs to be recorded into Document document block objects for subsequent vectorized storage; document block embedding, i.e. vectorization, is the process of converting text data into vector matrices. This step has a direct impact on the effect of subsequent retrieval; vector storage, storing the vectorized data of the document block in the vector database, so that efficient retrieval operations can be performed based on the similarity of the vector space.

[0201] It should be noted that the intelligent questioning method provided in the embodiment of the present invention first vectorizes and stores the foreseeable similarity problems and the related explanations of professional terms / keywords, and stores the correct SQL corresponding to the similarity problems separately. When using the big model to generate SQL, the similarity problems and their SQL and the related explanations of professional terms / keywords provide a reference for the big model to improve the accuracy of the SQL generated by the big model.

[0202] It should be noted that the intelligent number-asking method provided by the present invention has the following characteristics:

[0203] a) A separate storage method is used for the storage of similarity questions and SQL. The text description information such as similarity questions or explanations of professional terms / keywords is stored in the vector database in a vectorized manner, while the SQL corresponding to the similarity questions is stored in an indexed manner, and the association with the similarity questions is achieved through the id stored in the SQL. This method can effectively improve the accuracy of knowledge retrieval.

[0204] b) The large model will dynamically load the table structure in the database when performing Text2SQL. Compared with the previous method of storing all database table structures in the vector database and retrieving the relevant table structure from the vector database according to the problem when the large model generates SQL, real-time dynamic loading of the table structure in the database will be more accurate.

[0205] c) In response to the problem of data display, the present invention relies on the learning ability of the large model and the ECharts front-end code sample to construct an Agent for data chart display, which can analyze the data and generate ECharts code according to the characteristics of the data and the user's questions. It can mainly generate ECharts code for bar charts, pie charts, and line charts to achieve visual display of data.

[0206] d) Double feedback mechanism: A double feedback mechanism is designed in the intelligent questioning method of the present invention. The first feedback mechanism is provided to developers, who can optimize the large model for certain inaccurate questions; the second feedback mechanism is provided to the business end, and users can provide feedback on questions that the large model answers incorrectly. After receiving the feedback, the operation and maintenance personnel can optimize these questions.

[0207] The intelligent questioning method provided in the embodiment of the present invention first obtains the question input by the user; and searches for target similarity questions similar to the user input question and / or explanations of related professional terms / keywords in a pre-established external vector database; wherein the external vector database stores multiple similarity questions and their corresponding structured query languages ​​SQL, as well as explanations of multiple professional terms / keywords; then the user input question is reorganized, and the reorganized user input question includes the original user input question, and at least one of the following: target similarity questions similar to the user input question and their corresponding SQL, and explanations of professional terms / keywords related to the user input question; then a first role is set for the large model in the system prompt words of the large model, and the database table structure information that needs to be intelligently questioned is assembled into the system prompt words of the large model; finally, the large model is used to generate a target SQL statement based on the first role, the database table structure information, and the reorganized user input question. The present invention introduces an external vector database to store historical similarity problems and their corresponding SQL statements or explanations of professional terms / keywords, providing a reliable basis for generating SQL. This design can not only reduce the possibility of hallucinations caused by large models, but also significantly improve the generation accuracy and system efficiency of Text2SQL tasks. In addition, by dynamically assembling database table structure information into the system prompt words of the large model in real time, compared with the traditional method (i.e. storing all database table structures in the vector database), it effectively avoids the problem of being unable to retrieve the corresponding database table structure due to inaccurate user description, thereby improving the effect of intelligent questioning. In summary, the present invention achieves comprehensive improvement in effect, cost, efficiency and accuracy, and solves the problems of poor effect and high cost of use of existing intelligent questioning methods due to complete reliance on large model capabilities to generate SQL, or over-reliance on RAG vector retrieval, or relatively complex intelligent questioning system design, and over-reliance on early semantic modeling.

[0208] Embodiment 2:

[0209] like Figure 7 As shown, this embodiment provides an intelligent number-asking device, which is used to execute the above-mentioned intelligent number-asking method, including:

[0210] An input question acquisition module 11 is used to acquire questions input by a user;

[0211] A similar content search module 12 is connected to the input question acquisition module 11 and is used to search for target similarity questions similar to the user input question and / or explanations of related professional terms / keywords in a pre-established external vector database; wherein the external vector database stores a plurality of similarity questions and their corresponding structured query languages ​​SQL, as well as explanations of a plurality of professional terms / keywords;

[0212] The input question reorganization module 13 is connected to the similar content search module 12 and is used to reorganize the user input question, wherein the reorganized user input question includes the original user input question and at least one of the following: a target similarity question similar to the user input question and its corresponding SQL, and an explanation of professional terms / keywords related to the user input question;

[0213] A first prompt word assembly module 14, connected to the input question reorganization module 13, is used to set a first role for the large model in the system prompt words of the large model, and assemble the database table structure information required for intelligent questioning into the system prompt words of the large model;

[0214] The target SQL statement generating module 15 is connected to the first prompt word assembling module 14, and is used to generate a target SQL statement based on the first role, database table structure information, and the reorganized user input question by using the large model.

[0215] Optionally, the device further comprises:

[0216] A first receiving module is used to receive an input similarity question and its corresponding SQL;

[0217] The second receiving module is used to receive the explanation of the input professional terms / keywords;

[0218] The first storage module is used to separately store the SQL corresponding to the input similarity question and record the id of the SQL storage in the metadata; wherein the similarity question and its corresponding SQL are associated through the id of the SQL storage;

[0219] The document block construction module is used to construct the input similarity questions and explanations of professional terms / keywords into document blocks;

[0220] The second storage module is used to convert the document block into a vector form through a preset embedding model, and store the vectorized data of the document block in the external vector database.

[0221] Optionally, the similar content search module 12 specifically includes:

[0222] An embedding vector conversion unit, used to convert the user input question into an embedding vector;

[0223] A similarity search unit is used to perform a similarity search in the external vector database using the embedded vector to find target similarity questions similar to the user input question and / or explanations of related professional terms / keywords.

[0224] Optionally, the device further comprises:

[0225] A parsing and execution module, used to parse and execute the target SQL statement to obtain the data returned after execution;

[0226] A visualization module is used to visualize the data returned after the execution.

[0227] Optionally, the parsing and execution module specifically includes:

[0228] A statement parsing unit, used to parse the target SQL statement generated by the large model through a pre-designed parser to obtain an SQL command;

[0229] The operation execution unit is used to convert the SQL command obtained by parsing into an operation executable by the database through a pre-designed SQL executor, and when it is verified that the operation is a query operation, execute the operation to obtain the data returned after the execution.

[0230] Optionally, the visualization module specifically includes:

[0231] a chart type acquisition unit, used to acquire a chart type specified by a user, or, if the user does not specify a chart type, determine and select a suitable chart type based on the characteristics of the data returned after the execution and the user input question;

[0232] A system prompt word assembling unit, used for setting a second role for the large model in the system prompt word of the large model, and assembling a chart code template corresponding to the chart type into the system prompt word of the large model;

[0233] A chart generating unit is used to generate a chart of the chart type by using the large model based on the second role, the chart code template, and the data returned after the execution.

[0234] Optionally, the device further comprises:

[0235] SQL statement display module, used to display the target SQL statement;

[0236] An SQL statement editing module is used to receive an editing operation of the target SQL statement by a user through an SQL editor;

[0237] An SQL statement running module, used to run the edited target SQL statement according to a user instruction, and display the query result of the edited target SQL statement;

[0238] The third storage module is used to save the user input question and the edited target SQL statement into the external vector database.

[0239] Embodiment 3:

[0240] refer to Figure 8 This embodiment provides an intelligent number-asking device, including a memory 21 and a processor 22. The memory 21 stores a computer program, and the processor 22 is configured to run the computer program to execute the intelligent number-asking method in Embodiment 1.

[0241] The memory 21 is connected to the processor 22. The memory 21 may be a flash memory, a read-only memory or other memory. The processor 22 may be a central processing unit or a single-chip microcomputer.

[0242] Embodiment 4:

[0243] This embodiment provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the intelligent number-asking method in the above-mentioned embodiment 1 is implemented.

[0244] The computer-readable storage medium includes volatile or non-volatile, removable or non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, computer program modules or other data). Computer-readable storage media include, but are not limited to, RAM (Random Access Memory), ROM (Read-Only Memory), EEPROM (Electrically Erasable Programmable read only memory), flash memory or other memory technology, CD-ROM (Compact Disc Read-Only Memory), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer.

[0245] In summary, the intelligent questioning method, device and readable storage medium provided by the embodiments of the present invention first obtain the question input by the user; and search for target similarity questions similar to the user input question and / or explanations of related professional terms / keywords in a pre-established external vector database; wherein the external vector database stores multiple similarity questions and their corresponding structured query languages ​​SQL, as well as explanations of multiple professional terms / keywords; then the user input question is reorganized, and the reorganized user input question includes the original user input question, and at least one of the following: target similarity questions similar to the user input question and their corresponding SQL, and explanations of professional terms / keywords related to the user input question; then a first role is set for the large model in the system prompt words of the large model, and the database table structure information that needs to be intelligently questioned is assembled into the system prompt words of the large model; finally, the large model is used to generate a target SQL statement based on the first role, the database table structure information, and the reorganized user input question. The present invention introduces an external vector database to store historical similarity problems and their corresponding SQL statements or explanations of professional terms / keywords, providing a reliable basis for generating SQL. This design can not only reduce the possibility of hallucinations caused by large models, but also significantly improve the generation accuracy and system efficiency of Text2SQL tasks. In addition, by dynamically assembling database table structure information into the system prompt words of the large model in real time, compared with the traditional method (i.e. storing all database table structures in the vector database), it effectively avoids the problem of being unable to retrieve the corresponding database table structure due to inaccurate user description, thereby improving the effect of intelligent questioning. In summary, the present invention achieves comprehensive improvement in effect, cost, efficiency and accuracy, and solves the problems of poor effect and high cost of use of existing intelligent questioning methods due to complete reliance on large model capabilities to generate SQL, or over-reliance on RAG vector retrieval, or relatively complex intelligent questioning system design, and over-reliance on early semantic modeling.

[0246] It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present invention, but the present invention is not limited thereto. For those of ordinary skill in the art, various modifications and improvements can be made without departing from the spirit and essence of the present invention, and these modifications and improvements are also considered to be within the scope of protection of the present invention.

Claims

1. An intelligent number-asking method, characterized in that: The method comprises: Get user input questions; Searching for target similarity questions and / or explanations of related professional terms / keywords similar to the question input by the user in a pre-established external vector database; wherein the external vector database stores a plurality of similarity questions and their corresponding structured query languages ​​SQL, as well as explanations of a plurality of professional terms / keywords; Reorganizing the user input question, wherein the reorganized user input question includes the original user input question and at least one of the following: a target similarity question similar to the user input question and its corresponding SQL, and an explanation of professional terms / keywords related to the user input question; Setting a first role for the large model in the system prompt words of the large model, and assembling the database table structure information that needs to be intelligently queried into the system prompt words of the large model; The large model is used to generate a target SQL statement based on the first role, database table structure information, and the reorganized user input question.

2. The method according to claim 1, characterized in that: Before searching the pre-established external vector database for target similarity questions similar to the user input question and / or explanations of related professional terms / keywords, the method further includes: Receive input similarity questions and their corresponding SQL; Receive interpretation of input professional terms / keywords; The SQL corresponding to the input similarity question is stored separately, and the id of the SQL storage is recorded in the metadata; wherein the similarity question and its corresponding SQL are associated through the id of the SQL storage; Construct the input similarity questions and explanations of professional terms / keywords into document chunks; The document block is converted into a vector form through a preset embedding model, and the vectorized data of the document block is stored in the external vector database.

3. The method according to claim 1, characterized in that The step of searching a pre-established external vector database for target similarity questions and / or explanations of related professional terms / keywords similar to the question input by the user specifically includes: Convert the user input question into an embedding vector; The embedded vector is used to perform a similarity search in the external vector database to find target similarity questions similar to the user input question and / or explanations of related professional terms / keywords.

4. The method according to claim 1, characterized in that After generating a target SQL statement using the large model based on the first role, database table structure information, and the reorganized user input question, the method further includes: Parse and execute the target SQL statement to obtain the data returned after execution; Visualize the data returned after the execution.

5. The method according to claim 4, characterized in that The parsing and executing of the target SQL statement to obtain the data returned after the execution specifically includes: Parsing the target SQL statement generated by the large model through a pre-designed parser to obtain an SQL command; The SQL command obtained by parsing is converted into an operation executable by the database through a pre-designed SQL executor, and when the operation is verified to be a query operation, the operation is executed to obtain the data returned after the execution.

6. The method according to claim 4, characterized in that The visualization of the data returned after the execution specifically includes: Obtaining a chart type specified by a user, or, if the user does not specify a chart type, determining and selecting an appropriate chart type based on the characteristics of the data returned after the execution and the user input question; Setting a second role for the large model in the system prompt words of the large model, and assembling a chart code template corresponding to the chart type into the system prompt words of the large model; The large model is used to generate a chart of the chart type based on the second role, the chart code template, and the data returned after the execution.

7. The method according to claim 1, characterized in that After generating a target SQL statement using the large model based on the first role, database table structure information, and the reorganized user input question, the method further includes: Display the target SQL statement; Receiving an editing operation of the target SQL statement by a user through an SQL editor; Run the edited target SQL statement according to the user's instruction, and display the query result of the edited target SQL statement; The user input question and the edited target SQL statement are saved in the external vector database.

8. An intelligent number-asking device, characterized in that: The device comprises: Input question acquisition module, used to obtain questions input by users; A similar content search module is connected to the input question acquisition module and is used to search for target similarity questions similar to the user input question and / or explanations of related professional terms / keywords in a pre-established external vector database; wherein the external vector database stores a plurality of similarity questions and their corresponding structured query languages ​​SQL, as well as explanations of a plurality of professional terms / keywords; An input question reorganization module, connected to the similar content search module, for reorganizing the user input question, wherein the reorganized user input question includes the original user input question and at least one of the following: a target similarity question similar to the user input question and its corresponding SQL, and an explanation of professional terms / keywords related to the user input question; A first prompt word assembly module, connected to the input question reorganization module, is used to set a first role for the large model in the system prompt words of the large model, and assemble the database table structure information required for intelligent questioning into the system prompt words of the large model; A target SQL statement generating module is connected to the first prompt word assembling module and is used to generate a target SQL statement based on the first role, database table structure information, and the reorganized user input question by using the large model.

9. An intelligent number-asking device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to implement the intelligent number-asking method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the intelligent number-asking method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Index extraction method, electronic equipment and computer program product

    CN119938870A

  • Index extraction method, electronic device and computer program product

    CN119938870B

  • Intelligent number asking method based on adaptive rule constraint and program product

    CN122086959A