Intelligent question number-oriented few-sample prompt dynamic structured query method

By developing a dynamic structured query system with few-shot prompts for intelligent data retrieval, which utilizes natural language processing and few-shot learning modules to dynamically generate structured queries, the system addresses the issues of weak generalization ability and insufficient template flexibility in intelligent data retrieval systems under few-shot scenarios, achieving high-accuracy data retrieval under low-resource conditions.

CN121807896APending Publication Date: 2026-04-07HANGZHOU HONGYUN SOFTWARE TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-30
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Existing intelligent query systems have weak generalization ability and insufficient template flexibility in scenarios with few samples, making it impossible to dynamically adapt to complex problems. This results in low query accuracy and makes it difficult to meet the personalized needs of emerging businesses and niche scenarios.

Method used

A few-shot prompt dynamic structured query system for intelligent question counting is adopted, which includes a hardware layer, a software layer, and a data layer. It uses a natural language processing module to extract intent and entity information, combines a few-shot learning module to match the best example template, dynamically generates query statements through a structured query generation module, and iteratively optimizes through a feedback optimization module.

Benefits of technology

It enables rapid adaptation to new fields under low-resource conditions, significantly improving the flexibility and accuracy of queries. It is applicable to multiple fields such as enterprise sales and financial transactions, and improves the system's query accuracy and user satisfaction in scenarios with few samples.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121807896A_ABST
    Figure CN121807896A_ABST
Patent Text Reader

Abstract

The invention provides an intelligent question number-oriented few-sample prompt dynamic structured query method, which realizes accurate data query under low resources by classifying and matching an optimal example template through natural language questions, dynamically generating structured query prompts and combining few-sample learning (Few-shot Learning) and an adaptive prompt strategy. The method does not need a large amount of annotated data, can quickly adapt to a new field, and remarkably improves the flexibility and accuracy of intelligent number asking.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of intelligent question answering technology, and in particular to a method for dynamic structured querying with few-sample prompts for intelligent questions, as well as a system, electronic device, and computer-readable storage medium for dynamic structured querying with few-sample prompts for intelligent questions. Background Technology

[0002] Intelligent Data Query refers to a technology where users describe their data needs using natural language, and the system automatically generates structured queries (such as SQL and SPARQL) and returns the results. It is widely used in scenarios such as enterprise reporting, data analysis, and government inquiries. Existing technologies suffer from the following pain points:

[0003] Weak generalization ability with few samples: Most methods rely on a large amount of labeled data to train the model. When domain data is scarce (such as emerging businesses or niche scenarios), the model is prone to overfitting, resulting in low accuracy of the generated query statements.

[0004] Insufficient template flexibility: Traditional fixed templates cannot adapt to complex problems (such as multiple condition combinations and fuzzy queries), leading to omissions or errors in query logic.

[0005] Poor dynamic adaptability: It cannot dynamically adjust the prompting strategy according to the semantic features of the question (such as intent, entity), making it difficult to cope with the personalized needs of users. Summary of the Invention

[0006] To address the technical problems existing in the prior art, the present invention provides the following technical solution:

[0007] On the one hand, a few-sample prompting dynamic structured query system for intelligent question counting is provided, including:

[0008] The hardware layer includes a computing server, a GPU accelerator card connected to the computing server, a distributed storage system, a relational database, an analytical database, and network devices;

[0009] The software layer, deployed above the hardware layer, includes:

[0010] The user interaction module is used to receive natural language questions input by users and display the query results;

[0011] The natural language processing module is used to preprocess the natural language problem and extract intent and entity information. The natural language processing module includes a few-shot intent classifier based on a prototype network.

[0012] The few-shot learning module includes an example template library, which is used to match the best example template based on the intent and entity information by semantic similarity calculation and rule filtering.

[0013] The structured query generation module is used to construct dynamic prompts based on the matched example templates and entity information, and to call the pre-trained model to generate structured query statements.

[0014] The data storage and access module is used to execute the structured query statement and return the results from the database;

[0015] The feedback optimization module is used to collect user feedback and perform active learning based on uncertainty sampling to optimize the example template library and pre-trained model;

[0016] The data layer is used to store raw business data, aggregated data, sample template library data, user feedback data, and labeled data.

[0017] On the other hand, a method for few-sample prompting dynamic structured query for intelligent question counting is provided, implemented based on the aforementioned system for few-sample prompting dynamic structured query for intelligent question counting, including:

[0018] The problem of receiving natural language input from users;

[0019] Natural language processing is performed on the natural language problem to extract intent and entity information, wherein intent extraction adopts a few-shot intent classification method based on prototype networks;

[0020] Based on the extracted intent and entity information, the best example template is matched from the example template library;

[0021] By combining the best matching example template with the entity information, a dynamic prompt is constructed;

[0022] The dynamic prompts are input into the pre-trained model to generate structured query statements;

[0023] Check if there is a result in the cache that corresponds to the current structured query statement. If so, return the cached result directly.

[0024] Execute the structured query statement to obtain the query results;

[0025] The query results are returned and displayed to the user.

[0026] Preferably, the few-shot intent classification method based on prototype networks includes:

[0027] For each intent category, the mean of the feature vectors of all samples in that category is calculated to obtain the prototype representation of that category;

[0028] For a natural language problem to be classified, extract its corresponding feature vector;

[0029] Calculate the distance between the feature vector and the prototype representation of each category;

[0030] The intent category corresponding to the prototype with the smallest distance is determined as the intent classification result of the natural language problem.

[0031] Preferably, the distance is a Mahalanobis distance, which is calculated by introducing the covariance matrix of the eigenvectors.

[0032] Preferably, matching the best example template from the example template library includes:

[0033] Based on the intent information, relevant candidate templates are retrieved from the example template library;

[0034] Calculate the semantic similarity between the natural language question and each candidate template;

[0035] The candidate templates are filtered according to rules based on the entity information.

[0036] Based on the semantic similarity and rule filtering results, the optimal example template is determined.

[0037] Preferably, constructing dynamic prompts includes employing a Chain of Reasoning (CoT) prompting method, wherein the dynamic prompts include examples of reasoning steps based on the best example template.

[0038] Preferably, constructing dynamic prompts further includes: employing an adaptive prompt adjustment method, the method comprising generating a dynamic prompt embedding sequence based on the intent and entity information using a multilayer perceptron, and concatenating the prompt embedding sequence before the input embedding sequence of the pre-trained model.

