Promql sentence generation method and device, equipment and readable storage medium

By extracting entity parameters and parsing historical statements from user queries, constructing a reference context using a vector database and a log database, generating PromQL query statements using a trained model, and iteratively optimizing through execution results, the problem of low efficiency in PromQL query statement generation has been solved, achieving efficient and accurate PromQL statement generation.

CN122173611APending Publication Date: 2026-06-09GUANGZHOU QUWAN NETWORK TECH 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
2026-03-17
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

In enterprise operations and maintenance practices, the complex syntax of PromQL and its high learning and usage threshold make it difficult to understand the meaning of monitoring metrics during cross-team collaboration, resulting in low efficiency in writing PromQL query statements and severely restricting the efficiency of R&D and operations.

Method used

By extracting entity parameters from user queries and identifying query requirements, the system retrieves target PromQL statements and parsed text blocks from a vector database and historical log database. It then uses a trained statement generation model to construct a reference context, generates PromQL query statements that meet the query requirements, and adaptively corrects the statements based on the execution results until the requirements are met.

Benefits of technology

It achieves automatic conversion and adaptive correction from natural language to PromQL statements, improves the efficiency of PromQL generation, ensures the accuracy and usability of the generated PromQL query statements, and lowers the writing threshold.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122173611A_ABST
    Figure CN122173611A_ABST
Patent Text Reader

Abstract

The application discloses a PromQL sentence generation method and device, equipment and a readable storage medium, the method comprises the following steps: identifying the query requirement of the user's question; recalling the target PromQL sentence and the sentence analysis text block matched with the query requirement from the vector database and the historical log library, and constructing the reference context; using the sentence generation model, generating the PromQL query sentence based on the reference context; executing the PromQL query sentence to obtain the execution result; updating the reference context when the PromQL query sentence cannot meet the query requirement; returning to the step of generating the PromQL query sentence for meeting the query requirement until the latest execution result meets the query requirement. It can be seen that the application can realize the conversion from natural language to PromQL sentence, effectively improve the PromQL generation efficiency, accuracy and usability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and more specifically, to a method, apparatus, device, and readable storage medium for generating PromQL statements. Background Technology

[0002] In enterprise operations and maintenance (O&M) practices, PromQL's complex syntax and high learning and usage barriers pose a significant challenge. Especially in O&M environments with large-scale parallel deployments across multiple departments and business lines, the sheer number of custom monitoring metrics reported by each team makes it difficult for different teams to intuitively understand the actual business implications of specific metrics during cross-team collaboration. This often requires substantial time for manual communication and aligning metric meanings before PromQL queries can be written. These issues directly result in low efficiency in writing PromQL queries, severely hindering both development and O&M efficiency.

[0003] Therefore, how to provide a method for adaptively generating PromQL query statements to improve R&D and operation efficiency has become a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0004] In view of this, this application provides a PromQL statement generation method, apparatus, device, and readable storage medium to address the shortcomings of low efficiency in existing PromQL query statement generation technologies.

[0005] To achieve the above objectives, the following solution is proposed:

[0006] A method for generating PromQL statements, comprising:

[0007] Extract entity parameters from user queries to identify the query requirements of the user queries;

[0008] Retrieve the target PromQL statement and statement parsing text block that match the query requirements from the vector database and historical log database;

[0009] Based on the target PromQL statement and the parsed text block of the statement, a reference context is constructed;

[0010] Using a trained statement generation model, based on the reference context, a PromQL query statement is generated to satisfy the query requirements;

[0011] Execute the generated PromQL query to obtain the execution result;

[0012] If the execution result indicates that the corresponding PromQL query statement cannot satisfy the query requirement, the reference context is updated based on the PromQL query statement and its matching execution result; the process returns to the step of generating a PromQL query statement to satisfy the query requirement based on the reference context using the trained statement generation model, until the latest execution result satisfies the query requirement.

[0013] Optionally, the step of extracting entity parameters from the user's query and identifying the user's query requirements includes:

[0014] Entity extraction is performed on the user query to extract entity parameters belonging to time range, resource object and / or monitoring indicator, and query requirements are generated.

[0015] Optionally, the step of entity extraction from the user query, extracting entity parameters belonging to time range, resource object, and / or monitoring metric, and generating query requirements includes:

[0016] The user's question is input into an LLM model trained with Few-shot Prompting. The LLM model is used to extract entity parameters, and the structured description output by the LLM model is used as the query requirement.

[0017] Optionally, the step of retrieving the target PromQL statement and statement parsing text block that match the query requirement from the vector database and historical log database includes:

[0018] The query requirements are converted into a high-dimensional vector using the vectorized model Embedding.

[0019] Retrieve all target file blocks that match the high-dimensional vector from the vector database. Each target file block contains a corresponding PromQL code block and a parsing description of different parameters in the corresponding PromQL code block.

[0020] Retrieve all successfully executed historical PromQL statements that match the high-dimensional vector from the historical log database;

