Intelligent question answering method, system and device based on large language model and database

By converting database information into text strings and representing them as vectors, and combining this with large language model generation technology, the problem of insufficient data understanding and reasoning capabilities of large language models in data analysis is solved, achieving high-precision intelligent question answering and personalized user experience.

CN118606348BActive Publication Date: 2024-11-08YUCANG TECH (BEIJING) CO LTD

Patent Information

Application Number
CN202411060050.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-05
Publication Date
2024-11-08
Estimated Expiration
2044-08-05

AI Technical Summary

Technical Problem

Existing large language models lack sufficient data understanding and reasoning capabilities in data analysis, rely on specific database structures, result in poor user experience, and fail to provide interpretability and personalized adjustments.

Method used

By converting database information into text strings and vector representations, and combining this with large language model generation technology, information retrieval and structured query language conversion are performed to generate accurate database query statements, which are then combined with natural language responses.

Benefits of technology

It improves the accuracy of intelligent question answering, enhances user trust and satisfaction, lowers the barrier to entry, and provides personalized and explainable answers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118606348B_ABST
    Figure CN118606348B_ABST
Patent Text Reader

Abstract

The present application discloses an intelligent question-answering method, system and device based on a large language model and a database, and relates to the field of natural language processing. The method comprises: converting information stored in a database into a text string, and then converting the text string into a vector representation to obtain a plurality of knowledge vectors; converting a user question into a vector representation to obtain a question vector; calculating the similarity between the question vector and each knowledge vector to determine a plurality of related knowledge vectors; constructing a first prompt word according to the text string corresponding to each related knowledge vector and the user question, and determining a first answer based on a first large language model; constructing a second prompt word according to the user question and a set of text strings, and converting the user question into a structured query language statement based on a second large language model; executing the structured query language statement in the database to obtain a second answer; and determining a final answer based on the first answer and the second answer. The present application improves the accuracy of generating answers in the intelligent question-answering process.
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 in particular to an intelligent question-answering method, system and device based on a large language model and database. Background Art

[0002] With the rapid development of information technology, natural language processing (NLP) and large language model (LLM) technologies have penetrated into all aspects of daily life. Of course, this includes the field of data analysis. Traditional data analysis relies on traditional databases or big data technologies. Data analysis usually requires manual writing of corresponding statistical report statements, and may require further processing of the results. The response scenarios are single, inefficient, and require high technical requirements for operators, which limits its ability to handle complex and variable user queries. In order to overcome these limitations, researchers began to explore the direct conversion of natural language (NL) into structured query language (SQL) through LLM, which is called text to structured query language (Text to Structured Query Language, Text2SQL). The data analysis system or intelligent question-answering system built with Text2SQL technology can flexibly and quickly respond to users' needs for data analysis scenarios, lower the user's usage threshold, and enhance user interaction.

[0003] Although the application of LLM in Text2SQL technology has brought significant convenience to the interaction between natural language and database, it still has some shortcomings that cannot be ignored in the context of existing technology.

[0004] 1. Insufficient data understanding and reasoning capabilities: Although large language models have made significant progress in understanding and generating natural language, their ability to understand complex database queries and reasoning is still limited. The database query statements generated during data analysis are not accurate enough, resulting in incorrect results, and they perform poorly when dealing with certain complex problems that require deep logical reasoning.

[0005] 2. Dependence on specific database structures: Although the current large-model intelligent question-answering system is designed to lower the user threshold, it still needs to adapt to specific database structures and patterns. For organizations with different database architectures or data formats, customized solutions or additional development work are required.

[0006] 3. Insufficient explainability: Although the current large-model intelligent question-answering system can generate natural language answers and graphical results, it cannot provide sufficient information to explain why specific data or answers are selected, resulting in reduced user trust in the results, especially in situations involving important decisions.

[0007] 4. Poor user experience: The current large-model intelligent question-answering system provides natural language interaction and output results with pictures and texts, but it cannot be personalized according to the user's personal preferences or habits, which limits the appeal of the large-model intelligent question-answering system among certain specific user groups. Summary of the invention

[0008] The purpose of this application is to provide an intelligent question-answering method, system and device based on a large language model and database, which can improve the accuracy of generating answers in the intelligent question-answering process.