[0039] Preferably, after generating the structured query statement, the method further includes a step of performing syntax validation on the structured query statement.

[0040] Preferably, the method further includes a feedback optimization step:

[0041] Receive user feedback on the accuracy of the query results;

[0042] If the feedback is inaccurate, record the feedback information and analyze the reasons;

[0043] When the cause is a model generation error, the pre-trained model is fine-tuned using labeled data based on the feedback information.

[0044] Preferably, the feedback optimization step further includes an active learning process:

[0045] Collect unlabeled natural language questions;

[0046] The unlabeled problem is predicted using the current model, and the uncertainty measure of the prediction results is calculated.

[0047] Select several issues with the highest uncertainty and submit them to experts for annotation;

[0048] The labeled data is added to the training set to optimize the few-shot intent classifier and / or the pre-trained model.

[0049] On the other hand, an electronic device is provided, comprising: a processor; and a memory storing computer-readable instructions, wherein when executed by the processor, the computer-readable instructions implement any of the methods described above for the few-sample prompting dynamic structured query method for intelligent query data.

[0050] On the other hand, a computer-readable storage medium is provided, wherein at least one instruction is stored therein, the at least one instruction being loaded and executed by a processor to implement any of the above-described methods of the few-sample prompting dynamic structured query method for intelligent question counting.

[0051] The beneficial effects of the technical solutions provided in the embodiments of the present invention include at least the following:

[0052] This proposed method for intelligent question counting, employing a few-shot prompting dynamic structured query approach, dynamically generates structured query prompts by matching the best example template through natural language question classification. Combining few-shot learning with an adaptive prompting strategy, it achieves accurate data retrieval with low resource requirements. This method does not require a large amount of labeled data, can quickly adapt to new domains, and significantly improves the flexibility and accuracy of intelligent question counting.

[0053] This solution addresses the weaknesses of existing intelligent query systems in few-shot scenarios, such as weak generalization and insufficient template flexibility, through techniques like few-shot intent classification, dynamic prompt generation, and active learning. The system employs a layered architecture, encompassing hardware, software, and data layers, achieving closed-loop optimization from user interaction to data querying. Experimental results demonstrate that this system outperforms existing methods in terms of SQL generation accuracy, query latency, and user satisfaction, making it suitable for various fields such as enterprise sales and financial transactions, and possessing broad application prospects. Attached Figure Description

[0054] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0055] Figure 1 This is a schematic diagram of the hardware composition of a few-sample prompt dynamic structured query system for intelligent question counting provided in an embodiment of the present invention;

[0056] Figure 2 This is a schematic diagram of the software functional architecture of a few-sample prompt dynamic structured query system for intelligent question counting provided in an embodiment of the present invention;

[0057] Figure 3 This is a schematic diagram illustrating the application process of a few-sample prompt dynamic structured query method for intelligent query data provided in an embodiment of the present invention. Detailed Implementation

[0058] The technical solution of the present invention will now be described with reference to the accompanying drawings.

[0059] In embodiments of the present invention, words such as "exemplarily," "for example," etc., are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" in the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the word "exemplary" is intended to present the concept in a concrete manner. Furthermore, in embodiments of the present invention, the meaning expressed by "and / or" can be both, or either one.

[0060] In the embodiments of this invention, the terms "image" and "picture" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, they convey the same meaning. Similarly, the terms "of," "corresponding (relevant)," and "corresponding" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, they convey the same meaning.

[0061] In this embodiment of the invention, sometimes a subscript such as W1 may be mistakenly written as a non-subscript form such as W1. When the difference is not emphasized, the meaning they express is the same.

[0062] To make the technical problems, technical solutions and advantages of the present invention clearer, a detailed description will be given below in conjunction with the accompanying drawings and specific embodiments.

[0063] This solution proposes a few-sample prompt dynamic structured query method for intelligent question counting. The core idea is to automatically classify natural language questions and match the best example template to dynamically generate structured query prompts, thereby achieving accurate data query and analysis with low resources.

[0064] The specific strategies are as follows:

[0065] This invention dynamically generates structured query suggestions by matching the best example template to natural language question classification. Combining few-shot learning with an adaptive suggestion strategy, it achieves accurate data retrieval with low resource requirements. This method does not require a large amount of labeled data, can quickly adapt to new domains, and significantly improves the flexibility and accuracy of intelligent question counting.

[0066] The implementation process of this solution will be described in detail below in conjunction with the system architecture.

[0067] This system adopts a layered architecture, forming a closed loop from user interaction to data query, covering the hardware layer, software layer (including core modules), and data layer. The composition and key components of each layer are described in detail below.

[0068] I. System Architecture and Hardware / Software Components

[0069] (a) Hardware layer

[0070] The hardware layer provides computing, storage, and networking support for the system, and must meet the requirements of low-latency inference, large-scale data storage, and high-concurrency access. The specific configuration is shown in Table 1 below:

[0071] Components Model / Specification Function Description Computing server Dell PowerEdge R750 (2 Intel Xeon Platinum 8480+ CPUs, 1TB DDR4 memory) Responsible for core computing tasks such as natural language processing, model inference, and structured query generation. GPU accelerator card NVIDIA A100 80GB (4 cards, forming a multi-card cluster) Accelerate the inference and fine-tuning of pre-trained models (such as Llama 2 and BERT) and improve processing speed. Distributed storage Hadoop HDFS (10 nodes, 4TB SSD per node) Store large amounts of raw data (such as sales records and user behavior) and intermediate results (such as sample template libraries). relational database MySQL 8.0 (master-slave architecture, 2 nodes) Store structured business data (such as product tables and order tables) and support SQL queries. Analytical database ClickHouse 23.11 (3-node cluster) Store aggregated data (such as monthly sales figures) and support fast OLAP queries. Network equipment Cisco Catalyst 9300 switch (100G port), Huawei CloudEngine 16800 router Achieve high-speed communication between the server and the terminal while ensuring low latency (≤10ms). terminal equipment Desktop computers (Windows / macOS), smartphones (iOS / Android) A terminal where users input natural language questions and view query results.

[0072] Table 1

[0073] like Figure 1 As shown, the connection relationship of the hardware layer is illustrated below:

[0074] 1. Computing and Acceleration / Storage Devices: The Dell PowerEdge R750 compute server connects to a cluster of four NVIDIA A100 80GB GPUs via a PCIe 4.0 interface (for model inference / fine-tuning); it connects to a Hadoop HDFS node (10-node SSD storage), a MySQL master-slave database, and a ClickHouse cluster via a 100G Ethernet interface (CiscoCatalyst 9300 switch) to enable data reading and writing and task distribution;

[0075] 2. Network and Terminals: The core network consists of Cisco switches and Huawei routers, which connect desktop / mobile terminals via HTTP / HTTPS protocols, ensuring that the user request forwarding latency is ≤10ms.

[0076] (ii) Software layer

[0077] like Figure 2 As shown, the software layer adopts a microservice architecture, divided into 6 core modules, each deployed independently yet working collaboratively. The following are the functions, technology selections, and key components of each module:

[0078] 1. User Interaction Layer

[0079] Functionality: Enables user interaction with the system, including natural language input, result display, and feedback collection.

[0080] Technology selection:

[0081] Web interface: Developed using React 18, it supports responsive design (adapting to desktop / mobile devices) and uses the Ant Design component library to enhance the interactive experience.

[0082] API Interface: Developed using FastAPI (Python 3.10), providing RESTful APIs (such as the / query interface for receiving natural language questions, and the / feedback interface for collecting user feedback), supporting high concurrency (≥1000 QPS).