[0021] Based on each historical PromQL statement and each target file block, a target PromQL statement matching the query requirement and the corresponding statement parsing text block are generated.

[0022] Optionally, the step of generating a target PromQL statement and its corresponding parsed text block that matches the query requirement based on each historical PromQL statement and each target file block includes:

[0023] Calculate the first similarity between the high-dimensional vector and each historical PromQL statement, and sort the historical PromQL statements in descending order of the first similarity to obtain the first sorting result;

[0024] Calculate the second similarity between the high-dimensional vector and the parsed content in each target file block, and sort the target file blocks in descending order of the second similarity to obtain the second sorting result;

[0025] Select the target PromQL statement and statement parsing text block that match the query requirements from the first sort result and the second sort result.

[0026] Optionally, the step of using a trained statement generation model to generate a PromQL query statement to satisfy the query requirements based on the reference context includes:

[0027] Identify whether the query request contains entity parameters with a corresponding time range. If so, standardize the entity parameters with the corresponding time range according to ISO 8601 to generate standardized time parameters.

[0028] Using the statement to generate the model, based on the reference context, a reference PromQL code block is determined, and based on the query requirements, the parameters of the reference PromQL code block are updated. The standardized time parameters are written into the updated reference PromQL code block to generate a PromQL query statement.

[0029] Optionally, the parsed text block contains target parsing descriptions for different target parameters;

[0030] The update of the reference context based on the PromQL query statement and its matching execution results includes:

[0031] Using the statement generation model, based on the execution result and the parsed text block of the statement, infer whether the matching rules and function combinations in the PromQL query statement are correct, and obtain the inference result; combine the inference result and the execution result to update the reference context.

[0032] A PromQL statement generation apparatus, comprising:

[0033] The identification module is used to extract entity parameters from user queries and identify the query requirements of the user queries;

[0034] The recall module is used to recall target PromQL statements and statement parsing text blocks that match the query requirements from the vector database and historical log database.

[0035] The construction module is used to construct a reference context based on the target PromQL statement and the parsed text block of the statement;

[0036] A generation module is used to generate a PromQL query statement that satisfies the query requirements based on the reference context, using a trained statement generation model.

[0037] The execution module is used to execute the generated PromQL query statement and obtain the execution result;

[0038] The update module is used to update the reference context based on the PromQL query statement and its matching execution result when the execution result shows that the corresponding PromQL query statement cannot meet the query requirements; and to call the generation module until the latest obtained execution result meets the query requirements.

[0039] A PromQL statement generation device, including a memory and a processor;

[0040] The memory is used to store programs;

[0041] The processor is used to execute the program and implement the various steps of the PromQL statement generation method described above.

[0042] A readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the PromQL statement generation method described above.

[0043] As can be seen from the above technical solutions, the PromQL statement generation method provided in this application extracts entity parameters from user queries and identifies the query requirements of the user queries. This method can structure fuzzy query requirements in natural language form and convert them into query requirements that the statement generation model can understand, avoiding the occurrence of requirement misunderstanding bias. This application constructs the reference context of the statement generation model by recalling and combining the target PromQL statement and the statement parsing text block from a vector database and a historical log database. Using the trained statement generation model, based on the reference context, a PromQL query statement to meet the query requirements is generated. The statement generation model can directly reuse historical effective experience and monitoring indicator semantic information that match the query requirements to complete the generation of PromQL query statements. There is no need to build PromQL statements from scratch, and the reference context comes from the vector database and historical logs. The log library offers strong interpretability and conforms to PromQL syntax specifications, reducing the probability of errors and the generation threshold of PromQL queries, thus accelerating the generation speed of PromQL queries. By executing the generated PromQL queries and obtaining the execution results, the legality, validity, and usability of the statements can be truly verified. This application updates the reference context based on the PromQL query and its matching execution results when the execution results indicate that the corresponding PromQL query cannot meet the query requirements. It then returns to the step of using a trained statement generation model to generate a PromQL query to meet the query requirements based on the reference context, continuing until the latest execution result satisfies the query requirements. This allows for adaptive correction based on execution feedback, continuously optimizing the generated results until a satisfactory PromQL query is obtained, improving the usability and success rate of the final statement. As can be seen, this application can generate PromQL query statements by identifying user queries, combining historical statements and parsed text to construct reference context, and iteratively optimizing based on execution results. This enables automatic conversion and adaptive correction of natural language to PromQL statements, effectively improving the efficiency of PromQL generation while ensuring the accuracy and usability of PromQL generation and reducing the writing threshold. Attached Figure Description

[0044] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0045] Figure 1This is a flowchart of a PromQL statement generation method disclosed in an embodiment of this application;

[0046] Figure 2 This is a structural block diagram of a PromQL statement generation device disclosed in an embodiment of this application;

[0047] Figure 3 This is a hardware structure block diagram of a PromQL statement generation device disclosed in an embodiment of this application. Detailed Implementation

