A multi-strategy retrieval and query adaptive combination enhanced generation method and system

By combining multi-strategy retrieval and query adaptation using the ERNIE-4.5-Medical and Qwen3-8B models, the problem of insufficient judgment of user query complexity in the question-and-answer system for TCM insomnia was solved, and efficient and accurate professional knowledge discovery and answer generation were achieved.

CN121455985BActive Publication Date: 2026-04-07CHENGDU UNIV OF TRADITIONAL CHINESE MEDICINE
View PDF 4 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-01-05
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Existing question-and-answer systems in the field of TCM insomnia lack adaptive judgment of the complexity of user queries, resulting in simple queries being over-complexed, while complex queries do not receive sufficient information support, and cannot simultaneously meet the differentiated needs of factual queries and inferential queries.

Method used

The system employs a complexity assessment module based on the ERNIE-4.5-Medical model and a main entity determination module based on the Qwen3-8B model to dynamically select multiple retrieval paths, including simple query paths and deep semantic retrieval. It also combines deep integration of knowledge graph and vector retrieval to improve the professionalism and accuracy of the answers.

Benefits of technology

It enables dynamic selection of retrieval strategies based on the semantic complexity of user queries, improving the accuracy and efficiency of the question-answering system, significantly enhancing the ability to discover professional domain knowledge and the accuracy of answer generation, and reducing the probability of knowledge blind spots and large model 'illusion' phenomena.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121455985B_ABST
    Figure CN121455985B_ABST
Patent Text Reader

Abstract

This invention discloses an enhanced generation method and system combining multi-strategy retrieval and query adaptation, relating to the fields of natural language processing and intelligent question answering. The method includes: S1, constructing a complexity judgment module for a binary classifier and a main entity determination module; S2, using the complexity judgment module to judge the complexity of the query statement Q and outputting the query result; S3, executing a simple query path if and only if the complexity judgment module outputs 1, otherwise proceeding to S4; S4, confirming the entity of the query statement Q through the main entity determination module; S5, executing deep semantic retrieval under complex queries if and only if the query complexity judgment module outputs 0 and the main entity determination module outputs; and executing a graph vector fusion retrieval path if and only if the query complexity judgment module outputs 0 and the main entity determination module outputs. This invention effectively improves the relevance and information completeness of the retrieval results, significantly enhances the ability to discover professional domain knowledge, and improves the accuracy of answer generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of natural language processing and intelligent question answering. More specifically, this invention relates to an enhanced generation method and system that combines multi-strategy retrieval with adaptive query processing. Background Technology

[0002] With the rapid development of Large Language Model (LLM) technology, its application in question-answering systems is becoming increasingly widespread. However, general-purpose LLMs still suffer from significant knowledge blind spots and "illusion" problems in vertical domains such as Traditional Chinese Medicine (TCM) question-answering, making it difficult to provide accurate and reliable domain-specific knowledge. Most existing Retrieval Augmentation (RAG) systems employ a single retrieval strategy, lacking the ability to adaptively assess the complexity of user queries and effectively handle queries with different semantic structures and information needs, resulting in low retrieval efficiency and unstable answer quality. This limitation is particularly pronounced in the field of TCM insomnia, where user queries range from simple symptom consultations to complex diagnostic and treatment principles and mechanistic analyses, urgently requiring an intelligent system capable of dynamically selecting retrieval strategies based on query characteristics.

[0003] While some current technologies attempt to improve performance by introducing knowledge graphs or vector retrieval, they still lack mechanisms for assessing query complexity and multi-strategy collaborative retrieval, making it difficult to improve the accuracy of answers to complex questions while maintaining system efficiency. Traditional Chinese medicine (TCM) knowledge itself has a unique hierarchical structure, and the standard RAG framework commonly suffers from insufficient retrieval accuracy, misunderstandings of technical terminology, and incomplete knowledge coverage in medical applications. This reflects the current lack of adaptive retrieval strategies for TCM and the absence of retrieval mechanisms capable of perceiving multi-level complexity. Existing medical question-answering systems lack effective perception of user query complexity, often employing a "one-size-fits-all" retrieval strategy. This leads to simple queries being over-complexed, while complex queries lack sufficient information support. A single retrieval strategy cannot simultaneously meet the differentiated needs of factual and inferential queries.

[0004] To overcome the aforementioned problems, related patents such as CN202510509412 propose a TCM question-answering method based on pre-training and retrieval enhancement, but do not involve adaptive judgment of query complexity; CN202510169903 utilizes knowledge graphs to enhance large models, but the retrieval path is fixed and cannot be dynamically adjusted. Therefore, there is an urgent need for a system that can adaptively select retrieval strategies based on query characteristics to achieve accurate and efficient vertical domain question answering.

[0005] The problem with existing technology is that:

[0006] 1. How to determine the complexity of user queries to avoid wasting resources and reducing effectiveness by using the same retrieval strategy for simple and complex queries.

[0007] 2. How to design a multi-strategy retrieval mechanism to cover diverse query needs, from simple semantic matching to complex relational reasoning.

[0008] 3. How to deeply integrate domain knowledge into the retrieval and generation process to improve the professionalism and accuracy of the answers. Summary of the Invention

[0009] One object of the present invention is to solve at least the above-mentioned problems and / or defects, and to provide at least the advantages described below.

[0010] To achieve these objectives and other advantages of the present invention, an enhanced generation method combining multi-strategy retrieval and query adaptation is provided, comprising:

[0011] S1. A module for judging the complexity of building a binary classifier based on the ERNIE-4.5-Medical model, and a module for determining the main entity based on a large language model;

[0012] S2. Use a complexity assessment module to assess the complexity of the user-input query statement Q and output the query results. ;

[0013] S3, if and only When =1, the multi-strategy retrieval execution module executes the simple query path; otherwise, it proceeds to S4.

[0014] S4. The main entity determination module confirms the entities in the query statement Q to obtain the corresponding number of main entities. ;

[0015] S5. If and only if the query complexity judgment module outputs... =0, and the main entity determines the module output. The multi-strategy retrieval execution module performs deep semantic retrieval under complex queries;

[0016] If and only if the query complexity judgment module outputs =0, and the main entity determines the module output. At that time, the multi-strategy retrieval execution module executes the graph vector fusion retrieval path.

[0017] Preferably, in S1, the complexity determination module is constructed as follows:

[0018] S110, Self-constructed dataset;

[0019] S111, Construct a complexity judgment standard;

[0020] S112. Using the ERNIE-4.5-Medical model as the basic architecture, the dataset obtained in S110 is used to train and evaluate the complexity judgment model.

[0021] The complexity judgment criteria include the following four dimensions:

[0022] Length standard: If the number of characters in a statement is ≤30, it is defined as a simple statement; otherwise, it is defined as a complex statement.

[0023] Terminology density standard: If a statement contains 0 to 1 TCM professional terms, it is defined as a simple statement; otherwise, it is defined as a complex statement.

[0024] Sentence structure standard: If a sentence is a single sentence with a simple structure and no compound logical relationship, it is defined as a simple sentence; otherwise, it is defined as a complex sentence.

[0025] Semantic depth standard: If a statement asks for a single fact, definition, or simple suggestion, it is defined as a simple statement; otherwise, it is defined as a complex statement.

[0026] In the complexity assessment criteria, if any dimension is defined as complex, then the query statement Q should be marked as complex.

[0027] Preferably, in S1, during the training of the complexity assessment model, the cross-entropy loss function is used as follows: L Perform model optimization:

[0028]

[0029] In the above formula, N For the sample size, y i For the first i The true label of each sample, and , For the model to the first i The probability that each sample is predicted to be a simple class, and , For query statement Q Vector representation after ERNIE model encoding W , b These are the weights and bias parameters of the classification layer, respectively, where σ is... sigmoid Activation function.

[0030] Preferably, in S1, the main entity determination module uses the Qwen3-8B model as its basic architecture and uses a hierarchical and progressive templated prompt word architecture to accurately extract TCM professional terms from the query statement, thereby obtaining an entity recognition engine specifically for the field of TCM insomnia.

[0031] The templated prompt word architecture includes:

[0032] The task definition layer for determining a unique main entity from an entity list based on traditional Chinese medicine diagnosis and treatment logic;

[0033] The rule constraint layer is used to explain the three-level decision-making principle of prioritizing the treatment subject, followed by the core disease, and supplementing the query focus. The decision-making principle of the rule constraint layer also includes: quantity judgment criteria.

[0034] An example demonstration layer showcasing the decision-making process through typical scenarios;

[0035] The reasoning guidance layer outputs structured results and explains the basis for decision-making.

[0036] Preferably, based on the three-level decision-making principle, for query statement Q, the main entity determination module obtains the selected set of main entities using the following formula. E main :

[0037]

[0038] In the above formula, To construct an inference function adapted to the field of TCM insomnia based on the Qwen3-8B model, For a normalized set of entities, and , Map Let e ​​be the term mapping function, and 'e' be the preliminary list of identified entities. Any single entity in the, The type to which entity e belongs is selected from the entity type hierarchy T. This is a prompt word template based on coding decision principles.

[0039] Preferably, the task definition layer includes: task objectives and a standardized entity type system;

[0040] The task objective is defined as "identifying medical entities in the query from a traditional Chinese medicine perspective";

[0041] The entity type system includes: disease type, syndrome type, traditional Chinese medicine type, prescription type, acupoint type, and treatment method type.

[0042] Preferably, in S3, the workflow of the simple query path includes:

[0043] S30. For query Q, a vector retrieval method is used to perform a similarity search, and the top 10 candidate document fragments with the highest similarity are retrieved using the following formula. C initial :

[0044]

[0045] In the above formula, Here, D is a retrieval function based on the BGE-large-zh model, D is a document knowledge base in the field of traditional Chinese medicine insomnia, and k represents the ranking. k =10 indicates that the top 10 candidate document fragments will be recalled;

[0046] S31. Reorder and score the candidate document fragments recalled in S30 using the following formula:

[0047]

[0048] In the above formula, Candidate document fragments The reordering score, It is the set of candidate document fragments recalled by the i-th subquery. This is a semantic relevance scoring function. For information integrity scoring function, For authority scoring function, , , These are the weight coefficients of the corresponding scoring function, and ;

[0049] S32. Based on the scores in S31, select the top 5 candidate document fragments as shown in the following formula to generate the answer. Answe 1:

[0050]

[0051] In the above formula, The large language model generated for the answer, Suggestion words specifically for simple searches This is the final set of the top 5 candidate document fragments.

[0052] Preferably, the workflow of the deep semantic retrieval includes:

[0053] S510. The total expanded entity set is obtained by using the following dual-path entity expansion mechanism. E total :

[0054]

[0055] In the above formula, E kg The set of entities obtained through a knowledge graph query, and

[0056] , For knowledge graph query functions, e primary for Emain A single master entity when =1, and , The maximum number of hops for the query depth. For a predefined set of relation types, E sem The set of entities obtained through semantic similarity retrieval, and

[0057] , e i For entities that belong to the entity set, cosine This is the cosine similarity calculation function. Emb For entity embedding functions, The semantic similarity threshold. This is a set of core entities extracted from a document knowledge base in the field of Traditional Chinese Medicine insomnia.

[0058] S511, Based on query statement Q Single main entity e primary and total extended entity set E total The multi-angle query set Q is generated using the following formula. multi :

[0059]

[0060] In the above formula, QueryConstruct is the query reconstruction algorithm, and aspect... i For the first i One search perspective N fised The number of subqueries is fixed.

[0061] S512, Regarding Q multi Each subquery in q i Create independent retrieval threads for parallel retrieval, and recall candidate document fragments independently for each retrieval thread using the following formula:

[0062]

[0063] In the above formula, subquery D represents a document knowledge base for the field of Traditional Chinese Medicine insomnia. It is the set of candidate document fragments recalled by the i-th subquery, where k represents the rank. k =5 indicates that 5 candidate document fragments are recalled;

[0064] S513. Merge all search results and re-rank and score the candidate document fragments recalled in S512 using the following formula:

[0065]

[0066] In the above formula, This is a semantic relevance scoring function. For information integrity scoring function, For authority scoring function, , , These are the weight coefficients of the corresponding scoring function, and ;

[0067] S514. Based on the scores in S512, generate the answer as follows: Answe 2:

[0068]

[0069] In the above formula, LLM Qwen3-8B The large language model generated for the answer, Prompt D C is a suggestion word specifically for deep semantic search queries. final This is the final output Top-K segment.

[0070] Preferably, the workflow of the graph vector fusion retrieval includes:

[0071] S520. Use GraphRAG's DRIFT Search method to perform multi-hop path retrieval, and obtain the knowledge graph path exploration through the following formula, so as to obtain a set of text fragments T that matches the graph path transformation. kg :

[0072]

[0073] In the above formula, PathToText is the path-to-text conversion function, P is the set of all discovered knowledge graph paths, and p is a single path in the set P;

[0074] S521. Perform a vector retrieval of the document knowledge base in the field of traditional Chinese medicine insomnia using the following formula to obtain a set of text fragments that complement the vector retrieval. Tvec :

[0075]

[0076] In the above formula, Retriever is the vector retrieval function, Q is the query statement, and D is the knowledge base of documents in the field of traditional Chinese medicine for insomnia. k Indicates ranking;

[0077] S522. The results of graph retrieval and vector retrieval are fused using the following formula:

[0078]

[0079] S523. After deduplication, scoring, and sorting the fusion results of S522, the following answer is generated: Answe 3:

[0080]

[0081] In the above formula, Prompt E This is a prompt word template specifically for graph vector fusion retrieval. T output For the set of search results, LLM Qwen3-8B The large language model generated for the answer, E main The main entity set.

[0082] A system applied to an enhanced generation method combining multi-strategy retrieval and query adaptation includes: a complexity judgment module, a main entity determination module, and a multi-strategy retrieval execution module.

[0083] This invention offers at least the following advantages: It dynamically selects retrieval strategies based on the semantic complexity of user queries, improving the accuracy and efficiency of question-answering systems. Specifically, it includes:

[0084] Firstly, the multi-strategy retrieval and query adaptive combination enhancement generation method proposed in this invention can automatically determine the complexity of user queries and flexibly select the optimal retrieval path for complex question-and-answer scenarios in vertical domains, thereby achieving deep integration of knowledge graphs and vector retrieval.

[0085] Secondly, the method of the present invention effectively improves the relevance and information completeness of the search results, and significantly enhances the ability to discover professional domain knowledge and the accuracy of answer generation.

[0086] Third, the method of the present invention can automatically identify complex relationships between multiple principal entities, support multi-angle and multi-level knowledge association analysis, and meet users' diverse needs for professional knowledge.

[0087] Fourth, the method of the present invention significantly improves retrieval efficiency and response speed through parallel retrieval and intelligent reordering mechanisms, and reduces the probability of knowledge blind spots and large model "illusion" phenomena.

[0088] Fifth, the overall solution of the method of the present invention does not require high-cost knowledge graph construction and maintenance, has good scalability and adaptability, and can be widely applied to intelligent question-answering systems in professional fields such as traditional Chinese medicine, medicine, and law.

[0089] Other advantages, objectives and features of the present invention will become apparent in part from the following description, and in part from those skilled in the art through study and practice of the invention. Attached Figure Description

[0090] Figure 1 This is a diagram of the overall system architecture of the present invention;

[0091] Figure 2 This is a flowchart illustrating the execution process of graph vector fusion retrieval in this invention.

[0092] Figure 3 This is a flowchart illustrating the execution process of deep semantic retrieval in this invention.

[0093] Figure 4 This is a flowchart illustrating the execution process of direct vector similarity retrieval in this invention.

[0094] Figure 5 This is a flowchart of the query complexity determination module in this invention;

[0095] Figure 6 This is a logic diagram of the main entity determination module in this invention. Detailed Implementation

[0096] The present invention will now be described in further detail with reference to the accompanying drawings, so that those skilled in the art can implement it based on the description.

