Text retrieval method and device, electronic equipment and storage medium
By obtaining user questions and determining the target table in the database to generate high-quality SQL statements, the problem of low SQL statement quality in the prior art resulting in poor text retrieval quality is solved, and a more accurate and satisfactory text retrieval effect is achieved.
Patent Information
- Application Number
- CN202411920124.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-24
- Publication Date
- 2025-05-13
AI Technical Summary
In the prior art, the quality of SQL statement generation is low, resulting in poor quality of text retrieval and does not meet the needs of users.
By obtaining text-type user questions, determining the target table in the database based on the question, and generating target SQL statements based on the content of the target table and the second prompt word, thereby performing high-quality text retrieval in the database.
Improve the quality of SQL statements, improve the accuracy of text retrieval and the ability to meet user needs.
Smart Images

Figure CN119988576A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of text retrieval, and in particular to a text retrieval method, device, electronic device and storage medium. Background Art
[0002] SQL statement is a query statement based on database. The quality of SQL statement determines the quality of text retrieval.
[0003] In the related art, the query method is usually: the user inputs relevant query information, the system generates a relevant SQL statement according to the query information, performs text retrieval in the database based on the SQL statement, and outputs relevant information.
[0004] However, in the current technical solutions, the quality of SQL statement generation is low, resulting in poor quality of text retrieval and failing to meet user needs. Summary of the invention
[0005] The embodiments of the present application provide a text retrieval method, device, electronic device and storage medium, which are helpful for generating high-quality SQL statements.
[0006] In a first aspect, an embodiment of the present application provides a text retrieval method, including: obtaining a text-based user question; determining a target table in a database based on the text-based user question; determining a target SQL statement based on the content of the target table and a second prompt word; and searching the database based on the target SQL statement.
[0007] In one possible implementation, determining a target table in a database based on the text-based user question includes: performing keyword matching in a text-based knowledge base based on the text-based user question to obtain a first matching result, and determining a target table based on the first matching result; or, performing keyword matching in a vector-based knowledge base based on a vector-based user question to obtain a second matching result, and determining a target table based on the second matching result; or, performing keyword matching in a text-based knowledge base based on the text-based user question to obtain a first matching result, performing keyword matching in a vector-based knowledge base based on the vector-based user question to obtain a second matching result, and determining a target table based on the first matching result and the second matching result; wherein, the vector-based user question is obtained by converting the text-based user question, and the vector-based knowledge base is obtained by converting the text-based knowledge base.
[0008] In one possible implementation, the text-based knowledge base at least includes a table description, and the table description is used to represent a refined expression of each table in the text-based knowledge base.
[0009] In one possible implementation manner, the table description is determined by the table structure and the first prompt word.
[0010] In one possible implementation manner, each table in the text-based knowledge base further includes user supplementary information, and the user supplementary information is used to supplement the table description.
[0011] In one possible implementation, each table in the text-based knowledge base also includes historical question-answer pairs, and the historical question-answer pairs include historical SQL statements and historical user questions.
[0012] In one possible implementation, after determining the target SQL statement based on the content of the target table and the second prompt word, the method further includes: in response to a user's selection operation, combining the target SQL statement and the text-based user question into a target question-answer pair; and updating the target question-answer pair to the historical question-answer pairs.
[0013] In one possible implementation, the first matching result includes n matching results, and each matching result of the n matching results includes m tables ranked top m in terms of recall rate; the second matching result includes n matching results, and each matching result of the n matching results includes m tables ranked top m in terms of recall rate; determining the target table based on the first matching result includes: counting the number of occurrences of each table in the first matching result, and taking the table with the highest number of occurrences in the first matching result as the target table; determining the target table based on the second matching result includes: counting the number of occurrences of each table in the second matching result, and taking the table with the highest number of occurrences in the second matching result as the target table; determining the target table based on the first matching result and the second matching result includes: counting the number of occurrences of each table in the first matching result and the second matching result, and taking the table with the highest number of occurrences in the first matching result and the second matching result as the target table.
[0014] In a second aspect, an embodiment of the present application provides a text retrieval device, comprising one or more functional modules, wherein the one or more functional modules are used to execute the text retrieval method as described in the first aspect.
[0015] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor and a memory, wherein the memory is used to store a computer program; the processor is used to run the computer program to implement the text retrieval method as described in the first aspect.
[0016] In a fourth aspect, an embodiment of the present application provides a readable storage medium, in which a program is stored. When the program is executed on an electronic device, the electronic device implements the text retrieval method as described in the first aspect.
[0017] In a fifth aspect, an embodiment of the present application provides a program, which, when executed on a processor of an electronic device, enables the electronic device to execute the text retrieval method as described in the first aspect.
[0018] In one possible design, the program in the fifth aspect may be stored in whole or in part on a storage medium packaged together with the processor, or may be stored in whole or in part on a memory not packaged together with the processor. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 A schematic diagram of the system architecture provided for an embodiment of the present application;
[0020] Figure 2 A flowchart of an embodiment of the text retrieval method provided in this application;
[0021] Figure 3 A schematic diagram of a knowledge base generation process provided in an embodiment of the present application;
[0022] Figure 4 A flowchart of another embodiment of the text retrieval method provided by the present application;
[0023] Figure 5 A schematic diagram of the structure of a text search device provided in an embodiment of the present application;
[0024] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0025] In the embodiments of the present application, unless otherwise specified, the character " / " indicates that the objects before and after the association are in an or relationship. For example, A / B can represent A or B. "And / or" describes the association relationship of the associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone.
[0026] It should be pointed out that the words "first", "second", etc. involved in the embodiments of the present application are only used to distinguish the description purpose, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated, nor can they be understood as indicating or implying order.
[0027] In the embodiments of the present application, "at least one" refers to one or more, and "plurality" refers to two or more. In addition, "at least one of the following" or similar expressions refers to any combination of these items, which may include any combination of single items or plural items. For example, at least one of A, B, or C may represent: A, B, C, A and B, A and C, B and C, or A, B and C. Among them, each of A, B, and C may be an element itself, or a set containing one or more elements.
[0028] In the embodiments of the present application, "exemplary", "in some embodiments", "in another embodiment", etc. are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of the word "exemplary" is intended to present concepts in a concrete way.
[0029] In the embodiments of the present application, "of", "corresponding", and "corresponding" can sometimes be used interchangeably. It should be noted that when the distinction between them is not emphasized, the meanings to be expressed are consistent. In the embodiments of the present application, communication and transmission can sometimes be used interchangeably. It should be noted that when the distinction between them is not emphasized, the meanings to be expressed are consistent. For example, transmission can include sending and / or receiving, which can be a noun or a verb.
[0030] The equal to involved in the embodiments of the present application can be used in conjunction with greater than, and is applicable to the technical solution adopted when greater than, and can also be used in conjunction with less than, and is applicable to the technical solution adopted when less than. It should be noted that when equal to is used in conjunction with greater than, it cannot be used in conjunction with less than; when equal to is used in conjunction with less than, it cannot be used in conjunction with greater than.
[0031] SQL statement is a query statement based on database. The quality of SQL statement determines the quality of text retrieval.
[0032] In the related art, the query method is usually: the user inputs relevant query information, the system generates a relevant SQL statement according to the query information, performs text retrieval in the database based on the SQL statement, and outputs relevant information.
[0033] However, in the current technical solutions, the quality of SQL statement generation is low, resulting in poor quality of text retrieval and failing to meet user needs.
[0034] Based on the above problems, this application provides a text retrieval method that helps to generate high-quality SQL statements.
[0035] Figure 1A schematic diagram of the system architecture provided for an embodiment of the present application.
[0036] refer to Figure 1 The system architecture may include a large language model 10 , a database 11 and a knowledge base 12 .
[0037] The large language model 10 is used to generate an SQL statement based on the user's question and the prompt word input by the user. The SQL statement is used to perform text search in the database to output corresponding search information.
[0038] It is understandable that, in the process of the large language model 10 generating SQL statements based on the user's question and the prompt word input by the user, the SQL statements can be generated based on the relevant information of the knowledge base.
[0039] The knowledge base may include multiple tables, and each table may include a corresponding table description.
[0040] In some optional embodiments, each table may also include user supplementary information.
[0041] In some optional embodiments, each table may also include historical question-answer pairs.
[0042] Among them, historical question and answer pairs can be generated by historical user questions and historical SQL statements.
[0043] Figure 2 The flowchart of an embodiment of the text retrieval method provided in this application includes the following steps:
[0044] Step 201, obtaining user questions.
[0045] Specifically, the user question may be a text sentence.
[0046] Step 202: determine a target table in a database based on the user's question.
[0047] Specifically, the database may include multiple tables, and the user's question may be used to perform text retrieval in the database, that is, the user's question may be used to perform text retrieval in multiple tables in the database.
[0048] The database can generate a corresponding textual knowledge base.
[0049] Each table in the knowledge base may include a corresponding table description, which may be used to represent a concise expression of the table in the text-based knowledge base, and the table description may be a sentence. The table description may be generated based on the table structure in the database and the first prompt word.
[0050] Exemplarily, the table structure of any table in the database and the first prompt word may be input into a preset large language model, thereby generating a table description corresponding to the table.
[0051] The first prompt word may be a prompt word input by the user. The large language model may be a pre-trained language model. The specific technical details of the large language model may refer to the description in the related art, which will not be repeated here.
[0052] In some optional embodiments, before generating a table description, the user may also clean the table structure to remove redundant information, thereby improving the efficiency and accuracy of the data foundation.
[0053] In some optional embodiments, in addition to the above table descriptions, each table in the database may also contain user supplementary information.
[0054] It is understandable that the above table description may not be accurate enough or complete enough because it is automatically generated by the model. In this case, the user can enter corresponding supplementary information, and the user supplementary information can be used to supplement the table description, that is, to improve the table description.
[0055] In some optional embodiments, in addition to the above table descriptions and user supplementary information, each table in the database may also contain historical question-answer pairs.
[0056] Among them, historical question and answer pairs can include historical user questions and historical SQL statements.
[0057] It is understandable that in the related art, text retrieval is performed in the full text of the database, that is, the text retrieval is for all tables, which is not targeted and the retrieval results are inaccurate.
[0058] The embodiment of the present application can first locate the target table, and determine the corresponding SQL statement based on the target table, so that the SQL statement is more targeted, thereby improving the accuracy of the search results.
[0059] Among them, the methods of determining the target table based on the user's question may include the following three:
[0060] Method 1: text retrieval based on text-based knowledge base.
[0061] It is understandable that in method 1, a text-based knowledge base may be used.
[0062] Now we take the text-based knowledge base containing table descriptions, user supplementary information and historical question-answer pairs as an example, and combine Figure 3 An example description of a text-based knowledge base is given below.
[0063] refer to Figure 3, the table structure of all tables can be obtained from the database, and the corresponding table description can be generated through the table structure of each table and the first prompt word entered by the user. Then, a text-based knowledge base can be generated based on the table descriptions of all tables, user supplementary information and historical question and answer pairs.
[0064] In the related art, when a large language model is associated with other databases, the large language model needs to be retrained, and the transferability is poor. The embodiment of the present application constructs a knowledge base so that the large language model can be associated with other databases without retraining, and the transferability is good.
[0065] It can be understood that the above examples only illustrate the example of a text-based knowledge base including table descriptions, user supplementary information and historical question and answer pairs. In some embodiments, the text-based knowledge base may also only include part of the table descriptions, user supplementary information and historical question and answer pairs, and the embodiments of the present application do not specifically limit this.
[0066] It is understandable that the text-based knowledge base contains multiple text-based tables, and each text-based table may contain a corresponding table description, user supplementary information, and historical question and answer pairs.
[0067] Next, through the text-based user questions, n keyword matches can be performed in the text-based knowledge base, where in each keyword match, m tables with the top m recall rates can be output. Next, the number of occurrences of each table in these n keyword matches can be counted, and the table with the most occurrences can be used as the target table. Where n and m are positive integers greater than 1.
[0068] Method 2: text retrieval based on vector knowledge base.
[0069] It is understandable that in method 2, a vector knowledge base may be used.
[0070] Among them, the vector knowledge base can be converted from the text knowledge base.
[0071] For example, an Embedding network can be used to convert a text-based knowledge base into a vector-based knowledge base.
[0072] It is understandable that the vector-type knowledge base may include multiple vector-type tables, wherein each vector-type table may include table description, user supplementary information, historical question-and-answer pairs and other related information.
[0073] The specific method of acquiring the text-based knowledge base can refer to the relevant description in the above embodiment, which will not be repeated here.
[0074] The text-based user questions are converted into vector-based user questions, and the vector-based user questions can be used to perform n keyword matches in the vector-based knowledge base, wherein in each keyword match, m tables with the top m recall rates can be output. Then, the number of occurrences of each table in these n keyword matches can be counted, and the table with the most occurrences can be used as the target table.
[0075] Method 3: text retrieval based on text-based knowledge base and vector-based knowledge base.
[0076] It is understandable that method 3 can be considered as a combination of method 1 and method 2.
[0077] In method 3, n keyword matches can be performed in the text-based knowledge base through text-based user questions, wherein in each keyword match, m tables with the top m recall rates can be output. n keyword matches can be performed in the vector-based knowledge base through vector-based user questions, wherein in each keyword match, m tables with the top m recall rates can be output. It can be seen that through the above 2n keyword matches, 2n*m output results can be obtained. Then, the number of occurrences of each table in these 2n*m output results can be counted, and the table with the most occurrences can be used as the target table.
[0078] Step 203: determine the target SQL statement based on the content of the target table and the second prompt word.
[0079] Specifically, after the target table is determined, the content of the target table may be obtained.
[0080] Next, the target SQL statement may be determined based on the content of the target table and the second prompt word.
[0081] The second prompt word may be a related prompt word input by the user.
[0082] Exemplarily, the content of the target table and the second prompt word may be input into a preset large language model, thereby generating a corresponding SQL statement.
[0083] Step 204: search in the database based on the target SQL statement.
[0084] Specifically, after searching in the database based on the target SQL statement, corresponding search results can be obtained.
[0085] In the related art, the quality of SQL statements is limited by the capabilities of the large language model itself. This application determines a more targeted target table through user input information, and generates SQL statements based on the target table, so that the SQL statements are not limited by the capabilities of the large language model itself, are more targeted, and the retrieval results are more accurate.
[0086] The above Figure 1-Figure 3 The text retrieval method provided in the embodiment of the present application is exemplarily described. In some optional embodiments, the historical question-answer pairs in the knowledge base can also be updated to enrich and improve the knowledge base, thereby facilitating the generation of high-quality SQL statements.
[0087] Figure 4 This is a flowchart of another embodiment of the text retrieval method provided by the present application. After step 203, the following steps may also be included:
[0088] Step 401, in response to a user's selection operation, a target SQL statement and a user's question are combined into a target question-answer pair.
[0089] Specifically, after obtaining the search results, the user can evaluate the quality of the SQL statement based on the search results.
[0090] If the user feels that the search results meet the user's needs, it can be determined that the SQL statement generated this time is of high quality. In this case, the user can combine the SQL statement generated this time (for the convenience of explanation, the SQL statement generated this time is called the target SQL statement) with the user's question this time to form a target question-answer pair. Or,
[0091] If the user feels that the search results do not meet the user's needs, there is no need to form a target question-answer pair, that is, the question-answer pairs with poor quality can be filtered out to avoid error accumulation and ensure the long-term accuracy and effectiveness of the knowledge base.
[0092] Step 402: Update the target question-answer pair to the historical question-answer pairs in the knowledge base.
[0093] Figure 5 A schematic diagram of the structure of a text search device provided in an embodiment of the present application is shown in FIG. Figure 5 As shown, the text search device 50 comprises: an acquisition module 51, a determination module 52 and a search module 53; wherein,
[0094] An acquisition module 51 is used to acquire a text-based user question;
[0095] A determination module 52 is used to determine a target table in the database based on the text-based user question; and to determine a target SQL statement based on the content of the target table and a second prompt word;
[0096] The retrieval module 53 is used to search the database based on the target SQL statement.
[0097] In one possible implementation, the determination module 52 is further configured to perform keyword matching in a text-based knowledge base based on the text-based user question to obtain a first matching result, and determine a target table based on the first matching result; or
[0098] Perform keyword matching in a vector-based knowledge base based on the vector-based user question to obtain a second matching result, and determine a target table based on the second matching result; or
[0099] Perform keyword matching in a text-based knowledge base based on the text-based user question to obtain a first matching result, perform keyword matching in a vector-based knowledge base based on the vector-based user question to obtain a second matching result, and determine a target table based on the first matching result and the second matching result;
[0100] The vector-type user question is obtained by converting the text-type user question, and the vector-type knowledge base is obtained by converting the text-type knowledge base.
[0101] In one possible implementation, the text-based knowledge base at least includes a table description, and the table description is used to represent a refined expression of each table in the text-based knowledge base.
[0102] In one possible implementation manner, the table description is determined by the table structure and the first prompt word.
[0103] In one possible implementation manner, each table in the text-based knowledge base further includes user supplementary information, and the user supplementary information is used to supplement the table description.
[0104] In one possible implementation, each table in the text-based knowledge base also includes historical question-answer pairs, and the historical question-answer pairs include historical SQL statements and historical user questions.
[0105] In one possible implementation, the text search device 50 further includes:
[0106] An updating module, configured to form a target question-answer pair by combining the target SQL statement and the text-based user question in response to a user selection operation;
[0107] The target question-answer pair is updated to the historical question-answer pair.
[0108] In one possible implementation, the first matching result includes n matching results, each of which includes m tables ranked top m in terms of recall rate; the second matching result includes n matching results, each of which includes m tables ranked top m in terms of recall rate;
[0109] The determination module 52 is further configured to count the number of occurrences of each table in the first matching result, and to use the table with the highest number of occurrences in the first matching result as the target table;
[0110] The determination module 52 is further configured to count the number of occurrences of each table in the second matching result, and to use the table with the highest number of occurrences in the second matching result as the target table;
[0111] The determination module 52 is further configured to count the number of occurrences of each table in the first matching result and the second matching result, and use the table with the highest number of occurrences in the first matching result and the second matching result as the target table.
[0112] Figure 5 The text retrieval device 5 provided in the exemplary embodiment can be used to execute the technical solution of the method embodiment shown in this application. Its implementation principle and technical effects can be further referred to the relevant description in the method embodiment.
[0113] It should be understood that the division of the various modules of the above text retrieval device 5 is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software calling through processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software calling through processing elements, and some modules can be implemented in the form of hardware. For example, the detection module can be a separately established processing element, or it can be integrated in a chip of a terminal device. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together, or they can be implemented independently. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in a processor element or instructions in the form of software.
[0114] For example, the above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more microprocessors (DSP), or one or more field programmable gate arrays (FPGA). For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0115] Figure 6The present invention provides a schematic diagram of the structure of an electronic device 600 provided in an embodiment of the present invention. The electronic device 600 may include: at least one processor; and at least one memory connected to the processor in communication. The memory stores program instructions executable by the processor. The processor in the electronic device 600 calls the program instructions to perform the actions performed in the storage access method provided in the embodiment of the present invention.
[0116] like Figure 6 As shown, the electronic device 600 is in the form of a general computing device. The components of the electronic device 600 may include but are not limited to: one or more processors 610, a memory 620, a communication bus 640 connecting different system components (including the memory 620 and the processor 610), and a communication interface 630.
[0117] The communication bus 640 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor or a local bus using any of a variety of bus structures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnection (PCI) bus.
[0118] The electronic device 600 typically includes a variety of computer system readable media, which can be any available media that can be accessed by the terminal device, including volatile and non-volatile media, removable and non-removable media.
[0119] The memory 620 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) and / or cache memory. The terminal device may further include other removable / non-removable, volatile / non-volatile computer system storage media. Figure 6Not shown, a disk drive for reading and writing a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing a removable non-volatile optical disk (e.g., a compact disc read only memory (CD-ROM), a digital versatile disc read only memory (DVD-ROM), or other optical media) may be provided. In these cases, each drive may be connected to the communication bus 640 via one or more data medium interfaces. The memory 620 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present application.
[0120] A program / utility having a set (at least one) of program modules may be stored in memory 620, such program modules including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules generally perform the functions and / or methods of the embodiments described herein.
[0121] The electronic device 600 may also communicate with one or more external devices (e.g., keyboard, pointing device, display, etc.), one or more devices that enable a user to interact with the terminal device, and / or any device that enables the terminal device to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through the communication interface 630. In addition, the electronic device 600 may also communicate with the network adapter ( Figure 6 The network adapter can communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through the communication bus 640. It should be understood that although Figure 6 Not shown, other hardware and / or software modules may be used in conjunction with the electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, disk arrays (Redundant Arrays of Independent Drives; hereinafter referred to as: RAID) systems, tape drives, and data backup storage systems.
[0122] The processor 610 executes various functional applications and data processing by running the programs stored in the memory 620, such as implementing the method provided in the embodiment of the present application.
[0123] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 600. In other embodiments of the present application, the electronic device 600 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0124] In the above embodiments, the processor involved may include, for example, a CPU, a DSP, a microcontroller or a digital signal processor, and may also include a GPU, an embedded neural network processor (Neural-network Process Units; hereinafter referred to as: NPU) and an image signal processor (Image Signal Processing; hereinafter referred to as: ISP). The processor may also include necessary hardware accelerators or logic processing hardware circuits, such as ASIC, or one or more integrated circuits for controlling the execution of the program of the technical solution of the present application. In addition, the processor may have the function of operating one or more software programs, and the software programs may be stored in a storage medium.
[0125] An embodiment of the present application also provides a readable storage medium, which stores a program. When the program is run on a terminal device, the terminal device executes the method provided by the embodiment shown in the present application.
[0126] An embodiment of the present application also provides a program product, which includes a program. When the program product is run on a terminal device, the terminal device executes the method provided by the embodiment shown in the present application.
[0127] In the embodiments of the present application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent the existence of A alone, the existence of A and B at the same time, and the existence of B alone. Among them, A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" and similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b and c can be represented by: a, b, c, a and b, a and c, b and c, or a and b and c, where a, b, c can be single or multiple.
[0128] Those of ordinary skill in the art will appreciate that the various units and algorithm steps described in the embodiments disclosed herein can be implemented in a combination of electronic hardware, computer software, and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0129] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0130] In several embodiments provided in the present application, if any function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory; hereinafter referred to as: ROM), random access memory (Random Access Memory; hereinafter referred to as: RAM), disk or optical disk, and other media that can store program codes.
[0131] The above is only a specific implementation of the present application. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. The protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A text retrieval method, characterized in that: The method comprises: Get text-based user questions; Determine a target table in a database based on the text-based user question; Determine a target SQL statement based on the content of the target table and the second prompt word; The database is searched based on the target SQL statement.
2. The method according to claim 1, characterized in that Determining a target table in a database based on the text-based user question includes: Perform keyword matching in a text-based knowledge base based on the text-based user question to obtain a first matching result, and determine a target table based on the first matching result; or Perform keyword matching in a vector-based knowledge base based on the vector-based user question to obtain a second matching result, and determine a target table based on the second matching result; or Perform keyword matching in a text-based knowledge base based on the text-based user question to obtain a first matching result, perform keyword matching in a vector-based knowledge base based on the vector-based user question to obtain a second matching result, and determine a target table based on the first matching result and the second matching result; The vector-type user question is obtained by converting the text-type user question, and the vector-type knowledge base is obtained by converting the text-type knowledge base.
3. The method according to claim 2, characterized in that The text-based knowledge base at least includes a table description, and the table description is used to represent a refined expression of each table in the text-based knowledge base.
4. The method according to claim 3, characterized in that The table description is determined by the table structure and the first prompt word.
5. The method according to claim 3 or 4, characterized in that: Each table in the text-based knowledge base also includes user supplementary information, and the user supplementary information is used to supplement the table description.
6. The method according to claim 5, characterized in that Each table in the text-based knowledge base also includes historical question-answer pairs, and the historical question-answer pairs include historical SQL statements and historical user questions.
7. The method according to claim 6, characterized in that After determining the target SQL statement based on the content of the target table and the second prompt word, the method further includes: In response to a user's selection operation, the target SQL statement and the text-based user question are combined into a target question-answer pair; The target question-answer pair is updated to the historical question-answer pair.
8. The method according to claim 2, characterized in that: The first matching result includes n matching results, and each matching result in the n matching results includes m tables ranked top m in terms of recall rate; the second matching result includes n matching results, and each matching result in the n matching results includes m tables ranked top m in terms of recall rate; Determining the target table based on the first matching result includes: Counting the number of occurrences of each table in the first matching result, and taking the table with the highest number of occurrences in the first matching result as the target table; Determining the target table based on the second matching result includes: Counting the number of occurrences of each table in the second matching results, and taking the table with the highest number of occurrences in the second matching results as the target table; The determining a target table based on the first matching result and the second matching result comprises: The number of occurrences of each table in the first matching result and the second matching result is counted, and the table with the highest number of occurrences in the first matching result and the second matching result is used as the target table.
9. A text retrieval device, characterized in that: The device comprises: The acquisition module is used to obtain text-based user questions; A determination module, used to determine a target table in a database based on the text-based user question; and to determine a target SQL statement based on the content of the target table and a second prompt word; A retrieval module is used to search in the database based on the target SQL statement.
10. An electronic device, characterized in that: include: A processor and a memory, wherein the memory is used to store a program; and the processor is used to run the program to implement the text retrieval method as described in any one of claims 1 to 8.
11. A readable storage medium, characterized in that: The readable storage medium stores a program, and when the program is run on an electronic device, the text retrieval method according to any one of claims 1 to 8 is implemented.