A method and system for integrating retrieval and enhancing generation capabilities
By constructing a basic SQL set and query condition reasoning driven by a large language model, the high cost of storage and computing resources in the integration of AI chatbots with traditional business systems is solved, realizing low-cost, real-time, and efficient RAG technology integration, which is suitable for various business scenarios such as e-commerce customer service, government affairs consultation, and financial inquiry.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANDONG XINGWEI JIUZHOU SECURITY TECH CO LTD
- Filing Date
- 2026-04-02
- Publication Date
- 2026-06-30
AI Technical Summary
Existing technologies for integrating AI chatbots with traditional business systems suffer from high storage costs, high computational resource requirements, poor real-time performance, limited hardware resources, and insufficient query accuracy. In particular, they are difficult to achieve efficient and stable operation in small parameter models and resource-constrained environments.
By constructing a basic SQL set, performing field semantic analysis, utilizing a large language model for intent analysis and query condition reasoning, generating rule-driven SQL query statements, and combining a dynamic correction mechanism, data can be queried directly in a relational database, avoiding dependence on vector databases and knowledge graphs, adapting to small parameter models, and realizing a lightweight RAG technology solution.
It achieves low-cost, low-resource-consumption RAG technology integration, ensuring system real-time performance and query accuracy, adapting to small-parameter models, reducing hardware resource requirements, and is suitable for various business scenarios, especially for small and medium-sized enterprises and edge computing environments.
Smart Images