[0048] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0049] This application provides a PromQL statement generation method, which can be applied to various R&D systems or software maintenance systems, as well as various computer terminals or smart terminals. The executing entity can be the processor or server of the computer terminal or smart terminal.

[0050] Next, combine Figure 1 The PromQL statement generation method of this application is described in detail, including the following steps:

[0051] Step S1: Extract entity parameters from the user's question to identify the query requirements of the user's question.

[0052] Specifically, it can respond to vague questions from users and generate user-generated questions.

[0053] User questions can include one or more of the following key information: specific monitoring metrics, time range, resource objects, and filtering criteria.

[0054] For example, a user could ask, "Check yesterday's CPU status."

[0055] Entity parameter extraction technology can be used to identify and extract key information from user queries, thereby clarifying the user's query needs.

[0056] Step S2: Retrieve the target PromQL statement and statement parsing text block that match the query requirements from the vector database and historical log database.

[0057] Specifically, PromQL stands for Prometheus query language.

[0058] The vector database can store file blocks with multiple metrics. Each file block contains a query code block written in PromQL syntax corresponding to the metric and the parsing of the corresponding query code block.

[0059] Each parsing may include the function description of the code block contained in the corresponding query code block, the semantic description of the metric, the metric resource type, the explanation of parameter values, the metric unit, the function vector used, the substitutability of parameter values, and / or the requirements for setting parameter values, etc.

[0060] For example, one of the file blocks may be:

[0061] Query code block:

[0062] api_http_requests_total{method="POST", handler=" / messages"}

[0063] api_http_requests_total is the number of business http requests, which is often used by users to count the request volume of business services, etc.; method is the request method; handler is the request path.

[0064] Another example, another file block may be:

[0065] Query code block:

[0066] sum(cloud_redis_cpu{cluster="k8s-tc-bj-1-yunwei",resource_name=~".*<Redis name>.*",solo_belong="instance"}) by (resource_name)

[0067] Function description of the code block: Query and calculate the CPU usage rate of the specified Redis.

[0068] Unit: %

[0069] Metric resource type: Redis

[0070] Label description:

[0071] Cluster: The cluster name is k8s-tc-bj-1-yunwei, metric is the cluster where the data is located, which is a fixed value and does not need to be changed.

[0072] resource_name is the Redis resource name. When there are multiple, they can be separated by |. Note that * fuzzy matching is retained.

[0073] The vector database can be one of the vector databases such as Milvus and Chroma.

[0074] The historical log database can include two types of PromQL statements: one type can be PromQL statements that have been executed successfully, and the other type can be multiple PromQL statements with reasons for execution failure.

[0075] PromQL statements in the historical log repository can contain one or more query blocks.

[0076] Step S3: Construct a reference context based on the target PromQL statement and the parsed text block of the statement.

[0077] Specifically, the recalled target PromQL statements and their corresponding parsed text blocks can be integrated to form a structured reference context.

[0078] Referring to the target PromQL statement in the context is an excellent example that can be used to dispel the illusion of custom metrics.

[0079] The reference context may contain specific PromQL statements, as well as detailed information such as the function description, indicator semantics, and parameter explanations of some code blocks within the PromQL statements.

[0080] Step S4: Using the trained statement generation model, based on the reference context, generate a PromQL query statement to meet the query requirements.

[0081] Specifically, multiple types of training samples can be used to train and adjust the parameters of the initial sentence generation model to obtain a trained sentence generation model.

[0082] The initial statement generation model can be an LLM model;

[0083] One type of training sample may include corresponding training metrics, training requirements, reference PromQL statements and reference statement parsing, and PromQL successful execution statements generated based on the reference PromQL statements and reference statement parsing.

[0084] Another type of training sample may include corresponding training metrics, training requirements, reference PromQL statements and reference statement parsing, PromQL execution failure statements generated based on reference PromQL statements and reference statement parsing, failure reasons, and modification methods.

[0085] Reasons for failure may include dimension mismatch, incorrect parameter values, etc.

[0086] Modification methods may include changing the Group by label or changing the Metric name.

[0087] A statement generation model can be used to generate PromQL query statements based on the reference context and query requirements.

[0088] Step S5: Execute the generated PromQL query statement to obtain the execution result.

[0089] Specifically, the PromQL-Proxy tool can be used to execute the generated PromQL query statements in a real cluster and obtain the execution results.

[0090] Step S6: When the execution result shows that the corresponding PromQL query statement cannot meet the query requirements, update the reference context based on the PromQL query statement and its matching execution result; return to step S4 until the latest obtained execution result meets the query requirements.

[0091] Specifically, it can be detected whether the execution result contains time-series data corresponding to the monitoring metric. If not, it can be determined that the execution result indicates that the corresponding PromQL query statement cannot meet the query requirements. In this case, the execution result may include error information such as syntax errors and Empty query result. Based on the PromQL query statement and its matching execution result, the reference context can be updated; the execution step S4 can be returned until the latest obtained execution result meets the query requirements.