[0097] This invention proposes an enhanced generation method and system that combines multi-strategy retrieval with adaptive querying. Its core lies in dynamically classifying query types through a query complexity judgment module, selecting the optimal retrieval strategy based on principal entity analysis, and finally generating professional answers by combining a large language model. The overall system architecture and corresponding module logic are as follows: Figures 1 - 6 As shown, it includes the following modules:

[0098] 1. Query complexity assessment module:

[0099] Feature system design:

[0100] A binary classifier is built based on the ERNIE-4.5-Medical model to determine whether a query is simple or complex.

[0101] Input features: query length, number of entities, question word type, semantic complexity;

[0102] Output: Simple query label (output 1) or complex query label (output 0);

[0103] Semantic features include query intent (single concept query vs. multi-dimensional analysis), term density (number of technical terms), and logical complexity (whether there are related words such as comparison, condition, and causation).

[0104] Structural features include query length distribution, sentence type (interrogative, declarative, exclamatory), and grammatical structure (simple vs. compound sentences).

[0105] Domain Characteristics: Specific characteristics and judgment criteria were designed for the field of TCM-based insomnia, as follows:

[0106] ① Syndrome type mentioned: Does it include common syndrome types in the field of TCM insomnia (such as complex syndrome types such as "liver stagnation transforming into fire", "deficiency of both heart and spleen", "phlegm-heat disturbing the interior", "heart and kidney disharmony", or basic syndrome types such as "liver blood deficiency" and "deficiency-heat disturbing the interior");

[0107] ② Key words for treatment methods: Does it include descriptions of traditional Chinese medicine characteristic treatment methods (such as "differentiation of syndromes and treatment", "compatibility", "nourishing blood and calming the mind", "clearing heat and resolving phlegm", "acupuncture", "acupoint massage", etc.)?

[0108] ③ Formula / Traditional Chinese Medicine Association: Does it include formula combinations (such as "Gui Pi Tang combined with Wen Dan Tang" or "Suan Zao Ren Tang plus Yuan Zhi") or descriptions of combined use of traditional Chinese medicines?

[0109] (It should be noted that the terminology database for the field of TCM insomnia is listed in "Complexity Judgment Criteria and Terminology Density Criteria" below.)

[0110] Construction of training dataset for complexity assessment model:

[0111] Data generation: The large language model (Qwen3-8B) is used to generate query statements for the field of TCM insomnia, covering different lengths, term densities, and sentence structures. The generation logic is guided by prompt A.

[0112] By designing a refined prompt B, the LLM is guided to automatically annotate the previously generated queries: an annotated dataset is constructed to train a lightweight text classification model, as detailed below:

[0113] Based on the following four complexity criteria, label the complexity of queries in the field of TCM insomnia (simple = 1, complex = 0). Output "labeling result + reason". If the semantic depth is simple but other dimensions are complex, the semantic depth will be used as the final labeling factor:

[0114] 1. Length standard: ≤30 characters = simple, >30 characters = complex;

[0115] 2. Terminology density standard: 0-1 TCM terms (refer to the terminology database) = simple; ≥2 terms / complex syndromes / formula combinations = complex.

[0116] 3. Sentence structure standards: Simple sentences without logical connectors = simple; Compound sentences / containing logical connectors / implicit multiple sub-sentences = complex.

[0117] 4. Semantic depth standard: Asking about a single fact / definition / usage = simple; involving syndrome differentiation and treatment / etiology and pathogenesis / treatment comparison / comprehensive conditioning = complex;

[0118] Terminology Database for Traditional Chinese Medicine in the Field of Insomnia:

[0119] Symptoms: Insomnia, excessive dreaming, palpitations, forgetfulness;

[0120] Syndrome types: deficiency of both heart and spleen, liver stagnation transforming into fire, phlegm-heat disturbing the interior, disharmony between heart and kidney, deficiency of liver blood, and internal disturbance of deficiency heat;

[0121] Chinese medicinal herbs: Ziziphus jujuba seed, Anemarrhena asphodeloides, Poria cocos, Polygala tenuifolia;

[0122] Formulas: Suanzaoren Tang, Guipi Tang, Wendan Tang;

[0123] Treatment methods include: syndrome differentiation and treatment, nourishing blood and calming the mind, clearing heat and resolving phlegm, and acupoint massage;

[0124] Complex syndrome: Deficiency of both heart and spleen with internal disturbance of phlegm-heat, liver stagnation transforming into fire with dampness;

[0125] Formula combination: Gui Pi Tang combined with Wen Dan Tang, Suan Zao Ren Tang plus Yuan Zhi.

[0126] Example:

[0127] Search query: "What are the uses of Suanzaoren Tang (Ziziphus jujuba seed decoction) for treating insomnia?"

[0128] Annotation results: 1

[0129] Reasons: 1. Length 22 characters ≤ 30 (simple); 2. Two terms (Ziziphus jujuba seed soup, insomnia, complex); 3. No related words in a single sentence (simple); 4. Single usage query (simple semantics); triggering semantic depth priority calibration, ultimately marked as 1.

[0130] Dataset attributes: A total of 1600 labeled samples were generated, covering the core scenarios in the field of TCM insomnia (symptom query, syndrome query, prescription query, mechanism query, comparison query, etc.). The ratio of training set: test set: validation set is 7:2:1, and the ratio of positive and negative samples is balanced (simple vs. complex ≈ 1:1).

[0131] Complexity judgment criteria:

[0132] Please make a comprehensive judgment based on the following four dimensions. If any one of the "complex" characteristics is met, it should be marked as "complex":

[0133] Length standard: A statement with ≤30 characters is defined as a simple statement, and a statement with >30 characters is defined as a complex statement.

[0134] Terminology density standard: Simple sentences contain 0 to 1 TCM professional terms (e.g., insomnia, jujube seed decoction, deficiency of both heart and spleen, calming the mind). Complex sentences contain 2 or more TCM professional terms, or involve complex syndromes (e.g., disharmony between heart and kidney, internal disturbance of phlegm and heat), formula combinations (e.g., Gui Pi Tang combined with Wen Dan Tang), treatment methods (e.g., nourishing blood and calming the mind, clearing heat and resolving phlegm), etc.

[0135] Sentence structure standards: Simple sentences are defined as single sentences with simple structures and no complex logical relationships; complex sentences contain multiple clauses; use logical connectives (such as "in addition to... also...", "if... then...", "because... therefore..."); or a question may contain multiple sub-questions.

[0136] Semantic depth standard: Simple statements ask for a single fact, definition, or simple advice, while complex statements involve requests for syndrome differentiation and treatment, analysis of etiology and pathogenesis, comparison of treatment plans, combination of multiple methods (such as prescription + diet + massage), or personalized conditioning plans.

[0137] Model building and training:

[0138] The ERNIE model was used as the basic architecture and fine-tuned using 1600 labeled samples. The samples cover various query scenarios in the field of TCM insomnia, with a balanced ratio of positive and negative samples (simple vs. complex ≈ 1:1).

[0139] Training hyperparameters: learning rate 3e-5, batch size 32, number of training epochs 5, weight decay 0.01, optimized using cross-entropy loss function.

[0140] Evaluation metric: Test set accuracy 95%.

[0141] 1.1 Feature Quantization and Vector Representation

[0142] Let query Q eigenvectors F ( Q ) is represented as:

[0143]

[0144] 1.1.1 Length Features f len Obtained through the following formula:

[0145]

[0146] in, L ( Q ) indicates a query Q The number of characters.

[0147] 1.1.2 Terminology Density Characteristics f term Obtained through the following formula:

[0148]

[0149] in, To find the number of professional terms in Traditional Chinese Medicine, Tmax The normalization factor for the maximum number of terms in the training set. T max =6 (Normalization factor for the maximum number of terms in the training set, based on: the number of terms in extremely complex queries in the field of TCM insomnia is ≤6, such as "Gui Pi Tang combined with Wen Dan Tang for treating insomnia caused by deficiency of both heart and spleen with internal disturbance of phlegm and heat" contains 6 term units, which can cover more than 99% of scenarios and ensure the distinguishability of feature values). If ,but .

[0150] 1.1.3 Syntactic Structure Complexity Obtained through the following formula:

[0151]

[0152] in: , This is a multi-clause indicator function (1 if it exists, 0 otherwise). There are indicator functions for logical connectives. For implicit multi-problem indicator functions, , , All are weighting coefficients, and satisfy the following conditions: ;

[0153] 1.1.4 Semantic Deep Features Obtained through the following formula:

[0154]

[0155] In the above formula, , , , These correspond to: syndrome differentiation and treatment, etiology and pathogenesis analysis, comparison of treatment plans, and comprehensive conditioning plan. Among them, ,when This indicates semantic depth complexity, when It indicates a simple semantic depth.

[0156] 1.1.5 Domain Characteristics Obtained through the following formula:

[0157]

[0158] in, , Indicator functions are mentioned for TCM syndrome types; The indicator function is mentioned in the key words of the treatment method; and each indicator function has a corresponding characteristic of 1, otherwise it is 0.

[0159] 1.2 Complexity Classification Model

[0160] A binary classifier is built based on the ERNIE model. :

[0161]

[0162] in: To query the representation vector of Q after encoding by the ERNIE model, W and b are the weights and bias parameters of the classification layer, respectively, and σ is the sigmoid activation function. y =1 corresponds to a simple query.

[0163] 1.3 Decision-making rules

[0164] The final complexity assessment is based on the comprehensive decision function:

[0165]

[0166] This formula represents the problem classifier. Decision-making rules:

[0167] If the maximum value among the length feature, term feature, structural feature, and semantic feature is greater than or equal to the rule threshold. If the condition is met, the problem is classified as class 0; otherwise, it is classified as class 1. Rule Threshold The determination is based on the F1 score of the validation set. Generally speaking... That is, when At that time, the model had the highest F1 score (0.89), a false positive rate of 8% for simple queries, and a recall rate of 90% for complex queries.

[0168] Decision logic explanation: If semantic depth features (Semantic complexity) is directly classified as a complex query (0); if the semantic depth is simple... If the maximum value of other features is ≥0.3, then it is judged as complex (0), otherwise it is simple (1).

[0169] 1.4 Training Objectives

[0170] Model optimization using the cross-entropy loss function:

[0171]

[0172] Where: L is the loss function value, N is the number of samples, and y i Let be the true label of the i-th sample. Let be the probability that the model predicts the i-th question as a simple category;

[0173] The formula calculates the cross-entropy between the predicted probabilities and the true labels for all samples and takes the average.

[0174] 2. Main Entity Determination Module

[0175] This module implements named entity recognition and main entity selection based on a large language model. Its process includes:

[0176] Entity recognition component:

[0177] The system employs the Qwen3-8B model for few-shot learning, achieving accurate extraction of TCM terminology through carefully designed prompting engineering. Using the Qwen3-8B model as its foundational architecture, and leveraging its powerful contextual understanding capabilities, a dedicated entity recognition engine for the TCM-based insomnia field is constructed.

[0178] The prompt word project adopts a structured template design, which clearly defines the task objectives and output format for entity recognition. Specifically, the template consists of: first, defining the task objective as "identifying medical entities in a query from a Traditional Chinese Medicine (TCM) perspective"; then providing a standardized entity type system, including six categories: symptoms (e.g., insomnia, palpitations, excessive dreaming), syndromes (e.g., deficiency of both heart and spleen, liver stagnation transforming into fire), Chinese herbs (e.g., jujube seed, polygala), prescriptions (e.g., Guipi Decoction, jujube seed decoction), acupoints (e.g., Shenmen, Neiguan), and treatment methods (e.g., calming the mind, clearing heat and resolving phlegm). The template embeds few-shot learning examples, demonstrating the standard process of entity recognition through carefully selected labeled samples. For example, the input "I've recently been experiencing insomnia, excessive dreaming, palpitations, and forgetfulness" corresponds to the output "['insomnia', 'excessive dreaming', 'palpitations', 'forgetfulness']". These examples cover recognition scenarios for different types of entities.

[0179] During the model inference process, the system fills the user's query into the designated position of the template and outputs a preliminary entity list through the generation capability of the large language model.

[0180] Next, entity normalization is performed. Based on the constructed TCM terminology mapping table, the identified entities are unified into standard expressions. This mapping table contains common synonyms, abbreviations and variants, such as mapping "can't sleep" to "insomnia", "jujube seed" to "sour jujube seed", and "peaceful sleep" to "calming the mind", etc.

[0181] 2.1 Entity Recognition Component

[0182] 2.1.1 Few-shot learning for entity recognition

[0183] Let the user query be Q, the entity recognition process can be formalized as follows:

[0184] in, E raw This is a preliminary list of identified entities, and , where n is the number of entities (n≥0); The entity recognition prompt template includes: "Task definition, entity type system T, and few sample examples";

[0185] Task definition: "Identify medical entities in the query from a Traditional Chinese Medicine perspective";

[0186] Entity type system: ;

[0187] Few sample examples: ;

[0188] 2.1.2 Entity Normalization Processing

[0189] in, Here, e is the terminology mapping function, based on the constructed TCM terminology mapping table, where e is the list of entities initially identified. E raw Any single entity in the, Type ( e ) represents the type to which entity e belongs, selected from the entity type system T.

[0190] 2.2 Determining the Main Entity

[0191] This module achieves accurate identification of the main entity through a carefully designed prompting engineering. This mechanism simulates the clinical thinking process of traditional Chinese medicine experts, transforming complex medical logic into a computable semantic reasoning task.

[0192] The prompt word architecture adopts a layered and progressive structure, including: a task definition layer, a rule constraint layer, an example demonstration layer, and a reasoning guidance layer. Among them, the task definition layer explicitly requires the model to determine the unique main entity from the entity list based on the TCM diagnosis and treatment logic; the rule constraint layer elaborates on the three-level decision-making principle of prioritizing the treatment subject, followed by the core disease, and supplementing the query focus; the example demonstration layer shows the decision-making process through typical scenarios; and the reasoning guidance layer requires the model to output structured results and explain the decision basis.

[0193] The specific prompt template is structured as follows: "As a TCM expert, please determine the main entities and their quantities based on the following entity list": Entity list: {entity list};

[0194] The main decision-making principles for the entity list include:

[0195] 1. Priority given to therapeutic agents: Therapeutic agents such as traditional Chinese medicine, prescriptions, and acupoints are given priority.

[0196] 2. Core Symptom Principle: When there is no primary treatment option, select the core health problem;

[0197] 3. Query focus principle: Determine the focus based on interrogative words and semantic emphasis;

[0198] 4. Quantity judgment criteria: Single main entity: The query focuses on the analysis and discussion of a single core concept; Multiple main entities: Used to query comparisons, associations or interactions involving two or more entities.

[0199] 2.2.1 Quantification of Decision-Making Principles

[0200] The decision-making principle quantification formula is as follows. The actual selection of the principal entity is accomplished through LLM, rather than by directly calculating these scores.

[0201] The principle of prioritizing treatment recipients is as follows:

[0202]

[0203] in: I For indicator functions; W ( e The weighting coefficients are: formula = 3, acupoint = 2, and Chinese medicine = 1, reflecting the principle that "formula takes priority over acupoint > Chinese medicine". Type ( e ) represents the entity type;

[0204] The core disease principles are as follows:

[0205] in: This indicates that "no therapeutic entity exists," at which point the score for the core symptom is... Otherwise, it is 0;

[0206] The query focus principle is as follows:

[0207]

[0208] 2.2.2 Main Entity Selection Function

[0209] Based on the above principles, the selection of the main entity can be formalized as follows:

[0210]

[0211] in, E mian For the selected set of main entities, LLM Qwen3-8B To construct an inference function adapted to the field of TCM insomnia based on the Qwen3-8B model (denoted as ). LLM Qwen3-8B ), E norm For a normalized set of entities, and , E raw This is a preliminary list of identified entities. MapLet e ​​be the term mapping function. E raw Any single entity in the query, where Q is the user's query statement. To determine the query complexity, Prompt mian This is a prompt word template for encoding decision principles.

[0212] 2.2.3 Search Strategy Decision