[0009] To achieve the above objectives, this application provides the following solutions.

[0010] In a first aspect, the present application provides an intelligent question answering method based on a large language model and a database, comprising:

[0011] Converting the information stored in each data table in a database into a text string to obtain a text string set; the database is a pre-built knowledge database;

[0012] Convert each text string in the text string set into a vector representation to obtain a plurality of knowledge vectors;

[0013] Obtaining a user question and converting the user question into a vector representation to obtain a question vector;

[0014] Calculating the similarity between the question vector and each knowledge vector respectively, and determining a plurality of relevant knowledge vectors according to the similarity between the question vector and each knowledge vector;

[0015] Constructing a first prompt word according to the text string corresponding to each relevant knowledge vector and the user question, and determining a first answer according to the first prompt word based on a pre-trained first language model;

[0016] Constructing a second prompt word according to the user question and the text string set, and converting the user question into a structured query language statement according to the second prompt word based on a pre-trained second language model;

[0017] Executing the structured query language statement in the database to obtain a second answer;

[0018] A final answer is determined based on the first answer and the second answer.

[0019] In a second aspect, the present application provides an intelligent question-answering system based on a large language model and a database, comprising:

[0020] A database data processing module, used to convert the information stored in each data table in the database into a text string to obtain a text string set; the database is a pre-built knowledge database;

[0021] A vectorization processing module, connected to the database data processing module, for converting each text string in the text string set into a vector representation to obtain a plurality of knowledge vectors, obtaining user questions, and converting the user questions into vector representations to obtain question vectors;

[0022] a large model retrieval generation module, connected to the vectorization processing module, for respectively calculating the similarity between the question vector and each knowledge vector, and determining a plurality of related knowledge vectors according to the similarity between the question vector and each knowledge vector, constructing a first prompt word according to the text string corresponding to each related knowledge vector and the user question, and determining a first answer according to the first prompt word based on a pre-trained first large language model;

[0023] A large model text-to-sentence conversion module, connected to the vectorization processing module, is used to construct a second prompt word according to the user question and the text string set, and convert the user question into a structured query language sentence according to the second prompt word based on a pre-trained second large language model;

[0024] a structured query language execution module, connected to the large model text conversion module, and configured to execute the structured query language statement in the database to obtain a second answer;

[0025] The answer output module is connected to the large model retrieval generation module and the structured query language execution module respectively, and is used to determine the final answer based on the first answer and the second answer.

[0026] In a third aspect, the present application provides a computer device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-mentioned intelligent question-answering method based on a large language model and a database.

[0027] According to the specific embodiments provided by the present application, the present application discloses the following technical effects: The present application provides an intelligent question-answering method, system and device based on a large language model and a database, by converting the information stored in each data table in the database into a text string, and converting the text string and the user question into a vector representation, using the retrieval enhancement generation technology to determine multiple related knowledge vectors, and combining the large language model to generate a first answer, and then according to the user question and the text string set, using the large language model to convert the user question into a structured query language statement, and executing the structured query language statement in the database to generate a second answer, and finally determining the final answer based on the first answer and the second answer. Combining the retrieval enhancement generation technology, the large language model and the Text2SQL technology improves the accuracy of generating answers in the intelligent question-answering process, and at the same time enhances the user's trust and satisfaction with the intelligent question-answering process. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0029] Figure 1 This is an application environment diagram of an intelligent question-answering method based on a large language model and database in one embodiment of the present application.

[0030] Figure 2 A flowchart of an intelligent question-answering method based on a large language model and a database is provided for one embodiment of the present application.

[0031] Figure 3 The figure is a flowchart of processing database data in one embodiment of the present application.

[0032] Figure 4 This is a flowchart of processing user questions in one embodiment of the present application.

[0033] Figure 5 A module diagram of an intelligent question-answering system based on a large language model and a database provided in one embodiment of the present application. DETAILED DESCRIPTION

[0034] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions 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 are within the scope of protection of this application.

