Intelligent customer service implementation method of medicine knowledge graph based on AI large model
By building a medical knowledge graph based on AI big model, using dynamic weight adjustment and LoRA fine-tuning optimization model, the problems of low drug recommendation matching and logical errors in the traditional big language model in the medical e-commerce field are solved, and efficient and accurate drug recommendation and question-and-answer services are achieved.
Patent Information
- Application Number
- CN202510527672.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-25
- Publication Date
- 2025-08-08
AI Technical Summary
The traditional large language model has low matching results of traditional Chinese medicine recommendations in the medical e-commerce field with instructions, and cannot deeply correlate specific drugs and users. It is easy to have logical errors or low confidence problems in complex reasoning tasks.
The DeepSeek model extracts preliminary semantic information from the drug instructions, user health records and disease databases, performs dynamic weight adjustment and comprehensive scoring, builds a medical knowledge graph, and uses Neo4J graph database storage, combines the large language model DeepSeek to perform drug association matching and question-and-answer pair generation, and uses LoRA fine-tuning and iterative verification mechanism to optimize the model.
It improves the confidence of drug recommendations, ensures the accuracy and structure of knowledge graph data, improves the analysis efficiency and question-and-answer accuracy of complex medical questions, and prevents misleading answers.
Smart Images

Figure CN120450709A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method and computing device for implementing intelligent customer service based on a medical knowledge graph of an AI large model. Background Art
[0002] With the rapid development of the pharmaceutical e-commerce industry, the demand for online health consultation and drug purchase is increasing. Users hope to obtain accurate medication recommendations, disease-assisted diagnosis, and interactive drug inquiries through intelligent customer service systems.
[0003] Currently, intelligent customer service systems are widely used in the pharmaceutical e-commerce sector. Their core technologies include rule-based knowledge question-answering systems, search-based question-answering systems, and generative question-answering systems based on large language models. Generative question-answering systems based on large language models can generate more natural responses that meet user needs and support multi-round dialogue interactions.
[0004] However, the application of traditional large language models in the field of pharmaceutical e-commerce still faces certain challenges, including:
[0005] 1. The drug recommendation results generated by traditional general large models have a low degree of match with the indications in the instructions;
[0006] 2. The general model cannot make recommendations to users based on the medicines sold in the pharmaceutical e-commerce mall;
[0007] 3. When dealing with complex reasoning tasks such as drug interactions and matching disease diagnosis and treatment standards, traditional large models are prone to logical errors or low-confidence answers;
[0008] 4. User health records and drug recommendations are not deeply linked.
[0009] To address the above issues, an AI large-model intelligent customer service system is needed for specific drugs and specific users to achieve deep association between existing online drugs and consulting users, thereby performing standard matching and making drug recommendations more confident. Summary of the Invention
[0010] One of the purposes of the embodiments of the present invention is to provide an intelligent customer service implementation method and system, computing device and computer storage medium based on the medical knowledge graph of AI big model, which is applied to online drug customer service, and an AI big model intelligent customer service system for specific drugs and specific users, so as to achieve deep association between existing online drugs and consulting users, thereby performing standard matching of drugs and users, making the confidence of drug recommendations higher.
[0011] In order to solve the above technical problems, in a first aspect, an embodiment of the present invention provides a method for constructing a medical knowledge graph based on an AI large model, the method comprising:
[0012] The DeepSeek model is used to extract preliminary semantic information from drug instructions, user health records, and disease databases.
[0013] Dynamically adjust the weight of each extracted preliminary semantic result to obtain a comprehensive score for each preliminary semantic extraction result;
[0014] When the comprehensive score exceeds the preset threshold, the triple corresponding to the extraction result corresponding to the comprehensive score is included in the final medical knowledge graph.
[0015] Preferably, the dynamically adjusting the weight of each extracted preliminary semantic result to obtain a comprehensive score for each preliminary semantic extraction result specifically includes:
[0016] The initially extracted semantic information and standard description are input into the pre-trained semantic encoder respectively to obtain vector representations, denoted as v_extract and v_standard, and the semantic matching score S is calculated using cosine similarity. The calculation formula is as follows:
[0017]
[0018] Set the preset threshold T and construct the dynamic adjustment function g(S,T) as a piecewise function, as follows:
[0019] When 0≤S<T, g(S,T)=exp[(ST) / T];
[0020] When T≤S≤1, g(S,T)=1+(ST) / (T);
[0021] The initial weight of each initially extracted semantic information is set to W0, and the dynamically adjusted weight is W new Expressed as:
[0022] W new =W0×g(S,T);
[0023] All the initially extracted semantic information is weighted and summed according to the adjusted weights to obtain the comprehensive score R, which is calculated as follows:
[0024] R=∑(W new ,i×Score_i);
[0025] Among them, Score_i represents the original score of the i-th preliminary extraction result.
[0026] Furthermore, the method further comprises:
[0027] After building the medical knowledge graph, we use the Neo4J graph database to store and retrieve the medical knowledge graph in the form of a graph.
[0028] The medical knowledge graph includes:
[0029] In the drug knowledge subgraph, associations are established between drug nodes based on drug interactions;
[0030] In the disease knowledge subgraph, treatment relationships and contraindication relationships are formed between disease nodes and drug nodes to achieve bidirectional links;
[0031] In the user knowledge subgraph, the user's symptom description is mapped to the corresponding symptom node in the disease subgraph, and the user's drug preference is associated with the drug node.
[0032] Furthermore, the method further comprises:
[0033] Based on the large language model DeepSeek, data preprocessing is performed on drug instructions. The data preprocessing process includes:
[0034] The DeepSeek model uses its pre-trained Transformer architecture to define the extraction function F_extract for the input drug instructions text:
[0035] F_extract(T) = {(entity, attribute, value) | attribute∈{"adverse reaction","indication"}};
[0036] Among them, F_eatract uses the self-attention mechanism to capture the dependencies between different parts of the text, automatically identifies key descriptions and maps them to corresponding attributes to construct a pharmaceutical knowledge subgraph.
[0037] In a second aspect, in order to achieve the purpose of the present invention, an embodiment of the present invention further provides a method for implementing intelligent customer service based on a medical knowledge graph of an AI large model, the method comprising:
[0038] Based on the symptom descriptions in the drug knowledge subgraph, the DeepSeek model uses a generative approach to automatically construct user questions and simultaneously complete drug association matching, specifically including:
[0039] Assume that each indication in the drug knowledge subgraph is described as s, and define the question generation function F_query: q = F_query(s) = f(s; θ);
[0040] Here, θ represents the generation parameters of the general large-scale model DeepSeek in the medical field, and the function f uses context information to generate natural language questions;
[0041] DeepSeek has a built-in matching module F_match, which is used to calculate the drug matching score based on the similarity between the indication s and the drug description, and select the top 2 to 3 related drugs based on the drug matching score, namely:
[0042] D=F_match(s)={d|d∈K,rank(sim(s,d))≤3};
[0043] And form question-answer pair data (q, D), where q is the automatically generated question and D is the set of drugs related to the question.
[0044] Furthermore, the method further comprises:
[0045] The question-answer pair data (q, D) is labeled according to the dialogue turn, and the overall dialogue sequence is: Dialogue = {(q1, a1), (q2, a2), ..., (q_N, a_N)};
[0046] Among them, each a i The answer content is generated based on the matching drug D;
[0047] Define the serialization conversion function F_JSON to map the Dialog ue into JSON format and store it in the form of an array consisting of question-answer key-value pairs.
[0048] Furthermore, the method further comprises:
[0049] The logical consistency of the entire dialogue sequence Dialogue is verified through an iterative verification mechanism, which includes:
[0050] Define the logical coherence scoring function L(q,a)∈[0,1], where q is the generated question and a is the corresponding answer;
[0051] Set a threshold θ. When L(q,a) < θ, the current dialogue pair does not meet the requirements. Update the current dialogue data so that the dialogue data gradually converges to a logically coherent state. The update formula is:
[0052] Dia log ue n+1 =Dia log ue n +λ·(θ-L(q,a));
[0053] Among them, Dialogue nrepresents the question-answer pair data after the nth iteration, λ is the correction step size parameter, which is used to control the adjustment amplitude of each iteration. The iterative process is repeated until L(q,a)≥θ is satisfied or the maximum number of iterations N_max is reached, and the final PharmRx-SE dataset that meets the requirements of logical coherence is obtained.
[0054] Furthermore, the method further comprises:
[0055] DeepSeek-R1 was selected as the base large model, and the PharmRx-SE dataset was selected to perform LoRA fine-tuning on the base large model to obtain a fine-tuning model.
[0056] Furthermore, the LoRA fine-tuning of the large base model specifically includes:
[0057] In the pre-trained model, let the query-key-value weight matrix in the original base model be W Q , W K , W V ∈R d×k , where d and k represent the dimensions of input and output, respectively, by adding two low-rank matrices A∈R d×k and B∈R r×k To modify W Q , W K , W V , where r<<min(d,k);
[0058] The query-key-value linear transformation after LoRA fine-tuning is expressed as:
[0059]
[0060] During the fine-tuning process, the cross entropy loss function L is used to measure the gap between the model prediction output and the actual label. Its formula is:
[0061]
[0062] Among them, y i represents the true label of the i-th sample, Represents the predicted probability of the model output.
[0063] Furthermore, the method further comprises:
[0064] Based on the AdamW optimizer, combined with dynamic learning rate scheduling and regularization methods, the model is optimized twice to calculate the first-order momentum mt and second-order momentum vt of the gradient. The calculation formula is:
[0065] m t =β1m t-1 +(1-β1)gt
[0066]
[0067] Among them, g t is the current gradient, β1 and β2 are the decay coefficients of the first-order and second-order momentum respectively.
[0068] In order to ensure that the model drops rapidly in the early stage of training and converges smoothly in the later stage, the cosine annealing learning rate scheduling method is adopted, and its formula is:
[0069]
[0070] Among them, η t is the learning rate at the tth update, η max is the initial learning rate, η min is the minimum learning rate, and T is the total number of training cycles.
[0071] In a third aspect, an embodiment of the present invention further provides a computing device, comprising a processor and a memory, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the method as described above.
[0072] Compared with the existing technology, the method for constructing a medical knowledge graph based on an AI large model and the method for implementing intelligent customer service provided by the embodiments of the present invention have at least the following beneficial effects:
[0073] The embodiment of the present invention ensures that the constructed medical knowledge graph data is accurate and structured through multi-source data preprocessing and dynamic weight adjustment; uses LoRA to fine-tune the large model so that the model can more accurately identify user symptoms and match the indications in the drug instructions; based on the Langchain framework and integrating the GraphQAChain algorithm, using the Neo4J graph database and standardized interface, it realizes efficient two-way interaction between the large model and the knowledge graph, thereby improving the efficiency of analyzing complex medical problems. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] The preferred embodiments will be described below in a clear and understandable manner with reference to the accompanying drawings to further illustrate the above-mentioned characteristics, technical features, advantages and implementation methods of the present invention.
[0075] Figure 1 This is a flow chart of a method for constructing a medical knowledge graph based on an AI large model according to an embodiment of the present invention;
[0076] Figure 2 This is a flow chart of a method for implementing an intelligent customer service system based on a medical knowledge graph of an AI large model according to an embodiment of the present invention;
[0077] Figure 3 This is a schematic diagram of an AI-based big model-based medical knowledge graph accessed into a big model according to an embodiment of the present invention;
[0078] Figure 4 This is a schematic diagram of the computing device structure for implementing a method for constructing a medical knowledge graph based on an AI big model and a method for realizing intelligent customer service according to an embodiment of the present invention. DETAILED DESCRIPTION
[0079] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the specific embodiments of the present invention will be described below with reference to the accompanying drawings. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings and other embodiments can be obtained based on these drawings without inventive work.
[0080] To simplify the drawings, only portions relevant to the invention are schematically depicted in each figure; they do not represent the actual structure of the product. Furthermore, to simplify the drawings and facilitate understanding, in some figures, only one component with the same structure or function is schematically depicted or labeled. In this document, "one" not only means "only one" but also "more than one."
[0081] The following mainly describes in detail the implementation of the technical solution of the present invention by taking some specific embodiments as examples.
[0082] like Figure 1 As shown, in order to achieve the purpose of the present invention, an embodiment of the present invention provides a method for constructing a medical knowledge graph based on an AI large model, the method comprising:
[0083] S1, extract preliminary semantic information from drug instructions, user health records and disease database respectively through DeepSeek model;
[0084] S2. Dynamically adjust the weight of each extracted preliminary semantic result to obtain a comprehensive score for each preliminary semantic extraction result;
[0085] S3. When the comprehensive score exceeds a preset threshold, the triple corresponding to the extraction result corresponding to the comprehensive score is included in the final medical knowledge graph.
[0086] First, we leveraged the text processing capabilities of a large language model and used the DeepSeek model to extract entity information from data sources such as drug instructions, user health records, and disease databases. This includes:
[0087] a. Extract the drug name, ingredients, indications, contraindications and other attribute information from the drug instructions;
[0088] b. Extract symptom entities and health status features from user health records;
[0089] c. Extract disease names, diagnosis and treatment standards, and treatment methods from the disease database.
[0090] Then, a multi-dimensional relationship is constructed based on the extracted entity information, including:
[0091] Establish therapeutic and contraindication relationships between drug entities and disease entities;
[0092] Build a symptom matching relationship between the user entity and the disease entity;
[0093] Build interaction relationships between drug entities.
[0094] Table 1: Example table of extracted relations
[0095] Header Entity relation Tail Entity Drug A treat Disease X Drug B Taboo Disease Y User Entity Symptom Matching Disease Z
[0096] When using a large model to extract data to construct a medical knowledge graph, the inventors discovered that the extraction results were noisy or partially incomplete. To address this, the present invention proposes a dynamic weight adjustment algorithm to address these issues. Furthermore, the invention utilizes a feedback iteration mechanism and a weighted fusion strategy to perform a further joint verification and quality optimization of the large model extraction results, ensuring that the initial extraction results meet the requirements for knowledge graph construction.
[0097] First, using the large-scale DeepSeek model to perform semantic extraction on drug instructions, user health records, and disease databases, we can obtain rich entity and attribute information as well as preliminary relationship candidates. However, the large-scale model can be affected by data fuzziness, ambiguity, or domain-specific terminology during the extraction process, resulting in inconsistencies or low confidence in some information.
[0098] In this context, the embodiment of the present invention uses a dynamic weight adjustment algorithm to verify and optimize the preliminary extraction results. The specific implementation details of the dynamic weight adjustment algorithm are as follows:
[0099] The preliminary extraction results and standard descriptions are input into the pre-trained semantic encoder respectively to obtain vector representations, denoted as v_extract and v_standard, and the semantic matching score S is calculated using cosine similarity. The formula is as follows:
[0100]
[0101] The value of the semantic matching score S is between 0 and 1. The larger the value, the closer the extraction result is to the standard description in semantics.
[0102] Among them, the standard description refers to the clear and standardized extraction results obtained by manually annotating target entities for a certain type of information extraction task, which is used as a control benchmark. Generally, only the initially extracted text is manually annotated. For example, a specific instance: (head entity, relationship, tail entity) (Amoxicillin, contraindication, allergic to penicillin and its derivatives).
[0103] To quickly downweight the results with low matching scores and moderately upweight the results with high matching scores, a preset threshold T is introduced. Among them, low matching score: 0 <= S < T, high matching score: T <= S < 1
[0104] Construct a dynamic adjustment function g(S, T). In the embodiment of the present invention, g(S, T) is designed as a piecewise function, specifically as follows:
[0105] When 0 ≤ S < T, g(S, T) = exp[(S - T) / T];
[0106] When T ≤ S ≤ 1, g(S, T) = 1 + (S - T) / (T);
[0107] Then, set the initial weight of each initially extracted result to W0, and the dynamically adjusted weight W new is expressed as:
[0108] W new = W0 × g(S, T);
[0109] The role of the dynamic adjustment formula is: when the semantic matching score S of the extraction result is lower than the preset threshold T, the weight is rapidly reduced in an exponential decay manner to filter out noise information; when S is higher than the threshold T, the weight is moderately increased linearly to prevent overamplifying its influence due to a single high score.
[0110] Finally, perform a weighted sum of all initially extracted results according to the adjusted weights to obtain a comprehensive score R. The calculation formula is:
[0111] [[ID=3l]]R = Σ(W new ,i × Score_i);
[0112] Among them, Score_i represents the original score of the i-th initially extracted result. Only when the comprehensive score R exceeds the preset threshold R_threshold, the triple <head entity, relationship, tail entity> corresponding to the extraction result is included in the construction of the final medical knowledge graph.
[0113] After constructing the medical knowledge graph, the embodiment of the present invention uses the Neo4J graph database to implement the storage and query of the medical knowledge graph.
[0114] Among them, Neo4J is a high-performance graph database ("graph model") written in Java language, which can represent complex network structures and store and retrieve data in the form of graphs.
[0115] During the knowledge graph construction process, associations are established between the drug nodes in the drug knowledge subgraph based on drug interactions; in the disease knowledge subgraph, treatment relationships and contraindication relationships are formed between disease nodes and drug nodes to achieve bidirectional links; the user knowledge subgraph maps the user's symptom description to the corresponding symptom node in the disease subgraph, and at the same time associates the user's drug preferences with the drug nodes.
[0116] Through a multi-dimensional relationship network, multi-level associations between drugs and diseases, users and diseases, and drugs are achieved, thereby supporting functions such as disease diagnosis assistance, personalized health advice generation, and drug interaction query.
[0117] During the query process, the system leverages Neo4J's efficient graph query capabilities and its built-in query language to rapidly retrieve nodes and their relationships. By setting query conditions, it can quickly locate the disease node corresponding to the user's symptoms. Based on the relationship between drugs and diseases, it returns information on drugs that meet the indication requirements, thereby assisting in disease diagnosis and drug recommendations.
[0118] Based on the large language model DeepSeek, we preprocessed the data of drug instructions sold in the pharmaceutical e-commerce mall. The data preprocessing process consists of three stages:
[0119] First, the DeepSeek model uses its pre-trained Transformer architecture to achieve end-to-end extraction of drug instructions. For the input text T, the extraction function F_extract is defined as shown in the following formula:
[0120] F_extract(T) = {(entity, attribute, value) | attribute∈{"adverse reaction","indication"}};
[0121] Among them, F_eatract uses the self-attention mechanism to capture the dependencies between different parts of the text, automatically identifies key descriptions and maps them to corresponding attributes, and constructs a drug knowledge subgraph K based on the output results.
[0122] like Figure 2 As shown, an embodiment of the present invention provides a method for implementing intelligent customer service based on the aforementioned medical knowledge graph based on the AI big model, the method comprising:
[0123] S4. Based on the symptom descriptions in the drug knowledge subgraph, the DeepSeek model uses a generative approach to automatically construct user questions and simultaneously complete drug association matching, including:
[0124] Assume that each indication in the drug knowledge subgraph is described as s, and define the question generation function F_query: q = F_query(s) = f(s; θ);
[0125] Here, θ represents the generation parameters of the general large-scale model DeepSeek in the medical field, and the function f uses context information to generate natural language questions;
[0126] DeepSeek has a built-in matching module F_match, which is used to calculate the drug matching score based on the similarity between the indication s and the drug description, and select the top 2 to 3 related drugs based on the drug matching score, that is: D = F_match(s) = {d|d∈K,rank(sim(s,d))≤3};
[0127] S5. Question-answer pair data (q, D) is formed, where q is an automatically generated question and D is a set of drugs related to the question.
[0128] Based on the symptom descriptions extracted from the drug knowledge subgraph K, DeepSeek uses a generative approach to automatically construct user questions and simultaneously complete drug association matching.
[0129] Assume that each indication in the drug knowledge subgraph K is described as s, and define the question generation function F_query: q = F_query(s) = f(s; θ);
[0130] Here, θ represents the generation parameters of the general large-scale model DeepSeek in the medical field, and the function f uses contextual information to generate natural language questions.
[0131] At the same time, DeepSeek has a built-in matching module F_match, which is used to calculate the drug matching score based on the similarity between the indication s and the drug description, and select the top 2 to 3 related drugs based on the drug matching score, namely:
[0132] D=F_match(s)={d|d∈K,rank(sim(s,d))≤3};
[0133] Finally, question-answer pair data (q, D) is formed, where q is the automatically generated question and D is the set of drugs related to the question.
[0134] The generated question-answer pair data (q, D) is labeled according to the conversation turn and then converted into a JSON serialized structure. Suppose the overall conversation sequence is:
[0135] Dialog ue={(q1,a1),(q2,a2),...,(q_N,a_N)};
[0136] Among them, each a i The answer content is generated based on the matching drug D.
[0137] Define the serialization conversion function F_JSON to map the Dialog ue into JSON format. The JSON structure is stored in the form of an array consisting of question-answer key-value pairs.
[0138] Finally, the logical consistency of the conversation data is verified through an iterative verification mechanism, which is mainly described by the following formula:
[0139] Define a logical coherence scoring function L(q,a)∈[0,1], where q is the generated question and a is the corresponding answer. This function is used to evaluate the logical consistency and professionalism of the question-answer pair.
[0140] Set a threshold θ. When L(q,a) < θ, the current dialogue pair is considered to have failed to meet the requirements and needs to be corrected. The goal of the correction is to gradually converge the dialogue data to a state with higher logical coherence. Define an update function U to correct the current dialogue data. The update formula is:
[0141] Dia log ue n+1 =Dia log ue n +λ·(θ-L(q,a))
[0142] Among them, Dialogue n represents the question-answer pair data after the nth iteration, and λ is the modified step size parameter, which is used to control the adjustment amplitude of each iteration. The above iterative process is repeated until L(q,a)≥θ is satisfied or the maximum number of iterations N_max is reached.
[0143] The embodiment of the present invention uses an iterative verification mechanism to make the conversation data undergo multiple corrections and eventually form a PharmRx-SE data set that meets the requirements of logical consistency.
[0144] In this embodiment of the present invention, DeepSeek-R1 is selected as the base large model, and the PharmRx-SE dataset is selected to perform LoRA fine-tuning on the base large model to obtain a fine-tuning model, which can reduce the number of parameters to be updated while maintaining the model's expressiveness.
[0145] The embodiment of the present invention ensures that the constructed medical knowledge graph data is accurate and structured through multi-source data preprocessing and dynamic weight adjustment; uses LoRA to fine-tune the large model so that the model can more accurately identify user symptoms and match the indications in the drug instructions; based on the Langchain framework and integrating the GraphQAChain algorithm, using the Neo4J graph database and standardized interface, it realizes efficient two-way interaction between the large model and the knowledge graph, thereby improving the efficiency of analyzing complex medical problems.
[0146] In the pre-trained model, let the query-key-value weight matrix in the original model be W Q , W K , W V ∈R d×k , where d and k represent the dimensions of input and output respectively. By adding two low-rank matrices A∈R d×k and B∈R r×k To modify W Q , W K , W V , where r<<min(d,k).
[0147] The query-key-value linear transformation after LoRA fine-tuning is expressed as:
[0148]
[0149] During the fine-tuning process, the cross entropy loss function L is used to measure the gap between the model prediction output and the actual label. Its formula is:
[0150]
[0151] Among them, y i represents the true label of the i-th sample, Represents the predicted probability of the model output.
[0152] The model is trained with backpropagation using this loss function, and the loss change on the validation set is monitored using an early stopping strategy to prevent overfitting. To ensure the fine-tuning effect, the following key parameters are set in this embodiment, and their specific values are shown in Table 2:
[0153] Table 2: Key parameter settings for fine-tuning process
[0154] Parameter name illustrate Setting value Learning rate Parameter update step size <![CDATA[1×10 -4 ]]> BatchSize Low-rank matrix parameter dimension 32 Low rank dimension r Symptom Matching 8 Weight decay Regularization parameter 0.01 Training cycle Number of iterations 50
[0155] After obtaining the fine-tuned model after LoRA fine-tuning, in order to further improve the model's ability in medical question-answering tasks, the embodiment of the present invention is based on the AdamW optimizer, combined with dynamic learning rate scheduling and regularization methods, to perform secondary optimization on the model. In each parameter update process, the first-order momentum m of the gradient is first calculated. tand the second-order momentum v t , and its update formula is:
[0156] m t =β1m t-1 +(1-β1)g t
[0157]
[0158] Among them, g t is the current gradient, β1 and β2 are the decay coefficients of the first-order and second-order momentum respectively.
[0159] Subsequently, the parameters are updated according to the corrected momentum value, and a weight decay term is added to suppress overfitting.
[0160] In order to ensure that the model drops rapidly in the early stage of training and converges smoothly in the later stage, the cosine annealing learning rate scheduling method is adopted, and its formula is:
[0161]
[0162] Among them, η t is the learning rate at the tth update, η max is the initial learning rate, η min is the minimum learning rate, and T is the total number of training cycles.
[0163] During the optimization process, the model is evaluated on the validation set, primarily using metrics such as accuracy, recall, F1-score, and confidence analysis. After each training cycle, the model's performance on the validation set is calculated. If both accuracy and F1-score exceed preset thresholds, the optimization strategy is considered to have achieved the desired effect.
[0164] Therefore, the embodiment of the present invention constructs a multi-dimensional relationship network graph with higher accuracy and more comprehensive coverage based on data preprocessing and medical knowledge graph and stores it using the Neo4J graph database.
[0165] Then, the LangChain open source framework is used to connect the graph database to the large model.
[0166] LangChain aims to simplify application development based on large language models. The LangChain framework's chain mechanism connects different components to streamline data transmission and processing. Through modular design, context management, and multi-tool integration, it helps developers quickly build complex AI applications (such as chatbots and intelligent customer service systems).
[0167] The framework supports large language models to interact directly with graph databases. In LangChain, through modules such as GraphStore (managing database connections and schema information), GraphRetriever (retrieving relevant subgraph context based on query results), and GraphQAChain (or GraphCypherQAChain specifically for Neo4J), a complete pipeline from natural language to graph query to answer generation is built to enable LLM to interact with multiple graph databases.
[0168] This feature allows users to query and manipulate graph data using natural language, enabling efficient data association, knowledge graph construction, and intelligent query capabilities. By combining graph databases and language models, GraphQAChain can handle complex queries and data relationships, providing intelligent question-and-answer services.
[0169] The Langchain framework includes a component called GraphIndexCreator that can parse sentences and create knowledge graphs, but this component is currently limited and cannot process long text corpora.
[0170] To solve this problem, Figure 3 As shown, the specific steps of the embodiment of the present invention to connect the graph database to the large model are:
[0171] 1. Design a REST or GraphQL interface, insert a lightweight API layer into Chain, and use the FastAPI framework to design the interface for invocation within Chain to achieve real-time extraction of graph database data. The extracted data is converted into a unified format, recorded as structured data D, that is, D = I(DB,Q), where I represents the interface function and Q is the user query. The subgraph data related to the query is returned, as follows:
[0172] First, define the input model and verification, where the model refers to the locally deployed and fine-tuned DeepSeek-R1.
[0173] The request is then routed to a custom tool that converts natural language into graph query statements, drives the query through the graph database, and converts the execution results into a JSON return type at the API layer before returning them to the caller.
[0174] Finally, it is integrated into the LangChain framework. Within the Chain definition, this API layer is used as a tool to enable dynamic calls by downstream Chains during multi-tool scheduling, enabling end-to-end real-time data extraction. The fine-tuned DeepSeek-R1 is first deployed on a local server. LangChain's HuggingFacePipeline class then leverages this to call the model without a network connection, allowing it to be directly called by LangChain, much like an online API.
[0175] 2. Configure GraphQAChain, set the graph database constructed in the previous embodiment as DB, and construct a graph object based on the graph database, which can be described by the formula:
[0176] Graph = Neo4JGraph(DB)
[0177] Among them, Neo4jGraph represents the process of initializing the graph data structure using the graph database DB.
[0178] Next, pass the above graph object into the GraphQAChain constructor to obtain a question-answer chain object, which is expressed as follows:
[0179] QAChain=Neo4JGraphQAChain(Graph)
[0180] The role of this chain interaction structure is to first pass the user's natural language query to the question-answering chain. Then, through a predefined process (query generation, error verification, query execution, and answer synthesis, all automatically completed in series by the sub-chains and tools within the chain), the query is converted into a search request suitable for the graph database.
[0181] Then, the structured data stored in the graph database is used for retrieval;
[0182] Finally, the retrieved information is injected into the large language model to generate the answer.
[0183] In an embodiment of the present invention, when a user submits a natural language query, the LangChain framework first calls a fine-tuned large language model to generate a preliminary answer.
[0184] To enhance the system's ability to handle complex queries, the system integrates the GraphQAChain algorithm (the GraphQAChain algorithm is a langchain encapsulation method with the following process: natural language → Cypher → execution → answer). This algorithm searches the medical knowledge graph in the Neo4J graph database and extracts drug attributes, indications, contraindications, and disease-related information related to the user's query.
[0185] The structured data is formatted and injected into a preset prompt template to guide the large-scale language model for secondary generation, thereby generating a final answer that is both professional and accurate, including:
[0186] First, the structured data obtained from the graph database is formatted using JSON to preserve the field hierarchy and readability. The formatting conversion uses the json.dumps method of the Python standard library.
[0187] Secondly, Langchain’s PromptTemplate class defines a prompt word structure containing {context} and {question} placeholders, injecting formatted data into the template to guide the model to focus on result interpretation and answer generation.
[0188] Compared with other solutions, the technical advantages of the embodiments of the present invention are:
[0189] Through multi-source data preprocessing and dynamic weight adjustment, the constructed medical knowledge graph data is ensured to be accurate and structured;
[0190] Use LoRA to fine-tune the large model to make it more accurate in identifying user symptoms and matching them with the indications in the drug instructions;
[0191] Based on the Langchain framework and integrated with the GraphQAChain algorithm, it uses the Neo4J graph database and standardized interfaces to achieve efficient two-way interaction between large models and knowledge graphs, improving the efficiency of analyzing complex medical problems.
[0192] The system can filter low-relevance or high-risk drug recommendations in real time and, combined with the medical knowledge graph, effectively prevent misleading answers;
[0193] The overall system forms a closed loop, which not only ensures the generation of preliminary answers, but also generates secondary answers by injecting prompt word templates through structured data, thereby improving the accuracy and professionalism of questions and answers.
[0194] In a third aspect, an embodiment of the present invention further provides a computing device, which includes a processor or a calculator and a memory, wherein the memory is used to store a computer program, and the computer program includes program instructions, and the processor or calculator is configured to call the program instructions to execute the method as described above.
[0195] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor or a calculator, the processor or the calculator executes the method as described above.
[0196] like Figure 4 As shown, an embodiment of the present application provides a computing device, which includes a processor or a calculator (not shown) 1001 and a memory 1002. The processor or calculator 1001 and the memory 1002 can be interconnected via a communication bus 1003. The communication bus 1003 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus 1003 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the memory 1002 is used to store a computer program, which includes program instructions. The processor 1001 is configured to call the program instructions, and the above program includes a method for executing some or all of the steps in the aforementioned method.
[0197] The processor 1001 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the above program.
[0198] The memory 1002 may be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM) or other type of dynamic storage device that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, an optical disc storage (including a compact disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor via a bus. The memory may also be integrated with the processor.
[0199] The electronic device 1000 may further include a communication module 1004 and a display 1005. The communication module 1004 may be connected to the optical tracking device for communication. The communication module 1004 may be a wireless communication module (eg, a WiFi module, a Bluetooth module, etc.) or a wired communication module.
[0200] In addition, the electronic device 1000 may also include common components such as a communication interface (eg, a USB interface, a microphone interface, etc.), an antenna, etc., which will not be described in detail here.
[0201] It should be noted that for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by this application.
[0202] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0203] In the several embodiments provided in this application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.
[0204] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0205] In addition, the functional units in the various embodiments of the application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software program modules.
[0206] If the integrated unit is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a memory, including a number of instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned memory includes: U disk, read-only memory (ROM), random access memory (RAM), mobile hard disk, magnetic disk or optical disk, etc., various media that can store program code.
[0207] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable memory, which may include: a flash drive, a read-only memory, a random access memory, a magnetic disk or an optical disk, etc.
[0208] The above is a detailed introduction to the embodiments of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of the present application. At the same time, for those skilled in the art, according to the idea of the present application, there may be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
[0209] It should be noted that the above embodiments can be freely combined as needed. The above are only preferred embodiments of the present invention. It should be noted that those skilled in the art can make several improvements and modifications without departing from the principles of the present invention, and such improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for constructing a medical knowledge graph based on an AI large model, characterized in that: The method comprises: The DeepSeek model is used to extract preliminary semantic information from drug instructions, user health records, and disease databases. Dynamically adjust the weight of each extracted preliminary semantic result to obtain a comprehensive score for each preliminary semantic extraction result; When the comprehensive score exceeds the preset threshold, the triple corresponding to the extraction result corresponding to the comprehensive score is included in the final medical knowledge graph.
2. The method for constructing a medical knowledge graph based on an AI large model according to claim 1, wherein: The step of dynamically adjusting the weight of each extracted preliminary semantic result to obtain a comprehensive score for each preliminary semantic extraction result specifically includes: The initially extracted semantic information and standard description are input into the pre-trained semantic encoder respectively to obtain vector representations, denoted as v_extract and v_standard, and the semantic matching score S is calculated using cosine similarity. The calculation formula is as follows: Set the preset threshold T and construct the dynamic adjustment function g(S,T) as a piecewise function, as follows: When 0≤S<T, g(S,T)=exp[(ST) / T]; When T≤S≤1, g(S,T)=1+(ST) / (T); The initial weight of each initially extracted semantic information is set to W0, and the dynamically adjusted weight is W new Expressed as: W new =W0×g(S,T); All the initially extracted semantic information is weighted and summed according to the adjusted weights to obtain the comprehensive score R, which is calculated as follows: R=∑(W new ,i×Score_i); Among them, Score_i represents the original score of the i-th preliminary extraction result.
3. The method for constructing a medical knowledge graph based on an AI large model according to claim 2, wherein: The method further comprises: After building the medical knowledge graph, we use the Neo4J graph database to store and retrieve the medical knowledge graph in the form of a graph. The medical knowledge graph includes: In the drug knowledge subgraph, associations are established between drug nodes based on drug interactions; In the disease knowledge subgraph, treatment relationships and contraindication relationships are formed between disease nodes and drug nodes to achieve bidirectional links; In the user knowledge subgraph, the user's symptom description is mapped to the corresponding symptom node in the disease subgraph, and the user's drug preference is associated with the drug node.
4. The method for constructing a medical knowledge graph based on an AI large model according to claim 3, wherein: The method further comprises: Based on the large language model DeepSeek, data preprocessing is performed on drug instructions. The data preprocessing process includes: The DeepSeek model uses its pre-trained Transformer architecture to define the extraction function F_extract for the input drug instructions text: F_extract(T) = {(entity, attribute, value) | attribute∈{"adverse reaction","indications"}}; Among them, F_eatract uses the self-attention mechanism to capture the dependencies between different parts of the text, automatically identifies key descriptions and maps them to corresponding attributes to construct a pharmaceutical knowledge subgraph.
5. A method for implementing intelligent customer service based on the AI large model-based medical knowledge graph according to claim 4, characterized in that: The method comprises: Based on the symptom descriptions in the drug knowledge subgraph, the DeepSeek model uses a generative approach to automatically construct user questions and simultaneously complete drug association matching, specifically including: Assume that each indication in the drug knowledge subgraph is described as s, and define the question generation function F_query: q = F_query(s) = f(s;θ); Here, θ represents the generation parameters of the general large-scale model DeepSeek in the medical field, and the function f uses context information to generate natural language questions; DeepSeek has a built-in matching module F_match, which is used to calculate the drug matching score based on the similarity between the indication s and the drug description, and select the top 2 to 3 related drugs based on the drug matching score, namely: D=F_match(s)={d|d∈K,rank(sim(s,d))≤3}; And form question-answer pair data (q, D), where q is the automatically generated question and D is the set of drugs related to the question.
6. The method for implementing intelligent customer service based on an AI large model according to claim 5, characterized in that: The method further comprises: The question-answer pair data (q, D) is labeled according to the dialogue turn, and the overall dialogue sequence is: Dialogue = {(q1, a1), (q2, a2), ..., (q_N, a_N)}; Among them, each a i The answer content is generated based on the matching drug D; Define the serialization conversion function F_JSON to map the Dialogue into JSON format and store it as an array of question-answer key-value pairs.
7. The method for implementing intelligent customer service based on an AI large model according to claim 5, characterized in that: The method further comprises: The logical coherence of the entire dialogue sequence Dialogue is verified through an iterative verification mechanism, which includes: Define the logical coherence scoring function L(q,a)∈[0,1], where q is the generated question and a is the corresponding answer; Set a threshold θ. When L(q,a) < θ, the current dialogue pair does not meet the requirements. Update the current dialogue data so that the dialogue data gradually converges to a logically coherent state. The update formula is: Dialogue n+1 =Dialogue n +λ·(θ-L(q,a)); Among them, Dialogue n represents the question-answer pair data after the nth iteration, λ is the correction step size parameter, which is used to control the adjustment amplitude of each iteration. The iterative process is repeated until L(q,a)≥θ is satisfied or the maximum number of iterations N_max is reached, and the final PharmRx-SE dataset that meets the requirements of logical coherence is obtained.
8. The method for implementing intelligent customer service based on an AI large model according to claim 6, wherein: The method further comprises: Select DeepSeek-R1 as the base model, select the PharmRx-SE dataset to perform LoRA fine-tuning on the base model to obtain a fine-tuned model; The LoRA fine-tuning of the large base model specifically includes: In the pre-trained model, let the query-key-value weight matrix in the original base model be W Q , W K , W V ∈R d×k , where d and k represent the dimensions of input and output, respectively, by adding two low-rank matrices A∈R d×k and B∈R r×k To modify W Q , W K , W V , where r<<min(d,k); The query-key-value linear transformation after LoRA fine-tuning is expressed as: During the fine-tuning process, the cross entropy loss function L is used to measure the gap between the model prediction output and the actual label. Its formula is: Among them, y i represents the true label of the i-th sample, Represents the predicted probability of the model output.
9. The method for implementing intelligent customer service based on an AI large model according to claim 8, characterized in that: The method further comprises: Based on the AdamW optimizer, combined with dynamic learning rate scheduling and regularization methods, the model is optimized twice to calculate the first-order momentum m of the gradient t and the second-order momentum v t , the calculation formula is: Among them, g t is the current gradient, β1 and β2 are the decay coefficients of the first-order and second-order momentum respectively. In order to ensure that the model drops rapidly in the early stage of training and converges smoothly in the later stage, the cosine annealing learning rate scheduling method is adopted, and its formula is: Among them, η t is the learning rate at the tth update, η max is the initial learning rate, η min is the minimum learning rate, and T is the total number of training cycles.
10. A computing device, characterized in that The computing device includes a processor and a memory, the memory is used to store a computer program, the computer program includes program instructions, and the processor is configured to call the program instructions to execute the method according to any one of claims 1 to 4 and 5 to 9.
Citation Information
Cited By
Remote medication guidance scheme pushing method and system based on AI multi-model fusion
CN121662330A