[0213] The retrieval strategy is determined based on the number of main entities as follows:

[0214] 2.2.4 The decision justification generation function is shown below:

[0215]

[0216] in, The cardinality (number) of the main entity set. The system defaults to identifying "insomnia" as the core symptom, triggering a deep semantic search.

[0217]

[0218] In the above formula, the decision-making principle applied is the principle on which one or several principles were ultimately used to make the main entity's choice decision.

[0219] 2.2.5 The structured output results are shown below:

[0220]

[0221] in, The main entity set, Number of main entities A list of types for each main entity. As a reason for the decision, This is a retrieval strategy based on the number of main entities.

[0222] 3. Multi-strategy retrieval execution module

[0223] 3.1 Simple Query Path

[0224] When the query complexity judgment module outputs At that time, the system executes a simple query path. A vector retrieval method is used, employing the BGE-large-zh model to encode the query into a 768-dimensional vector. A similarity search is then performed in the Faiss vector library to recall the Top-10 relevant segments.

[0225] Re-ranking: The BGE-reranker model is used to fine-rank the recall results, based on a weighted score of semantic relevance, information completeness, and authority. The top 5 most relevant segments are output as the search results.

[0226] In the steps, if and only if the query complexity judgment module outputs At that time, the system executes a simple query path, using the following conditional execution function:

[0227]

[0228] The search process is as follows:

[0229]

[0230] The reordering process is as follows:

[0231]

[0232] The reordering score function is as follows:

[0233]

[0234] Top-K selection is expressed by the following formula:

[0235]

[0236] Answer generation Answer 1 is expressed by the following formula:

[0237]

[0238] in, To determine the query complexity, To indicate a simple query, C initial This is the initial set of 10 candidate document fragments obtained from the search. Here, Q is the retrieval function based on the BGE-large-zh model, D is the user query, and C is the knowledge base of documents in the field of traditional Chinese medicine for insomnia. reranked S is the set of document fragments after reordering. rerank ( c i () is a document fragment c i The reordering score, This is the semantic relevance score function (calculated by BGE-reranker). For information integrity scoring function, For authority scoring function, , , These are the weight coefficients of the corresponding scoring function, and , For the final selection of the Top-5 document fragments, Prompt C LLM provides suggestions for simple queries. Qwen3-8B A large language model is generated for the answer.

[0239] 3.2 Complex Query Path - Deep Semantic Retrieval (Number of Main Entities = 1)

[0240] The knowledge graph expansion path is based on a knowledge graph system built on GraphRAG. It uses the built-in graph query interface to obtain directly related entities of the main entity, setting `max_hops=2` to explore second-degree relationships. The system sends a structured query request to GraphRAG, specifying the type and depth of relationships to be retrieved, and obtains all directly connected entities and their relationship attributes. The semantic similarity expansion path uses the BGE model to calculate the cosine similarity in vector space between the main entity and other entities in the TCM insomnia document knowledge base. Semantically related entities with a similarity greater than 0.7 are selected, with a focus on mining synonyms and near-synonyms.

[0241] If and only if the query complexity judgment module outputs And the main entity determines the module output. The system performs deep semantic retrieval under complex queries, that is, it uses the following conditional execution function:

[0242]

[0243] 3.2.1 Dual-path entity expansion mechanism

[0244] When the main entity set E mian When there is only one entity, let e primary satisfy The knowledge graph expansion path is then represented as:

[0245]

[0246] in, E kg GraphQuery is the set of entities retrieved from the knowledge graph, and it is the knowledge graph query function. E mian The main entity set, e primary It is a single primary entity, and e primary satisfy , That is, the maximum number of hops is 2 (query depth);

[0247] Rtypes is a preset set of relationship types (such as treatment relationship, etiological relationship, etc.).

[0248] Semantic similarity extension path:

[0249]

[0250] Among them, E sem is a set of entities retrieved based on semantic similarity, and e i is an entity belonging to the set of entities, and , where cosine is the cosine similarity calculation function and Emb is the entity embedding function, is the semantic similarity threshold, with a value of 0.7, e primary is a single main entity, that is, E mian the case where = 1.

[0251] is a set of core entities extracted from the document knowledge base in the traditional Chinese medicine insomnia field (no need to build separately, extracted in real-time / offline based on the text of the document knowledge base in the traditional Chinese medicine insomnia field). The specific extraction rules are as follows:

[0252] ① Based on the entity type system ;

[0253] ② Extracted by "rule matching + dictionary filtering": The matched traditional Chinese medicine term dictionary is the "Core Term Dictionary in the Traditional Chinese Medicine Insomnia Field" (with a scale of more than 5,000 entries). This dictionary is extracted based on public resources such as the "National Standard of Traditional Chinese Medicine Terms", the "Chinese Pharmacopoeia", and the "Great Dictionary of Traditional Chinese Medicine Formulas", and is supplemented and optimized in combination with the document knowledge base in the traditional Chinese medicine insomnia field, covering more than 95% of the core entities in the field;

[0254] ③ Extraction tool: Use jieba word segmentation + custom entity recognition rules (such as "formula type entities need to contain suffixes such as 'decoction', 'pill', 'powder', etc., and syndrome type entities need to contain keywords such as 'type','syndrome', '兼'"), and the extraction accuracy rate ≥ 90%;

[0255] The total extended entity set is expressed as:

[0256]

[0257] Among them, E total is the total entity set, E kg is the set of entities obtained through knowledge graph query, E sem is the set of entities retrieved through semantic similarity.

[0258] 3.2.2 Multi-query construction

[0259] The multi-query construction phase generates diverse retrieval perspectives based on the expanded entity set, and generates multi-angle queries based on the original query and the expanded entities. The system employs a query reconstruction algorithm to semantically combine the original query and the expanded entities, generating subqueries covering multiple dimensions such as chemical composition, mechanism of action, clinical application, and modern research. Each subquery must undergo semantic integrity verification (rule: containing "main entity"). e main "+Extended Entities+Perspective Keywords", without deviating from the original query intent, to ensure that the search scope is deepened from a specific perspective; the number of subqueries is fixed. (Covering all core perspectives), if E total If there are not enough entities to support 5 perspectives, then the core extended entity (such as "Sour Jujube Seed Soup") is reused to construct different perspectives to avoid missing perspectives.

[0260] Based on the original query Q and the main entity e main and extended entity set E total Generate multi-angle query sets Q multi :

[0261] QueryConstruct is the query reconstruction algorithm, and its specific steps are as follows:

[0262] Step 1: From E total Select the Top-5 core extended entities (by AND) e main The association strength is ranked, and the association strength is calculated based on the relation weights in the knowledge graph.

[0263] Step 2: For each aspect i (Search perspective) Match the corresponding extended entities (e.g., from the perspective of "key points of syndrome differentiation" match "syndrome type extended entities", from the perspective of "compatibility contraindications" match "traditional Chinese medicine / prescription extended entities");

[0264] Step 3: By "Original Query Intent + Main Entity" e main Generate subqueries using the phrase "+extended entity+view keyword";

[0265] aspect i For the first i Five core search perspectives in the field of TCM insomnia: aspect 1 = Key points of dialectics aspect 2 = Mechanism of actionaspect 3 = Clinical application aspect 4 = Modern research aspect 5 = Incompatible combinations;

[0266] N fixed To ensure a fixed number of subqueries, set to N fixed =5;

[0267] e main For a single main entity ( This ensures that subqueries always revolve around the core entity.

[0268] 3.2.3 Parallel Retrieval and Reordering

[0269] The system creates an independent retrieval thread for each subquery, performs semantic search in parallel in the vector library, and each thread independently recalls the Top-5 relevant fragments.

[0270] The BGE-reranker model is used to finely rank the recall results. Based on semantic relevance, information completeness, and authority, a weighted score is assigned, and the Top-15 fragments are finally output as the search results and submitted to Qwen3-8B for response.

[0271] 1) Parallel retrieval: For each subquery q i Parallel retrieval is performed using the following formula:

[0272]

[0273] In the above formula, C i Let i be the set of Top-5 relevant document fragments retrieved by the i-th subquery; if C i If fewer than 5 items are recalled, all will be retained (minimum 2 items will be retained; if fewer than 2 items are recalled, they will be retrieved from the Traditional Chinese Medicine Insomnia Special Document Library). D Supplement and q i (basic fragments with similar semantics) Retriever FAISS This is a search engine based on the FAISS vector library, which is constructed using literature excerpts from the field of traditional Chinese medicine for insomnia. D This is a dedicated document library for the field of Traditional Chinese Medicine in the area of ​​insomnia. k =5 is the number of recalled fragments for each subquery;

[0274] 2) Result fusion and reordering:

[0275] Merge all search results: .

[0276] Reordering score function:

[0277]

[0278] in, The semantic relevance score is calculated using the BGE-reranker. For information integrity scoring function, For authoritative scoring, the values ​​range from [0,1]. , , These are the weight coefficients of the corresponding scoring function, and ;

[0279] The final output Top-K segment is: .

[0280] 3.2.4 Answer Generation

[0281] The final output is:

[0282]

[0283] in, Prompt D These are suggestion words specifically designed for deep semantic search queries.

[0284] 3.3 Complex Query Path - Graph Vector Fusion Retrieval (Number of Main Entities ≥ 2):

[0285] For complex queries involving multiple entities, the system performs graph vector fusion retrieval, using GraphRAG's DRIFTSearch mechanism to achieve dynamic multi-hop reasoning, and then combines it with semantic matching of vector retrieval to achieve deep knowledge discovery with dual knowledge coverage of "relational logic + semantic details".

[0286] If and only if the query complexity judgment module outputs And the main entity determines the module output. At that time, the system executes the graph vector fusion retrieval path.

[0287] Conditional execution function:

[0288]

[0289] 3.3.1 Knowledge Graph Path Exploration

[0290] The system sends multi-entity relationship query requests to GraphRAG to retrieve different types of relationship paths, including treatment relationships, etiology relationships, syndrome relationships, and drug interaction relationships, ensuring that diverse knowledge associations are retrieved. GraphRAG's DRIFT Search method is used for dynamic multi-hop path retrieval. This method, based on the user query and the set of main entities, achieves deep relationship discovery through an iterative "question-answer-follow-up question" chain.

[0291] The set P of all paths discovered by multi-hop path retrieval is represented as:

[0292]

[0293] Where Q represents the user's query statement. DRIFTSearch For GraphRAG's dynamic inference search function, E main The main entity set, For a maximum number of jumps of 3, R types For the target relation type set.

[0294] The core mechanism of DRIFT Search is as follows:

[0295] 1) Initial search:

[0296]

[0297] In the above formula, PrimerRetrieval The initial retrieval function is based on the original query Q and the main entity set. E main Retrieve the most relevant content from knowledge graphs and community reports to generate preliminary answers. A 0. Construct dynamic inference chains.

[0298] DRIFT Search performs multi-hop reasoning through an iterative chain of "question-answer-follow-up question":

[0299]

[0300]

[0301] In the above formula, Q m+1 This is a follow-up problem for the (m+1)th step. A m+1 This is the targeted search result for step m+1. A m This is the answer for the m-th step. R types Let m be the set of target relation types, where m = 0, 1, 2, ..., K-1. , GenerateFollowUps To follow the question generation function, m is the current iteration step of multi-hop inference, and K is the total number of iterations. The specific steps are as follows:

[0302] Step 1: Analysis A m Traditional Chinese medicine related dimensions not covered in the text (such as...) A (0 symptoms, next step focuses on treatment).

[0303] Step 2: Based on E main The multi-entity comparison intent generates targeted follow-up questions (such as "What are the differences in the appropriate treatment methods for liver stagnation transforming into fire and deficiency of both heart and spleen?").

[0304] Retrieval : Targeted retrieval function, based on Q m+1 Retrieve the corresponding relationship paths in the graph (such as "liver stagnation transforming into fire → soothing the liver and purging fire", "heart and spleen deficiency → tonifying the heart and spleen").

[0305] 2) Path aggregation:

[0306]

[0307] Where P represents the set of all discovered reasoning paths, and Q represents the user's query. PathExtract The path extraction function has the rule of "only retaining complete paths containing 'main entity + TCM relationship + related entity', and filtering out meaningless fragmented paths" (e.g., retaining "liver stagnation transforming into fire → soothing the liver and purging fire → Gentian root decoction for purging the liver", and filtering out incomplete paths such as "liver stagnation transforming into fire → symptoms → bitter taste in the mouth").

[0308] E main The main entity set, The maximum number of reasoning jumps, R types For the target relation type set, A m For the first m The set of answers to jump. Q m Let m be the query set for the m-th hop.

[0309] 3) The graph path transformation is as follows:

[0310]

[0311]

[0312]

[0313] in, t iFor a single path p i through PathToText The converted text fragments are simplified with identifiers for easier subsequent citation. kg PathT is a collection of text fragments transformed from graph paths. oText Let p be a path-to-text conversion function, where p is a single path in set P, and P is the set of all discovered knowledge graph paths.

[0314] 3.3.3 Vector Retrieval of Document Knowledge Base in the Field of Traditional Chinese Medicine for Insomnia

[0315] Construction of a Document Knowledge Base for Traditional Chinese Medicine (TCM) Insomnia: This project involved collecting professional textual data on TCM insomnia (such as "Internal Medicine of Traditional Chinese Medicine," treatment guidelines, analyses of classic formulas, and academic papers). After preprocessing including data cleaning, deduplication, and segmentation, the text blocks were converted into high-dimensional vectors using BAAI / bge-large-zh and stored in a vector database, forming a TCM insomnia knowledge vector base. Furthermore, to improve retrieval quality and efficiency, the document knowledge base incorporated many common TCM concepts related to insomnia, organized into approximately 350 entries across eight categories: disease name, pathogenesis, syndrome differentiation, treatment method, formula, acupoint, diagnosis, and symptoms.

[0316] Vector retrieval:

[0317]

[0318] in, Tvec Let Q be the set of text fragments obtained by vector retrieval, Retriever be the vector retrieval function, Q be the user query, D be the TCM insomnia knowledge vector library, and k=10 be the top 10 most relevant documents returned by the retrieval.

[0319] 3.3.4 Integrated Search and Result Integration

[0320] The results from these graph retrievals are fused with the text fragments obtained from vector retrievals to form the final set of retrieval results. The system performs uniform deduplication on the fused result set, eliminating completely duplicate content while retaining complementary information from different sources.

[0321] 1) Results fusion:

[0322] 2) The final result after deduplication:

[0323]

[0324] 3) Unified Ranking: Based on the original relevance scores of each segment, a final ranking is performed, outputting the Top-10 segments with the highest information value:

[0325]

[0326] The ranking score function is as follows: , W rel , W info , W auth These are the weighting coefficients, and W rel + W info + W auth =1, f rel This is the semantic relevance score function (calculated by BGE-reranker). f info For information integrity scoring function, f auth This is an authority scoring function.

[0327] 3.4 Answer Generation

[0328] Ultimately, the retrieval-enhanced diagnostic process can be formalized as follows:

[0329]

[0330] in, Prompt E E is a prompt word template specifically for graph vector fusion retrieval. mian T is a set of multiple principal entities used to guide multi-entity comparative analysis. output This is the refined set of search results.

[0331] Example 1:

[0332] This example demonstrates simple query processing, such as a user query: "What is insomnia?" The processing flow for this example is as follows:

[0333] 1) Complexity judgment: Feature extraction shows that the query length is short (8 characters), there is no semantic depth, no atypical symptoms or complex logic, and it is classified as a simple query.

[0334] 2) Retrieval Strategy: Perform direct vector retrieval. The query is encoded into a 768-dimensional vector using the BGE-large-zh model. A similarity search is performed in the Faiss vector library to recall the Top-10 relevant segments. Subsequently, the BGE-reranker model is used to finely rank the recalled results, assigning weighted scores based on semantic relevance, information completeness, and authority, and outputting the top 5 segments as the retrieval results.