[0035] This application uses Retrieval-Augmented Generation (RAG) technology to enhance the Text2SQL technology based on a large language model. The core idea of ​​RAG is to combine information retrieval with large language model generation technology to enhance the performance of LLM by retrieving relevant information from an external knowledge base. This application applies RAG technology to the data analysis system, which can retrieve knowledge related to user queries in real time, and combine the generation capabilities of LLM to generate more accurate and rich answers. At the same time, it assists in generating database query statements, which can not only improve the performance of the data analysis system, but also enhance the user's trust and satisfaction with the system.

[0036] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.

[0037] The intelligent question answering method based on a large language model and a database provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be set up separately, or it can be integrated on the server 104, or it can be placed on the cloud or other servers. The terminal 102 can send the database and user questions to be processed to the server 104. After receiving the database and user questions to be processed, the server 104 performs intelligent question and answer to determine the final answer. The server 104 can feedback the final answer to the terminal 102. In addition, in some embodiments, the intelligent question and answer method based on the large language model and database can also be implemented by the server 104 or the terminal 102 alone.

[0038] The terminal 102 may be, but is not limited to, various desktop computers, laptop computers, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart vehicle-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers, or may be a cloud server.

[0039] In an exemplary embodiment, Figure 2 As shown, an intelligent question answering method based on a large language model and a database is provided. The method is executed by a computer device, and can be executed by a computer device such as a terminal or a server alone, or by a terminal and a server together. In the embodiment of the present application, the method is applied to Figure 1The server 104 in the example is used for explanation, and the steps include the following steps 201 to 208.

[0040] Step 201, convert the information stored in each data table in the database into a text string to obtain a text string set. The database is a pre-built knowledge database. The database is a relational database, a non-relational database or a cache database.

[0041] This application exports the contents of all data tables in the database into plain text strings so that they can be combined with the large language model prompts to generate relevant content. The text strings are in lightweight structured text table formats such as Markdown, character-separated values ​​(CSV) or JSON to retain more data structure and context information.

[0042] Specifically, the if-else branch selection strategy can be used to convert the content of the data table into a text string using a corresponding data processing method according to the requirements of the output file.

[0043] Each text string in the text string set includes table structure information and content information. That is, when each text string is exported, the table structure information is added at the beginning of the text string. The table structure information includes the table name, the Chinese meaning of the table name, each field name and the Chinese meaning of each field name, so that the large language model can better understand the context.

[0044] Each text string in the text string set corresponds to a data table in the database, or each text string in the text string set corresponds to a record in a data table in the database.

[0045] For example, there is a data table in the database, whose name is person_info in English and personnel information table in Chinese. Its table structure and records are shown in Table 1.

[0046] Table 1 Personnel information table

[0047]

[0048] When each text string corresponds to a data table in the database, the contents stored in the above personnel information table are converted into text strings in three formats as shown below.

[0049] (1) Convert to Markdown format: Markdown uses the string concatenation method. The string concatenation is performed according to the Markdown format. The converted text string is as follows.

[0050] “#person_info(personnel information table): #ID (personnel number), Name (name), Age (age), City (city); |ID|Name|Age|City|; |-----|-----|-----|-----|; |1|Name A|30|City A1|; |2|Name B|25|City B1|”.

[0051] (2) Convert to CSV format: CSV also uses the string concatenation method and concatenates according to the CSV format. The converted text string is as follows.

[0052] "Table name: person_info (personnel information table); field names: ID (personnel number), Name (name), Age (age), City (city); ID, Name, Age, City; 1, Name A, 30, City A1; 2, Name B, 25, City B1".

[0053] (3) Convert to JSON format: JSON is constructed using relevant tools and methods, such as hutool in Java and methods in the json library in Python. The converted text string is as follows.

[0054] “{"Table name":"person_info(Personnel information table)","Field name":["ID(Personnel number)","Name(Name)","Age(Age)","City(City)"],"Content":[{"ID":1,"Name":"Name A","Age":30,"City":"City A1"},{"ID":2,"Name":"Name B","Age":25,"City":"City B1"}]}".

[0055] When each text string corresponds to a record in a data table in the database, the contents stored in the above personnel information table are converted into text strings in three formats as shown below.

[0056] (1) Convert to Markdown format: The converted text string is as follows.