[0083] Mobile SDK: Developed based on Flutter, supports iOS / Android platforms, and integrates voice input functionality (using iFlytek's speech recognition API).

[0084] Key components:

[0085] Input box: Supports text / voice input and displays input suggestions in real time (such as "Please enter your query, e.g., Top 5 mobile phone sales in North China last month").

[0086] Results panel: Displays query results in tables / charts (ECharts), and supports exporting to Excel / PDF.

[0087] Feedback button: Provides three options: "Accurate", "Inaccurate", and "Needs optimization". Clicking it triggers the feedback process.

[0088] 2. Natural Language Processing (NLP) Layer

[0089] Function: Preprocesses natural language questions input by users, extracts intent, entities and key features, laying the foundation for subsequent classification and template matching.

[0090] Technology selection:

[0091] Word segmentation: Uses Jieba (Chinese) and NLTK (English), and supports custom dictionaries (such as "North China region" and "sales volume").

[0092] Entity Recognition (NER): Using spaCy (English) and BERT-NER (Chinese, based on Hugging FaceTransformers), entities such as time, region, and product category are recognized.

[0093] Intent Classification: Using a few-shot classification model (Prototypical Networks), extracting features based on BERT-base to achieve intent recognition under low resources.

[0094] Key Components:

[0095] Preprocessing Pipeline: Input question → Word segmentation → Stop word removal (such as "de", "shi") → Entity annotation (such as "[Time: last month] [Region: North China] [Product: mobile phone] [Requirement: Top 5 sales]").

[0096] Intent Classifier: Output intent labels (such as "Sales ranking query", "Amount statistics query", "Trend analysis query"), with an accuracy rate ≥ 95% (verified on the few-shot dataset FewShotWoz).

[0097] 3. Few-shot Learning Layer

[0098] Function: According to the intent label output by the NLP layer, match the best template from the example template library to provide few-shot prompts for structured query generation.

[0099] Technical Selection:

[0100] Example Template Library: Stored using MongoDB 6.0, with the structure as follows (JSON format): {

[0101] "intent": "Sales ranking query",

[0102] "template": "Please generate the SQL statement for querying the Top [quantity] sales of [product category] in [region] within [time range].",

[0103] "examples":

[0104] Dynamic Matching Module: Using a combination of semantic similarity calculation (BERT-base) and rule filtering (such as time format verification) to select the template that best matches the current question from the template library.

[0105] Key Components:

[0106] Template Retrieval Engine: Built based on Elasticsearch 8.0, supporting fast retrieval of templates by intent label and entity type (response time ≤ 50ms).

[0107] Similarity Calculator: Calculate the cosine similarity between the question and the template (based on the [CLS] vector of BERT), with the threshold set to 0.7 (if higher than the threshold, the match is successful; otherwise, active learning is triggered).

[0108] 4. Structured Query Generation Layer

[0109] Function: Combines the matched example template with the current question to generate dynamic suggestions and calls the pre-trained model to generate structured queries (such as SQL, SPARQL).

[0110] Technology selection:

[0111] Hint construction: Chain-of-Thought (CoT) hints are used to combine example templates with questions to guide the model to generate logically coherent queries.

[0112] Pre-trained model: Llama 2 70B (locally deployed, with inference speed optimized based on the vLLM framework), supports few-shot cue learning, and achieves a generation accuracy of ≥90% (verified on SQL generation tasks).

[0113] Query validation: SQLParse (Python library) is used to check the syntax of the generated SQL statements to avoid syntax errors.

[0114] Key components:

[0115] Hint Generator: Generates CoT hints based on templates and questions. For example: Example: The SQL for the question "What were the top 3 computer products in terms of sales revenue in South China in the third quarter of 2023?" is:

[0116] SELECT product_name, SUM(sales) AS total_sales FROM sales_data

[0117] WHERE region='South China' AND category='Computer' AND time_period='2023Q3'

[0118] GROUP BY product_name ORDER BY total_sales DESC LIMIT 3.

[0119] The question is: "What were the top 5 mobile phone sales in North China last month?" Please generate the corresponding SQL statement.

[0120] Model inference interface: The inference function of Llama 2 is encapsulated using FastAPI, which supports batch requests (≤100 records / batch) and inference latency ≤200ms.

[0121] 5. Data Storage and Access Layer

[0122] Function: Stores business data and intermediate results, and supports the execution and return of structured queries.

[0123] Technology selection:

[0124] Relational database: MySQL 8.0, which stores transactional data (such as the order table and the product table) and supports ACID properties.

[0125] Analytical database: ClickHouse 23.11, which stores aggregated data (such as the monthly sales table monthly_sales) and supports fast grouping and sorting queries.

[0126] Caching: Redis 7.0 caches frequently queried results (such as "today's sales") to reduce database pressure (cache hit rate ≥ 80%).

[0127] Key components:

[0128] Data synchronization tool: Debezium is used to achieve real-time synchronization from MySQL to ClickHouse (latency ≤ 1 second), ensuring the timeliness of the analyzed data.

[0129] Query execution engine: Uses JDBC driver to connect to MySQL / ClickHouse, executes the generated SQL statements, and returns the results (supports JSON / CSV format).

[0130] 6. Feedback Optimization Layer

[0131] Function: Collect user feedback, optimize the example template library and pre-trained models, and form a closed-loop iteration.

[0132] Technology selection:

[0133] Feedback collection: Redis Stream is used to store user feedback (such as "the query is inaccurate" or "the template needs to be adjusted"), and high-concurrency writes are supported (≥1000 QPS).

[0134] Active learning: Uncertainty sampling is used to select high-value unlabeled issues and push them to domain experts for labeling.

[0135] Model fine-tuning: Llama 2 is fine-tuned using LoRA (Low-Rank Adaptation) technology to reduce computational costs (fine-tuning time ≤ 2 hours / 1000 data points).

[0136] Key components:

[0137] Feedback Analyzer: Uses Spark Streaming to analyze feedback data in real time and statistically analyze the reasons for "inaccurate" queries (e.g., template matching errors account for 30%, model generation errors account for 70%).

[0138] Active learning engine: Calculates the entropy value (uncertainty index) of unlabeled questions and selects the top 10% of questions with the highest entropy values ​​to push to experts (e.g., "What credit card transactions of more than 1,000 yuan were made by Zhang San in the past week?").

[0139] II. Data Layer

[0140] The data layer is the "fuel" of the system, encompassing raw data, intermediate data, and labeled data, as detailed in Table 2 below:

[0141] Data types Example Storage location use Original business data Order table order (order_id, user_id, product_id, amount, create_time) MySQL Supports transactional queries (such as "query Zhang San's orders"). Aggregated data Monthly sales data table: monthly_sales(month, region, category, total_sales) ClickHouse Supports analytical queries (such as "Mobile phone sales revenue in North China in November 2023"). Example template library Sales ranking query template (including question examples, prompt templates, and SQL examples) MongoDB Provides examples for few-shot learning and supports dynamic matching. User feedback data The feedback table contains the following parameters: query_id, user_id, is_accurate, reason. Redis→HDFS Used to optimize template libraries and models (e.g., queries with "is_accurate=false" need to be re-annotated). Annotated data Unmarked issues + expert-annotated templates / SQL (e.g., "Zhang San's credit card transactions exceeding 1000 yuan in the past week" → template "Query records where [user] [transaction type] exceeds [amount] within [time range]") MongoDB Expand the example template library to improve the learning effect with few samples.

[0142] Table 2

[0143] The user interaction layer (React / Flutter) is deployed on the terminal and communicates with the computing server through the FastAPI interface;

[0144] The NLP / few-shot learning / query generation layer is deployed on a computing server CPU / GPU, calling internal modules and models;

[0145] The data storage layer (MySQL / ClickHouse / Redis) is deployed on the corresponding hardware nodes and interacts with the computing server via JDBC / ODBC;

[0146] The feedback optimization layer (Spark Streaming) is deployed on a compute server + HDFS to read Redis Stream data.

[0147] Key Protocols and Data Acquisition Examples

[0148] Data acquisition protocol:

[0149] Business data: Debezium + Kafka (2.8+ protocol) synchronizes with MySQL → ClickHouse;

[0150] User feedback: Redis Stream (RESP 3) storage supports 1000+ QPS writes;

[0151] Internal communication protocol:

[0152] Low-latency module (NLP inference): gRPC 1.50+;

[0153] High throughput module (template retrieval): HTTP / 2;

[0154] Terminal communication: HTTP / 2 protocol (multiplexing reduces latency).

[0155] III. Software and Hardware Interaction Process

[0156] The core process of the system is "user input → NLP processing → template matching → query generation → data query → result return → feedback optimization", and the specific steps are as follows:

[0157] 1. User requests transmission

[0158] Terminal → Server: The user enters the question on the web interface and sends it to the FastAPI interface (HTTP / 2 protocol, multiplexing) via an HTTP POST request (JSON format).

[0159] Network forwarding: Cisco switches forward requests to the compute server via 100G Ethernet with a latency of ≤10ms.

[0160] 2. Internal module interaction

[0161] NLP preprocessing: FastAPI calls Jieba word segmentation (local function), BERT-NER entity recognition (gRPC protocol, low latency), output intent / entity;

[0162] Template matching: Retrieve templates from the Elasticsearch REST API, call the BERT model (shared memory) to calculate similarity, and select the best template;

[0163] Query generation: Call the Llama 2 inference interface (gRPC protocol) to generate SQL, and validate the syntax using SQLParse (a local function).

[0164] 3. Data storage interaction

[0165] Cache check: The compute server queries the cache via the Redis RESP protocol; if a cache miss occurs, the cache is retrieved from the database.

[0166] Database query: Connects to ClickHouse via JDBC protocol to execute SQL and returns JSON results;

[0167] Data synchronization: The MySQL order table is synchronized to ClickHouse in real time via Debezium CDC (Kafka protocol), with a latency of ≤1 second.

[0168] 4. Feedback and Interaction

[0169] Feedback collection: When a user clicks "Accurate", FastAPI writes the feedback to a Redis Stream (RESP 3 protocol).

[0170] Feedback processing: Spark Streaming reads data from the Redis Stream API for real-time analysis; if model optimization is needed, Llama 2 parameters are updated via the LoRA fine-tuning interface (gRPC).

[0171] The following example, using a scenario of querying enterprise sales data (where a user enters "What were the top 5 mobile phone sales in North China last month?"), details the software and hardware interaction process (e.g., ...). Figure 3 (as shown)

[0172] (a) Step 1: User input natural language problem

[0173] Terminal device: Users enter the question "What were the top 5 mobile phone sales in North China last month?" on the web interface and click the "Search" button.

[0174] Network equipment: Cisco switches forward requests to compute servers (FastAPI interface) with a latency of ≤10ms.

[0175] (ii) Step 2: NLP layer preprocessing

[0176] Computational server: FastAPI receives requests and invokes the NLP layer's preprocessing pipeline.

[0177] Word segmentation: Jieba breaks down the question into "Last month / North China / Mobile / Sales / Top 5 / Which / Products?".

[0178] Entity recognition: BERT-NER identified the following entities: [Time: Last month], [Region: North China], [Product: Mobile phone], [Demand: Top 5 in sales].

[0179] Intent Classification: Prototypical Networks are used to classify the question as “sales ranking query” (intent label).

[0180] Prototype network principle (generating prototype points in the feature space for each intent category to support few-shot intent classification, providing representative points in the feature space for each intent category in the few-shot intent classification module of this solution, and solving the data scarcity problem of intent recognition in low-resource scenarios):

[0181] For each intent category (such as "sales ranking query" or "amount statistics query"), calculate its prototype representation:

[0182] ,

[0183] in, It is the prototype of the k-th class (for each intent category (such as "sales ranking query" or "transaction details query"), the average value of all sample features of that category is calculated as the prototype point of that category in the feature space, making the distinction between categories clearer). It is the number of samples in the k-th class. It is the i-th sample of the k-th class, and f is the feature extraction function (here, the [CLS] vector of BERT-base, with a dimension of 768).

[0184] The network calculates the average of all sample features for each intent category, which serves as the representative point of that category in the feature space.

[0185] For a new question x, calculate the cosine distance between its feature f(x) and all prototypes, and select the category with the smallest distance (determining the intent category of the user's input natural language question is a prerequisite for the few-shot learning layer to match example templates):

[0186]

[0187] in:

[0188] The intent category to which the new question belongs (calculate the cosine distance between the feature vector of the new question and the prototype points of all intent categories, and select the category with the smallest distance as the intent label of the question (e.g., classify "Top 5 mobile phone sales in North China last month" as "sales ranking query")).

[0189] : The feature vector of the new problem;

[0190] : The prototype of the k-th type of intention;

[0191] Cosine distance: measures the similarity between feature vectors; the smaller the value, the more similar they are.

[0192] Result: The intent classification result is "sales ranking query", and the entity information is {time: last month, region: North China, product: mobile phone, quantity: 5}.

[0193] (III) Step 3: Matching example templates for few-shot learning layer

[0194] Computational server: The NLP layer passes the intent label and entity information to the few-shot learning layer for dynamic template matching.

[0195] Template retrieval: Elasticsearch retrieves templates from the library based on the intent tag "sales ranking query" and returns all relevant templates (such as "SQL statement to query the top [quantity] sales in [time range] [region] [product category]").

[0196] Similarity calculation: The semantic similarity between the question and each template is calculated using BERT-base (based on the cosine distance of the [CLS] vector), and the template with the highest similarity is selected (e.g., similarity 0.85).

[0197] Rule filtering: Check whether the placeholders in the template (such as [time range]) match the entity information (such as "last month" conforming to the [time range] format), and filter out templates that do not match.

[0198] Result: The matched template is "Please generate an SQL statement to query the top [quantity] sales revenue within [time range] [region] [product category]", as shown in the example below:

[0199] Question: What were the top 3 computer products in terms of sales revenue in South China in the third quarter of 2023?

[0200] SQL: SELECT product_name, SUM(sales) AS total_sales FROM sales_dataWHERE region='South China' AND category='Computer' AND time_period='2023Q3' GROUP BYproduct_name ORDER BY total_sales DESC LIMIT 3.

[0201] (iv) Step 4: The structured query generation layer generates SQL.

[0202] Computational server: The few-shot learning layer passes the matched template and entity information to the structured query generation layer to generate dynamic hints.

[0203] Hint construction: Replace the placeholders in the template with entity information to generate CoT hints (as in the example above).

[0204] Model Inference: Call the Llama 2 inference interface, input prompts, and generate SQL statements.

[0205] Query validation: SQLParse checks the generated SQL syntax (such as whether GROUP BY and ORDER BY are missing) to ensure there are no syntax errors.

[0206] Result: The generated SQL statement is:

[0207] SELECT product_name, SUM(sales) AS total_sales

[0208] FROM sales_data

[0209] WHERE region='North China' AND category='Mobile' AND time_period='2023-11'

[0210] GROUP BY product_name

[0211] ORDER BY total_sales DESC

[0212] LIMIT 5;

[0213] (Note: "Last month" has been converted to "2023-11", based on the current system time of 2023-12-01).

[0214] (v) Step 5: Data storage and access layer executes queries

[0215] Computing Server: The structured query generation layer passes SQL statements to the data storage and access layer to execute queries.

[0216] Cache check: Redis checks if the SQL statement (e.g., "Top 5 mobile phone sales in North China last month") exists in the cache. If it does, the result is returned directly (cache hit rate ≥ 80%).

[0217] Database query: If the cache is not hit, connect to ClickHouse using the JDBC driver (because sales_data is an aggregate table stored in ClickHouse) and execute the SQL statement.

[0218] Results Returned: ClickHouse returns query results (such as product name, sales amount) in JSON format.

[0219] (vi) Step 6: Displaying results in the user interaction layer

[0220] Terminal device: The data storage and access layer returns the results to the user interaction layer, and the web interface displays them in tables and charts.

[0221] Table: Displays product name and sales revenue (sorted from highest to lowest).

[0222] Chart: A bar chart generated using ECharts visually displays the differences in sales revenue for each product.

[0223] Feedback button: When a user clicks "Accurate" or "Inaccurate", the feedback process is triggered.

[0224] (vii) Step 7: Feedback optimization layer closed-loop iteration

[0225] Computational server: If a user clicks "Inaccurate" (e.g., "The sales revenue of 'Huawei Mate 60' in the query results should be 480,000, not 450,000"), the feedback optimization layer will initiate the optimization process:

[0226] Feedback collection: Redis Stream stores feedback information (query_id: 123, user_id: 456, is_accurate: false, reason: sales data error).

[0227] Cause analysis: Spark Streaming real-time analysis feedback revealed that the "sales data error" was due to the sales_data table in ClickHouse not being synchronized in a timely manner (order data in MySQL was not synchronized to ClickHouse).

[0228] Data repair: Debezium triggers a full synchronization to resynchronize the data in the MySQL order table to ClickHouse (synchronization time ≤ 10 minutes).

[0229] Model optimization: If the feedback reason is "model generation error" (e.g., SQL statement lacking GROUP BY), use LoRA to fine-tune Llama 2:

[0230] Fine-tune the data: Collect 1,000 queries with "model generation errors" (such as "What are the transactions that Zhang San spent more than 1,000 yuan on his credit card in the past week?") and the correct SQL.

[0231] LoRA configuration: rank Learning rate Batch size=32, training epochs=3.

[0232] Result: After fine-tuning, the accuracy of the model in generating SQL improved by 15% (from 85% to 100%).

[0233] IV. Introduction to Core Algorithms

[0234] The core advantage of this system lies in its accurate querying in few-shot scenarios, relying on the following key technologies: few-shot intent classification (prototype network), dynamic prompt generation (CoT+ adaptive prompts), and active learning (uncertainty sampling). The principles and optimization methods of these technologies are described in detail below.

[0235] (a) Few-shot Intent Classification: Prototypical Networks

[0236] Problem: Traditional intent classification models (such as BERT) require a large amount of labeled data (≥1000 items / class), while in intelligent question counting scenarios, labeled data in new domains is often insufficient (≤10 items / class).

[0237] Solution: Use a prototype network to achieve few-shot classification through "prototype representation" (supporting 1-shot / 5-shot learning).

[0238] Principle Review:

[0239] The prototype network maps each category to a prototype point in the feature space (e.g., the prototype of "sales ranking query" is the feature mean of all samples in that category).

[0240] For a new problem, calculate the distance between its features and all prototypes, and select the category with the smallest distance (as in the formula above).

[0241] Optimization methods:

[0242] Feature enhancement: Data augmentation (such as synonym replacement and word order adjustment) is used to expand the few-sample dataset (e.g., “Top 5 mobile phone sales in North China last month” → “Top 5 mobile phone sales in North China last month”) to increase the generalization ability of the prototype.

[0243] Distance function optimization: Mahalanobis distance is used instead of cosine distance to consider the correlation between features (such as the correlation between "time" and "location"), thereby improving classification accuracy (by 5%).

[0244] Mahalanobis distance formula (optimizes the distance function of the prototype network, considers the correlation between features, improves the accuracy of intent classification with few samples, and solves the problem that traditional cosine distance does not consider the correlation between features):

[0245] ,

[0246] in, The Mahalanobis distance between vectors is calculated by introducing the covariance matrix of the features and adjusting the distance calculation method to more accurately reflect the distribution differences between different feature dimensions (such as the correlation between "time" and "region" features).

[0247] Each represents a sample feature vector;

[0248] T is the category prototype (mean vector);

[0249] It is the covariance matrix of the features (estimated using a small sample of data).

[0250] (ii) Dynamic prompt generation: CoT+ Adaptive Prompt Tuning

[0251] Problem: Fixed prompts (such as "Please generate an SQL statement to query the top [quantity] sales within [time range] [region] [product category]") cannot adapt to complex problems (such as "What are the transactions that Zhang San spent more than 1,000 yuan on his credit card in the past week and belong to the 'food and beverage' category?"), causing the model to generate errors.

[0252] Solution: Use CoT hints (guided model to generate intermediate inference steps) combined with adaptive hints (dynamically adjust hints based on problem characteristics).

[0253] 1. Mind Chain (CoT) Hints

[0254] Principle: CoT hints add intermediate inference steps to the example, guiding the model to imitate human thought processes (such as "need to query transactions of the past week → filter Zhang San's credit card spending → amount exceeds 1000 yuan → belongs to the catering category → return transaction records").

[0255] Example:

[0256] Question: What were the transactions Zhang San made in the past week that exceeded 1,000 yuan and fell under the "dining" category?

[0257] hint:

[0258] 1. Determine the time range: the past week (the current date is 2023-12-01, so the time range is from 2023-11-24 to 2023-11-30).

[0259] 2. Filter users: Zhang San (user_id=123).

[0260] 3. Filter transaction type: credit card purchase (transaction_type='credit card').

[0261] 4. Filter by amount: more than 1000 yuan.

[0262] 5. Filter by category: Food and Beverage (category='Food and Beverage').

[0263] The corresponding SQL statement is:

[0264] SELECT FROM transaction_data WHERE user_id=123 AND transaction_type='Credit Card' AND transaction_date BETWEEN '2023-11-24' AND '2023-11-30' ANDamount>1000 AND category='Catering';

[0265] The question is: What transactions in the past week did Li Si withdraw more than 500 yuan from his savings card? Please generate the corresponding SQL statements.

[0266] Results: CoT hints improved the accuracy of the model's generated SQL by 25% (verified on a few-sample SQL generation task).

[0267] 2. Adaptive Prompt Tuning

[0268] Problem: Fixed CoT prompts cannot adapt to the characteristics of different questions (such as "time range" which may be "the past week" or "the third quarter of 2023"), resulting in a decrease in the effectiveness of the prompts.

[0269] Solution: Adaptive prompts are used to dynamically generate prompts based on the characteristics of the question (such as intent and entities).

[0270] Principle (Dynamically generating hint embedding sequences that adapt to problem characteristics, improving hint effectiveness, and solving the pain point that fixed hints cannot adapt to complex problems):

[0271] Assume the input embedding of the pre-trained model is ( It is the embedding of the input token, with a dimension of 768.

[0272] Adaptive prompts generate an additional embedding sequence (m is the suggested length, such as...) ),in Generated by a small MLP:

[0273]

[0274] in, The i-th element of the prompt embedding sequence (a dynamic prompt embedding is generated by a small multilayer perceptual MLP based on the intent of the question and entity features (such as time, location, user), and concatenated before the question embedding and input into the pre-trained model).

[0275] g() is a 2-layer MLP (input dimension = intent feature dimension + entity feature dimension = 10 + 20 = 30, hidden layer dimension = 256, activation function = ReLU), and x is the feature of the question (such as the one-hot vector of the intent label "sales ranking query" and the embedding of the entity "time: last month"). These are the learnable parameters of the MLP (number ≤ 100,000).

[0276] P is concatenated before E to obtain a new input embedding. The input is then fed into the pre-trained model.

[0277] The goal of adaptive suggestions is to minimize the cross-entropy loss (optimizing the MLP parameters of adaptive suggestions to make the generated suggestions more relevant to the problem requirements and improve the effectiveness of dynamic suggestions):

[0278] ,

[0279] in:

[0280] L: Cross-entropy loss (by minimizing the cross-entropy between the model's predictions and the true labels, the MLP parameters are adjusted to improve the quality of the suggestions, making the generated suggestions more relevant to the semantic requirements of the question).

[0281] N: Size of the few-sample dataset (e.g., ...) );

[0282] Model on samples The predicted probability distribution;

[0283] :sample The true label (such as the correct SQL statement or intent category).

[0284] Results: Adaptive suggestions improved the accuracy of SQL generation by 20% (from 80% to 100%), which is better than fixed suggestions (10%).

[0285] (III) Active Learning: Uncertainty Sampling

[0286] Question: In scenarios with few samples and scarce labeled data (≤100 samples / class), how to select high-value unlabeled questions to maximize model performance improvement?

[0287] Solution: Employ uncertainty sampling, select the problem with the highest model prediction uncertainty, and push it to domain experts for annotation.

[0288] principle:

[0289] For an unlabeled question x, the model predicts its class distribution as follows: (K is the number of categories, such as ).

[0290] Uncertainty is measured by entropy (the higher the entropy, the higher the uncertainty):

[0291] ,

[0292] This represents the entropy value predicted by the model for problem x.

[0293] K is the number of intent categories;

[0294] The model predicts that question x belongs to the k-th class of intent. The probability of )

[0295] Select the top M problems with the highest entropy values ​​(e.g., ... ), and push it to experts for annotation.

[0296] Example:

[0297] Unmarked question: "What credit card transactions exceeding 1000 yuan were made by Zhang San in the past week?"

[0298] The model predicts the category distribution: P(y|x) = [0.3 (sales ranking query), 0.4 (transaction details query), 0.3 (amount statistics query)].

[0299] Entropy value: ≈ 1.098 (High entropy, large uncertainty).

[0300] Result: The question was pushed to experts for annotation, and after annotation, it was added to the sample template library (template "Query records of [user] [transaction type] exceeding [amount] within [time range]").

[0301] Results: Active learning improved the model's classification accuracy by 15% (from 85% to 100%), which is better than random sampling (5% improvement).

[0302] V. Application Methods, Steps, and Case Studies

[0303] (I) Application Methods and Steps

[0304] The application method of this system follows the process of "input → processing → output → optimization". The specific steps and output results are shown in Figure 3 below:

[0305] step Operation Description Responsible party Output 1 Users can enter natural language questions on the web interface (such as "What were the top 5 mobile phone sales in North China last month?"). user Natural Language Problems 2 The system calls the NLP layer for preprocessing (word segmentation, entity recognition, intent classification). system Intent tags (e.g., "sales ranking query"), entity information (e.g., "time: last month") 3 The system matches sample templates (such as "SQL statement to query the top [quantity] sales in [region] [product category] within [time range]"). system Matching templates and examples 4 The system generates dynamic suggestions (CoT+ adaptive suggestions) and calls the pre-trained model to generate SQL. system Structured query statements (such as SQL) 5 The system executes SQL statements and returns the results (tables + charts). system Query results (e.g., product name, sales amount) 6 Users can view the results and click "Accurate" or "Inaccurate". user Feedback information (e.g., "accurate" or "inaccurate") 7 The system collects feedback and optimizes the example template library and pre-trained models. system Optimized template library (e.g., adding new templates), and fine-tuned models (e.g., Llama 2).

[0306] Table 3

[0307] (II) Scenario Case: Customer Transaction Inquiry in the Financial Sector

[0308] Scenario Description: A bank customer needs to query "What transactions in the past week did Zhang San spend more than 1,000 yuan on his credit card and fall under the 'dining' category?" The system needs to generate an accurate SQL statement to query the transaction table in MySQL (which stores customer transaction data).

[0309] Detailed steps to follow:

[0310] The user entered: "What credit card transactions exceeding 1000 yuan in the past week were categorized as 'dining'?"

[0311] NLP preprocessing:

[0312] Word segmentation: "What transactions did Zhang San make in the past week that exceeded 1000 yuan in credit card spending and belonged to the 'dining' category?"

[0313] Entity recognition: [Time: Past week], [User: Zhang San], [Transaction type: Credit card spending], [Amount: 1000 yuan], [Category: Catering].

[0314] Intent classification: Using a prototype network, the classification result is "Transaction details query" (intent label).

[0315] Template matching:

[0316] Template retrieval: Elasticsearch retrieves templates from the library based on "Transaction Details Query" and returns the template "SQL statement for querying transaction records within [time range] [user] [transaction type] that exceed [amount] and belong to [category]".

[0317] Similarity calculation: The semantic similarity between the question and the template is 0.9 (higher than the threshold of 0.7), so the match is successful.

[0318] Prompt generation:

[0319] CoT Tip: "Example: The SQL for the question 'What transactions in the past month have Li Si withdrawn more than 500 yuan from his savings card and fall under the 'Entertainment' category?' is: SELECT" FROM transaction WHERE user_name='Li Si' AND transaction_type='Debit card withdrawal' AND transaction_date BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH) AND CURRENT_DATE() AND amount>500 AND category='Entertainment'. Now the question is: What are the transactions where Zhang San's credit card consumption exceeded 1000 yuan and belonged to the 'Food and beverage' category in the past week? Please generate the corresponding SQL statement.

[0320] Adaptive hint: MLP generates hint embeddings , concatenated in front of the question embedding.

[0321] Model inference:

[0322] Llama 2 generates the SQL statement: "SELECT FROM transaction WHERE user_name='Zhang San' AND transaction_type='Credit card consumption' AND transaction_date BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 1 WEEK) AND CURRENT_DATE() AND amount>1000 AND category='Food and beverage';

[0323] SQLParse checks the syntax and there is no error.

[0324] Query execution:

[0325] Cache check: There is no cache for this SQL in Redis (first query).

[0326] Database query: JDBC connects to MySQL, executes the SQL statement, and returns the results (such as 5 transaction records, including transaction time, amount, and merchant name).

[0327] Result display:

[0328] The web interface displays the transaction records in a table (sorted from new to old) and shows the daily consumption amount in a bar chart.

[0329] When the user clicks "Accurate", the feedback information is stored in Redis.

[0330] Optimization and iteration:

[0331] Feedback analysis: Spark Streaming statistics show that 95% of queries are "accurate," so no optimization is needed.

[0332] Template Library Expansion: Add this question and template to the sample template library ("Transaction Details Query" category) to enrich template diversity.

[0333] VI. System Performance Evaluation

[0334] The performance of this system was evaluated on the few-shot dataset FewShotWoz (containing 1000 intelligent question counting questions, divided into 10 categories, with 100 data points per category), and compared with existing methods (fixed hints, zero-shot learning). The results are shown in Table 4 below:

[0335] index This system (adaptive prompts + active learning) Fixed Tip (CoT) Zero-shot learning (without prompts) SQL generation accuracy rate (%) 100 80 60 Query latency (ms) 200 250 300 Small sample data requirement (number of records / classes) 10 50 100 User satisfaction (%) 95 85 75

[0336] Table 4

[0337] This solution proposes a few-shot prompt-based dynamic structured query method for intelligent querying. Through techniques such as few-shot intent classification, dynamic prompt generation, and active learning, it addresses the weaknesses of existing intelligent querying systems, including weak generalization ability and insufficient template flexibility in few-shot scenarios. The system adopts a layered architecture, encompassing hardware, software, and data layers, achieving closed-loop optimization from user interaction to data querying. Experimental results show that this system outperforms existing methods in terms of SQL generation accuracy, query latency, and user satisfaction. It is applicable to multiple fields such as enterprise sales and financial transactions, and has broad application prospects.

[0338] It should also be understood that the memory in the embodiments of the present invention can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous DRAM (DDR SDRAM), enhanced synchronous DRAM (ESDRAM), synchronous linked DRAM (SLDRAM), and direct rambus RAM (DR RAM).

[0339] The above embodiments can be implemented, in whole or in part, by software, hardware (such as circuits), firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable system. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more sets of available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium. A semiconductor medium can be a solid-state drive.

[0340] It should be understood that the term "and / or" in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. A and B can be singular or plural. Additionally, the character " / " in this article generally indicates an "or" relationship between the preceding and following related objects, but it can also represent an "and / or" relationship. Please refer to the context for a more accurate understanding.

[0341] In this invention, "at least one" means one or more, and "more than one" means two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of a single item or a plurality of items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, and c can be a single item or multiple items.

[0342] It should be understood that, in various embodiments of the present invention, the order of the above-mentioned process numbers does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0343] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0344] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the devices, systems, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0345] In the embodiments provided by this invention, it should be understood that the disclosed devices, systems, and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between systems or units may be electrical, mechanical, or other forms.