[0335] 3) Answer generation: The retrieved Top-5 fragments are concatenated with the user query according to the preset simple query prompt template, and input into the Qwen3-8B model to generate the final answer: "Insomnia, known as 'insomnia' in traditional Chinese medicine, is characterized by frequent sleep disorders...".

[0336] Example 2:

[0337] This example demonstrates deep semantic retrieval within a complex query, such as the user query: "What is the pharmacological mechanism of jujube seed in treating insomnia?" The processing flow for this example is as follows:

[0338] 1) Complexity judgment: Feature extraction shows high terminology density (including professional terms such as "sour jujube seed" and "pharmacological mechanism") and complex logic (involving mechanism analysis), and is classified as a complex query.

[0339] 2) Main Entity Determination: The entity recognition component outputs ['Sour Jujube Seed', 'Insomnia']. Based on the principle of "treatment subject priority", the main entity is determined to be "Sour Jujube Seed", and the entity quantity is 1.

[0340] 3) Search strategy: Perform deep semantic search.

[0341] 4) Dual-path expansion: Knowledge graph expansion path: Using "sour jujube seed" as the main entity, set max_hops=2 to query the knowledge graph and obtain directly related entities, such as ['saponin', 'flavonoid']. Semantic similarity expansion path: Calculate the cosine similarity between "sour jujube seed" and other entities in the TCM insomnia document knowledge base, and select entities with a similarity greater than 0.7, such as ['polygala tenuifolia', 'sedative'].

[0342] Merging them yields the total extended entity set E_total=['Saponins','Flavones','Polygala tenuifolia','Sedatives'].

[0343] 5) Multi-query construction: Based on the original query and extended entities, generate sub-queries from 5 perspectives, such as "chemical composition of jujube seed and insomnia" and "the effect of jujube seed saponins on GABA receptors".

[0344] 6) Parallel retrieval and re-ranking: For each subquery, parallel retrieval is performed in the Faiss vector library, recalling the Top-5 relevant fragments for each, resulting in a total of 25 fragments. The BGE-reranker model is used for unified re-ranking, and the Top-15 fragments are output based on weighted scores.

[0345] 7) Answer generation: The refined Top-15 fragments are concatenated with the user query according to the complex query prompt template, and input into the Qwen3-8B model to generate a mechanism analysis answer containing content such as saponin effects and neurotransmitter regulation.

[0346] Example 3:

[0347] This example demonstrates graph-vector fusion retrieval in complex queries. For instance, if a user queries: "What is the difference between liver stagnation transforming into fire and deficiency of both heart and spleen in the field of insomnia?", the processing flow for this example is as follows:

[0348] 1) Complexity assessment: Feature extraction shows that it contains multiple TCM professional terms ("liver stagnation transforming into fire", "insomnia", "heart and spleen deficiency") and has a clear comparison intention, and is classified as a complex query.

[0349] 2) Main Entity Determination: The entity recognition component outputs ['Liver Qi Stagnation Transforming into Fire', 'Insomnia', 'Heart and Spleen Deficiency']. Based on the principle of "treatment subject priority" and the comparison intent of the query, the main entities are determined to be ['Liver Qi Stagnation Transforming into Fire', 'Heart and Spleen Deficiency'], and the number of entities is ≥2.

[0350] 3) Search strategy: Perform graph vector fusion search.

[0351] 4) Knowledge Graph Path Exploration: Setting max_hops=3, dynamic path exploration is performed using GraphRAG's DRIFT Search method. The system performs the following multi-hop inference process based on queries and main entities:

[0352] 5) Initial search (Primer):

[0353] The system identifies the core entities and comparison intents in the query.

[0354] Retrieve basic information related to "liver stagnation transforming into fire" and "deficiency of both heart and spleen" from the knowledge graph.

[0355] 6) Generating a preliminary answer: "Liver stagnation transforming into fire syndrome and deficiency of both heart and spleen syndrome are common types of insomnia."

[0356] 7) Multi-hop reasoning process:

[0357] First step: Generate follow-up questions for "Main symptoms and characteristics of insomnia due to liver stagnation and fire," and retrieve symptom information such as "irritability, bitter taste in the mouth, dry throat, dizziness, and headache." Simultaneously, generate questions for "Main symptoms and characteristics of insomnia due to deficiency of both heart and spleen," and retrieve symptom information such as "palpitations, forgetfulness, loss of appetite, and pale complexion."

[0358] The second step: Based on the differences in symptoms, a follow-up question was generated: "Comparison of treatment methods for the two syndrome types." The search revealed treatment paths for "Liver Qi Stagnation Transforming into Fire → Treatment: Soothing the Liver and Clearing Fire → Formula: Gentian Root Decoction for Clearing Liver Fire" and "Heart and Spleen Deficiency → Treatment: Tonifying the Heart and Spleen → Formula: Spleen-Nourishing Decoction for Gui Pi."

[0359] The third step: Further generate follow-up questions on "the differences in etiology and pathogenesis between the two syndrome types", and explore in depth the pathological mechanisms of "liver qi stagnation transforming into fire → etiology: emotional distress → pathogenesis: liver qi stagnation transforming into fire" and "heart and spleen deficiency → etiology: excessive thinking → pathogenesis: heart blood depletion and spleen qi deficiency".

[0360] 8) Path Aggregation: The knowledge paths discovered in the above multi-hop reasoning process are aggregated into a natural language description T_kg, including:

[0361] Symptom comparison pathway: "Insomnia due to liver stagnation transforming into fire is characterized by irritability, bitter taste in the mouth, and dry throat; insomnia due to deficiency of both heart and spleen is characterized by palpitations, forgetfulness, and loss of appetite."

[0362] Treatment approaches differ: "For liver stagnation transforming into fire, the treatment principle is to soothe the liver and purge the fire, using Gentiana Longdancao Decoction; for deficiency of both heart and spleen, the treatment principle is to tonify the heart and spleen, using Guipi Decoction."

[0363] 9) Etiology and pathogenesis: "Liver stagnation transforming into fire is mostly due to emotional distress, with liver qi stagnation transforming into fire and disturbing the heart; deficiency of both heart and spleen is mostly due to excessive thinking, depletion of heart blood, and weakness of spleen qi."

[0364] 10) Fusion Retrieval and Result Integration: Simultaneously, vector retrieval is used to obtain the Top-10 text fragments T_vec directly related to the query, including discussions on the differences between the two syndrome types in TCM textbooks and clinical guidelines. The results of fusing the two are T_fused = T_kg ∪ T_vec. The fused results are deduplicated and uniformly ranked, and the Top-10 fragments with the highest information value are output based on a weighted score of semantic relevance, information completeness, and authority.

[0365] 11) Answer generation: The final search results are combined with the prompt template for comparative analysis based on the user query, and input into the Qwen3-8B model to generate a comprehensive explanation of the differences in etiology, symptoms, treatment methods, and prescriptions, highlighting the core differences between the two syndromes in clinical manifestations, treatment principles, and medication selection.

[0366] The above solution is merely an illustration of a preferred example and is not limited thereto. When implementing this invention, appropriate substitutions and / or modifications can be made according to the user's needs.

[0367] Although embodiments of the present invention have been disclosed above, they are not limited to the applications listed in the specification and embodiments. It can be applied to various fields suitable for the present invention. Other modifications can be readily made by those skilled in the art. Therefore, without departing from the general concept defined by the claims and their equivalents, the present invention is not limited to the specific details and examples shown and described herein.

Claims