[0092] If so, it can be determined that the execution result shows that the corresponding PromQL query statement meets the query requirements; at this time, the time series data can be charted and displayed without manual intervention for troubleshooting.

[0093] It also identifies several metrics similar to the monitoring metrics, and uses the above method to generate PromQL query statements corresponding to each similar metric, providing users with display links to the time series data corresponding to multiple similar metrics.

[0094] It can also provide semantic information of monitoring indicators and methods for adjusting indicator values, and has the ability to continuously learn and evolve.

[0095] Successfully executed PromQL queries can be written back to the historical log database.

[0096] As can be seen from the above technical solutions, the PromQL statement generation method provided in this application extracts entity parameters from user queries and identifies the query requirements of the user queries. This method can structure fuzzy query requirements in natural language form and convert them into query requirements that the statement generation model can understand, avoiding the occurrence of requirement misunderstanding bias. This application constructs the reference context of the statement generation model by recalling and combining the target PromQL statement and the statement parsing text block from a vector database and a historical log database. Using the trained statement generation model, based on the reference context, a PromQL query statement to meet the query requirements is generated. The statement generation model can directly reuse historical effective experience and monitoring indicator semantic information that match the query requirements to complete the generation of PromQL query statements. There is no need to build PromQL statements from scratch, and the reference context comes from the vector database and historical logs. The log library offers strong interpretability and conforms to PromQL syntax specifications, reducing the probability of errors and the generation threshold of PromQL queries, thus accelerating the generation speed of PromQL queries. By executing the generated PromQL queries and obtaining the execution results, the legality, validity, and usability of the statements can be truly verified. This application updates the reference context based on the PromQL query and its matching execution results when the execution results indicate that the corresponding PromQL query cannot meet the query requirements. It then returns to the step of using a trained statement generation model to generate a PromQL query to meet the query requirements based on the reference context, continuing until the latest execution result satisfies the query requirements. This allows for adaptive correction based on execution feedback, continuously optimizing the generated results until a satisfactory PromQL query is obtained, improving the usability and success rate of the final statement. As can be seen, this application can solve the problem of invisible private metrics by identifying user queries, constructing PromQL query statements with reference context by combining historical statements and parsed text, reducing model illusion, and iteratively optimizing based on execution results. It can achieve automatic conversion and adaptive correction from natural language to PromQL statements, effectively improving the efficiency of PromQL generation while ensuring the accuracy and usability of PromQL generation and lowering the writing threshold.

[0097] In some embodiments of this application, the process of step S1, extracting entity parameters from the user's query and identifying the query requirements of the user's query, is described in detail as follows:

[0098] S10. Entity extraction is performed on the user query to extract entity parameters belonging to time range, resource object and / or monitoring indicator, and query requirements are generated.

[0099] Specifically, the Agent can be used to extract entity parameters related to time range, resource object, and / or monitoring metrics from user queries.

[0100] For example, when a user asks "Query the server's memory usage yesterday", the Agent can identify the time range as "yesterday", the resource object as "server", and the monitoring metric as "memory usage", transforming key information from natural language into a structured query requirement.

[0101] As can be seen from the above technical solution, this embodiment provides an optional method for extracting entity parameters from user queries and identifying the query requirements of the user's query. This method can convert the user's fuzzy monitoring requirements into structured query intents, avoiding interference from irrelevant information and improving the matching degree between the subsequently generated PromQL statements and the user's needs.

[0102] In some embodiments of this application, the process of step S10, which involves entity extraction from the user query to extract entity parameters belonging to time range, resource object, and / or monitoring indicator, and generating query requirements, is described in detail below:

[0103] S100. Input the user's question into the LLM model trained by Few-shot Prompting, extract entity parameters using the LLM model, and use the structured description output by the LLM model as the query requirement.

[0104] Specifically, the training process of this LLM model can be as follows:

[0105] Obtain example statements corresponding to different query scenarios, which include entity parameters such as time range, resource objects, and monitoring metrics, and construct a training sample set;

[0106] The initial LLM model can be trained using a training sample set, and a few examples and corresponding hints can be provided during the training process to guide the initial LLM model to learn how to accurately extract entity parameters from the input natural language and generate a structured query requirement description.

[0107] After multiple rounds of training and optimization, an LLM model trained with Few-shot Prompting can be obtained.

[0108] One example of a structured query requirement is as follows: Metric type: "CPU utilization"; Time range: "yesterday"; Resource object: "pod"; Filter condition: "high utilization".

[0109] As can be seen from the above technical solution, this embodiment provides an optional method for extracting entities from user queries, extracting entity parameters belonging to time ranges, resource objects, and / or monitoring indicators, and generating query requirements. Through this method, an LLM model trained with Few-shot Prompting can be used to complete the extraction of entity parameters and the generation of structured query requirements, achieving automated conversion from natural language to structured query requirements, improving processing efficiency and accuracy, and reducing manual intervention and errors. Furthermore, the model used in this application learns through a small number of examples and can quickly adapt to different query scenarios and changes in requirements, enhancing the flexibility and practicality of this application.