[0057] “#person_info(personnel information table): #ID(personnel number), Name(name), Age(age), City(city); |ID|Name|Age|City|; |-----|-----|-----|-----|; |1|NameA|30|CityA1|”, “#person_info(personnel information table): #ID(personnel number), Name(name), Age(age), City(city); |ID|Name|Age|City|; |-----|-----|-----|-----|; |2|NameB|25|CityB1|”.

[0058] (2) Convert to CSV format: The converted text string is as follows.

[0059] "Table name: person_info (personnel information table); field names: ID (personnel number), Name (name), Age (age), City (city); ID, Name, Age, City; 1, Name A, 30, City A1", "Table name: person_info (personnel information table); field names: ID (personnel number), Name (name), Age (age), City (city); ID, Name, Age, City; 2, Name B, 25, City B1".

[0060] (3) Convert to JSON format: The converted text string is as follows.

[0061] “{"Table name":"person_info(Personnel information table)","Field name":["ID(Personnel number)","Name(Name)","Age(Age)","City(City)"],"Content":{"ID":1,"Name":"Name A","Age":30,"City":"City A1"}},{"Table name":"person_info(Personnel information table)","Field name":["ID(Personnel number)","Name(Name)","Age(Age)","City(City)"],"Content":"ID":2,"Name":"Name B","Age":25,"City":"City B1"}}".

[0062] Experiments show that when the data in the data table is long text, it is better to convert a record into a text string.

[0063] Step 202: Convert each text string in the text string set into a vector representation to obtain a plurality of knowledge vectors.

[0064] In this embodiment, Figure 3 As shown, each text string in the text string set is converted into a vector representation using an embedded large language model. Specifically, the text string is converted into a high-dimensional vector representation, and then the vector representation is stored in a vector database, and an index is constructed to ensure that the vector similarity retrieval can be performed efficiently later.

[0065] In another exemplary embodiment, each text string generates a file, and the file is first read and then the text string in the file is converted into a high-dimensional vector representation in step 202. In this embodiment, the file can be processed asynchronously after it is generated, that is, step 201 and step 202 can be completed at different times.

[0066] For example, when a data table is converted into a text string, the embedded large language model is used to convert it into a high-dimensional vector: 0.191519, 0.622109, 0.437728, 0.785359, ....., 0.276464. When a record is converted into a text string, the embedded large language model is used to convert it into two high-dimensional vectors: 0.789258, 0.098512, 0.442332, 0.380669, ..., 0.355001; 0.024636, 0.693512, 0.421212, 0.858349, ..., 0.880256.

[0067] Step 203: Obtain the user's question and convert the user's question into a vector representation to obtain a question vector.

[0068] In this embodiment, an embedded large language model is used to convert the user question into a vector representation. The dimension of the question vector is the same as the dimension of each knowledge vector.

[0069] Step 204, respectively calculating the similarity between the question vector and each knowledge vector, and determining a plurality of related knowledge vectors according to the similarity between the question vector and each knowledge vector.

[0070] Specifically, Figure 4 As shown, the question vector is input into the vector database for retrieval, and according to the similarity between the question vector and each knowledge vector, multiple knowledge vectors are sorted from high to low according to the similarity, and the first N knowledge vectors are used as relevant knowledge vectors, where N is the number of relevant knowledge vectors. N>0, and N is usually 1 to 5.

[0071] Similarity calculation methods include inner product similarity, cosine similarity, Euclidean distance, Manhattan distance, Jaccard similarity, etc. This application uses cosine similarity.

[0072] (1) Inner product similarity directly uses the inner product of vectors to measure the similarity between vectors. This method is simple and intuitive and is suitable for certain specific application scenarios.

[0073] (2) Cosine similarity is used to measure the cosine value of the angle between two vectors. Its value range is between -1 and 1. The closer the value is to 1, the more similar the two vectors are, and the closer the value is to -1, the less similar the two vectors are. The calculation formula of cosine similarity is: or ;in, Representation vector v 1 and vector v The cosine similarity of 2, Representation vector v 1 and vector v 2, Representation vector v 1 and vector v The dot product of 2, Representation vector v norm (length) of 1, Representation vector v 2-norm (length).

