A service optimization method and computer device for LLMs
By deploying a service program outside of the LLM to preprocess the query text, fuzzy time expressions are converted into precise time information, thus solving the time illusion problem in time-related queries in LLM and improving the accuracy of the answers.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 浙江飞猪网络技术有限公司
- Filing Date
- 2026-06-23
- Publication Date
- 2026-07-21
AI Technical Summary
Large Language Models (LLMs) lack real-time date awareness and accurate date calculation capabilities, which leads to time illusions when processing time-related queries, resulting in inaccurate answers.
The temporal semantic disambiguation function is decoupled from the internal inference process of LLM and deployed as an independent service program running on the server. This service program preprocesses the query text, converts ambiguous time expressions into precise time information, and submits it to LLM for inference calculation after being annotated in the query text.
It significantly improves the accuracy of LLM in handling time representation tasks, eliminates the time illusion problem, and ensures that the parsing and transformation of time information are completed by deterministic rules and algorithms.
Smart Images

Figure CN122432355A_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of artificial intelligence technology, and in particular to a service optimization method and computer device for LLM. Background Technology
[0002] Large Language Models (LLMs) are deep learning models trained on massive amounts of text data. LLMs can understand and generate natural language text and are widely used in scenarios such as intelligent customer service, virtual assistants, itinerary planning, and schedule management. Users can ask questions or give instructions to the LLM by inputting natural language query text. The LLM then infers from the query text based on the knowledge and patterns learned during its training and generates corresponding responses.
[0003] However, LLM training data typically has a defined cutoff date. Once training is complete, the knowledge stored internally in the model is fixed and no longer automatically updated. This means that LLMs lack the ability to acquire real-time information.
[0004] For example, when a user asks an LLM "What's the weather like today?", the LLM cannot automatically obtain the current system date and therefore cannot calculate which day "today" is. Similarly, if a user enters "Remind me to have a meeting at 3 PM tomorrow," the LLM can understand the semantics of "remind" and "meeting," but it struggles to accurately map "tomorrow" to a specific Gregorian calendar date.
[0005] It is evident that, in practical applications, errors caused by LLM's lack of real-time date awareness and accurate date calculation capabilities can have serious consequences for applications that rely on time information.
[0006] For example, in trip planning scenarios, time illusions might lead users to be given incorrect travel dates. In schedule reminder scenarios, time illusions might lead to reminders being set at the wrong time. In holiday query scenarios, time illusions might lead users to receive incorrect holiday dates. Summary of the Invention
[0007] The technical solutions provided in the embodiments of this specification aim to decouple the time semantic disambiguation function from the internal inference process of LLM and deploy it as an independently running service program on the server. This service program preprocesses the query text before the LLM performs inference calculations, so as to convert the time-related text fragments contained in the query text into accurate time information.
[0008] According to a first aspect of the embodiments of this specification, a service optimization method for an LLM is provided, applied to a service program deployed on a server; wherein the service program establishes a communication connection with the LLM; the method includes: Obtain the query text input by the user into the LLM; wherein the query text contains text fragments related to time expression; Generate precise time information that semantically matches the text fragment, and mark the precise time information in the query text at the position corresponding to the text fragment; The query text labeled with the precise time information is submitted to the LLM, which then performs inference calculations on the query text.
[0009] Optionally, the text fragments related to time expression include: text fragments that are related to time but use language expressions that cannot be directly mapped to precise time information according to semantics.
[0010] Optionally, the LLM initiates service calls to the service program based on a preset calling specification; Obtain the query text entered by the user into the LLM, including: The system receives service call information sent by the LLM through the communication connection; wherein the service call information is service call information generated by the LLM based on the call specification for initiating a service call to the service program; the service call is a service call to the service program initiated by the LLM when it identifies that the query text contains a text fragment related to time expression; the service call information includes the query text input by the user to the LLM; Obtain the query text contained in the service call information.
[0011] Optionally, generating precise time information that semantically matches the text fragment includes: Determine the time expression type of the text fragments related to time expression contained in the query text; Based on the precise time calculation method corresponding to the time expression type, the precise time information of the semantic matching of the text fragments related to the time expression is calculated; wherein, different time expression types correspond to different precise time calculation methods.
[0012] Optionally, the service program maintains multiple sets of matching rules with priority; wherein, the matching rules are used to determine the time expression type of the text fragments related to time expression contained in the query text; different matching rules correspond to different time expression types; Determining the time expression type of the time-related text fragments contained in the query text includes: The query text is matched against the multiple sets of matching rules in descending order of priority. If the query text is successfully matched with any of the multiple sets of matching rules, the time expression type corresponding to that set of matching rules is determined as the time expression type corresponding to the time-related text fragment contained in the query text.
[0013] Optionally, the matching rule includes a regular expression; wherein the regular expression is used to describe the string features of a text segment related to the time expression type corresponding to the regular expression; The query text is matched against the multiple sets of matching rules in descending order of priority. If the query text matches any set of matching rules, the time expression type corresponding to that set of matching rules is determined as the time expression type corresponding to the time-related text fragments contained in the query text, including: According to the priority from high to low, the text fragments contained in the query text are matched with the multiple sets of regular expressions in turn; if any text fragment contained in the query text successfully matches any set of regular expressions, the text fragment is extracted from the query text, and the time expression type corresponding to the set of regular expressions is determined as the time expression type corresponding to the extracted text fragment.
[0014] Optionally, the precise time information is annotated at the position in the query text corresponding to the text fragment, including: Determine the position of the last character of the text segment within the query text; The precise time information is marked at the position of the character following the last character of the text fragment in the query text.
[0015] Optionally, based on the precise time calculation method corresponding to the time expression type, the precise time information of the semantic matching of the text fragments related to the time expression is calculated, including: If multiple text fragments corresponding to different time expression types are extracted from the query text, the precise time information that semantically matches the multiple text fragments is calculated based on the precise time calculation method corresponding to the different time expression types. Marking the precise time information onto the position in the query text corresponding to the text fragment includes: Determine the position of the first character of the plurality of text segments in the query text; The positions of the first character in the query text are sorted in reverse order, and the precise time information that semantically matches the multiple text segments is sequentially marked at the position of the next character after the position of the last character of the multiple text segments in the query text, according to the sorted order.
[0016] Optionally, the method further includes: The precise time information that semantically matches the multiple text fragments is sequentially marked after the last character of the multiple text fragments in the query text. If multiple precise time information is marked at any character position, the target precise time information with the highest priority of the matching rule is retained, and other precise time information other than the target precise time information is removed from the multiple precise time information.
[0017] Optionally, the LLM makes service calls to the service program based on the MCP protocol; the service program includes service programs based on the MCP protocol. The priority indicates the frequency of use of the time expression type corresponding to the matching rule; wherein, the magnitude of the priority is positively correlated with the frequency of use.
[0018] According to a second aspect of the embodiments of this specification, a computer device is also provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor performs the executable instructions to implement the steps of the method as described in any of the first aspects above.
[0019] According to a third aspect of the embodiments of this specification, a computer program product is also provided, comprising a computer program / instructions that, when executed by a processor, implement the steps of the method as described in any one of the first or second aspects above.
[0020] In the above technical solution, the time semantic disambiguation function is decoupled from the internal inference process of LLM and deployed as an independent service program on the server. This service program preprocesses the query text before the LLM performs inference calculations to convert the time-related text fragments contained in the query text into accurate time information.
[0021] Specifically, after receiving the query text input by the user into the LLM, the service program generates semantically matched precise time information for the time-related text fragments contained in the query text. This precise time information is then directly annotated at the corresponding text fragment position in the query text. The annotated query text is then submitted to the LLM for inference and computation. In this way, deterministic computation tasks can be separated from the probabilistic inference engine of the LLM and handled by a dedicated service program. This ensures that the parsing and transformation of time information no longer depends on the inference capabilities of the LLM, but is accomplished by deterministic rules and algorithms. This fundamentally eliminates the time illusion caused by the LLM's lack of real-time date awareness and precise date calculation capabilities, thereby significantly improving the accuracy of the LLM's responses in tasks involving time expressions.
[0022] Furthermore, when determining the time expression type contained in the query text, the service program employs multiple sets of priority matching rules. These matching rules are matched against the query text sequentially in descending order of priority. Once a match is successful, the matched text fragment is categorized into the corresponding type. By configuring matching rules with different priorities, this scheme can flexibly handle situations where the same text may match multiple time expression types simultaneously, and can prioritize the more frequently used type for subsequent calculations, balancing recognition accuracy and processing efficiency.
[0023] Furthermore, when the service program annotates precise time information into the query text, if the query text contains multiple text fragments corresponding to different time expression types, the service program will sequentially annotate the corresponding precise time information at the end of each fragment according to their position in the query text from back to front. This reverse annotation strategy can avoid the problem of subsequent annotation position indexes becoming invalid due to changes in text length caused by preceding annotations, ensuring that all annotations are accurately placed in the target position. Attached Figure Description
[0024] To more clearly illustrate the technical solutions of the embodiments in this specification, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0025] Figure 1 This is a schematic diagram of a system architecture provided in an exemplary embodiment.
[0026] Figure 2 This is a flowchart illustrating a service optimization method for LLM as provided in an exemplary embodiment.
[0027] Figure 3 This is an exemplary embodiment of a data flow diagram showing the collaborative operation of various engines within a service program.
[0028] Figure 4 This is a flowchart of the workflow of a multi-pattern regular expression matching engine provided in an exemplary embodiment.
[0029] Figure 5 This is an example diagram of conflict resolution and annotation generation provided in an exemplary embodiment.
[0030] Figure 6 This is a comparison diagram of the effects of a reverse insertion strategy and a sequential insertion strategy provided by an exemplary embodiment.
[0031] Figure 7 This is a schematic structural diagram of an electronic device provided in an exemplary embodiment.
[0032] Figure 8 This is a block diagram of a service optimization apparatus for LLM provided in an exemplary embodiment. Detailed Implementation
[0033] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0034] It should be noted that the steps of the corresponding methods are not necessarily performed in the order shown and described in this specification in other embodiments. In some other embodiments, the methods may include more or fewer steps than described in this specification. Furthermore, a single step described in this specification may be broken down into multiple steps in other embodiments; and multiple steps described in this specification may be combined into a single step in other embodiments.
[0035] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties. The collection, use and processing of related data shall comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals shall be provided for users to choose to authorize or refuse.
[0036] Currently, LLMs commonly suffer from the temporal hallucination problem when processing time-related natural language queries.
[0037] The so-called time illusion problem refers to the phenomenon that LLM generates incorrect date information when processing time-related queries due to its lack of real-time date awareness.
[0038] In practical applications, LLM is essentially a probability distribution model trained on massive amounts of static text data. During the training phase, the model learns the statistical relationships between words, sentences, and concepts in the training data by adjusting its internal parameters.
[0039] Once training is complete, the model's parameters are fixed, and all the knowledge it contains is actually a snapshot of the world's state before the training data cutoff date. The model itself has no ability to perceive real-time changes in the external world.
[0040] For example, it cannot know the current day and second of the system's clock. When a user enters a query containing a time expression, such as "Will it rain tomorrow?", the LLM receives only a string of text symbols. LLM, with its language understanding capabilities, can infer that "tomorrow" is a pronoun representing a relative time, referring to the day after the current date. However, since it cannot obtain the current system date, it cannot calculate the specific Gregorian calendar date corresponding to "tomorrow". At this point, the LLM can only fit what it considers the most likely result based on the statistical patterns of which dates the word "tomorrow" typically co-occurs with in the training data. This fitted result is sometimes correct, but its unreliability becomes apparent in many scenarios involving complex calendars or offset calculations.
[0041] In related technologies, common approaches to overcome the time illusion problem mentioned above include the following: One common practice is to hard-inject the current date into the system prompt.
[0042] For example, adding a statement like "Today is April 17, 2026" to the beginning of each dialogue prompt might seem to give LLM a time reference, but the problem isn't solved. During multi-turn dialogues or long-chain inference, the self-attention mechanism of LLM has a decay effect on the global information of long texts, causing later generated text to gradually fade or forget the date information mentioned at the beginning. When users ask questions consecutively, or when the questions involve complex time expressions requiring multiple calculations—such as asking about tomorrow's weather followed by the day after, and then asking what time the meeting is scheduled for next Tuesday—LLM may have lost the initially set time anchor when performing the next round of calculations. This deficiency is more pronounced in scenarios involving lunar calendar conversions, solar term calculations, and holiday adjustments. These calculations require deterministic algorithms or queries of pre-defined data tables, and LLM itself lacks the built-in ability to call such deterministic tools. Forcing it to perform these tasks is essentially using a probabilistic inference engine to perform mathematical calculations, the result of which is naturally uncertain.
[0043] Another common approach is to introduce external time entity recognition tools.
[0044] For example, precise time information can be identified by introducing a Named Entity Recognition (NER) model. These models are trained through supervised learning to create a classifier specifically designed to extract time entities from text. While this approach improves the recall of time representations, its limitations are significant. NER models require a large amount of labeled data matching the target scene for training. For newly emerging time representation patterns or newly established holidays, the model needs to be re-labeled and retrained to adapt. Identifying time entities is only the first step; the NER model itself does not perform the mathematical transformation from vague text to precise dates. It can only select a segment of text and label it with the abstract term "time." The specific Gregorian date that this segment refers to requires additional rules or modules downstream. Introducing such a deep learning model significantly increases the system's complexity and the latency of the inference chain.
[0045] It is evident that the above technical solutions generally fail to effectively decouple the temporal semantic disambiguation task from the LLM inference task. Computation and inference are mixed in the same black box, causing two fundamentally different tasks to hinder each other.
[0046] In view of this, this application provides a service optimization scheme for LLM.
[0047] In this technical solution, the temporal semantic disambiguation function can be completely separated from the internal reasoning mechanism of the LLM and decentralized to an independent service program based on deterministic rules and algorithms. This service program acts as a preprocessing gateway, preprocessing the user's query text before it enters the LLM. It performs recognition, calculation, and rewriting, replacing all ambiguous time expressions with precise, standard date information that can be directly read by the LLM. This text, now free of temporal ambiguity, is then passed to the LLM for subsequent reasoning.
[0048] In this way, deterministic computation tasks can be separated from the probabilistic inference engine of LLM and handled by a dedicated service program. This allows the parsing and transformation of time information to be performed by deterministic rules and algorithms, rather than relying on the inference capabilities of LLM. This fundamentally eliminates the time illusion caused by LLM's lack of real-time date awareness and precise date calculation capabilities, thereby significantly improving the accuracy of LLM's responses in tasks involving time representation.
[0049] The technical solutions of the embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0050] First, we introduce the overall architecture of a service optimization system for LLM provided in the embodiments of this application.
[0051] Figure 1 This is a schematic diagram of a system architecture provided in an exemplary embodiment. For example... Figure 1 As shown, the system may include a server 10, a large language model (LLM) 20, a user terminal 30, and networks 12 and 13 connecting them.
[0052] Server 10 deploys service program 11. Service program 11 can be a process or container instance running independently of LLM 20, and its physical carrier can be any of a separate physical server, cloud host, virtual machine, or container cluster. Service program 11 provides a standardized service call interface that conforms to the Model Context Protocol (MCP) specification. The MCP protocol defines a standardized method for bidirectional communication between the large language model and external tools or data sources. Under the MCP protocol framework, service program 11 acts as an MCP server, registering itself and its list of available tools with the MCP client.
[0053] LLM 20 can be any large language model instance that supports the MCP protocol, such as the GPT series models, Gemini series models, Wenxin Yiyan, Tongyi Qianwen, etc. LLM 20 is typically hosted in the cloud by a third-party service provider, offering inference services via API. Upon receiving a user query, LLM 20 can determine whether to invoke external tools based on the MCP protocol and generate the corresponding service call request.
[0054] User terminal 30 can be a personal computer, smartphone, tablet, smart speaker, or any electronic device capable of running client applications. The user inputs natural language query text on the terminal via a graphical or voice interface, and the client program sends the query text to LLM 20 via network 13.
[0055] Networks 12 and 13 may include any combination of one or more communication media such as the Internet, mobile communication networks, local area networks, or leased line connections. Server 10 and LLM 20 communicate with each other through network 12, and LLM 20 and user terminal 30 communicate with each other through network 13.
[0056] Within the service program 11, based on functionality, it can be divided into three sub-engine modules: a multi-pattern regular expression matching engine 111, a multi-calendar date calculation engine 112, and a conflict resolution and annotation generation engine 113. These three engines form a sequential execution pipeline, with the output of the upstream engine serving as the input of the downstream engine.
[0057] Understandable, Figure 1 The system architecture shown is merely an example. In practical applications, more advanced architectures can be implemented. Figure 1 Based on the system architecture shown, the architecture of the above system can be flexibly adjusted according to actual needs. This application embodiment does not limit the specific physical deployment form of the system.
[0058] Next, the specific implementation of the technical solution will be described in detail based on the method flow provided in this embodiment and in conjunction with the accompanying drawings.
[0059] Please see Figure 2 , Figure 2 This is a flowchart illustrating a service optimization method for LLM as provided in an exemplary embodiment. The method may include the following execution steps: Step S210: Obtain the query text input by the user into the LLM; wherein the query text contains text fragments related to time expression; The execution entity of the above method may specifically include the service program 11 deployed on the server 10. For example, in practical applications, the service program 11 can be a persistent background daemon or cloud function instance that continuously listens for service call requests from the LLM 20 side.
[0060] Before step S210 is executed, service program 11 needs to complete a series of initialization and registration preparations.
[0061] In some embodiments, after the service program 11 starts, it can first load the configuration files, rule bases, and data files required by its internal functional modules. For example, it loads the 15 sets of regular expression pattern files required by the multi-pattern regular expression matching engine 111, and loads the lunar calendar data table, statutory holiday data table, solar term astronomical algorithm parameters, etc. required by the multi-calendar date calculation engine 112.
[0062] Afterwards, service program 11 can proactively initiate a registration request to the specified MCP client based on the configuration information.
[0063] In practical applications, the MCP client can be either the host platform of LLM 20 or a standalone MCP gateway. The registration request may include a detailed description of the tools provided by service program 11.
[0064] The detailed description can be expressed in natural language.
[0065] For example, in some embodiments, the above detailed description is as follows: "This tool is used to parse and rewrite all types of time expressions in Chinese query text, including but not limited to relative dates such as today, tomorrow, and the day after tomorrow; weekdays with prefixes such as Wednesday and Monday of the following week; Chinese statutory holidays such as Spring Festival and National Day; traditional lunar festivals such as Lantern Festival, Dragon Boat Festival, and Mid-Autumn Festival; lunar dates such as the first day of the first lunar month and the twenty-third day of the twelfth lunar month; the twenty-four solar terms such as the Beginning of Spring and the Winter Solstice; Western holidays such as Christmas and Thanksgiving; religious holidays such as Easter; and annual cycle expressions such as Q1 and the first half of the year. The input of this tool can be a string containing query text, and the output can be the rewritten text after all the fuzzy time expressions in the query text have been replaced with standard Gregorian calendar dates marked in parentheses. After receiving this tool description, the LLM host platform can add it to the list of tools that LLM can call."
[0066] Users can enter query text on user terminal 30 based on their needs; for example, in one scenario, the query text could be: "Please check flight tickets for Wednesday afternoon the week after next, and also see what events are happening around New Year's Day next year." After the user enters the query text on user terminal 30, the query text can be sent to LLM 20.
[0067] After receiving the query text, LLM 20 can perform semantic-level recognition of the query text according to the MCP protocol. At this time, LLM 20 does not need to parse the specific meaning of "next Wednesday" or "New Year's Day" itself, but rather matches the semantic features of the query text with the description text of all registered tools to determine whether the query text contains text fragments related to time expressions; For example, since the query text contains keywords that closely match the description of the time tool, such as "the week after next," "Wednesday," "next year," and "New Year's Day," LLM 20 can determine that the query text contains text fragments related to time expressions. This query needs to call the tools provided by service program 11 to process it.
[0068] If the LLM determines that the query text contains text fragments related to time expression, the LLM 20 can generate a service call message according to the calling specifications defined in the MCP protocol and initiate a service call to the aforementioned service program.
[0069] The service call information can be a structured data packet containing various parameters that LLM 20 extracts from the user's query text and needs to pass to the tool.
[0070] For example, if the query text is "Please help me check the flight tickets for Wednesday afternoon the week after next, and also see what activities are available around New Year's Day next year", one of the core parameter fields can be named query_text, and its value is the original query text entered by the user, that is, please help me check the flight tickets for Wednesday afternoon the week after next, and also see what activities are available around New Year's Day next year.
[0071] Then, LLM 20 can send the service call information to the service program 11 on the server 10 via network 12.
[0072] After receiving the service call information sent by LLM 20, service program 11 can parse and extract the value of the query_text field from the information, thereby obtaining the original query text input by the user to the LLM. At this point, service program 11 has completed the acquisition of the query text.
[0073] In the above scheme, the way service program 11 obtains the query text mainly relies on the active invocation of LLM 20.
[0074] In another embodiment, in a different embodiment, the service program 11 can also be used as a pre-middleware embedded in the LLM host platform. Before the user query text reaches the LLM 20, it first flows through the service program 11 for preprocessing. This method does not rely on the tool invocation mechanism of the LLM 20, but is achieved through interception at the request routing level, and is applicable to scenarios where the LLM itself does not support the MCP protocol or the tool invocation mechanism.
[0075] It should be noted that the text fragments related to time expressions in the above query text can specifically be fuzzy time expressions input by the user.
[0076] It should be explained that the so-called fuzzy time expression can specifically include text fragments that, although semantically related to time, use language expressions that cannot directly map to precise time information by the computer according to their literal meanings. Such text fragments are extremely common in daily natural language, and their core feature is that the expression itself does not contain complete digital information that can be directly parsed into the standard Gregorian calendar date.
[0077] For example, the word "tomorrow" contained in the query text input by the user. Although humans can easily calculate the specific date it refers to by combining the current date, this word itself is only composed of the Chinese character "明" representing relative offset and the word "天" representing the time unit, and does not contain any numbers of year, month, and day. The computer program cannot obtain the corresponding Gregorian calendar date by simply parsing the literal meaning of the two characters "tomorrow". Therefore, the expression "tomorrow" belongs to a typical text fragment related to time expression, that is, the fuzzy time expression that needs to be recognized and converted in this solution.
[0078] Step S220: Generate precise time information that semantically matches the text fragment, and label the precise time information at the position corresponding to the text fragment in the query text; After the service program 11 obtains the query text input by the user, it can start the internal pipeline processing process.
[0079] Please refer to Figure 3 , Figure 3 which is a data flow diagram showing the collaborative work of each engine inside a service program provided by an exemplary embodiment.
[0080] In some embodiments, such as Figure 3As shown, the original query text 301 is first fed into a multi-pattern regular expression matching engine 111. This engine scans and classifies the query text, outputting a set of text fragments 302 with type labels. This set is then fed into a multi-calendar date calculation engine 112. This engine can use the corresponding calculator to calculate the precise time information for each text fragment in the set, based on its type label, and generate a structured matching-date mapping table 303. This mapping table 303 is then fed into a conflict resolution and annotation generation engine 113. This engine arbitrates conflicts and formats the results in the mapping table, ultimately generating the rewritten query text 304.
[0081] Next, the internal working mechanisms of the multi-pattern regular expression matching engine 111 and the multi-calendar date calculation engine 112 will be described in detail.
[0082] In some embodiments, the multi-pattern regular expression matching engine 111 can be responsible for determining the time expression type of text fragments related to time expression contained in the query text. The service program 11 can maintain a priority list of multiple sets of matching rules in local memory. Each set of matching rules corresponds to a preset time expression type.
[0083] When determining the time expression type of the time-related text fragments contained in the query text, the engine can specifically match the query text with the above multiple sets of matching rules in descending order of priority. If the query text successfully matches any of the above multiple sets of matching rules, the time expression type corresponding to that set of matching rules can be determined as the time expression type corresponding to the time-related text fragments contained in the query text.
[0084] The specific types of the matching rules mentioned above are not further restricted in this specification.
[0085] For example, in some embodiments, the matching rules described above may include regular expressions, in which case the list of matching rules may contain one or more regular expressions. These regular expressions are used to describe the string characteristics that a text fragment matching that type should possess.
[0086] Please see Figure 4 , Figure 4 This is a flowchart of the workflow of a multi-pattern regular expression matching engine provided in an exemplary embodiment.
[0087] In some embodiments, such as Figure 4As shown, the workflow of this multi-pattern regular expression matching engine begins with receiving query text. Initially, the engine can initialize an empty list of matching results to store subsequent successful matches. Then, the engine can iterate through all registered matching rule groups in descending priority order.
[0088] For the currently traversed rule group, the engine can call all the regular expressions within it to attempt to match the current query text. If any of the regular expressions matches successfully, the engine records the complete text segment matched, the starting character index and the ending character index of the text segment in the query text, and appends the time expression type label corresponding to the rule group to this matching record.
[0089] After completing the matching process for a rule group, the engine can terminate the matching for that rule group and stop trying the remaining regular expressions within that group. The engine then continues to iterate through rule groups of the next priority. This process continues until all matching rule groups of all priorities have been traversed. Finally, the engine outputs a list containing all matched records.
[0090] For example, in one instance, each record can be represented as a triple, such as: {type: A, text: B, start and end positions: [C, D]}.
[0091] It should be noted that the specific meaning of the priority of the above-mentioned multiple sets of matching rules is not specifically limited in this specification, and can be flexibly set based on actual needs.
[0092] In some embodiments, the priority of the matching rule can represent the frequency of use or parsing priority of the time expression type corresponding to the matching rule. The higher the frequency of use or the more explicit the semantics of the time expression type, the higher its priority can be set to ensure its accurate identification.
[0093] For example, in one instance, the above matching rule group could contain a total of 15 matching rule categories: Category 1: Relative Date Recognition: Matching relative date expressions such as "tomorrow", "the day after tomorrow", and "the day after that".
[0094] Category 2: Relative weekday recognition with prefix: matching expressions such as "next Thursday", "this Friday", "this Saturday".
[0095] Category 3: Relative weekend recognition: Matching expressions such as "next weekend", "this weekend", and "the weekend after next".
[0096] Category 4: Identification of Chinese statutory holidays: Matching the names of 7 Chinese statutory holidays, including "Spring Festival", "National Day", and "Qingming Festival".
[0097] Category 5: Identification of traditional Chinese festivals: Matching 12 traditional Chinese festivals such as "Lantern Festival", "Qixi Festival", "Double Ninth Festival", and "New Year's Eve".
[0098] Category 6: Lunar calendar date recognition: Matching lunar calendar date expressions such as "January 15th", "December 23rd", and "August 1st".
[0099] Category 7: Western / International Holiday Recognition: Matches 16 Western / international holidays such as "Christmas", "Valentine's Day", "Halloween", and "Independence Day".
[0100] Category 8: Season Recognition: Matching seasonal expressions such as "spring", "summer", and "winter".
[0101] Category 9: Twenty-Four Solar Terms Identification: Matching the names of 24 solar terms such as "Spring Equinox", "Winter Solstice", and "Beginning of Autumn".
[0102] Category 10: Relative Month Recognition: Matching expressions such as "next month" to calculate the complete date range of the next month (including year-end processing and month-end day calculation).
[0103] Category 11: Specific Gregorian calendar date recognition: Match Gregorian calendar date expressions such as "July 15" and "July 15, 2023", perform date validity verification, and then label the date.
[0104] Category 12: Lunar calendar prefixed numeric date recognition: Matches numeric formats such as "Lunar August 15th" with a lunar / agricultural calendar prefix.
[0105] Category 13: Unprefixed weekday recognition: Matches independent expressions such as "Wednesday", "Sunday", etc.
[0106] Category 14: Annual cycle identification: Matching annual cycle expressions such as "Q1"-"Q4", "S1"-"S2", "first half of the year", "second half of the year".
[0107] Category 15: Religious Holiday Recognition: Matching religious holidays that require dynamic calculation, such as "Easter", "Ramadan", and "Thanksgiving".
[0108] The 15 sets of matching rules mentioned above are sorted in descending order of frequency of use. The first category has the highest priority, the 15th category has the lowest priority, and the priorities of the other categories can be arranged in descending order of their specific category numbers.
[0109] By employing this priority-based matching method, the problem of overlapping hits caused by differences in regular expression syntax and natural text ambiguity can be cleverly solved.
[0110] For example, the query text containing "Lantern Festival" could match either the Level 5 Lunar Traditional Festival Recognizer or a broader rule. Since the Level 5 rule has a higher priority, the engine will capture and mark it first, without having to wait to traverse all rules for redundant post-arbitration. Disambiguation logic is naturally integrated from the matching stage.
[0111] In practical applications, each of the recognizers listed above can contain one or more regular expressions.
[0112] For example, taking the Level 1 Chinese statutory holiday identifier as an example, its regular expression can be similar to: (?P <holiday>Spring Festival | National Day | Qingming Festival | Labor Day | Dragon Boat Festival | Mid-Autumn Festival | New Year's Day.
[0113] This expression matches all currently valid Chinese statutory holidays as an enumeration group. Once a match is found, the fragment is tagged with a high-priority Chinese statutory holiday.
[0114] Taking the second-level relative weekday recognizer with prefix as an example, its core regular expression can be written as: (?P <prefix>(?:Next(?:Next)?|[Upper and Lower Volumes]))Week(?P) <weekday>[One, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, day])。
[0115] This expression can extract prefix information through the named capture group "prefix". Its pattern "(?:下(?:下)?|[上下本])" can match several common prefixes such as "下下", "下", "上", and "本". The target week number is extracted through the named capture group "weekday", and its pattern "[一二三四五六日天]" supports the full week expressions from "一" to "日" and "天". When "下下周周三" appears in the user text, this regular expression can capture "下下" as the prefix offset and "三" as the target week. After the engine records this text segment, it will label it with the type of relative week with a prefix and send it to the next multi-calendar date calculation engine 112.
[0116] Taking the 4th-level relative date recognizer as an example, its regular expression can be: (?P<rel_day>大后天|后天|明天|今天|昨天|前天|大前天). This expression matches common relative date offset words.
[0117] Taking the 6th-level lunar date recognizer as an example, its regular expression needs to consider the combination method of lunar month and date. The lunar month, also known as the lunar calendar month, can have special names such as "正月", "冬月", "腊月", etc., or digital names from "一月" to "十二月". The lunar date can be from "初一" to "初十", from "十一" to "廿九" or "三十", as well as digital expressions. The corresponding regular expression needs to match the sequential combination of month words and date words.
[0118] Taking the 9th-level annual cycle recognizer as an example, its regular expression can be: (?P <quarter>Q[1-4]|S[1-2])|(?P <half>First half of the year | Second half of the year.
[0119] This expression can match quarterly expressions such as Q1 and Q2, semi-annual expressions such as S1 and S2, as well as Chinese words for the first half and second half of the year.
[0120] Taking the 12th level twenty-four solar terms identifier as an example, its regular expression directly lists the names of the twenty-four solar terms in the enumeration group; For example: (?P<solar_term> Spring Begins | Rain Water | Awakening of Insects | Spring Equinox | Pure Brightness | Grain Rain | Summer Begins | Grain Full | Grain in Ear | Summer Solstice | Minor Heat | Major Heat | Autumn Begins | End of Heat | White Dew | Autumn Equinox | Cold Dew | Frost's Descent | Winter Begins | Minor Snow | Major Snow | Winter Solstice | Minor Cold | Major Cold.
[0121] Of course, in practical applications, the specific types of the above matching rules are not entirely limited to regular expressions.
[0122] For example, in some embodiments, for lunar calendar dates with a fixed format, a rule function can be used to complete the recognition. This rule function can first locate the month and day keywords in the text, then map the first month to January and the twelfth month to December according to a preset lunar month alternative name mapping table, and then extract the day numbers thereafter to construct a complete type label.
[0123] Please continue reading Figure 4 Once the multi-pattern regular expression matching engine 111 has completed the location and classification of fuzzy time expression fragments, the multi-calendar date calculation engine 112 can take over the calculation task.
[0124] The core function of the multi-calendar date calculation engine 112 is to calculate the precise time information of the semantic matching of the text fragments related to the time expression based on the precise time calculation method corresponding to the time expression type.
[0125] It should be noted that different time-expression text fragments can correspond to different precise time calculation methods. The engine can pre-define dedicated calculation functions or data query modules for each supported time expression type.
[0126] For example, taking the relative date types of the first category mentioned above, such as tomorrow and the day after tomorrow, the offsets are +1 day and +2 days respectively. The engine can directly obtain the current system date and then add the corresponding offset number of days. During this process, it is necessary to handle boundary cases such as crossing months, crossing years, and February 29th of a leap year. For example, if the current date is December 31, 2026, tomorrow's calculation needs to advance the month to January 1st of the following year. This type of processing can be accomplished by calling the standard date and time library of the underlying operating system, which already has complete Gregorian calendar rules built-in.
[0127] Taking the prefixed relative weekday type of the second category mentioned above as an example, the prefix offset and target weekday need to be extracted from the capture group information attached to the type label. The calculation logic for the prefix offset is as follows: "this" indicates an offset of 0 weeks, "this" indicates an offset of 1 week, "this" indicates an offset of 2 weeks, and "this" indicates an offset of -1 week.
[0128] Using the current system date as the time anchor, assuming the current date is Friday, April 17, 2026, then this week is defined as the entire week including that date (from Monday to Sunday). This Wednesday, with an offset of 0, traces back to Monday, which is April 13th, and Wednesday corresponds to April 15th. Next Wednesday, with an offset of 1, requires shifting the entire week forward by 7 days, corresponding to April 22nd. The Wednesday two weeks later, with an offset of 2, is shifted forward another 7 days, corresponding to April 29th.
[0129] This step of the calculation can be expressed by the following formula: Target date = Anchor date + (7 × Offset) + (Target weekday index - Anchor weekday index).
[0130] The weekday index can be defined as an integer value where Monday is 0 and Sunday is 6. The engine performs this deterministic integer operation to obtain the accurate Gregorian calendar date.
[0131] With the power of the aforementioned Category 5 (traditional lunar festivals) and Category 6 (lunar date types), the engine needs to utilize pre-stored lunar calendar data. This data can be represented as a year-to-year mapping table, where the key is the Gregorian calendar year and the values are the corresponding lunar year information, including whether there is a leap month, which leap month it is, and the Gregorian date of the first day of each month. When a user query only contains a lunar date like the 15th day of the first lunar month without specifying the year, the engine needs to infer the year first. The inference logic can employ a strategy of using the next year if the date has passed. That is, the engine quickly calculates the current lunar year and date based on the current Gregorian date. Then, it determines whether the target lunar date has already passed. If it has, the target year is set to the following Gregorian year. If the user query explicitly includes a year prefix, such as last year, next year, or 2024 (an absolute year), then that specified year is directly used as the target year for the table lookup. After determining the target year, the engine looks up the Gregorian calendar date D corresponding to the first day of the first month from the lunar calendar data table for that year. Then, the Gregorian calendar date of the fifteenth day of the first month is D + 14 days.
[0132] Taking the 9th type of the 24 solar terms mentioned above as an example, the engine can use mature astronomical algorithms in the industry to calculate the specific Gregorian calendar date and time corresponding to each solar term. The specific implementation details will not be described in detail here.
[0133] For the fourth type of Chinese statutory holidays mentioned above, the engine needs to query a pre-built statutory holiday database after completing the basic date calculation. This database is updated regularly and stores annual notices regarding the arrangements for some holidays. The database records the name of each holiday, its start and end dates in the Gregorian calendar, and the make-up workdays for any adjusted workdays. For example, the holiday data for New Year's Day 2027 might be recorded as: January 1st to January 3rd, 2027, a total of 3 days. After calculating that New Year's Day is January 1st, 2027, the engine retrieves this complete holiday period from the table and returns it as precise time information. This way, the LLM (Local Management Module) will not overlook the changes in date ranges caused by adjusted workdays when subsequently scheduling related plans.
[0134] For the 15 types of religious holidays mentioned above, such as Easter, the calculation rules are somewhat special. The date of Easter is determined by the rule that it falls on the first Sunday after the first full moon following the spring equinox. This calculation cannot be achieved through simple table lookups and offsets; it requires a specialized algorithm, such as the anonymous Gregorian calendar algorithm. This algorithm takes an integer representing the year as input, performs a series of modulo and arithmetic operations, and outputs the month and date of Easter. The engine can internally encapsulate a function that implements this algorithm. Once the expression "Easter" is recognized and the target year is determined, the function can be directly called to perform the calculation.
[0135] In some embodiments, in practical applications, among the multiple hit results output by the multi-pattern regular expression matching engine 111, there will inevitably be a large number of positional overlaps and semantic conflicts caused by the cross-over of different regular expression patterns.
[0136] For example, the phrase "the week after next Wednesday" in the query text might be fully matched by the Level 2 relative weekday recognizer with prefixes, or it might be partially matched as "the week after next" by the Level 3 relative weekend recognizer. Additionally, "the week after next Wednesday" as a substring within this long phrase might also be matched by a lower-priority recognition pattern. Leaving this unprocessed will lead to chaotic final annotation information.
[0137] Please see Figure 5 , Figure 5 This is an example diagram of conflict resolution and annotation generation provided in an exemplary embodiment.
[0138] In some embodiments, such as Figure 5 As shown, the workflow of the conflict resolution and annotation generation engine 113 can be used to solve the above problems.
[0139] After receiving the mapping table, Engine 113 first sorts all matching records in the table according to their starting index in the original text, from smallest to largest. Then, the engine performs a two-pointer scan from left to right to detect and resolve all overlapping matching groups. The principle of resolution is that for any two or more overlapping matching records, only the one with the highest priority is retained, and the other lower priority records are removed from the table.
[0140] The priority of each match is determined by the level number preset by the matching rule engine when defining various recognizers; the smaller the number, the higher the priority. After this round of resolution, what remains in the mapping table are the unique and non-conflicting valid matching records finally confirmed by this round of query.
[0141] After resolving the conflict, Engine 113 obtained the final list of labeled tasks.
[0142] For example, the list of annotation tasks could be a data table consisting of several data records containing {original text fragments, precise time information, and start and end position indices}.
[0143] Next, this precise time information can be inserted as annotations into the query text at the positions corresponding to the above text fragments to generate the rewritten query text.
[0144] In some embodiments, the precise time information can be annotated in the query text at a position immediately adjacent to the aforementioned text fragment.
[0145] In this case, the precise time information is annotated to the position in the query text corresponding to the text fragment, which may specifically include: Determine the position of the last character of the text segment in the query text; mark the precise time information as the position of the character following the position of the last character of the text segment in the query text.
[0146] In some embodiments, the specific format of the annotation can be: insert a pair of half-angle brackets at the position of the character immediately following the last character of the original text fragment, and fill in the precise time information of the semantic matching of the fragment within the brackets.
[0147] Instructions are needed; you cannot simply insert from front to back. Inserting from front to back results in all text after the insertion point being shifted to the right in the character sequence by an offset equal to the length of the insertion tag string. This causes any old indexes recorded in the original text for subsequent insertion positions to immediately become invalid.
[0148] For example, if a tag for "Wednesday two weeks from now" is inserted at the beginning, the original text length increases, and the position index for subsequent New Year's Day tags will no longer be the value calculated initially. When the New Year's Day tag is executed next, the index will still use the old index to find the insertion point, inevitably inserting the tag data between incorrect characters, resulting in misplaced and incorrect tagging results.
[0149] Please see Figure 6 , Figure 6 This is a comparison diagram of the effects of a reverse insertion strategy and a sequential insertion strategy provided by an exemplary embodiment.
[0150] In some embodiments, such as Figure 6 As shown, in order to avoid insertion errors caused by dynamic changes in the index, engine 113 can strictly adopt a reverse insertion strategy.
[0151] The reverse insertion strategy is based on the idea that it does not operate according to the order in which the original text fragments appear in the original text, but rather sorts them from the beginning position of the original text in reverse order.
[0152] In some embodiments, if multiple text fragments corresponding to different time expression types are extracted from the above query text, the precise time information that semantically matches the multiple text fragments can usually be calculated based on the precise time calculation method corresponding to the different time expression types. In this case, when the precise time information is marked to the position in the query text corresponding to the text fragment, firstly, the position of the first character of the multiple text fragments in the query text can be determined; Then, the positions of the first character in the query text are sorted in reverse order, and the precise time information that semantically matches the multiple text fragments is sequentially marked as the position of the next character in the query text after the position of the last character of the multiple text fragments.
[0153] For example, after sorting, a processing queue can be formed, with the last text segment of the original text at the head of the queue and the first text segment at the tail. Then, the engine can start from the head of the queue, sequentially retrieve the data records to be processed from the annotation task list, and insert the annotated text at the character position following the end index recorded in the data record.
[0154] Because the segments near the end of the sentence are processed first, the character offset caused by the insertion operation only occurs after the current insertion point. This area is a safe zone that has already been processed and has no further insertion tasks. For the preceding text segments that have not yet been processed, their original positions in the original text remain valid because they have not been disturbed by the insertion. As the processing queue progresses and finally completes the annotation of the sentence-beginning segments, all annotations are placed precisely in their expected positions.
[0155] After annotating all time segments, Engine 113 can also insert an additional current time base declaration at the beginning of the rewritten query text. The declaration can be formatted as "Today is YYYY year M month D day, week X," where YYYY, M, D, and X are provided by the current system time. This time anchor declaration provides LLM with a unified and clear contextual reference when understanding the precise dates in the rewritten text.
[0156] In practical applications, during the above reverse insertion process, it is still possible that due to incomplete matching arbitration, two matching results with different priorities may happen to share the exact same start and end positions.
[0157] For example, even after the precise time information that semantically matches the above multiple text fragments is sequentially marked at the position of the next character after the last character of the multiple text fragments in the query text, there may still be a situation where multiple precise time information are marked at a certain character position.
[0158] This situation is rare, but it can occur when two regular expression patterns have an inclusion relationship or are completely equivalent.
[0159] In some embodiments, to address this issue, after sequentially marking the precise time information that semantically matches the plurality of text fragments at the position of the last character of the plurality of text fragments in the query text, if multiple precise time information are marked at any character position, the target precise time information with the highest priority of the matching rule among the multiple precise time information is retained, and other precise time information other than the target precise time information is removed from the multiple precise time information.
[0160] For example, in implementation, after each label insertion, engine 113 can immediately check whether a label of the same type inserted in a previous operation already exists at the insertion position. If it does, the engine determines the priority of the original matching rules corresponding to the two labels, retains only the label corresponding to the one with the higher priority, and removes the other label. This local secondary resolution can serve as an auxiliary micro-step in the reverse insertion process, further ensuring the uniqueness and correctness of the labeling results.
[0161] The above process completes the systematic disambiguation and rewriting of all ambiguous time expressions in the query text.
[0162] Step S230: Submit the query text labeled with the precise time information to the LLM so that the LLM can perform inference calculations on the query text.
[0163] After the service program 11 generates the rewritten query text, the text can be encapsulated in the data packet of the service call response through the service call return channel of the MCP protocol and sent back to the LLM 20 that originally initiated the call.
[0164] Upon receiving this response, the LLM 20's internal dialogue management module or task orchestration module discards the original fuzzy query text and instead sends the received, precisely annotated, rewritten query text as the true context of the user's input in this round into the LLM's inference engine.
[0165] The problem LLM faces at this point no longer involves any ambiguity in time expression. The key time information in the query text has been explicitly declared through the Gregorian calendar dates enclosed in parentheses. LLM no longer needs to perform any date calculations beyond its capabilities; it only needs to retrieve knowledge, plan steps, refine language, and generate responses based on this defined date information.
[0166] This approach, which generates precise time information through a preprocessing stage and then annotates it into the query text, completely separates the deterministic task of time calculation from the uncertain task of language reasoning in terms of process and architecture.
[0167] On the one hand, service program 11 can focus on ensuring a zero error rate for time information using deterministic rules and algorithms.
[0168] On the other hand, LLM 20 can focus on providing smooth and intelligent human-computer interaction with its powerful probabilistic models.
[0169] Both perform their respective functions and are efficiently connected through the standardized interface of MCP.
[0170] It should be noted that in the scheme described in this embodiment, the core computational logic of service program 11—namely, multi-pattern regular expression matching, multi-calendar date conversion, and position conflict resolution and reverse order annotation—can be executed entirely by local code on server 10. The computation process does not rely on any external search engine or cloud API service; it is all completed within the local process or local network, and the response time can be controlled at the millisecond level. This localized processing mechanism avoids latency caused by unstable external services or network jitter, making it particularly suitable for AI Agent and intelligent assistant scenarios with high real-time requirements.
[0171] In a typical deployment scenario, Service Program 11 can be containerized and packaged, enabling elastic scaling and load balancing through orchestration platforms such as Kubernetes. When an LLM application cluster faces high-concurrency queries, the number of Service Program 11 instance replicas can be horizontally scaled on demand to ensure that throughput matches the size of the LLM inference instance cluster. Because Service Program 11 is stateless, newly added instances can immediately pull the latest holiday data tables and rule base versions from a remote configuration center and be deployed to provide services in production. This ensures both the availability and maintainability of the overall solution.
[0172] By employing the methods described above, the root cause of incorrect answers—the uncertain time estimation process—has been completely removed from the LLM workflow. This significantly improves the accuracy of LLM responses when handling queries containing various types of time expressions. For example, by treating time disambiguation as a preprocessing step and entrusting it to a deterministic algorithm, the above approach prevents LLM from making any guesses or biases regarding ambiguous time expressions on probabilistic inference paths, thus fundamentally eliminating the problem of time illusions in LLM.
[0173] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
[0174] Corresponding to the embodiments of the methods described above, this specification also provides embodiments of apparatus, electronic devices, and storage media.
[0175] Figure 7 This is a schematic structural diagram of an electronic device provided in an exemplary embodiment. Please refer to... Figure 7 At the hardware level, the device includes a processor 702, an internal bus 704, a network interface 706, memory 708, and non-volatile memory 710, and may also include other necessary hardware. One or more embodiments of this specification can be implemented in software, such as the processor 702 reading the corresponding computer program from the non-volatile memory 710 into memory 708 and then running it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0176] like Figure 8 As shown, Figure 8 This specification illustrates a block diagram of a service optimization apparatus for LLM based on an exemplary embodiment. This apparatus can be applied to, for example... Figure 7 The electronic device shown deploys a service program to implement the technical solution of this specification. The service program establishes a communication connection with an LLM; the device includes: The acquisition module 801 acquires the query text input by the user into the LLM; wherein the query text contains text fragments related to time expression; The annotation module 802 generates precise time information that semantically matches the text fragment, and annotates the precise time information to the position in the query text corresponding to the text fragment; The submission module 803 submits the query text labeled with the precise time information to the LLM, so that the LLM can perform inference calculations on the query text.
[0177] Accordingly, this specification also provides an electronic device including a processor; a memory for storing processor-executable instructions; wherein the processor is configured to implement all the steps in the previously described method flow.
[0178] Accordingly, this specification also provides a computer-readable storage medium having stored thereon executable computer program instructions; wherein, when executed by a processor, the instructions implement all the steps in the previously described method flow.
[0179] Accordingly, this specification also provides a computer program product having executable computer program instructions stored thereon; wherein, when the computer program instructions are executed by a processor, they implement all the steps in the previously described method flow.
[0180] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or physical entities, or by products with certain functions. A typical implementation device is a server system. Of course, it is not excluded that with the future development of computer technology, the computer implementing the functions of the above embodiments may be, for example, a personal computer, a laptop computer, an in-vehicle human-machine interaction device, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.
[0181] While one or more embodiments of this specification provide the operational steps of the methods described in the embodiments or flowcharts, more or fewer operational steps may be included based on conventional or non-inventive means. The order of steps listed in the embodiments is merely one possible order of execution among many steps and does not represent the only possible order. In actual device or end product execution, the methods shown in the embodiments or drawings may be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed data processing environment). The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, product, 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, product, or apparatus. Without further limitations, it is not excluded that the process, method, product, or apparatus that includes the elements may also have other identical or equivalent elements. For example, the use of terms such as "first," "second," etc., is used to indicate names and does not indicate any particular order.
[0182] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, when implementing one or more of these specifications, the functions of each module can be implemented in one or more software and / or hardware components, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, 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, indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.
[0183] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0184] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0185] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0186] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0187] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0188] Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0189] Those skilled in the art will understand that one or more embodiments of this specification can be provided as a method, system, or computer program product. Therefore, one or more embodiments of this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0190] One or more embodiments of this specification can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a particular task or implement a particular abstract data type. One or more embodiments of this specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules can reside in local and remote computer storage media, including storage devices.
[0191] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, system embodiments are basically similar to method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. In the description of this specification, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0192] The above description is merely an embodiment of one or more embodiments of this specification and is not intended to limit the scope of this specification. Various modifications and variations can be made to the one or more embodiments of this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims.< / half> < / quarter> < / weekday> < / prefix> < / holiday>
Claims
1. A service optimization method for LLM, applied to service programs deployed on the server side; wherein, The service program establishes a communication connection with the LLM; the method includes: Obtain the query text input by the user into the LLM; wherein the query text contains text fragments related to time expression; Generate precise time information that semantically matches the text fragment, and mark the precise time information in the query text at the position corresponding to the text fragment; The query text labeled with the precise time information is submitted to the LLM, which then performs inference calculations on the query text.
2. The method according to claim 1, wherein the time-related text fragment includes: It is a text fragment related to time, but it uses a language expression that cannot be directly mapped to precise time information according to semantics.
3. The method according to claim 1, wherein the LLM initiates a service call to the service program based on a preset calling specification; Obtain the query text entered by the user into the LLM, including: The system receives service call information sent by the LLM through the communication connection; wherein the service call information is service call information generated by the LLM based on the call specification for initiating a service call to the service program; the service call is a service call to the service program initiated by the LLM when it identifies that the query text contains a text fragment related to time expression; the service call information includes the query text input by the user to the LLM; Obtain the query text contained in the service call information.
4. The method according to claim 3, generating precise time information that semantically matches the text fragment, comprising: Determine the time expression type of the text fragments related to time expression contained in the query text; Based on the precise time calculation method corresponding to the time expression type, the precise time information of the semantic matching of the text fragments related to the time expression is calculated; wherein, different time expression types correspond to different precise time calculation methods.
5. The method according to claim 4, wherein the service program maintains multiple sets of matching rules with priority; wherein, The matching rules are used to determine the time expression type of the text fragments related to time expression contained in the query text; different matching rules correspond to different time expression types. Determining the time expression type of the time-related text fragments contained in the query text includes: The query text is matched against the multiple sets of matching rules in descending order of priority. If the query text matches any one of the multiple sets of matching rules, the time expression type corresponding to that set of matching rules will be determined as the time expression type corresponding to the time expression-related text fragment contained in the query text.
6. The method according to claim 5, wherein the matching rule includes a regular expression; wherein, The regular expression is used to describe the string characteristics of text fragments related to the time expression type corresponding to the regular expression; The query text is matched against the multiple sets of matching rules in descending order of priority. If the query text matches any set of matching rules, the time expression type corresponding to that set of matching rules is determined as the time expression type corresponding to the time-related text fragments contained in the query text, including: According to the priority order from highest to lowest, the text fragments contained in the query text are matched with the multiple sets of regular expressions in turn; If any text fragment contained in the query text successfully matches any one of the multiple sets of regular expressions, the text fragment is extracted from the query text, and the time expression type corresponding to that set of regular expressions is determined as the time expression type corresponding to the extracted text fragment.
7. The method according to claim 6, wherein the precise time information is annotated to the position in the query text corresponding to the text fragment, comprising: Determine the position of the last character of the text segment within the query text; The precise time information is marked at the position of the character following the last character of the text fragment in the query text.
8. The method according to claim 7, wherein, based on the precise time calculation method corresponding to the time expression type, the precise time information of the semantic matching of the text fragment related to the time expression is calculated, comprising: If multiple text fragments corresponding to different time expression types are extracted from the query text, the precise time information that semantically matches the multiple text fragments is calculated based on the precise time calculation method corresponding to the different time expression types. Marking the precise time information onto the position in the query text corresponding to the text fragment includes: Determine the position of the first character of the plurality of text segments in the query text; The positions of the first character in the query text are sorted in reverse order, and the precise time information that semantically matches the multiple text segments is sequentially marked at the position of the next character after the position of the last character of the multiple text segments in the query text, according to the sorted order.
9. The method according to claim 8, further comprising: The precise time information that semantically matches the multiple text fragments is sequentially marked after the last character of the multiple text fragments in the query text. If multiple precise time information is marked at any character position, the target precise time information with the highest priority of the matching rule is retained, and other precise time information other than the target precise time information is removed from the multiple precise time information.
10. The method according to claim 5, wherein the LLM makes service calls to the service program based on the MCP protocol; the service program includes a service program based on the MCP protocol; The priority indicates the frequency of use of the time expression type corresponding to the matching rule; wherein... The priority level is positively correlated with the frequency of use.
11. A computer device, comprising a memory; a processor and a computer program stored in the memory and executable on the processor, wherein, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 10.
12. A computer program product comprising a computer program that, when executed by a processor, implements the steps of the method of any one of claims 1 to 10.