[0346] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0347] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0348] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0349] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A few-sample dynamic structured query system for intelligent question counting, characterized in that, include: The hardware layer includes a computing server, a GPU accelerator card connected to the computing server, a distributed storage system, a relational database, an analytical database, and network devices; The software layer, deployed above the hardware layer, includes: The user interaction module is used to receive natural language questions input by users and display the query results; The natural language processing module is used to preprocess the natural language problem and extract intent and entity information. The natural language processing module includes a few-shot intent classifier based on a prototype network. The few-shot learning module includes an example template library, which is used to match the best example template based on the intent and entity information by semantic similarity calculation and rule filtering. The structured query generation module is used to construct dynamic prompts based on the matched example templates and entity information, and to call the pre-trained model to generate structured query statements. The data storage and access module is used to execute the structured query statement and return the results from the database; The feedback optimization module is used to collect user feedback and perform active learning based on uncertainty sampling to optimize the example template library and pre-trained model; The data layer is used to store raw business data, aggregated data, sample template library data, user feedback data, and labeled data.

2. A method for dynamic structured query with few-sample hints for intelligent querying, characterized in that, include: The problem of receiving natural language input from users; Natural language processing is performed on the natural language problem to extract intent and entity information, wherein intent extraction adopts a few-shot intent classification method based on prototype networks; Based on the extracted intent and entity information, the best example template is matched from the example template library; By combining the best matching example template with the entity information, a dynamic prompt is constructed; The dynamic prompts are input into the pre-trained model to generate structured query statements; Check if there is a result in the cache that corresponds to the current structured query statement. If so, return the cached result directly. Execute the structured query statement to obtain the query results; The query results are returned and displayed to the user.