[0074] (3) Euclidean distance is used to measure the true distance between two vectors. The smaller the value, the more similar the vectors are. Its calculation formula is: ;in, Representation vector v 1 and vector v 2's Euclidean distance, Representation vector v 1 in i The values ​​in the dimensions, Representation vector v 2 in i The values ​​in the dimensions, n Representation vector v 1 or vector v Dimension 2.

[0075] Properties of Euclidean distance: Non-negativity: , and the equality holds if and only if v 1= v 2. Identity: ; Triangle inequality: ,in, v 3 is another vector.

[0076] (4) Manhattan distance is used to measure the distance between two vectors. The smaller the value, the more similar the vectors are. Its calculation formula is: ;in, Representation vector v 1 and vectorv 2. The properties of Manhattan distance are similar to those of Euclidean distance.

[0077] (5) Jaccard similarity is used to measure the similarity between two vectors. It is particularly suitable for data represented by vectors, such as documents, user preferences, and item sets in recommendation systems. Its calculation formula is: ;in, Representation vector v 1 and vector v 2 Jaccard similarity, Representation vector v 1 and vector v The number of elements in the intersection of 2, Representation vector v 1 and vector v The value range of Jaccard similarity is between [0,1], and the larger the value, the more similar it is. Representation vector v 1 and vector v 2 are exactly the same, Representation vector v 1 and vector v 2 have no common elements.

[0078] Step 205: construct a first prompt word according to the text string corresponding to each relevant knowledge vector and the user question, and determine a first answer according to the first prompt word based on a pre-trained first language model.

[0079] In an exemplary embodiment, the first large language model is a dialogue large language model, such as Wenxinyiyan, GPT-4, etc. The first prompt word enables the first large language model to generate an answer to the user's question according to the text string.

[0080] An example of the first prompt word is given below.

[0081] You are an intelligent conversational customer service representative. Now, based on the reference text content provided below, you are organizing and answering user questions.

[0082] ##User question: How many people are there?

[0083] ## Reference text.

[0084] Table name: person_info (personnel information table).

[0085] Field name: ID (personnel number, Name, Age, City).

[0086] ID, Name, Age, City.

[0087] 1. Name A, 30, City A1.

[0088] Table name: person_info (personnel information table).

[0089] Field name: ID (personnel number, Name, Age, City).

[0090] ID, Name, Age, City.

[0091] 2, Name B, 25, City B1.

[0092] ##Restriction: You cannot answer content other than the reference text.

[0093] ##Requirements: Fluent language, in line with language habits.

[0094] The answer of the first language model: According to the provided content, the personnel information table currently records the information of two persons: Name A (30 years old, city A1) and Name B (25 years old, city B1).

[0095] Step 206: construct a second prompt word according to the user question and the text string set, and convert the user question into a structured query language statement according to the second prompt word based on a pre-trained second language model.

[0096] In an exemplary embodiment, the second large language model is a conversational large language model (such as Wenxinyiyan, GPT-4, etc.) or a Text2SQL large language model, such as a database generative pre-trained decoder (DataBase Generative Pre-trained Transformer, DB-GPT).

[0097] The second largest language model converts user questions into corresponding SQL statements. This conversion process can generally be divided into the following steps.

[0098] (1) Natural language understanding: First, we need to understand the natural language questions raised by users. This involves technologies such as grammatical parsing, entity recognition, and relation extraction in order to correctly understand the intent of the question and the entities involved.

[0099] (2) Semantic analysis: After understanding the surface meaning of the problem, it needs to be converted into a more structured representation for subsequent processing, including generating data structures such as logical forms or semantic analysis trees.

[0100] (3) SQL statement generation: Based on the results of semantic analysis, the corresponding SQL query statement is generated. The database model and grammar rules need to be considered to ensure that the generated SQL statement can correctly query the database and obtain the required information.

[0101] The following is an example of how the second largest language model converts user questions into SQL statements.

[0102] User question: How many people are there?

[0103] (1) Natural language understanding: The user's question is: "How many people are there?" This is a question that asks about the number of data entries under specific conditions. In the natural language understanding stage, it is recognized that the main intention of the user's question is to obtain the number of records in a specific data table in the database.

[0104] (2) Semantic parsing: After understanding the surface meaning of the user's question, convert it into a more structured form. This stage usually generates a logical form or semantic parse tree to subsequently generate SQL query statements.

