Data query method, device and equipment based on recall strategy optimization RAG
By introducing RAG technology with recall strategy optimization in large language models, establishing a vector database and combining prompt word engineering, the problems of inaccurate identification and limitations of application processes in data queries are solved, and higher query accuracy and correlation are achieved.
Patent Information
- Application Number
- CN202411973425.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-11
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
There are problems in the process of inaccurate identification and limitations in the application process of existing data query based on large language models, resulting in inaccurate query content and low correlation.
Using RAG (Retrieval-Augmented Generation) technology based on recall strategy optimization, we use vector database to extract the search conditions in user questions, and combine the prompt word engineering to limit the application scenario scope to build a large language model user dialogue question and answer data query application.
It improves the accuracy of the user's natural language understanding of the large language model, avoids understanding deviations, realizes the massive data query function of user dialogue, and ensures the accuracy and application effect of the model.
Smart Images

Figure CN119807227A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a data query method, device and equipment for optimizing RAG based on a recall strategy. Background Art
[0002] With the advancement of digital transformation of enterprises, data analysis has become the key to enterprises gaining competitive advantages. The capabilities of the big language model are highly consistent with the development trend of data analysis, so data analysis has become one of the important implementation scenarios of the big model. In the past, data analysis mainly relied on professional data analysts or IT departments, and business departments often lacked the ability or tools to meet their own data analysis needs. The big language model can lower the threshold for using data analysis tools through natural language processing and generation capabilities, so that non-technical personnel can easily perform data analysis. Traditional data analysis methods often require users to have a certain technical background and operate through dragging and dropping. The conversational interaction method supported by the language big model allows users to ask questions in natural language and automatically complete data analysis and report generation, greatly improving the user's interactive experience.
[0003] However, in the existing data query process based on large language models, there is an issue of inaccurate recognition of users’ natural language. And as users’ actual needs continue to change, there are certain limitations in the processing process when facing different query scenarios, resulting in inaccurate query content and low relevance. Summary of the invention
[0004] In order to solve the problems of inaccurate recognition and limited application process in existing data query through large language models, the present invention provides a data query method, device and equipment based on recall strategy optimization RAG.
[0005] In order to achieve the above-mentioned object of the invention, the present invention provides the following technical solutions:
[0006] In a first aspect, the present invention provides a data query method for optimizing RAG based on a recall strategy, the method comprising:
[0007] Get user questions;
[0008] Performing a linear scan on the user question based on the constructed vector database to generate a query vector, and performing search and matching according to the query vector to obtain matching vector data;
[0009] Inputting the user question, the prompt word and the matched vector data into the large language model; wherein the prompt word includes a restriction condition and a query scenario, the restriction condition is used to instruct the large language model to convert the natural language into an SQL query statement, and the query scenario is used to instruct the large language model to match the corresponding database;
[0010] Acquire original data matching the user question in the database according to the SQL query statement returned by the large language model;
[0011] The large language model is combined with the user question, the original data and the context to generate an answer to the question and return it to the user.
[0012] According to a specific implementation, in the above data query method, the process of constructing the vector database includes:
[0013] The text data to be queried is cleaned and divided into blocks, and each block of text data is converted into vector data through the embedding model;
[0014] Building an index based on the Elasticsearch vector database, and storing the vector data in the index to complete the building;
[0015] The text data to be queried includes a database table structure, database table fields, and question-answer pairs based on the database table.
[0016] According to a specific implementation, in the above data query method, the user question is linearly scanned through the embedding model to generate a query vector; the embedding model adopts the bge-large-zh word embedding model.
[0017] According to a specific implementation, in the above data query method, the index adopts a nearest neighbor index, and stores the vector data through a greedy algorithm.
[0018] According to a specific implementation, in the above data query method, performing search and matching according to the query vector includes:
[0019] Calculating the cosine similarity between the query vector and the vector data;
[0020] The vector data most similar to the query vector is screened out based on a predetermined threshold.
[0021] According to a specific implementation, in the above data query method, the predetermined threshold is optimized by combining the particle swarm and the accuracy of the answer to the question to obtain the optimal threshold.
[0022] According to a specific implementation, in the above data query method, after the user receives the original data, the user's satisfaction and suggestions for the answer to the question are obtained, and the text data to be queried is optimized based on the satisfaction and suggestions.
[0023] According to a specific implementation, in the above data query method, the method further includes:
[0024] The answers to the questions are presented in a chart or table using a visualization tool.
[0025] In a second aspect, the present invention provides a data query device for optimizing RAG based on a recall strategy, the device comprising:
[0026] A dialogue module, used to create a user dialogue interface and obtain user questions and prompt words input by the user according to the user dialogue interface;
[0027] A processing module is used to implement a data query method based on a recall strategy to optimize RAG as described in any of the above items to generate a question answer.
[0028] In a third aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that when the computer program is executed by a processor, the computer executes a data query method for optimizing RAG based on a recall strategy as described in any one of the above items.
[0029] Compared with the prior art, the present invention has the following beneficial effects:
[0030] The present invention utilizes a large language model in combination with RAG technology, establishes a vector database, extracts search conditions in user questions, and then combines prompt word engineering to limit the scope of application scenarios, thereby constructing a data query application for user dialogue questions and answers of a large language model. At the same time, the present invention proposes an optimization method for optimizing the selection of vector database search results based on confidence in RAG technology according to the application scenario, so that the RAG model can more accurately understand the user's natural language, avoid understanding bias, realize the massive data query function of user dialogues, and ensure the accuracy and application effect of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 A flowchart of a data query method for optimizing RAG based on a recall strategy provided by an embodiment of the present invention;
[0032] Figure 2 The present invention provides a threshold parameter optimization process. DETAILED DESCRIPTION
[0033] The present invention is further described in detail below in conjunction with test examples and specific implementation methods. However, this should not be understood as the scope of the above subject matter of the present invention being limited to the following embodiments, and all technologies realized based on the content of the present invention belong to the scope of the present invention.
[0034] The present invention discloses a data query method, device and equipment based on a recall strategy to optimize a RAG model. The method mainly includes establishing a vector database using RAG technology, and the database includes a table structure, documents and question-answer pairs. According to user questions and answers, the prompt engineering constraint application scenario scope is used in combination with RAG technology, and the user language is converted into SQL language using the LLM large language model, and the data results are queried from the database and automatically assembled into data and chart forms for return. Finally, the vector database is optimized according to user evaluation to improve the effectiveness and reliability of the model.
[0035] The development of RAG technology also benefits from the continuous evolution of related technologies. From the initial simple RAG to advanced RAG, and then to modular RAG, RAG technology has gone through multiple stages of development and optimization. These optimizations include more sophisticated data cleaning, designing document structure, and adding metadata to improve text consistency, accuracy, and retrieval efficiency; as well as introducing query search engines, integrating multiple answers, and other technologies to break through the traditional retrieval-generation framework.
[0036] Through natural language processing and generation capabilities, RAG technology can lower the threshold for using data analysis tools, allowing non-technical personnel to easily perform data analysis.
[0037] The development background of RAG (Retrieval-Augmented Generation) technology mainly stems from the limitations and challenges faced by large language models (LLMs) in practical applications. It is against the background of the limitations of large language models and the ever-changing practical needs that RAG technology came into being. RAG technology provides a new solution for large language models by combining information retrieval and text generation technology. It retrieves relevant information from a wide range of text databases before the language model generates answers, and then uses this information to guide the generation process. This approach greatly improves the accuracy and relevance of the content, effectively alleviates the hallucination problem of large language models, increases the speed of knowledge updating, and enhances the traceability of content generation. The development of RAG technology can be divided into several key stages:
[0038] 1. Pre-training stage: Early RAG technology mainly focused on how to enhance the capabilities of language models by injecting additional knowledge through pre-training models.
[0039] 2. Rapid development after the launch of ChatGPT: With the launch of large language models such as ChatGPT, research on RAG technology has also rapidly emerged. This stage of research mainly focuses on providing LLMs with richer and more timely information to answer more complex knowledge-intensive reasoning tasks.
[0040] 3. Fine-tuning techniques and enhancement of reasoning capabilities: With the further development of the potential of LLMs, RAG's research has gradually shifted to enhancing reasoning capabilities and exploring various improvement methods in the fine-tuning process.
[0041] RAG (Retrieval-Augmented Generation) technology is an innovative model architecture that cleverly combines information retrieval with text generation. It efficiently retrieves task-related information from a large document collection or knowledge base, and uses this information as a reference for generating text. Finally, a powerful generation model (such as T5 or BART) outputs the final text or answer. This technical principle has been widely used in multiple natural language processing tasks, including building question-answering systems that can answer various questions, automatically generating article paragraphs, documents or automatic summaries, creating intelligent assistants and virtual agents, improving traditional information retrieval systems, filling entity relationships in knowledge graphs, using external knowledge bases to provide in-depth and accurate answers, achieving instant knowledge updates, highly customized capabilities for various vertical fields, and implementing security controls by restricting knowledge base permissions. RAG technology not only improves the accuracy and reliability of generated text, but also reduces training costs, bringing revolutionary changes to the field of natural language processing.
[0042] The present invention takes enterprise production operation management as the application scenario, and the data source is the enterprise production project database.
[0043] Specifically, please refer to Figure 1 , which shows a flow chart of a data query method for optimizing RAG based on a recall strategy provided by an embodiment of the present invention, the method comprising:
[0044] Step 1: Get user questions.
[0045] Step 2: Perform a linear scan on the user question based on the constructed vector database to generate a query vector, and perform search and matching based on the query vector to obtain matching vector data.
[0046] The process of constructing the vector database includes:
[0047] The text data to be queried is cleaned and divided into blocks, and each block of text data is converted into vector data through the embedding model;
[0048] Building an index based on the Elasticsearch vector database, and storing the vector data in the index to complete the building;
[0049] The text data to be queried includes a database table structure, database table fields, and question-answer pairs based on the database table.
[0050] Specifically, the collected data is cleaned, including removing noise, inaccurate information, format errors, etc. The cleaned text data is divided into smaller blocks for vector representation and retrieval. In this embodiment, behavioral units are used for block division. A deep learning word embedding model is used to convert text blocks into vector representations. These vectors can capture the semantic information of the text, so that similar texts in the vector space have similar vectors. The vectors are stored in the index for fast retrieval. In this solution, the Elasticsearch vector database is used to build the index, and the hierarchical navigable small world (HNSW) graph is used to improve retrieval efficiency.
[0051] It should be noted that Elasticsearch stores these vectors in the index. When building the index, a variety of data structures can be used to optimize vector searches. A common method is to use an approximate nearest neighbor (ANN) index. When building the index, the vectors are organized into a multi-layer graph structure. When inserting a vector, a greedy algorithm is used to connect the new vector to the existing nodes in the graph, so that when searching, you can quickly navigate to areas close to the query vector. This structure can balance the accuracy and efficiency of the search to a certain extent, because it can avoid exhaustive comparisons of all vectors.
[0052] Specifically, three text data samples are as follows:
[0053] (1) Database table structure
[0054] contract_signed_datevarchar(100)NULL DEFAULT NULL COMMENT Contract signing date
[0055] contract_typevarchar(100)NULL DEFAULT NULL COMMENT Contract type (including: traditional, engineering, investment);
[0056] industry_type varchar(200)NULL DEFAULT NULL COMMENT Industry type (highway, highway maintenance & inspection & reinforcement, municipal roads, etc.).
[0057] (2) Database table fields
[0058] "Second Transportation Design Institute"
[0059] "Central and West Africa":"Central and West Africa Transportation Design Institute"
[0060] "Central and Western Africa Institute": "Central and Western Africa Transportation Design Institute".
[0061] (3) Question-answer pairs based on database tables
[0062] What is the amount of newly signed contracts in the Beijing-Tianjin-Hebei region in the first half of 2024?
[0063] SELECT FORMAT(SUM(amount),2)AS total_amount FROM t_contract WHEREbelonging_region='Beijing-Tianjin-Hebei region'AND contract_signed_date BETWEEN'2024-01-01'AND'2024-06-30'.
[0064] Specifically, the present invention uses Elasticsearch to implement vector data storage and search. In the calculation of vector functions, all matching documents are linearly scanned. RAG is similar to providing a textbook for the model, allowing it to retrieve information based on a specific query. This method is suitable for models that need to answer specific queries or solve specific information retrieval tasks. However, RAG is not suitable for teaching models to understand a wide range of fields or learn new languages, formats or styles.
[0065] Fine-tuning is similar to having students do in-depth learning on a specific subject. This approach is useful when the model needs to replicate a specific structure, style, or format. Fine-tuning can improve the performance of the base model and make interactions more frequent and efficient. It is particularly suitable for emphasizing existing knowledge in the base model, modifying or customizing the model's output, and providing complex instructions to the model. However, fine-tuning is not suitable for incorporating new knowledge in the model or for situations that require rapid iteration of new use cases. RAG and fine-tuning are not mutually exclusive, but can complement each other and can enhance the model at different levels. In some cases, combining these two techniques can achieve the best model performance. The entire process of optimization and fine-tuning using RAG may require multiple iterations to achieve satisfactory results. Existing research has demonstrated the significant advantages of retrieval-augmented generation (RAG) compared to other methods for optimizing large language models: RAG improves accuracy by linking answers to external knowledge, reducing hallucination problems in language models, and making generated responses more accurate and reliable; the use of retrieval technology can identify the latest information. Compared with traditional language models that rely solely on training data, RAG keeps responses timely and accurate; transparency is an advantage of RAG. Users can verify the accuracy of answers through references, increasing trust in model output; RAG has customization capabilities. By indexing relevant texts, model corpora can be customized for different fields to provide knowledge support for specific fields; in terms of security and privacy management, the built-in role and security control database in RAG can better control the use of data. It can handle large-scale data sets without updating all parameters and creating training kits, making it more cost-effective; finally, the results obtained by RAG are more trustworthy. RAG selects deterministic results from the latest data, while fine-tuned models may have hallucinations and inaccuracies when processing dynamic data, lacking transparency and credibility.
[0066] After the user's question enters the vector database, it will be matched with the text data to be queried in the knowledge base. If the question is related to the document fragment in the knowledge base, the relevant document fragment will be obtained and returned, and then the similar documents and questions will be spliced and input into the big model. If the question does not match the text data to be queried in the knowledge base, similar text will be retrieved based on the question-answer pairs in the vector database and input into the big model.
[0067] According to a specific implementation, this embodiment uses the same embedding model as in the training phase to convert the user's question into a vector, and then performs index matching through the search function of the vector database.
[0068] Specifically, the present invention uses the Elasticsearch vector database to implement vector data storage and search. In the vector function calculation, all matching documents will be linearly scanned. First, a vector search is performed in the Elasticsearch vector database, and the user question needs to be converted into a vector representation. This is accomplished through a pre-trained deep learning model. The embodiment of the present invention uses the bge-large-zh word embedding model for vectorization. The model converts the input words and sentences into 1024-dimensional vectors. This process is called embedding. This vector can represent the semantic information of the sentence to some extent.
[0069] When performing a vector search, the user enters a question, which is converted into a query vector through the same embedding as that used to generate the index vector. Elasticsearch searches for the vector that is most similar to the query vector in the indexed vector space. Similarity calculation is a key step in vector search. The similarity measurement method used in this embodiment is cosine similarity, which measures the cosine value of the angle between two vectors. It pays more attention to the direction of the vector and is more effective for semantic similarity in high-dimensional space. For example, for two text vectors, a high cosine similarity means that they are more semantically similar.
[0070] During the indexing process, the search algorithm starts from the top level of the index graph, quickly locates the area that may contain similar vectors, and then gradually refines the search to the lower levels, calculating the cosine similarity between the query vector and the candidate vector, and finally returns the document corresponding to the vector that is most similar to the query vector. At the same time, Elasticsearch can also combine other filtering conditions such as text fields to further filter and sort the search results, providing information that better meets user needs.
[0071] It is understandable that in the field of natural language processing (NLP), cosine similarity is widely used as an efficient vector space model measurement method to measure the semantic similarity between two texts. In specific scenarios, such as user question-answering systems, in order to standardize and constrain the data search process and improve the ability of large models to accurately understand and respond to user statement dialogues, the present invention constructs a vector database that stores a small number of carefully selected user question-answer pairs. These question-answer pairs serve as a knowledge base and provide key reference information for the model, which helps the model more accurately locate the dialogue data conditions that meet user needs.
[0072] However, although the amount of text data in the vector database is limited, they play a vital role in the accuracy of the overall large model question answering. If all the text data in the vector database is blindly referenced during the training process, unnecessary noise may be introduced, resulting in deviations in the mapping of user question-answer pairs to database screening conditions, thus affecting the final answer quality of the model.
[0073] To overcome this challenge, the present invention cleverly introduces cosine similarity to optimize the screening process of question-answer pairs in the vector database.
[0074] Specifically, the cosine similarity is used to calculate the cosine value of the angle between the user's question vector and each question-answer pair vector in the database as an indicator to measure the semantic similarity between the two. Then, according to the set similarity threshold, the question-answer pairs that are semantically closest to the user's question are screened out. These screened question-answer pairs are returned to the big model as an important reference for the model to generate answers.
[0075] In this way, the present invention not only improves the accuracy and efficiency of question-answer pair screening in the vector database, but also further enriches the semantic understanding ability of the large model when processing user questions and answers. This method of combining cosine similarity and vector database provides a new and effective solution for user question-answering systems in the field of natural language processing, which helps to promote the continuous development and progress of related technologies.
[0076] Specifically, the implementation includes:
[0077] Calculating the cosine similarity between the query vector and the vector data;
[0078] The vector data most similar to the query vector is screened out based on a predetermined threshold.
[0079] Furthermore, a reasonable similarity threshold can be set according to actual needs, and only those question-answer pairs that exceed the standard are retained as subsequent processing objects. In the present invention, a method for selecting an optimal threshold is proposed, such as Figure 2 As shown in the figure, by introducing the optimization concept of the particle swarm algorithm, the user question and answer accuracy and similarity are used as evaluation criteria to cyclically search for the optimal threshold.
[0080] Step 3: Input the matched vector data, user questions and prompt words into the large language model.
[0081] In this embodiment, the matched vector data only retains those vector data exceeding the predetermined threshold as subsequent processing objects. In a possible implementation, the first three results exceeding the predetermined threshold are processed.
[0082] Furthermore, after the user question enters the vector database, vector data analysis will be performed and key data fields will be formed. At this time, a fixed scenario is set for the big model through the prompt word engineering to understand the scenarios of the big model and the user's question. Therefore, the big model needs to have the ability to read and understand the scenario and the ability to improve and optimize the text. Taking into account the use background of the present invention, the constraint scenario is designed in advance, the user input data and output task results are clearly pointed out, and the problem constraint restrictions are given. It is hoped that the prompt word engineering will constrain the understanding of the big model's questions and generate user answers. Therefore, the prompt word engineering in the present invention is designed as follows:
[0083] You are a senior database expert. Please understand the table structure based on the database DDL statements and generate SQL statements based on user questions.
[0084] constraint:
[0085] 1. Please understand the user's intention based on the user's question, and use the given table structure definition to create a syntactically correct SQL. If SQL is not required, directly answer the user's question (it should be noted that there is no need to generate SQL, which means no query action. For general questions, it may not be necessary to specifically query the database. In this case, the content can be generated and returned directly through the large model based on the user's question).
[0086] 2. You can only use the tables provided in the table structure information to generate SQL. If you cannot generate SQL based on the provided table structure, please say: "The provided table structure information is insufficient to generate SQL queries." It is prohibited to fabricate information at will.
[0087] 3. Be careful not to make mistakes in the relationship between tables and columns when generating SQL
[0088] 4. Please check the correctness of the SQL and optimize the query performance if it is correct.
[0089] Step 4: Obtain original data matching the user question in the database according to the SQL query statement returned by the large language model.
[0090] Step 5: Generate an answer to the question by combining the user question, the original data and the context through the large language model, and return it to the user.
[0091] The filtered data is put into a large model for assembly, and the large model is used to assemble it into natural and fluent dialogue answers based on the user's questions and context, and graphic table tools are used to build appropriate statistical charts and graphs for presentation.
[0092] Compared with the prior art, the method of the present invention has the following beneficial effects:
[0093] (1) Improving the accuracy and adaptability of the model: By embedding the text data to be queried in the current scenario into the vector database of the RAG model and performing training, the model can better understand and adapt to questions in specific scenarios, thereby improving the accuracy of the answers.
[0094] (2) Enhance the targetedness of the model: Design a reasonable and effective prompt word engineering template so that the large language model can be used in a specific scenario, which helps to improve the application effect of the model in specific fields.
[0095] (3) Ensure the accuracy of user question feedback: Add a threshold limit mechanism to the RAG vector database to determine whether to refer to the question and answer pairs to return results by judging the relevance of the question and answer pairs, thereby ensuring the accuracy of user question feedback.
[0096] (4) Optimizing model performance: The concept of particle swarm is introduced to cyclically search for the optimal threshold parameters. By setting the cyclic parameters and random values, the optimal threshold is found based on the accuracy of user question feedback, so that the overall model has the best effect.
[0097] (5) Improve data query efficiency: Provide a query method, device and apparatus for obtaining user corpus, training large models and prompt word engineering codes, and storing user dialogues, semantic decomposition and data records. This makes data query more efficient and improves user experience.
[0098] On the other hand, the present invention also provides a data query device for optimizing RAG based on a recall strategy, characterized in that the device comprises:
[0099] A dialogue module, used to create a user dialogue interface and obtain user questions and prompt words input by the user according to the user dialogue interface;
[0100] The processing module is used to implement the data query method based on the recall strategy optimization RAG as described in any one of the above items to generate a question answer. Specifically comprising:
[0101] Training module: responsible for the training of vector database, including preprocessing of massive data, text retrieval, etc.;
[0102] Search module: responsible for combining user semantics with trained data in the vector database to search and decompose user question statements and keywords.
[0103] Scenario module: The purpose of embedding prompt word engineering is to standardize the usage scenarios of large models and make the large model a proprietary model in a certain scenario.
[0104] Data module: The filtering conditions extracted by the large model are converted into database query statements (SQL statements) and input into the database for query.
[0105] Integration module: Put the filtered data into the big model for assembly, use the big model to assemble it into natural and fluent dialogue answers based on the user's questions and context, and use graphic table tools to build appropriate statistical charts and graphs for presentation.
[0106] Feedback module: Based on the user's feedback on the answers, the feedback results are returned to the training module for fine-tuning to continuously improve the accuracy of large-model question and answering.
[0107] Furthermore, an embodiment of the present invention also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer executes a data query method for optimizing RAG based on a recall strategy as described in any one of the above items.
[0108] In the embodiments of the present invention, the processor may be an integrated circuit chip having the ability to process signals. The processor may be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0109] The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present invention can be directly embodied as a hardware decoding processor for execution, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The processor reads the information in the storage medium and completes the steps of the above method in combination with its hardware.
[0110] The storage medium may be a memory, which may be, for example, a volatile memory or a nonvolatile memory, or may include both volatile and nonvolatile memory.
[0111] Among them, the non-volatile memory can be a read-only memory (ROM), a programmable ROM (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory.
[0112] The volatile memory may be a random access memory (RAM) which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), sync link DRAM (SLDRAM), and direct rambus RAM (DRRAM).
[0113] The storage media described in the embodiments of the present invention are intended to include, but are not limited to, these and any other suitable types of memory.
[0114] It should be understood that the device disclosed in the embodiment of the present invention can be implemented in other ways. For example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the communication connection between modules can be through some interfaces, indirect coupling or communication connection of servers or units, which can be electrical or other forms.
[0115] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each module may exist physically separately, or two or more modules may be integrated into one processing unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional unit.
[0116] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of 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 invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0117] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A data query method based on recall strategy optimization RAG, characterized in that: The method comprises: Get user questions; Performing a linear scan on the user question based on the constructed vector database to generate a query vector, and performing search and matching according to the query vector to obtain matching vector data; Inputting the user question, the prompt word and the matched vector data into the large language model; wherein the prompt word includes a restriction condition and a query scenario, the restriction condition is used to instruct the large language model to convert the natural language into an SQL query statement, and the query scenario is used to instruct the large language model to match the corresponding database; Acquire original data matching the user question in the database according to the SQL query statement returned by the large language model; The large language model is combined with the user question, the original data and the context to generate an answer to the question and return it to the user.
2. According to claim 1, a data query method based on recall strategy optimization RAG is characterized in that: The process of constructing the vector database includes: The text data to be queried is cleaned and divided into blocks, and each block of text data is converted into vector data through the embedding model; An index is constructed based on an Elasticsearch vector database, and the vector data is stored in the index to complete the construction; wherein the text data to be queried includes a database table structure, database table fields, and question-answer pairs based on the database table.
3. The data query method based on recall strategy optimization RAG according to claim 2 is characterized in that: The user question is linearly scanned through the embedding model to generate a query vector; the embedding model adopts the bge-large-zh word embedding model.
4. The data query method based on recall strategy optimization RAG according to claim 2 is characterized in that: The index adopts the nearest neighbor index and stores the vector data through a greedy algorithm.
5. The data query method based on recall strategy optimization RAG according to claim 2 is characterized in that: Performing search and matching according to the query vector includes: Calculating the cosine similarity between the query vector and the vector data; The vector data most similar to the query vector is screened out based on a predetermined threshold.
6. The data query method based on recall strategy optimization RAG according to claim 4 is characterized in that: The predetermined threshold is optimized by combining the particle swarm and the accuracy of the answer to the question to obtain the optimal threshold.
7. The data query method based on recall strategy optimization RAG according to claim 2 is characterized in that: After the user receives the original data, the user's satisfaction and suggestions for the answer to the question are obtained, and the text data to be queried is optimized according to the satisfaction and suggestions.
8. The data query method based on recall strategy optimization RAG according to claim 1 is characterized in that: The method further comprises: The answers to the questions are presented in a chart or table using a visualization tool.
9. A data query device based on recall strategy optimization RAG, characterized in that: The device comprises: A dialogue module, used to create a user dialogue interface and obtain user questions and prompt words input by the user according to the user dialogue interface; A processing module is used to implement a data query method based on optimizing RAG by a recall strategy as described in any one of claims 1 to 8 to generate a question answer.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer executes a data query method for optimizing RAG based on a recall strategy as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Hybrid recommendation method based on Cauchy distribution quantum-behaved particle swarm optimization
CN103971161A
Water affair industry knowledge question-answering system implementation method and system based on large language model
CN118193711A
Large model generation method and device and computer program product
CN118427214A
Intelligent question answering method, system and equipment based on large language model and database
CN118606348A
Underground coal mine early warning data query method and system based on language large model
CN118733608A
Cited By
Relational data query method and system based on RAG architecture
CN121210489A