1. An enhanced generation method combining multi-strategy retrieval and query adaptive methods, characterized in that, include: S1. A module for judging the complexity of building a binary classifier based on the ERNIE-4.5-Medical model, and a module for determining the main entity based on a large language model; S2. Use a complexity assessment module to assess the complexity of the user-input query statement Q and output the query results. ; S3, if and only When =1, the multi-strategy retrieval execution module executes the simple query path; otherwise, it proceeds to S4. S4. The main entity determination module confirms the entities in the query statement Q to obtain the corresponding number of main entities. ; S5. If and only if the query complexity judgment module outputs... =0, and the main entity determines the module output. The multi-strategy retrieval execution module performs deep semantic retrieval under complex queries; If and only if the query complexity judgment module outputs =0, and the main entity determines the module output. At that time, the multi-strategy retrieval execution module executes the graph vector fusion retrieval path; In S1, the complexity determination module is constructed as follows: S110, Self-constructed dataset; S111, Construct a complexity judgment standard; S112. Using the ERNIE-4.5-Medical model as the basic architecture, the dataset obtained in S110 is used to train and evaluate the complexity judgment model. The complexity judgment criteria include the following four dimensions: Length standard: If the number of characters in a statement is ≤30, it is defined as a simple statement; otherwise, it is defined as a complex statement. Terminology density standard: If a statement contains 0 to 1 TCM professional terms, it is defined as a simple statement; otherwise, it is defined as a complex statement. Sentence structure standard: If a sentence is a single sentence with a simple structure and no compound logical relationship, it is defined as a simple sentence; otherwise, it is defined as a complex sentence. Semantic depth standard: If a statement asks for a single fact, definition, or simple suggestion, it is defined as a simple statement; otherwise, it is defined as a complex statement. In the complexity judgment criteria, if any dimension is defined as complex, then the query statement Q should be marked as complex. In S1, during the training of the complexity assessment model, the cross-entropy loss function is used as follows: L Perform model optimization: In the above formula, N For the sample size, y i For the first i The true label of each sample, and , For the model to the first i The probability that each sample is predicted to be a simple class, and , For query statement Q Vector representation after ERNIE model encoding W , b These are the weights and bias parameters of the classification layer, respectively, where σ is... sigmoid Activation function.

2. The enhanced generation method combining multi-strategy retrieval and adaptive query as described in claim 1, characterized in that, In S1, the main entity determination module uses the Qwen3-8B model as its basic architecture. It uses a hierarchical and progressive templated prompt word architecture to accurately extract TCM professional terms from the query statement, thereby obtaining an entity recognition engine specifically for the field of TCM insomnia. The templated prompt word architecture includes: The task definition layer for determining a unique main entity from an entity list based on traditional Chinese medicine diagnosis and treatment logic; The rule constraint layer is used to explain the three-level decision-making principle of prioritizing the treatment subject, followed by the core disease, and supplementing the query focus. The decision-making principle of the rule constraint layer also includes: quantity judgment criteria. An example demonstration layer showcasing the decision-making process through typical scenarios; The reasoning guidance layer outputs structured results and explains the basis for decision-making.

3. The enhanced generation method combining multi-strategy retrieval and adaptive query as described in claim 2, characterized in that, Based on the three-level decision-making principle, for query statement Q, the main entity determination module obtains the selected set of main entities using the following formula. E main : In the above formula, To construct an inference function adapted to the field of TCM insomnia based on the Qwen3-8B model, For a normalized set of entities, and , Map Let e ​​be the term mapping function, and 'e' be the preliminary list of identified entities. Any single entity in the, The type to which entity e belongs is selected from the entity type hierarchy T. This is a prompt word template based on coding decision principles.

4. The enhanced generation method combining multi-strategy retrieval and adaptive query as described in claim 2, characterized in that, The task definition layer includes: task objectives and a standardized entity type system; The task objective is defined as "identifying medical entities in the query from a traditional Chinese medicine perspective"; The entity type system includes: disease type, syndrome type, traditional Chinese medicine type, prescription type, acupoint type, and treatment method type.

5. The enhanced generation method combining multi-strategy retrieval and adaptive query as described in claim 1, characterized in that, In S3, the workflow of the simple query path includes: S30. For query Q, a vector retrieval method is used to perform a similarity search, and the top 10 candidate document fragments with the highest similarity are retrieved using the following formula. C initial : In the above formula, Here, is a retrieval function based on the BGE-large-zh model, D is a document knowledge base in the field of traditional Chinese medicine insomnia, and k represents the ranking. k =10 indicates that the top 10 candidate document fragments will be recalled; S31. Reorder and score the candidate document fragments recalled in S30 using the following formula: In the above formula, Candidate document fragments The reordering score, It is the set of candidate document fragments recalled by the i-th subquery. This is a semantic relevance scoring function. For information integrity scoring function, For authority scoring function, , , These are the weight coefficients of the corresponding scoring function, and ; S32. Based on the scores in S31, select the top 5 candidate document fragments as shown in the following formula to generate the answer. Answe 1: In the above formula, The large language model generated for the answer, Suggestion words specifically for simple searches This is the final set of the top 5 candidate document fragments.

6. The enhanced generation method combining multi-strategy retrieval and adaptive query as described in claim 1, characterized in that, The workflow of deep semantic retrieval includes: S510. The total expanded entity set is obtained by using the following dual-path entity expansion mechanism. E total : In the above formula, E kg The set of entities obtained through a knowledge graph query, and , For knowledge graph query functions, e primary for E main A single master entity when =1, and , The maximum number of hops for the query depth. For a predefined set of relation types, E sem The set of entities obtained through semantic similarity retrieval, and , e i For entities that belong to the entity set, cosine This is the cosine similarity calculation function. Emb For entity embedding functions, The semantic similarity threshold. This is a set of core entities extracted from a document knowledge base in the field of Traditional Chinese Medicine insomnia. S511, Based on query statement Q Single main entity e primary and total extended entity set E total The multi-angle query set Q is generated using the following formula. multi : In the above formula, QueryConstruct is the query reconstruction algorithm, and aspect... i For the first i One search perspective N fised The number of subqueries is fixed. S512, Regarding Q multi Each subquery in q i Create independent retrieval threads for parallel retrieval, and recall candidate document fragments independently for each retrieval thread using the following formula: In the above formula, subquery D represents a document knowledge base for the field of Traditional Chinese Medicine insomnia. It is the set of candidate document fragments recalled by the i-th subquery, where k represents the rank. k =5 indicates that the top 5 candidate document fragments will be recalled; S513. Merge all search results and re-rank and score the candidate document fragments recalled in S512 using the following formula: In the above formula, This is a semantic relevance scoring function. For information integrity scoring function, For authority scoring function, , , These are the weight coefficients of the corresponding scoring function, and ; S514. Based on the scores in S512, generate the answer as follows: Answe 2: In the above formula, LLM Qwen3-8B The large language model generated for the answer, Prompt D C is a suggestion word specifically for deep semantic search queries. final This is the final output Top-K segment.

7. The enhanced generation method combining multi-strategy retrieval and adaptive query as described in claim 1, characterized in that, The workflow of the graph vector fusion retrieval includes: S520. Use GraphRAG's DRIFT Search method to perform multi-hop path retrieval, and obtain the knowledge graph path exploration through the following formula, so as to obtain a set of text fragments T that matches the graph path transformation. kg : In the above formula, PathToText is the path-to-text conversion function, P is the set of all discovered knowledge graph paths, and p is a single path in the set P; S521. Perform a vector retrieval of the document knowledge base in the field of traditional Chinese medicine insomnia using the following formula to obtain a set of text fragments that complement the vector retrieval. Tvec : In the above formula, Retriever is the vector retrieval function, Q is the query statement, and D is the knowledge base of documents in the field of traditional Chinese medicine for insomnia. k Indicates ranking; S522. The results of graph retrieval and vector retrieval are fused using the following formula: S523. After deduplication, scoring, and sorting the fusion results of S522, the following answer is generated: Answe 3: In the above formula, Prompt E This is a prompt word template specifically for graph vector fusion retrieval. T output For the set of search results, LLM Qwen3-8B The large language model generated for the answer, E main The main entity set.

8. A system applied to the enhanced generation method combining multi-strategy retrieval and adaptive query as described in any one of claims 1-7, characterized in that, include: Complexity assessment module, main entity determination module, and multi-strategy retrieval execution module.

Citation Information

Patent Citations

  • Traditional Chinese medicine question and answer system of knowledge graph enhanced large language model

    CN120086339A

  • Traditional Chinese medicine knowledge question-answering method based on pre-training and retrieval enhancement

    CN120429399A

  • Medical large model analysis method and system based on multi-strategy deep slow thinking and storage medium

    CN120144729A

  • Multi-path recall retrieval method and system based on dynamic weight distribution and storage medium

    CN121255840A