[0105] (3) SQL query generation: Generate the corresponding SQL query statement based on the results of semantic analysis. For the question "How many people are there?", the generated SQL statement can be a simple aggregation query to count the number of records in a specific table. Based on the given table information, the SQL statement can be generated: SELECT COUNT( ) AS num_people FROM person_info. This counts the number of all records in the person_info table and returns the result as an alias of num_people.

[0106] The second largest language model in this application is constructed based on a specific scenario or is pre-trained and fine-tuned based on a general large language model.

[0107] Furthermore, an example of the second prompt word is given below.

[0108] You are a database administrator and need to convert the following natural language input from the user into SQL statements.

[0109] #Table information: person_info (personnel information table): #ID (personnel number), Name (name), Age (age), City (city); |ID|Name|Age|City|; |-----|-----|-----|-----|; |1|Name A|30|City A1|; |2|Name B|25|City B1|.

[0110] #User question: How many people are there?

[0111] #Restrictions and requirements: Only output correct SQL statements and do not return other information.

[0112] Step 207: execute the structured query language statement in the database to obtain a second answer.

[0113] Specifically, the structured query language statement is first verified and optimized using a static analysis tool and a structured query language optimizer to obtain a verified and optimized structured query language statement, ensuring that the generated SQL statement is safe and can be executed efficiently. Then, the verified and optimized structured query language statement is executed in the database to obtain a second answer. Specifically, a database execution engine is called to execute the verified and optimized SQL statement, and a corresponding execution result is obtained to generate a second answer in the form of a data table.

[0114] Step 208: Determine a final answer based on the first answer and the second answer.

[0115] In this application, the first answer and the second answer are combined and output to the user as a whole result. The first answer is in text form and the second answer is in chart form, ensuring that the final output contains both a detailed explanation of the user's question and specific data support.

[0116] Based on the example provided above, the user's question is: How many people are there? The final answer returned is: First answer: According to the content provided, the personnel information table currently records the information of two people: Name A (30 years old, city A1) and Name B (25 years old, city B1). Second answer: Number of people: 2.

[0117] Based on the same inventive concept, the embodiment of the present application also provides an intelligent question-answering system based on a large language model and a database for implementing the intelligent question-answering method based on a large language model and a database involved above. The implementation scheme for solving the problem provided by the system is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more embodiments of the intelligent question-answering system based on a large language model and a database provided below can refer to the limitations of the intelligent question-answering method based on a large language model and a database above, and will not be repeated here.

[0118] In an exemplary embodiment, Figure 5 As shown, an intelligent question-answering system based on a large language model and a database is provided, including: a database data processing module 501, a vectorization processing module 502, a large model retrieval generation module 503, a large model text-to-sentence module 504, a structured query language execution module 505 and an answer output module 506.

[0119] The database data processing module 501 is used to convert the information stored in each data table in the database into a text string to obtain a text string set. The database is a pre-built knowledge database.

[0120] Specifically, in the database data processing module 501, the user uploads an EXCEL worksheet or document, reads the file content and performs data preprocessing. If the user uploads an EXCEL worksheet, the EXCEL worksheet is parsed by the parser, which supports multiple worksheets and reads according to the worksheet. The worksheet name is used as the table name of the data table, and the title is used as the field of the data table. The field is translated, and the data table is organized into a database data definition language and stored in the metadata table. At the same time, a data table is created to store the content. If the user uploads a document, the user needs to download the template and upload it after arranging it according to the template. The parser parses it according to the template format. The parsed content includes the table name, field name, field content, etc. After parsing, the data table is organized into a database data definition language and stored in the metadata table. At the same time, a data table is created to store the content. At the same time, it is stored in a non-relational database for inverted indexing in order to generate SQL statements more accurately and assist the model in finding the corresponding operation fields.

[0121] The vectorization processing module 502 is connected to the database data processing module 501, and the vectorization processing module 502 is used to convert each text string in the text string set into a vector representation, obtain multiple knowledge vectors, obtain user questions, and convert the user questions into vector representations to obtain question vectors.

[0122] Specifically, the vectorization processing module 502 organizes the data parsed by the database data processing module 501 into a text according to each row of data including the table name, field name, and field content, and vectorizes and stores it in the vector database; at the same time, it converts user questions into question vectors for vector retrieval.