[0110] In some embodiments of this application, the process of retrieving the target PromQL statement and the parsed text block of the statement that matches the query requirement from the vector database and the historical log database is described in detail as follows:

[0111] S20. Using the vectorized model Embedding, the query requirements are converted into a high-dimensional vector.

[0112] Specifically, a vectorized model, Embedding, can be used to convert textual query requirements into high-dimensional vectors.

[0113] Embedding can be an open-source model such as OpenAI text-embedding-3 or HuggingFace.

[0114] High-dimensional vectors are represented as numerical vectors that can be computed by computers, making it easier to capture semantic information in query requirements.

[0115] S21. Retrieve all target file blocks that match the high-dimensional vector from the vector database. Each target file block contains a corresponding PromQL code block and a parsing description of different parameters in the corresponding PromQL code block.

[0116] Specifically, file blocks that match high-dimensional vectors can be retrieved from a vector database using cosine similarity as target file blocks.

[0117] Each target file block contains a PromQL code block for the entity parameters involved, as well as a multi-dimensional target parsing description including parameter value setting requirements, semantic description, indicator resource type, parameter value interpretation, indicator unit, function vector used, parameter value substitutability, parameter value setting requirements, and PromQL code block function description.

[0118] S22. Retrieve from the historical log database all historical PromQL statements that were successfully executed and matched the high-dimensional vector.

[0119] Specifically, the LogsRetriever tool can be used to search for successfully executed PromQL statements that match a high-dimensional vector from a historical log database using cosine similarity.

[0120] S23. Based on each historical PromQL statement and each target file block, generate a target PromQL statement and its corresponding parsed text block that match the query requirements.

[0121] Specifically, the retrieved historical PromQL statements can be matched and integrated with the target file blocks, and the target PromQL statements that best meet the requirements can be selected based on the entity parameters and semantic information in the query requirements.

[0122] It can extract the parameter parsing description of the corresponding PromQL code block in the target file block and generate a statement parsing text block corresponding to the target PromQL statement.

[0123] As can be seen from the above technical solution, this embodiment provides an optional method for retrieving target PromQL statements that match the query requirements from a vector database and a historical log database. This method fully utilizes the rich historical resources in the vector database and historical log database to retrieve target PromQL statements and their parsed text blocks that highly match the query requirements, effectively leveraging historical experience, avoiding repetitive work, and improving generation efficiency and accuracy. Furthermore, the multi-dimensional parameter analysis helps users better understand the structure and meaning of the generated PromQL statements, enhancing the user experience.

[0124] In some embodiments of this application, the process of generating a target PromQL statement and its corresponding parsed text block that matches the query requirement based on each historical PromQL statement and each target file block is described in detail below:

[0125] S230. Calculate the first similarity between the high-dimensional vector and each historical PromQL statement, and sort each historical PromQL statement in descending order of the first similarity to obtain the first sorting result.

[0126] Specifically, the cosine similarity between the high-dimensional vector and each historical PromQL statement can be calculated as the first similarity, and the historical PromQL statements can be sorted from largest to smallest according to the first similarity to obtain the first sorting result.

[0127] S231. Calculate the second similarity between the high-dimensional vector and the parsed content in each target file block, and sort each target file block according to the second similarity from largest to smallest to obtain the second sorting result.

[0128] Specifically, the cosine similarity between the high-dimensional vector and the parsed content in each target file block can be calculated as the second similarity, and the target file blocks can be sorted from largest to smallest according to the second similarity to obtain the second sorting result.

[0129] S232. Select the target PromQL statement and statement parsing text block that match the query requirements from the first sorting result and the second sorting result.

[0130] Specifically, selection can be made in various ways. For example, the first N historical PromQL statements in the first sorting result can be selected as each target PromQL statement; the first M target file blocks in the second sorting result can be selected as each statement parsing text block.

[0131] Alternatively, historical PromQL statements in the first sorting result with a first similarity greater than a preset similarity threshold can be used as target PromQL statements; and target file blocks in the second sorting result with a second similarity greater than a preset similarity threshold can be used as parsed text blocks for each statement.

[0132] As can be seen from the above technical solution, this embodiment provides an optional method for generating a target PromQL statement and its corresponding parsed text block that matches the query requirement based on each historical PromQL statement and each target file block. Through this method, the similarity between the high-dimensional vector and the parsed content of the historical PromQL statements and target file blocks is calculated, and the results are sorted according to the similarity. This allows for the selection of the target PromQL statement and its corresponding parsed text block that best matches the query requirement, ensuring that the generated PromQL statement closely matches the user's actual query needs.

[0133] In some embodiments of this application, the process of step S4, generating a PromQL query statement to satisfy the query requirements based on the reference context using a trained statement generation model, is described in detail below:

[0134] S40. Identify whether the query request contains entity parameters with a corresponding time range. If so, standardize the entity parameters with the corresponding time range according to ISO 8601 to generate standardized time parameters.

[0135] Specifically, it can be identified whether the query request contains entity parameters with a corresponding time range, such as time-related entity phrases like "yesterday" or "the past hour".

[0136] If so, use the ISO 8601 standard to convert the entity parameters of the corresponding time range into a 24-hour format to obtain standardized time parameters.

[0137] For example, convert "yesterday" to "2026-11-10 00:00:00 to 2026-11-10 24:00:00".

[0138] If not, the model can be generated directly using the statement, the reference PromQL code block can be determined based on the reference context, and the parameters of the reference PromQL code block can be updated based on the query requirements to generate a PromQL query statement.

[0139] S41. Using the statement generation model, based on the reference context, determine the reference PromQL code block, and based on the query requirements, update the parameters of the reference PromQL code block, write the standardized time parameters into the updated reference PromQL code block, and generate a PromQL query statement.

[0140] Specifically, the context is used as the prompt word Prompt in the statement generation model. The statement generation model is used to analyze the syntactic structure and syntactic logic of the target PromQL statement, such as indicator names and clustering functions, to obtain the analysis results.

[0141] If a query statement for this query requirement is generated for the first time, the AI ​​Agent can assume that directly replacing the parameter values ​​can generate a query statement that meets the query requirements. The statement generation model can then select one of the multiple target PromQL statements as a reference PromQL code block. Based on the analysis results and query requirements, the parameters of the reference PromQL code block are updated, and the standardized time parameters are written into the updated reference PromQL code block to generate the PromQL query statement.

[0142] If this is not the first time a query statement for this query requirement has been generated, the AI ​​Agent can assume that directly replacing the parameter values ​​cannot generate a query statement that satisfies the query requirement. In this case, the statement generation model can regenerate the analysis results based on the execution results, and update one of the target PromQL statements by applying label matching rules or function combinations based on the latest reference context and the latest analysis results, generating a reference PromQL code block. The parameters of the reference PromQL code block are updated based on the analysis results and the query requirement, and the standardized time parameters are written into the updated reference PromQL code block to generate the PromQL query statement.

[0143] As can be seen from the above technical solution, this embodiment provides an optional method for generating PromQL query statements to meet the query requirements based on the reference context using a trained statement generation model. Through this method, the generation of PromQL query statements can be completed through the logical reorganization of user intent determination, historical case reference, and statement generation model. This achieves an Agent framework combining Reason and Action, enabling the statement generation model to call external APIs and adjust the PromQL query statements based on the results.

[0144] In some embodiments of this application, the process of updating the reference context based on the PromQL query statement and its matching execution result in step S6 is described in detail as follows:

[0145] S60. Using the statement generation model, based on the execution result and the parsed text block of the statement, infer whether the matching rules and function combinations in the PromQL query statement are correct, and obtain the inference result; combine the inference result and the execution result to update the reference context.

[0146] Specifically, a statement generation model can be used to deeply analyze the parameter usage based on the execution results and parsed text blocks. This allows for inference about whether failed PromQL queries exhibit function combination anomalies and / or matching rule usage anomalies, such as special uses or combinations of certain parameters in specific scenarios. Simultaneously, the accuracy of the PromQL query statements should be carefully verified, including whether parameter value settings are reasonable, thus obtaining comprehensive inference results.

[0147] As can be seen from the above technical solution, this embodiment provides an optional method for updating the reference context based on the PromQL query statement and its matching execution results. Through this method, the reference context can be updated in a targeted manner by combining the inference result and the execution result itself, ensuring that the reference context more accurately reflects the actual situation and providing a more reliable basis for the generation of subsequent query statements.

[0148] Next, we will combine Figure 2 The PromQL statement generation apparatus provided in this application will be described in detail. The PromQL statement generation apparatus described below can be compared with the PromQL statement generation method described above.

[0149] See Figure 2 It can be observed that the PromQL statement generation device may include:

[0150] The identification module 10 is used to extract entity parameters from user queries and identify the query requirements of the user queries.

[0151] Recall module 20 is used to recall target PromQL statements and statement parsing text blocks that match the query requirements from the vector database and historical log database;

[0152] Module 30 is used to construct a reference context based on the target PromQL statement and the parsed text block of the statement;

[0153] The generation module 40 is used to generate a PromQL query statement that satisfies the query requirements based on the reference context using a trained statement generation model.

[0154] Execution module 50 is used to execute the generated PromQL query statement and obtain the execution result;

[0155] The update module 60 is used to update the reference context based on the PromQL query statement and its matching execution result when the execution result shows that the corresponding PromQL query statement cannot meet the query requirements; and to call the generation module 40 until the latest obtained execution result meets the query requirements.

[0156] Furthermore, the identification module 10 may include:

[0157] The query requirement generation unit is used to extract entities from the user's query, extract entity parameters belonging to time range, resource object and / or monitoring indicator, and generate query requirements.

[0158] Furthermore, the query request generation unit may include:

[0159] The entity parameter extraction subunit is used to input the user's question into an LLM model trained by Few-shot Prompting, extract entity parameters using the LLM model, and use the structured description output by the LLM model as the query requirement.

[0160] Furthermore, the recall module 20 may include:

[0161] A high-dimensional vector generation unit is used to convert the query requirements into high-dimensional vectors using a vectorized model Embedding.

[0162] The target file block retrieval unit is used to retrieve all target file blocks that match the high-dimensional vector from the vector database. Each target file block contains a corresponding PromQL code block and a parsing description of different parameters in the corresponding PromQL code block.

[0163] The historical PromQL statement retrieval unit is used to retrieve all historical PromQL statements that have been successfully executed and match the high-dimensional vector from the historical log database.

[0164] The statement parsing text block generation unit is used to generate a target PromQL statement and its corresponding statement parsing text block that match the query requirements, based on each historical PromQL statement and each target file block.

[0165] Furthermore, the statement parsing text block generation unit may include:

[0166] The first sorting result generation subunit is used to calculate the first similarity between the high-dimensional vector and each historical PromQL statement, and sort each historical PromQL statement in descending order of the first similarity to obtain the first sorting result;

[0167] The second sorting result generation subunit is used to calculate the second similarity between the high-dimensional vector and the parsed content in each target file block, and sort each target file block in descending order of the second similarity to obtain the second sorting result;

[0168] The statement parsing text block selection sub-unit is used to select the target PromQL statement and statement parsing text block that match the query requirements from the first sorting result and the second sorting result.

[0169] Furthermore, the generation module 40 may include:

[0170] The standardized time parameter generation unit is used to identify whether the query requirement contains entity parameters of a corresponding time range. If so, the entity parameters of the corresponding time range are standardized according to ISO 8601 to generate standardized time parameters.

[0171] The PromQL query statement generation unit is used to utilize the statement generation model, determine a reference PromQL code block based on the reference context, update the parameters of the reference PromQL code block based on the query requirements, write the standardized time parameters into the updated reference PromQL code block, and generate a PromQL query statement.

[0172] Furthermore, the update module 60 may include:

[0173] The reference context update unit is used to use the statement generation model to infer whether the matching rules and function combinations in the PromQL query statement are correct based on the execution result and the parsed text block of the statement, and obtain the inference result; and update the reference context by combining the inference result and the execution result.

[0174] The PromQL statement generation apparatus provided in this application embodiment can be applied to PromQL statement generation devices, such as PC terminals, cloud platforms, servers, and server clusters. Optionally, Figure 3 The hardware structure block diagram of the PromQL statement generation device is shown, with reference to... Figure 3 The hardware structure of a PromQL statement generation device may include: at least one processor 1, at least one communication interface 2, at least one memory 3, and at least one communication bus 4.

[0175] In this embodiment of the application, the number of processor 1, communication interface 2, memory 3, and communication bus 4 is at least one, and processor 1, communication interface 2, and memory 3 communicate with each other through communication bus 4;

[0176] Processor 1 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention.

[0177] Memory 3 may include high-speed RAM, and may also include non-volatile memory, such as at least one disk storage device;

[0178] The memory stores a program, which the processor can call. The program is used for:

[0179] Extract entity parameters from user queries to identify the query requirements of the user queries;

[0180] Retrieve the target PromQL statement and statement parsing text block that match the query requirements from the vector database and historical log database;

[0181] Based on the target PromQL statement and the parsed text block of the statement, a reference context is constructed;

[0182] Using a trained statement generation model, based on the reference context, a PromQL query statement is generated to satisfy the query requirements;

[0183] Execute the generated PromQL query to obtain the execution result;

[0184] If the execution result indicates that the corresponding PromQL query statement cannot satisfy the query requirement, the reference context is updated based on the PromQL query statement and its matching execution result; the process returns to the step of generating a PromQL query statement to satisfy the query requirement based on the reference context using the trained statement generation model, until the latest execution result satisfies the query requirement.

[0185] Optionally, the refined and extended functions of the program can be referred to the above description.

[0186] This application embodiment also provides a readable storage medium that can store a program suitable for execution by a processor, the program being used for:

[0187] Extract entity parameters from user queries to identify the query requirements of the user queries;

[0188] Retrieve the target PromQL statement and statement parsing text block that match the query requirements from the vector database and historical log database;

[0189] Based on the target PromQL statement and the parsed text block of the statement, a reference context is constructed;

[0190] Using a trained statement generation model, based on the reference context, a PromQL query statement is generated to satisfy the query requirements;

[0191] Execute the generated PromQL query to obtain the execution result;