Figure CN122045226B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of artificial intelligence technology, specifically relating to a method and system for integrating search and enhanced generation capabilities. Background Technology
[0002] With the rapid development of artificial intelligence technology, especially the increasing maturity of natural language processing technology represented by large language models, many enterprises are actively exploring the integration of AI chatbots into their existing business systems in order to improve customer service efficiency and reduce human resource costs. However, traditional business systems are usually built on relational databases (such as MySQL, Oracle, and SQL Server) or search engines (such as Elasticsearch), whose data structures are complex, updated frequently, and typically lack semantic-based query capabilities, thus posing significant challenges to the effective integration of AI.
[0003] Currently, the mainstream technological approaches for integrating AI with existing business systems mainly include the following:
[0004] RAG scheme based on vector database:
[0005] The solution transforms business data into vectors, stores them in a dedicated vector database, retrieves relevant context through semantic similarity, and then uses a large language model to generate responses. While this approach excels in semantic understanding, it also has several significant limitations: it requires an additional vector database, increasing storage costs and architectural complexity; business data needs to be synchronized to the vector database via an ETL process, making real-time performance difficult to guarantee, and the development and maintenance costs of the synchronization process are high; furthermore, it has high requirements for computing resources, especially GPU memory and computing power, making it unsuitable for deployment scenarios with small-parameter models (such as 8B-32B) in resource-constrained environments.
[0006] Text-to-SQL solution:
[0007] This approach directly converts user queries into SQL statements using a large language model, retrieving results directly from the database. The challenges of this approach are: generating accurate SQL becomes drastically more difficult when dealing with complex database structures (such as multi-table joins and nested queries); models with smaller parameter sets have limited reasoning capabilities, leading to SQL statements prone to syntax errors or logical inconsistencies, and difficulty in accurately understanding field meanings, potentially resulting in incorrect or incomplete query results.
[0008] Knowledge graph-based RAG solution:
[0009] Transforming business data into knowledge graphs and leveraging graph databases for relational reasoning and retrieval offers certain advantages in handling complex relationships, but its application is also limited: building high-quality knowledge graphs requires a large number of tokens and places high demands on model context length; the construction and maintenance costs of the graph are high, making it unsuitable for small and medium-sized enterprises with limited resources; and it is not applicable to dynamic business scenarios where data changes frequently.
[0010] Furthermore, existing RAG solutions generally rely on high-performance GPUs, large video memory, and large models with long context windows, making them difficult to deploy on edge devices or low-configuration servers. This greatly limits the promotion and application of related technologies in traditional enterprises.
[0011] In summary, there is an urgent need for a search augmentation generation (RAG) technology solution that can achieve high efficiency, stability, and low cost without modifying existing business systems, relying on vector databases, adapting to small parameter models, and having low hardware resource requirements, so as to systematically solve the various problems faced by the existing methods. Summary of the Invention
[0012] In view of this, the purpose of this invention is to provide a low-cost, highly compatible, and low-resource-consumption RAG (Retrieval Enhancement Generation) implementation method, specifically designed to solve the following technical problems:
[0013] How to achieve seamless integration of AI chatbots with traditional business systems without altering the existing backend architecture and database structure;
[0014] How to avoid dependence on vector databases or knowledge graphs, thereby significantly reducing the overhead of storage and computing resources;
[0015] How to adapt to models with a moderate number of parameters (8B-32B) and ensure that they can still run stably in hardware environments with limited inference capabilities and scarce video memory resources;
[0016] How to accurately retrieve core data that is highly relevant to the user's question even when the model context length is limited;
[0017] How to effectively perform intent recognition, condition extraction, and structured query language (SQL) generation for natural language problems without relying on complex NLP models or external services;
[0018] Ultimately, a lightweight, reusable, easy-to-deploy, and highly real-time RAG technology solution was developed, enabling it to be widely applied to various business scenarios such as e-commerce customer service, government affairs consultation, and financial inquiries.
[0019] The first aspect of this invention provides a method for integrating enhanced retrieval capabilities, comprising the following steps:
[0020] S1: Construct a basic SQL set. Each basic SQL in the basic SQL set corresponds to a preset business intent and includes a statement that queries specific business fields from the database and placeholder condition fields for dynamically populating query conditions. The basic SQL includes placeholder condition fields after the WHERE clause for subsequent dynamic concatenation of query conditions.
[0021] S2: Based on the database fields involved in the basic SQL set, perform semantic analysis on each field and establish a mapping relationship between the field and the noun type, wherein the noun type is used to describe the semantic category to which the field content belongs;
[0022] S3: Receive the user's natural language question, perform intent analysis using a large language model, and match and select one or more basic SQL statements corresponding to the natural language question from the basic SQL set;
[0023] S4: Based on the mapping relationship between the fields and noun types, use a large language model to perform query condition reasoning on the natural language question, extract the specific nouns corresponding to the noun types, process the specific nouns into compound words, and generate expanded words from the processed nouns to obtain the query conditions;
[0024] S5: Based on the selected base SQL and the query conditions, generate an executable complete SQL query statement according to preset rules;
[0025] S6: Execute the complete SQL query statement, retrieve the query results from the database, and dynamically correct the query results to make them conform to the preset context length requirements;
[0026] S7: Combine the natural language question and the corrected query results into prompt words, input them into the large language model, and generate a natural language answer.
[0027] In step S4, the compound word processing of the specific noun further includes: performing word segmentation on the compound noun; removing the cohesive words in the word segmentation results and retaining the free words; using a large language model to determine the inclusion or subordinate relationship between the free words, removing the hypernyms and retaining the hyponyms as keywords.
[0028] In step S4, generating extended words for the specific noun further includes: generating one or more of the following: synonyms, hyponyms, pinyin, or English translations for the specific noun, and the extended words are on the same level as the original noun to enhance the matching coverage.
[0029] The mapping relationship between fields and noun types established in step S2 also includes introducing dummy variables "start date" and "end date" for the date field to handle time range descriptions.
[0030] The preset rules in step S5 include: for date fields, using range comparison operators to construct conditions; for query conditions of different fields, using AND logical operators to connect them; for different noun types under the same field or multiple nouns / extended words under the same noun type, using OR logical operators to connect them; for multiple sub-nouns split from compound words, using AND logical operators to connect them; and all field matching is implemented using fuzzy matching.
[0031] The step S6 of dynamically correcting the query results further includes: determining whether the estimated number of tokens in the query results exceeds a preset threshold; if it exceeds the first threshold, changing the connection method between fields in the SQL statement from AND to OR to expand the query range and then querying again; if the result is empty, changing the connection method between fields in the SQL statement from OR to AND to narrow the query range and then querying again, or increasing the range of expanded terms and then querying again.
[0032] The step S6 of dynamically correcting the query results further includes: if the estimated number of tokens for the query results is between the first threshold and the second threshold, then the similarity between each query result and the user's question is calculated using an embedding model, and some results with low similarity are removed until the total number of tokens is lower than the preset requirement.
[0033] The basic SQL constructed in step S1 explicitly lists the specific field names in its query fields and assigns aliases to the fields that help the large language model understand them.
[0034] In step S7, when combining the corrected query results into prompt words, the header and data content of the query results are combined into a complete table and input into the large language model. The header is a field alias defined in SQL.
[0035] In a second aspect, the present invention provides a system for retrieving enhanced generation capabilities, used to perform the method, comprising:
[0036] Basic SQL building module: configured to build and store a basic SQL set, each basic SQL in the basic SQL set corresponding to a preset business intent and containing a statement for querying specific business fields from the database as well as placeholder condition fields;
[0037] The semantic analysis module is configured to establish and store the mapping relationship between fields and noun types based on the database fields involved in the underlying SQL set.
[0038] Intent analysis module: configured to receive natural language questions from users and use a large language model to match and select one or more corresponding basic SQL queries from the set of basic SQL queries;
[0039] Conditional reasoning module: configured to perform query conditional reasoning on the natural language question based on the mapping relationship between the field and the noun type, extract the specific noun corresponding to the noun type, and perform word expansion generation and / or compound word processing on the specific noun to obtain the query conditions;
[0040] SQL generation module: configured to generate executable complete SQL query statements according to preset rules based on the selected base SQL and the query conditions;
[0041] The query and correction module is configured to execute the complete SQL query statement, retrieve the query results from the database, and dynamically correct the query results to make them conform to the preset context length requirements.
[0042] The large language model interaction module is configured to combine the natural language question and the corrected query results into prompt words, input them into the large language model, and obtain the generated natural language answer.
[0043] The beneficial effects of this invention are:
[0044] Compared with the prior art, the present invention exhibits the following outstanding advantages:
[0045] 1. Extremely low deployment cost, fully reusing existing infrastructure:
[0046] This invention requires no additional deployment of vector databases, knowledge graphs, or dedicated hardware. It can run entirely on the enterprise's existing relational databases (such as MySQL and Oracle) and lightweight large language models. Compared to traditional RAG solutions that require building dedicated vector storage clusters and developing complex ETL data synchronization processes, this invention significantly reduces storage resource overhead and system construction costs, has a short implementation cycle, and is particularly suitable for small and medium-sized enterprises with limited budgets and hardware resources, as well as edge computing scenarios.
[0047] 2. Completely eliminate vectorization dependencies and improve system real-time performance:
[0048] This invention completely bypasses the text vectorization process by using field semantic analysis and rule-driven SQL generation. Traditional solutions require synchronizing business data to a vector library and performing similarity retrieval, resulting in significant data synchronization delays. This invention directly queries the source database, and updates to business data are reflected in the query results in real time, ensuring the timeliness and accuracy of information and effectively solving the pain point of "data lag" in traditional RAG solutions.
[0049] 3. Adapts to small parameter models with low hardware resource consumption:
[0050] This invention employs rule-based condition construction and fuzzy matching techniques to transform complex semantic retrieval problems into structured database query tasks, significantly reducing the requirements for the reasoning capabilities of large language models. Experiments show that this solution can run stably under the configuration of the implementation example, with a GPU memory usage of less than 10GB, perfectly adapting to small parameter models ranging from 8B to 32B, and solving the deployment bottleneck of traditional solutions that rely on high-performance GPUs and large GPU memory support (>24GB).
[0051] 4. Low context length requirement, dynamic correction mechanism ensures stability:
[0052] This invention controls the scale of query results from the source by using a preset "basic SQL + dynamic conditions" mode. Simultaneously, it introduces a dynamic correction mechanism based on a token threshold, automatically adjusting the query granularity or performing similarity filtering when the returned data volume is too large, ensuring that the context length of the input language model remains controllable. This allows the solution to adapt to small models with limited context windows, avoiding model inference failures or performance degradation due to excessively long inputs.
[0053] 5. High query accuracy and interpretability:
[0054] This invention eliminates the uncontrollable risks of "black box" SQL generation in traditional Text2SQL solutions. It adopts a rule-driven approach to construct query statements, resulting in clear SQL structures and traceable logic. The mapping relationship between fields and noun types, the rules for handling compound words, and the logic for generating extended words are all explicitly defined, facilitating debugging, auditing, and optimization by maintenance personnel, and significantly improving the interpretability and reliability of the system.
[0055] 6. Wide range of applications and strong scalability:
[0056] The core mechanism of this invention does not depend on a specific database type or business domain. As long as the target system supports standard SQL or SQL-like query languages (such as Elasticsearch's DSL), it can be quickly integrated by adapting the basic SQL and field mapping relationships. It has been successfully applied to various business scenarios such as e-commerce customer service, government affairs consultation, and financial inquiries, demonstrating good versatility and portability.
[0057] In summary, this invention achieves efficient, stable, and real-time RAG capability integration with extremely low resource overhead. It significantly outperforms existing technical solutions in terms of deployment cost, hardware compatibility, query accuracy, and system maintainability, providing a practical and lightweight technical path for the intelligent transformation of traditional enterprises. Attached Figure Description
[0058] The present invention includes the following figures:
[0059] Figure 1 This is a schematic diagram of the module composition and data flow of the integrated retrieval enhanced generation capability system in an embodiment of the present invention. Detailed Implementation
[0060] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with specific embodiments and the accompanying drawings.
[0061] It should be noted that, unless otherwise defined, the technical or scientific terms used in the embodiments of this application should have the ordinary meaning understood by one of ordinary skill in the art to which this application pertains. The terms "first," "second," and similar terms used in the embodiments of this application do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are only used to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0062] Example 1
[0063] This embodiment uses an e-commerce customer service system as an example to illustrate in detail the specific implementation process of the integrated retrieval enhancement generation capability method provided by the present invention.
[0064] Implementation environment configuration:
[0065] Hardware environment: Standard server (CPU: 16 cores, RAM: 32GB, GPU: RTX 3060, VRAM: 12GB).
[0066] Software environment:
[0067] Database: MySQL 8.0, containing tables for orders, after-sales, products, and reviews.
[0068] Large Language Model: DeepSeek-R1-Distill-Llama-8B (local deployment).
[0069] Embedding model: paraphrase-MiniLM-L6-v2 (used for similarity calculation).
[0070] Development languages: Python 3.10 + FastAPI + SQLAlchemy.
[0071] Step S1: Construct the basic SQL collection.
[0072] Based on the e-commerce customer service requirements, four business intentions were pre-defined, and corresponding basic SQL statements were manually written. Each basic SQL statement explicitly lists the specific fields and uses `as` (the SQL syntax for assigning aliases to field / column names) to provide aliases that aid model understanding. Simultaneously, `WHERE 1=1` is reserved as a placeholder condition field for dynamic conditions. See Table 1 for details:
[0073] Table 1. Intents and their corresponding basic SQL
[0074]
[0075] Step S2: Field semantic analysis.
[0076] Analyze the database field content involved in the above basic SQL and establish a mapping relationship between the fields and noun types.
[0077] Noun types include: name, mobile phone number, ID card number, city, province, company name, product name, website, etc.
[0078] A single field can correspond to multiple noun types (e.g., the "Recipient Information" field may contain name, phone number, and address simultaneously).
[0079] Create a mapping table: {field name: [list of noun types]};
[0080] For example, after analyzing the orders table, the following mapping is obtained:
[0081] {
[0082] "receiver": ["name", "phone number"],
[0083] "address": ["province", "city", "detailed address"],
[0084] "product_name": ["Product Name"],
[0085] "date": ["Start Date", "End Date"] / / Introduces two dummy variables, "Start Date" and "End Date," to handle the time range.
[0086] }
[0087] Step S3: Intent Analysis.
[0088] The system receives a user's natural language question: "I want to check Zhang San's mobile phone order in Jinan." It then constructs prompt words and uses a large language model (DeepSeek-R1-Distill-Llama-8B) for intent classification.
[0089] Example of prompt words:
[0090] # Analysis Methods
[0091] Please determine which business intent the following questions belong to.
[0092] Optional intents: [Order inquiry, after-sales progress, product information, user reviews]
[0093] # Input data
[0094] Question: I want to check Zhang San's mobile phone order in Jinan.
[0095] # Output Requirements
[0096] Please strictly adhere to the following JSON format for output:
[0097] {"intent": "xxx"}
[0098] Input the above prompts into the model, and the model is expected to output: {"intent": "Order Query"}. Therefore, select the basic SQL corresponding to "Order Query".
[0099] Step S4: Query condition reasoning.
[0100] (1) Noun type matching: Based on the field mapping in step S2, extract nouns and their corresponding noun types from the user's question using the large language model. {Noun type: [List of specific nouns]}.
[0101] Model inference input: Based on field mapping information, prompt the model to extract "name", "city" and "product name" from the question.
[0102] Reasoning result:
[0103] {
[0104] Name: ["Zhang San"],
[0105] "City": ["Jinan"],
[0106] Product Name: ["Mobile Phone"]
[0107] }
[0108] (2) Compound word processing: The extracted nouns are checked.
[0109] 1. For compound nouns (such as "Jinan City, Shandong Province"), perform word segmentation;
[0110] 2. Remove the glued words (such as "province", "city"), and retain the free words (such as "Shandong", "Jinan"); (for example, for "Jinan City, Shandong Province", remove "province" and "city", and retain "Shandong" and "Jinan")
[0111] 3. Remove the upper-level words and retain the lower-level words. Use a large language model to judge whether there is an "inclusion / subordination" relationship between multiple sub-words after compound word segmentation, and only retain the lower-level words as keywords (for example, for "Shandong" and "Jinan", only retain the lower-level word "Jinan");
[0112] 4. Retain all words without a subordination relationship;
[0113] "Jinan" is a compound word, perform word segmentation and processing on it.
[0114] Word segmentation: "Jinan" -> "Jinan" (no glued words, directly retain).
[0115] Subordination relationship judgment: In this example, there are no multi-level place names, no need to process.
[0116] (3)Expansion word generation: Generate synonyms, lower-level words, pinyin, English translations, etc. for the target noun as expansion words; the expansion words are at the same level as the original noun and are used to enhance the matching coverage rate; generate expansion words for the target noun to enhance the matching coverage rate.
[0117] "Zhang San" -> synonyms: "Mr. Zhang"; pinyin: "zhangsan"; English: "Zhang San".
[0118] "Jinan" -> lower-level words: "Lixia District", "Shizhong District" (based on common place name knowledge); English: "Jinan".
[0119] "Mobile phone" -> synonyms: "Smartphone", "Cell phone"; English: "mobile phone".
[0120] Finally, form the query condition mapping:
[0121] {
[0122] "Name": ["Zhang San", "Mr. Zhang", "zhangsan", "Zhang San"],
[0123] "City": ["Jinan", "Jinan", "Lixia District", "Shizhong District"],
[0124] Product Name: ["Mobile Phone", "Smartphone", "Mobile Phone"]
[0125] }
[0126] Step S5: SQL generation (rule-driven).
[0127] Based on the selected base SQL (order query) and the query conditions obtained in step S4, a complete SQL is generated according to preset rules.
[0128] The generation rules are as follows:
[0129] 1. Date field: Use BETWEEN start date AND end date or > start date AND < end date;
[0130] 2. Use AND to connect different fields;
[0131] 3. Multiple noun types under the same field are connected using OR;
[0132] 4. Multiple nouns / extensions of the same noun type are connected using OR;
[0133] 5. Use AND to connect the nouns that make up a compound word;
[0134] 6. All matches use LIKE '%...%' to achieve fuzzy matching.
[0135] Application of the rules in this embodiment:
[0136] Different fields (name, city, product name) are connected using AND. Multiple extended terms under the same field are connected using OR and grouped with parentheses. All matches are performed using LIKE '%...%' for fuzzy matching.
[0137] The generated SQL statement:
[0138] SELECT receiver as recipient, order_num as order number, product_name as product name, address as shipping address, date as order date
[0139] FROM orders
[0140] WHERE 1=1
[0141] AND (
[0142] receiver LIKE '%Zhang San%' OR receiver LIKE '%Mr. Zhang%' OR receiver LIKE '%zhangsan%' OR receiver LIKE '%Zhang San%' )
[0144] AND (
[0145] Address LIKE '%Jinan%' OR address LIKE '%Jinan%' OR address LIKE '%Lixia District%' OR address LIKE '%Shizhong District%' )
[0147] AND (
[0148] product_name LIKE '%phone%' OR product_name LIKE '%smartphone%' OR product_name LIKE '%mobile phone%' OR product_name LIKE '%mobile phone%' );
[0150] Step S6: Query and Dynamic Correction.
[0151] Based on the maximum context window supported by the model, the maximum threshold M for a single input is preset to 4000 tokens.
[0152] Execute the above SQL statement to retrieve the query results from the database.
[0153] Initial query: 15 records returned. It is estimated that these 15 records, after being converted into prompt words, will have a total of approximately 5624 tokens, or about 1.4MB.
[0154] Dynamic correction judgment: Since 1.4M > 1.0M and is less than the second threshold (e.g., 1.5M), the "medium result" processing flow is triggered.
[0155] A first threshold and a second threshold are preset, with the first threshold being less than the second threshold, which are used to trigger different correction strategies.
[0156] Correction action:
[0157] Using the paraphrase-MiniLM-L6-v2 embedding model, the user question "I want to check Zhang San's mobile phone order in Jinan" and 15 query results are vectorized separately.
[0158] Calculate the cosine similarity between each result and the user's question.
[0159] Sort by similarity from low to high, and remove the 5 records with the lowest similarity.
[0160] Correction result: 10 records are retained, and the total number of tokens is reduced to 0.9M, which is below the threshold M and meets the requirements.
[0161] Step S7: Generate answers using a large language model
[0162] The user's original question and the revised query results are combined into prompt words, which are then input into the large language model.
[0163] Constructed prompt words:
[0164] Question: I want to check Zhang San's mobile phone order in Jinan.
[0165] The data table is as follows (headers: Recipient | Order Number | Product Name | Shipping Address | Order Date):
[0166] [Data row 1: Zhang San | 20240328001 | Smartphone | XX Road, Lixia District, Jinan City | 2024-03-28]
[0167] [Data Row 2: Zhang San | 20240315023 | Mobile | YY Road, Shizhong District, Jinan City | 2024-03-15]
[0168] [Data Row 3: Li Si | 20240320045 | Mobile Phone | ZZ Road, Huaiyin District, Jinan City | 2024-03-20] # Note: This is an interference item that is still retained after similarity filtering, but the model should be able to select it autonomously according to the problem.
[0169] ... (Total 10 items)
[0170] Based on the information above, please answer the user's question using natural language.
[0171] Model output:
[0172] The search results show that Zhang San purchased a total of 2 mobile phones in Jinan, namely:
[0173] 1. Order Number: 20240328001, Product Name: Smartphone, Shipping Address: XX Road, Lixia District, Jinan City, Order Date: 2024-03-28
[0174] 2. Order Number: 20240315023, Product Name: Mobile Phone, Shipping Address: YY Road, Shizhong District, Jinan City, Order Date: 2024-03-15
[0175] The model successfully identified data rows 1 and 2 as relevant to the user's question, ignored the record for "Li Si," and generated an accurate answer.
[0176] Example 2
[0177] Based on the same inventive concept, this embodiment provides a low-cost system for integrating RAG capabilities, which is used to execute the method described in Embodiment 1. Figure 1 As shown, the system includes the following functional modules:
[0178] The Basic SQL Building Module is configured to build and store a collection of basic SQL statements. In e-commerce scenarios, this module pre-stores the basic SQL statements corresponding to four intents: "Order Query," "After-sales Progress," "Product Information," and "User Reviews." Each basic SQL statement includes a clearly defined list of fields, easy-to-understand field aliases, and a WHERE 1=1 placeholder condition field.
[0179] The semantic analysis module is configured to establish and store mappings between database fields and noun types based on the database fields involved in the underlying SQL collection. For example, this module stores mappings such as ["name", "phone number"] for the receiver field and ["province", "city", "detailed address"] for the address field, and introduces dummy variables for start and end dates for date fields.
[0180] The intent analysis module is configured to receive natural language questions from users (such as "I want to check Zhang San's mobile phone order in Jinan") and use a large language model to match and select the corresponding basic SQL from the basic SQL set. This module calls the large language model through a preset prompt word template and outputs the selected intent (such as "order query") and the corresponding basic SQL.
[0181] The conditional reasoning module is configured to perform query conditional reasoning on natural language questions based on the mapping relationship between fields and noun types, using a large language model. This module first extracts specific nouns from the question (such as "Zhang San," "Jinan," and "mobile phone") and their types, then performs compound word processing (such as processing "Lixia District") and expanded word generation (such as synonyms, pinyin, and English), finally outputting a structured query condition mapping.
[0182] The SQL generation module is configured to generate executable, complete SQL query statements based on the selected base SQL and query conditions, according to preset rules. This module incorporates built-in combinational logic such as AND between fields, OR between synonyms, AND for compound words, and BETWEEN for date ranges, and uses LIKE fuzzy matching to automatically generate SQL that can be executed by the database.
[0183] The query and correction module is configured to execute complete SQL queries, retrieve results from the database, and dynamically correct the results. This module first executes the SQL and then evaluates the size of the results. If the results are too numerous (e.g., >1.5M tokens, where M is the maximum number of tokens in a single input model), the conditions are relaxed (AND changed to OR) and the query is repeated. If the results are of moderate size (1.0M-1.5M tokens), the embedding model is invoked for similarity filtering. If the results are empty, the conditions are tightened (OR changed to AND) or expanded terms are added for a repeated query to ensure the final results meet the preset context length requirements.
[0184] The large language model interaction module is configured to combine the user's natural language question and the revised query results into prompts, input them into the large language model, and obtain the generated natural language answer. This module combines the raw records returned by the database with the table headers into a clear data table, guiding the large language model to generate the final answer.
[0185] The modules mentioned above work together, starting with the construction of basic SQL and finally generating natural language responses, to form a complete and low-cost RAG capability integration loop.
[0186] Figure 1 This diagram illustrates the module composition and data flow of the integrated retrieval-enhanced generation capability system in an embodiment of the present invention. Each step is represented by a box, and arrows indicate the data flow direction.
[0187] It should be noted that any process or method description in the embodiments can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of the invention includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order according to the functions involved, as should be understood by those skilled in the art to which the embodiments of the invention pertain.
[0188] It should be noted that the logic and / or steps in the embodiments, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable medium may be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.
[0189] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0190] Those skilled in the art will understand that all or part of the steps of the methods described in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.
[0191] Furthermore, in the embodiments of the present invention, the functional modules can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. The aforementioned storage medium can be a read-only memory, a hard disk, or an optical disk, etc.
[0192] The above embodiments have provided a detailed description of the technical solutions of the present invention. Obviously, the present invention is not limited to the described embodiments. Based on the embodiments of the present invention, those skilled in the art can make various changes, but any changes that are equivalent or similar to the present invention fall within the scope of protection of the present invention. Contents not described in detail in this specification are prior art known to those skilled in the art.
Claims
1. A method for integrating retrieval and enhancing generation capabilities, characterized in that, Includes the following steps: S1: Construct a basic SQL set, where each basic SQL in the basic SQL set corresponds to a preset business intent and includes a statement for querying specific business fields from the database and a placeholder condition field for dynamically populating query conditions. S2: Based on the database fields involved in the basic SQL set, perform semantic analysis on each field and establish a mapping relationship between the field and the noun type; S3: Receive the user's natural language question, perform intent analysis using a large language model, and match and select one or more basic SQL statements corresponding to the natural language question from the basic SQL set; S4: Based on the mapping relationship between the fields and noun types, use a large language model to perform query condition reasoning on the natural language question, extract the specific nouns corresponding to the noun types, process the specific nouns into compound words, and generate extended words from the processed nouns to obtain query conditions; wherein, the extended word generation is to generate one or more of the following for the specific nouns: synonyms, hyponyms, pinyin, or English translations; S5: Based on the selected base SQL and the query conditions, generate an executable complete SQL query statement according to preset rules; wherein, the generation of the complete SQL query statement is driven by rules, and the large language model does not participate in the construction of the SQL statement; S6: Execute the complete SQL query statement, retrieve the query results from the database, and dynamically correct the query results to meet the preset context length requirements; the dynamic correction of the query results in S6 further includes: determining whether the estimated number of tokens in the query results exceeds a preset threshold; if it exceeds the first threshold, changing the connection method between fields in the SQL statement from OR to AND to narrow the query range and then querying again; if the result is empty, changing the connection method between fields in the SQL statement from AND to OR to expand the query range and then querying again, or increasing the scope of expanded terms and then querying again; S7: Combine the natural language question and the corrected query results into prompt words, input them into the large language model, and generate a natural language answer.
2. The method according to claim 1, characterized in that, In step S4, the compound word processing of the specific noun further includes: performing word segmentation on the compound noun; removing cohesive words from the word segmentation results and retaining free words; using a large language model to determine the inclusion or subordination relationship between free words, removing hypernyms and retaining hyponyms as keywords.
3. The method according to claim 1, characterized in that, The mapping relationship between fields and noun types established in S2 also includes introducing "start date" and "end date" dummy variables for date fields to handle time range descriptions; the noun type is used to describe the semantic category to which the field content belongs.
4. The method according to claim 1, characterized in that, The preset rules in S5 include: for date fields, using range comparison operators to construct conditions; for query conditions of different fields, using AND logical operators to connect them; for different noun types under the same field or multiple nouns / extended words under the same noun type, using OR logical operators to connect them; for multiple sub-nouns split from compound words, using AND logical operators to connect them; and all field matching is implemented using fuzzy matching.
5. The method according to claim 4, characterized in that, The dynamic correction of the query results in S6 further includes: if the estimated number of tokens for the query results is between the first threshold and the second threshold, then the similarity between each query result and the user's question is calculated using an embedding model, and the results with low similarity are removed until the total number of tokens is lower than the preset requirement.
6. The method according to claim 1, characterized in that, The basic SQL constructed in S1 explicitly lists the specific field names in its query fields and assigns aliases to the fields that help the large language model understand them; The base SQL includes placeholder condition fields after the WHERE clause, which are used to dynamically construct query conditions later.
7. The method according to claim 1, characterized in that, In step S7, when combining the corrected query results into prompt words, the header and data content of the query results are combined into a complete table and input into the large language model. The header is a field alias defined in SQL.
8. A system for integrating search and enhanced generation capabilities, characterized in that, For performing the method according to any one of claims 1 to 7, comprising: Basic SQL building module: configured to build and store a basic SQL set, each basic SQL in the basic SQL set corresponding to a preset business intent and containing a statement for querying specific business fields from the database as well as placeholder condition fields; The semantic analysis module is configured to establish and store the mapping relationship between fields and noun types based on the database fields involved in the underlying SQL set. Intent analysis module: configured to receive natural language questions from users and use a large language model to match and select one or more corresponding basic SQL queries from the set of basic SQL queries; Conditional reasoning module: configured to perform query conditional reasoning on the natural language question based on the mapping relationship between the field and the noun type, using a large language model, extracting the specific nouns corresponding to the noun type, and performing word expansion generation and / or compound word processing on the specific nouns to obtain query conditions; wherein, the word expansion generation includes generating one or more of the following for the specific nouns: synonyms, hyponyms, pinyin, or English translations; SQL generation module: configured to generate an executable complete SQL query statement according to preset rules based on the selected base SQL and the query conditions; wherein, the generation of the complete SQL query statement is driven by rules, and the large language model does not participate in the construction of the SQL statement; The query and correction module is configured to execute the complete SQL query statement, retrieve query results from the database, and dynamically correct the query results to meet a preset context length requirement. The dynamic correction ensures that the estimated number of tokens in the query results does not exceed the preset context window length of the large language model. The dynamic correction further includes: determining whether the estimated number of tokens in the query results exceeds a preset threshold; if it exceeds the first threshold, changing the connection method between fields in the SQL statement from OR to AND to narrow the query range and then re-querying; if the result is empty, changing the connection method between fields in the SQL statement from AND to OR to expand the query range and then re-querying, or adding an expanded term range and then re-querying. The large language model interaction module is configured to combine the natural language question and the corrected query results into prompt words, input them into the large language model, and obtain the generated natural language answer.