[0123] The large model retrieval generation module 503 is connected to the vectorization processing module 502. The large model retrieval generation module 503 is used to respectively calculate the similarity between the question vector and each knowledge vector, and determine multiple related knowledge vectors according to the similarity between the question vector and each knowledge vector, construct a first prompt word according to the text string corresponding to each related knowledge vector and the user question, and determine a first answer according to the first prompt word based on a pre-trained first large language model.

[0124] The large model text-to-sentence module 504 is connected to the vectorization processing module 502. The large model text-to-sentence module 504 is used to construct a second prompt word according to the user question and the text string set, and based on a pre-trained second large language model, convert the user question into a structured query language statement according to the second prompt word.

[0125] Specifically, in the large model text-to-sentence module 504, a specific model that supports Text2SQL after training is used to perform deep semantic understanding of user questions, and at the same time, the information of the table in the database is sent to the large language model to generate corresponding SQL statements.

[0126] The structured query language execution module 505 is connected to the large model text conversion statement module 504, and the structured query language execution module 505 is used to execute the structured query language statement in the database to obtain a second answer.

[0127] Specifically, in the structured query language execution module 505, the SQL statements generated by the second largest language model are first optimized to improve the accuracy and efficiency of the query. The optimization methods include syntax checking, semantic verification, query rewriting, etc. At the same time, the user question, the search and positioning results, and the SQL statements returned by the second largest language model are structured and vectorized and saved. Then, the database execution engine is called to execute the optimized SQL statements and return the query results.

[0128] Furthermore, the user can edit the SQL statement and provide the modified SQL statement to the second largest language model for fine-tuning to enhance the capability of the second largest language model.

[0129] The answer output module 506 is connected to the large model retrieval generation module 503 and the structured query language execution module 505 respectively, and the answer output module 506 is used to determine the final answer according to the first answer and the second answer.

[0130] Specifically, in the answer output module 506, the final answer is presented to the user in a user-friendly manner, such as a table, a chart, etc.

[0131] This application can realize efficient, intelligent and accurate database intelligent question-answering function, providing users with a good user experience. This intelligent question-answering system can better understand natural language questions, generate and execute SQL statements, and generate natural language answers and data chart results at the same time, fully meeting the user's information needs. The specific technical effects include at least the following points.

[0132] (1) Efficient information retrieval and question-answer generation: Through the vectorized representation of the large language model and the vector database index, the most relevant items can be quickly retrieved from a large amount of textual database content, improving retrieval efficiency. Combining the retrieval results with the large language model prompts to generate answers to user questions can provide natural and context-related answers, making the user experience smoother.

[0133] (2) Accurate data query and result generation: Use a large language model to convert user natural language questions into SQL statements to achieve accurate data query and avoid users having to manually write complex SQL statements. Verify and optimize SQL statements before executing them to ensure that the generated SQL statements are safe and efficient, thereby improving query execution performance.

[0134] (3) Comprehensive answer presentation: Combine natural language answers with structured data results, provide detailed explanations and specific data support, and make the answers more comprehensive and convincing. Output results in a graphic and textual format to enhance users’ understanding and acceptance of the results.

[0135] (4) Flexible system architecture: Each part of the system (such as embedding generation, vector retrieval, answer generation, SQL generation, etc.) can be independently optimized and expanded, with good flexibility and maintainability.

[0136] (5) Improve user experience: Users only need to enter natural language questions and do not need to understand database structure or SQL syntax, which greatly reduces the usage threshold and improves user experience.

[0137] In an exemplary embodiment, a computer device is provided, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps in the above-mentioned method embodiments.

[0138] In an exemplary embodiment, a computer-readable storage medium is provided, storing a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0139] In an exemplary embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0140] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0141] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM).

[0142] The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. The non-relational database may include a distributed database based on blockchain, etc., but is not limited thereto. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but is not limited thereto.

[0143] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0144] This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. At the same time, for those skilled in the art, according to the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting this application.

Claims