[0192] If the execution result indicates that the corresponding PromQL query statement cannot satisfy the query requirement, the reference context is updated based on the PromQL query statement and its matching execution result; the process returns to the step of generating a PromQL query statement to satisfy the query requirement based on the reference context using the trained statement generation model, until the latest execution result satisfies the query requirement.

[0193] Optionally, the refined and extended functions of the program can be referred to the above description.

[0194] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0195] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0196] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. The various embodiments of this application can be combined with each other. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for generating PromQL statements, characterized in that, include: Extract entity parameters from user queries to identify the query requirements of the user queries; Retrieve the target PromQL statement and statement parsing text block that match the query requirements from the vector database and historical log database; Based on the target PromQL statement and the parsed text block of the statement, a reference context is constructed; Using a trained statement generation model, based on the reference context, a PromQL query statement is generated to satisfy the query requirements. Execute the generated PromQL query to obtain the execution result; If the execution result indicates that the corresponding PromQL query statement cannot meet the query requirements, the reference context is updated based on the PromQL query statement and its matching execution result. The process returns to the step of generating a PromQL query statement that satisfies the query requirements based on the reference context using the trained statement generation model, until the latest execution result satisfies the query requirements.

2. The PromQL statement generation method according to claim 1, characterized in that, The step of extracting entity parameters from user queries and identifying the query requirements of user queries includes: Entity extraction is performed on the user query to extract entity parameters belonging to time range, resource object and / or monitoring indicator, and query requirements are generated.

3. The PromQL statement generation method according to claim 2, characterized in that, The step of entity extraction from the user query, extracting entity parameters belonging to time range, resource object, and / or monitoring metric, and generating query requirements includes: The user's question is input into an LLM model trained with Few-shot Prompting. The LLM model is used to extract entity parameters, and the structured description output by the LLM model is used as the query requirement.

4. The PromQL statement generation method according to claim 1, characterized in that, The step of retrieving the target PromQL statement and statement parsing text block that match the query requirement from the vector database and historical log database includes: The query requirements are converted into a high-dimensional vector using the vectorized model Embedding. Retrieve all target file blocks that match the high-dimensional vector from the vector database. Each target file block contains a corresponding PromQL code block and a parsing description of different parameters in the corresponding PromQL code block. Retrieve all successfully executed historical PromQL statements that match the high-dimensional vector from the historical log database; Based on each historical PromQL statement and each target file block, a target PromQL statement matching the query requirement and the corresponding statement parsing text block are generated.

5. The PromQL statement generation method according to claim 4, characterized in that, The process of generating a target PromQL statement and its corresponding parsed text block that matches the query requirement, based on each historical PromQL statement and each target file block, includes: Calculate the first similarity between the high-dimensional vector and each historical PromQL statement, and sort the historical PromQL statements in descending order of the first similarity to obtain the first sorting result; Calculate the second similarity between the high-dimensional vector and the parsed content in each target file block, and sort the target file blocks according to the second similarity from largest to smallest to obtain the second sorting result; Select the target PromQL statement and statement parsing text block that match the query requirements from the first sort result and the second sort result.

6. The PromQL statement generation method according to claim 1, characterized in that, The step of generating a PromQL query statement to satisfy the query requirements using a trained statement generation model based on the reference context includes: Identify whether the query request contains entity parameters with a corresponding time range. If so, standardize the entity parameters with the corresponding time range according to ISO 8601 to generate standardized time parameters. Using the statement to generate the model, based on the reference context, a reference PromQL code block is determined, and based on the query requirements, the parameters of the reference PromQL code block are updated. The standardized time parameters are written into the updated reference PromQL code block to generate a PromQL query statement.

7. The PromQL statement generation method according to claim 1, characterized in that, The parsed text block contains target parsing descriptions for different target parameters; The update of the reference context based on the PromQL query statement and its matching execution results includes: Using the statement generation model, based on the execution result and the parsed text block of the statement, infer whether the matching rules and function combinations in the PromQL query statement are correct, and obtain the inference result; combine the inference result and the execution result to update the reference context.

8. A PromQL statement generation device, characterized in that, include: The identification module is used to extract entity parameters from user queries and identify the query requirements of the user queries; The recall module is used to recall target PromQL statements and statement parsing text blocks that match the query requirements from the vector database and historical log database. The construction module is used to construct a reference context based on the target PromQL statement and the parsed text block of the statement; A generation module is used to generate a PromQL query statement that satisfies the query requirements based on the reference context, using a trained statement generation model. The execution module is used to execute the generated PromQL query statements and obtain the execution results; The update module is used to update the reference context based on the PromQL query statement and its matching execution result when the execution result shows that the corresponding PromQL query statement cannot meet the query requirements. The generation module is invoked until the latest execution result satisfies the query requirements.

9. A PromQL statement generation device, characterized in that, Including memory and processor; The memory is used to store programs; The processor is configured to execute the program to implement each step of the PromQL statement generation method as described in any one of claims 1-7.

10. A readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the various steps of the PromQL statement generation method as described in any one of claims 1-7.