3. The method according to claim 2, characterized in that, The few-shot intent classification method based on prototype networks includes: For each intent category, the mean of the feature vectors of all samples in that category is calculated to obtain the prototype representation of that category; For a natural language problem to be classified, extract its corresponding feature vector; Calculate the distance between the feature vector and the prototype representation of each category; The intent category corresponding to the prototype with the smallest distance is determined as the intent classification result of the natural language problem.

4. The method according to claim 3, characterized in that, The distance is the Mahalanobis distance, which is calculated by introducing the covariance matrix of the eigenvectors.

5. The method according to claim 2, characterized in that, Match the best example template from the example template library, including: Based on the intent information, relevant candidate templates are retrieved from the example template library; Calculate the semantic similarity between the natural language question and each candidate template; The candidate templates are filtered according to rules based on the entity information. Based on the semantic similarity and rule filtering results, the optimal example template is determined.

6. The method according to claim 2, characterized in that, Constructing dynamic cues includes employing the Chain of Reasoning (CoT) cuing method, wherein the dynamic cues include examples of reasoning steps based on the best example template.

7. The method according to claim 6, characterized in that, The construction of dynamic prompts also includes: employing an adaptive prompt adjustment method, wherein the method includes generating a dynamic prompt embedding sequence based on the intent and entity information using a multilayer perceptron, and concatenating the prompt embedding sequence before the input embedding sequence of the pre-trained model.

8. The method according to claim 2, characterized in that, After generating the structured query statement, the method further includes a step of performing syntax validation on the structured query statement.

9. The method according to claim 2, characterized in that, The method also includes a feedback optimization step: Receive user feedback on the accuracy of the query results; If the feedback is inaccurate, record the feedback information and analyze the reasons; When the cause is a model generation error, the pre-trained model is fine-tuned using labeled data based on the feedback information.

10. The method according to claim 9, characterized in that, The feedback optimization step also includes an active learning process: Collect unlabeled natural language questions; The unlabeled problem is predicted using the current model, and the uncertainty measure of the prediction results is calculated. Select several issues with the highest uncertainty and submit them to experts for annotation; The labeled data is added to the training set to optimize the few-shot intent classifier and / or the pre-trained model.