1. An intelligent question answering method based on a large language model and database, characterized in that: The intelligent question answering method based on a large language model and a database includes: Converting the information stored in each data table in a database into a text string to obtain a text string set; the database is a pre-built knowledge database; Convert each text string in the text string set into a vector representation to obtain a plurality of knowledge vectors; Obtaining a user question and converting the user question into a vector representation to obtain a question vector; Calculating the similarity between the question vector and each knowledge vector respectively, and determining a plurality of relevant knowledge vectors according to the similarity between the question vector and each knowledge vector; Constructing a first prompt word according to the text string corresponding to each relevant knowledge vector and the user question, and determining a first answer according to the first prompt word based on a pre-trained first large language model; the first large language model is a dialogue large language model; Constructing a second prompt word according to the user question and the text string set, and converting the user question into a structured query language statement according to the second prompt word based on a pre-trained second language model; the second language model is a conversational language model or a text-to-structured query language language model; Executing the structured query language statement in the database to obtain a second answer specifically includes: using a static analysis tool and a structured query language optimizer to verify and optimize the structured query language statement to obtain a verified and optimized structured query language statement; executing the verified and optimized structured query language statement in the database to obtain the second answer; A final answer is determined based on the first answer and the second answer; the first answer is in text form; the second answer is in table form.

2. The intelligent question answering method based on a large language model and a database according to claim 1, characterized in that: The text string is in Markdown format, character separated value format or JSON format.

3. The intelligent question answering method based on a large language model and a database according to claim 1, characterized in that: Each text string in the text string set includes table structure information and content information; each text string in the text string set corresponds to a data table in the database, or each text string in the text string set corresponds to a record in a data table in the database.

4. The intelligent question answering method based on a large language model and a database according to claim 1, characterized in that: An embedded large language model is used to convert each text string in the text string set into a vector representation; and an embedded large language model is used to convert the user question into a vector representation.

5. The intelligent question answering method based on a large language model and a database according to claim 1, characterized in that: Determining multiple relevant knowledge vectors according to the similarity between the question vector and each knowledge vector, specifically including: According to the similarity between the problem vector and each knowledge vector, the multiple knowledge vectors are sorted from high to low according to the similarity, and the first N knowledge vectors are used as relevant knowledge vectors, where N is the number of relevant knowledge vectors, and N>0.

6. An intelligent question answering system based on a large language model and a database, applied to the intelligent question answering method based on a large language model and a database as claimed in any one of claims 1 to 5, characterized in that: The intelligent question answering system based on a large language model and a database includes: A database data processing module, used to convert the information stored in each data table in the database into a text string to obtain a text string set; the database is a pre-built knowledge database; A vectorization processing module, connected to the database data processing module, for converting each text string in the text string set into a vector representation to obtain a plurality of knowledge vectors, obtaining user questions, and converting the user questions into vector representations to obtain question vectors; a large model retrieval generation module, connected to the vectorization processing module, for respectively calculating the similarity between the question vector and each knowledge vector, and determining a plurality of related knowledge vectors according to the similarity between the question vector and each knowledge vector, constructing a first prompt word according to the text string corresponding to each related knowledge vector and the user question, and determining a first answer according to the first prompt word based on a pre-trained first large language model; A large model text-to-sentence conversion module, connected to the vectorization processing module, is used to construct a second prompt word according to the user question and the text string set, and convert the user question into a structured query language sentence according to the second prompt word based on a pre-trained second large language model; a structured query language execution module, connected to the large model text conversion module, and configured to execute the structured query language statement in the database to obtain a second answer; The answer output module is connected to the large model retrieval generation module and the structured query language execution module respectively, and is used to determine the final answer based on the first answer and the second answer.

7. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the intelligent question-answering method based on a large language model and a database as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Knowledge base question and answer method and device, electronic equipment and storage medium

    CN117290492A

  • Automatic question answering method and device, electronic equipment and readable storage medium

    CN117851563A

  • Intelligent manufacturing capability diagnosis method and device based on large language model and knowledge graph

    CN118410175A

  • Method for automatic question-answering and apparatus therefor

    KR101678787B1

  • Database query generation using natural language text

    US11520815B1

Cited By

  • Orthosis adaptive question and answer database construction method based on machine learning

    CN121524204A

  • A machine learning-based orthosis fitting question-and-answer database construction method

    CN121524204B