Traditional Chinese medicine syndrome differentiation question-answering system and method based on knowledge graph and large language model

By segmenting and constructing a TCM knowledge graph, and combining a large language model and an efficient graph retrieval algorithm, the problems of inconsistent data formats and information loss in the TCM knowledge system are solved, achieving efficient TCM knowledge retrieval and accurate symptom prediction.

CN121862376APending Publication Date: 2026-04-14NANJING UNIV OF POSTS & TELECOMM
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202512055586.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2025-12-30
Filing Date
2025-12-31
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Existing TCM knowledge retrieval and diagnosis systems face challenges in handling the complexity and lack of structure in ancient TCM texts and TCM concepts. Furthermore, large-scale model fine-tuning consumes significant resources, makes it difficult to effectively apply new knowledge, and suffers from the problem of mutual exclusion among TCM schools of thought.

Method used

By segmenting TCM-related data into fixed-size blocks, extracting entities and relationships using a large language model, constructing a TCM knowledge graph, and combining it with an efficient graph retrieval algorithm for querying, the system integrates local and global information to generate accurate symptom predictions.

Benefits of technology

It improves the efficiency of TCM knowledge extraction and the accuracy of question answering, solves the problems of inconsistent data formats, large semantic spans, and information loss, and achieves efficient knowledge retrieval and accurate symptom prediction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121862376A_ABST
    Figure CN121862376A_ABST
Patent Text Reader

Abstract

The invention discloses a traditional Chinese medicine syndrome differentiation question-answering system and method based on a knowledge graph and a large language model, and belongs to the technical field of large language models. Comprising an input unit, a segmentation unit, an entity and relationship extraction unit, a knowledge graph construction unit, a query generation unit and an output unit, and is characterized in that traditional Chinese medicine related ancient literature, past medical cases and modern outpatient medical record data are preprocessed and segmented into blocks by using a segmentation model to obtain segmented text blocks; according to the segmented text blocks, entities and relations are extracted from the text blocks through a large language model in combination with cue words; carrying out vectorization processing on the segmented text blocks by utilizing an embedded model, carrying out intelligent duplicate removal on the entities and the relationships through a knowledge graph technology, constructing a complete knowledge graph, and storing the knowledge graph into a knowledge base; according to query of a user, local keywords and global keywords are extracted through a large language model, the keywords are retrieved in a knowledge base and a knowledge graph after the large language model understands the question context of the user, and the retrieved knowledge is combined with a prompt word project to be returned to the large model to generate an accurate symptom answer; according to the invention, intelligent conversion and reasoning output from traditional Chinese medicine texts to symptom knowledge can be efficiently completed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to large language models, knowledge graphs, and retrieval enhancement generation, and particularly to a method and system for TCM syndrome differentiation and answering based on knowledge graphs and large language models, for achieving accurate and interpretable TCM syndrome differentiation and answering and symptom prediction. Background Technology

[0002] Traditional Chinese medicine (TCM) is a rich treasure trove of ancient medical knowledge and still holds significant value in modern healthcare systems. With the development of information technology, the level of informatization in my country's medical technology is continuously improving, particularly the digitalization and intelligentization of TCM, which has recently received considerable attention. Intelligent Q&A systems for TCM knowledge can help people quickly and accurately obtain TCM information. However, due to the sheer volume and profound content of ancient TCM texts, as well as the complexity of TCM practice, many researchers are attempting to build systems to assist TCM practitioners in consultation and diagnosis.

[0003] Traditional Chinese medicine (TCM) question-and-answer and symptom prediction is a complex task requiring comprehensive consideration of data processing from ancient TCM texts, construction of TCM knowledge graphs, and graph-based retrieval enhancement. Current TCM knowledge retrieval and diagnostic systems primarily follow the paradigm of fine-tuning general large language models (LLMs) on domain-specific datasets, such as ChatGPT, Qwen, ChatGLM, and LlaMA. ​​However, these systems often face significant challenges, including the complexity of parsing classical Chinese texts, the intricate relationships between TCM concepts (such as components, symptoms, and diagnostic principles), and the lack of structured data. Standardization of TCM knowledge data is a major issue, as TCM knowledge is mainly encoded in classical texts and case narratives rather than structured data. Factors such as symbolic reasoning, linguistic complexity, and terminological ambiguity hinder traditional AI systems from faithfully reproducing TCM principles. With the development of large model technology, some large models in the medical field have made progress. In the TCM field, ShenNong-TCM, trained with 110,000 instructions from TCM documents, implemented simple TCM knowledge question-and-answer through LoRA fine-tuning based on the LLaMA-7B TCM vocabulary. HuatuoGPT-II, through a combination of 1.1TB of training data in both Chinese and English medical fields and fine-tuning, along with proximal optimization to align with expert intent, outperforms GPT-4 in medical applications. These fine-tuned large models have given them a certain capability in the field of Traditional Chinese Medicine (TCM). However, fine-tuning is not only resource-intensive but also requires a large and comprehensive pre-training dataset. Adding new knowledge necessitates re-pre-training, which is inconvenient for our use. Furthermore, there may be issues such as mutual incompatibility of knowledge from different TCM schools of thought. Summary of the Invention

[0004] Objective: To overcome the shortcomings of existing technologies, this invention provides a Traditional Chinese Medicine (TCM) diagnostic question-and-answer system based on knowledge graphs and large language models. It utilizes a large language model to segment input TCM-related data into fixed-size blocks, then uses the large model to extract entities and relationships from these blocks. The extracted entities and their relationships are vectorized—the extracted data is embedded into a knowledge base to construct a TCM knowledge graph. This method generates a key-value pair for each node and relationship, where each key is a word and the corresponding value is a text paragraph. These entities and relationships retain the essence of TCM data knowledge, thus constructing a professional TCM knowledge graph. The generated TCM knowledge graph can not only be directly displayed for users to view, but also achieve rapid knowledge retrieval and querying through efficient graph retrieval algorithms. For query operations, the method vectorizes the user's query and identifies the semantics of the user's question. The method then combines graph retrieval algorithms with vectorized retrieval; this synergy allows the retrieval algorithm to effectively utilize local and global information, simplifying the search process and improving retrieval efficiency. Specifically, this method utilizes an efficient vector database to store TCM knowledge extracted from a large model, and then employs knowledge graph technology and retrieval enhancement techniques to respond to user queries. The method returns retrieved local keyword entities and their associated global relation nodes. Finally, it returns the retrieved key nodes and relationships to an LLM (Low-Level Model) to generate a symptom prediction that matches the input description, combining it with prompts. Our invention addresses the shortcomings of existing technologies through beneficial exploration and innovation, contributing to the inheritance of TCM and the intelligentization of TCM knowledge data, and providing a new technical solution for improving the efficiency of TCM knowledge extraction and the accuracy of TCM knowledge question answering.

[0005] Technical solution: To achieve the above objectives, the technical solution adopted by this invention is as follows: A TCM diagnostic question-answering system based on knowledge graphs and large language models includes an input unit, a segmentation unit, an entity and relation extraction unit, a knowledge graph construction unit, a query generation unit, and an output unit, wherein: The input unit is used to input relevant ancient Chinese medicine books, medical records from various dynasties, and modern outpatient medical records; it is also used for users to input query information. The segmentation unit uses a segmentation model to preprocess and segment relevant ancient Chinese medicine literature, historical medical records, and modern outpatient medical records into blocks, resulting in segmented text blocks. The entity and relation extraction unit is used to extract entities and relations from the segmented text blocks by combining a large language model with prompt words. The knowledge graph construction unit uses an embedding model to vectorize the segmented text blocks, and then uses knowledge graph technology to intelligently deduplicate these entities and relationships to construct a complete knowledge graph and store it in the knowledge base. The query generation unit extracts local and global keywords based on the user's query through a large model. After understanding the context of the user's question, the large language model retrieves these keywords from the knowledge base and knowledge graph, and combines the retrieved knowledge with prompt word engineering to return to the large model to generate an accurate symptom answer. The output unit is used to output the symptom answer; Preferably, the segmentation unit includes a sentence-level segmentation processing module, a sliding window-based semantic block segmentation module, a similarity calculation module, and a judgment and merging module, wherein: The sentence-level segmentation module is used to first perform preliminary segmentation of the ancient text using a text segmenter, dividing the entire text into segments according to periods and other semantic pause marks. Sentence fragments are used to obtain computable basic semantic units; The sliding window-based semantic segmentation module employs a dynamic semantic segmentation method based on sliding windows, setting the window size to [value missing]. Step size is The semantic similarity between adjacent sentences is calculated. When the similarity value between the semantic embedding vectors of three consecutive sentences is within a preset threshold range, they are merged into a complete semantic block. If the similarity is insufficient, the sentence group is treated as a separate semantic block.

[0006] Preferably, the entity and relation extraction unit includes a sentence-level segmentation processing module, a prompt word template module, and a model output structure module, wherein: The sentence-level segmentation processing module is used to input the semantic units obtained in the step into the large language model, and to perform semantic control in combination with the structured prompt word template; The prompt word template defined in the prompt word template module is as follows:

[0007] in, Define a function to represent the process of extracting entities and relations from semantic units. Represents semantic units, Represents a collection of entity types. This indicates that the semantic unit block of the input is extracted by the large model. Each entity instance contains a set of entity types, including diseases, symptoms, prescriptions, and medicinal materials. Represents a set of relation types. Indicates the extracted first A set of relation instances, with relation types including "treatment", "efficacy", and "correspondence"; The model output structure module is used to define the output of the large language model under the constraint of prompt word templates as follows:

[0008] The model output includes an entity set and a relation set, satisfying:

[0009] The final output format is:

[0010] in, This represents the final formatted output of the large model. Represents the inference function of a large language model. This represents the vector space in which the output of the large language model resides, where The output vector dimension is used for encoding structured semantics. Represents an entity instance. Indicates the first The set of entity extraction results after processing semantic units by a large language model. Indicates the semantic type of an entity. The semantic type representing the relation. Indicates the first One entity, Indicates the first The semantic type of an entity, This represents the location range of the entity within the text. Indicates the first The total number of entities extracted from each semantic unit. Indicates the first The head entity in the relation, Indicates the first Tail entity in a relation, Indicates the first Entities of relation type in the relationship, Expressing support for the first Textual evidence fragments establishing the relationship are used to enhance the interpretability and verifiability of the relationship extraction results. Indicates the first The total number of relations extracted from each semantic unit.

[0011] Preferably, the knowledge graph construction unit includes a vectorization encoding module, a similarity calculation and deduplication module, a traditional Chinese medicine knowledge graph module, and a knowledge base storage module, wherein: The vectorization encoding module is used to embed the extracted semantic blocks and entity relationship text. It uses a pre-trained embedding model to map the text to a fixed-dimensional vector space. Let the first... The text blocks are:

[0012] Its embedding representation is:

[0013] in, This represents the k-th semantic text block. This represents the i-th basic sentence unit in the original Chinese medicine text. The window length represents the semantic sliding window. Represents the k-th semantic block The semantic vector representation obtained after vectorization model encoding This represents the d-dimensional vector space in which the vector resides. To embed latitude, This is a text vectorization function; The similarity calculation and deduplication module is used to calculate the semantic similarity between entities using cosine similarity. ;when When the threshold is exceeded, the two entities are determined to be semantically identical and are merged, retaining their original attributes and all associated relationships. The TCM knowledge graph module is used to link the deduplicated entity set and relation set in a graph structure to construct a TCM knowledge graph.

[0014] in, Represents a knowledge graph of Traditional Chinese Medicine. Represents a set of entity nodes. Represents the set of relation edges.

[0015] The knowledge base storage module is used to store the TCM knowledge graph. Stored in the knowledge base in the form of [database name]. This represents the unique identifier of the k-th knowledge item in the vector knowledge base. This represents the semantic vector representation of the knowledge entry. This represents the original semantic text block content corresponding to the vector. Indicates the first Metadata information of the knowledge, This indicates the index number in the knowledge base.

[0016] Preferably, the query generation unit includes a prompt word encapsulation module, a local keyword extraction module, a global keyword extraction module, and a fusion and symptom prediction generation module, wherein: The prompt word encapsulation module is used to encapsulate the query information entered by the user into a structured question template through prompt word engineering; The local keyword extraction module is used by the large language model to identify key elements with TCM entity characteristics from the input text based on the prompt word template, and to determine the semantic dependency relationship between words through semantic annotation and context focusing mechanism, thereby extracting the local entities that are most closely related to the semantics of the user's question. The global keyword extraction module utilizes the global semantic understanding capability of the large language model to analyze the query intent from an overall semantic level, and locates the global topic by calculating the semantic similarity between the input text vector and the knowledge base topic vector. The fusion and symptom prediction generation module is used to perform semantic optimization on the results through prompt word engineering after the local and global search results are returned, and to perform multi-layer fusion based on weight parameters to obtain the symptom answer.

[0017] Preferably, the extraction process in the local keyword extraction module is defined as follows:

[0018] in, This represents a local keyword entity extracted from the user query. This represents the query entered by the user. It is a collection of entities in traditional Chinese medicine. For the constraints of the prompt word template, This indicates that under the constraint of prompt words, the model outputs keywords. The conditional probability; Subsequently, using this local entity as the retrieval center in the knowledge base and knowledge graph, precise retrieval is performed through its direct relation edges, achieving rapid location of locally related knowledge; this process can be represented as:

[0019] in, This represents the set of local associations retrieved centered around a local keyword entity. This represents an instance of a relation edge in a knowledge graph. Representing a knowledge graph, This represents the set of relational edges within it.

[0020] Preferably, in the global keyword extraction module, global keyword extraction is defined as follows:

[0021] in, This represents global keywords extracted from user queries, used for macro-level retrieval within the knowledge base. A collection of topics for the knowledge base. This represents a text vectorization embedding function. It is a semantic similarity function; Subsequently, a global search is performed in the topic hierarchy of the knowledge graph to locate the high-level entities and subordinate node information related to the topic, thereby obtaining a globally associated knowledge set.

[0022] Preferably, the fusion formula in the fusion and symptom prediction generation model is defined as:

[0023] in, This represents the comprehensive semantic representation obtained by fusing local and global keywords, with a fusion weight. Generated by the following gate function:

[0024] in, For a semantically gated vector with values ​​in the range [0,1], This represents a text semantic embedding function. and These are learnable parameters. Based on the gated vector, a dimension-by-dimensional fusion of local and global semantics is performed to obtain a comprehensive semantic representation.

[0025] Finally, the large language model was incorporated into the fusion results. Knowledge graph With knowledge base Execute the inference function:

[0026] in, This represents the syndrome prediction result ultimately generated by the large language model. Representing a knowledge graph, This represents the completed vectorized TCM knowledge base. This represents the inference function of a large language model optimized with prompt words.

[0027] Another objective of this invention is to provide a TCM diagnostic question-and-answer method based on knowledge graphs and large language models, comprising the following steps: Step 1: Use a segmentation model to preprocess and segment relevant ancient Chinese medicine books, medical records from various dynasties, and modern outpatient medical records into blocks to obtain segmented text blocks. Step 2: Based on the segmented text blocks, extract entities and relationships from them using a large language model combined with prompt words; Step 3: The segmented text blocks are vectorized using an embedding model. After intelligent deduplication of these entities and relationships using knowledge graph technology, a complete knowledge graph is constructed and stored in the knowledge base.

[0028] Step 4: Based on the user's query, local and global keywords are extracted through the big model. After understanding the context of the user's question, the big language model retrieves these keywords from the knowledge base and knowledge graph, and combines the retrieved knowledge with prompt words to return to the big model to generate accurate symptom answers.

[0029] Compared with the prior art, the present invention has the following advantages: 1. Existing data often suffers from inconsistent formats, verbose sentences, and large semantic spans. Traditional methods easily lead to information loss or contextual fragmentation during sentence segmentation and semantic block division. The Traditional Chinese Medicine (TCM) data preprocessing and segmentation module improves the quality of the dataset by preprocessing TCM-related texts, addressing the issues of non-standard formats and inaccurate descriptions in existing TCM data. This module introduces TCM clinical diagnostic and treatment terminology, aligns ancient texts with modern standardized terminology using a large model, and employs a segmentation model to clean and format the raw data. Based on textual structural features such as chapter titles, section numbers, and case numbers, the document is divided into multiple independent semantic blocks, outputting structured text. This provides high-quality data input for subsequent steps and improves data usability.

[0030] 2. Traditional information extraction models often rely on manual annotation or rule templates, which have limited ability to understand the classical Chinese expressions in traditional Chinese medicine (TCM) literature. The entity relation and extraction module of this invention uses a large model to understand the semantic structure of ancient texts. This module automates the extraction of TCM diagnostic entities and their semantic relationships from a dataset based on a large model and cue word engineering. The model performs semantic parsing on each text block, then extracts key TCM entities such as syndromes and symptoms, constructs semantic relationships between entities, and outputs a set of triples. These triples contain information such as syndromes and symptoms, providing strong theoretical support for subsequent syndrome diagnosis.

[0031] 3. Traditional methods for constructing TCM knowledge graphs rely on static knowledge tables or expert rules, making it difficult to achieve dynamic expansion and semantic normalization. The embedding model in the knowledge graph construction module can semantically vectorize TCM entities and relationships, and can also achieve intelligent deduplication and clustering in a high-dimensional vector space. The constructed knowledge graph stores rich TCM knowledge such as syndromes and pathogenesis, and can be fully integrated with modern clinical data.

[0032] 4. Intelligent Diagnostic Question Answering Module: Unlike traditional keyword matching question answering, this intelligent question answering module integrates two mechanisms: local keyword extraction and global semantic understanding. The large model possesses powerful language understanding capabilities. Through the local extraction mechanism, it can accurately identify key symptom information and diagnostic entities such as the four diagnostic methods in user input, and establish strong semantic links with local nodes of the knowledge graph. The global understanding mechanism calculates the topic direction of the query through semantic vectors, such as pathogenesis, to fully grasp the macro-intention of the user's question. Finally, the system achieves a comprehensive unity of contextual relevance and semantics through a semantic fusion mechanism.

[0033] 5. Traditional Chinese Medicine (TCM) Prompt Word Template Construction Module: This invention includes a TCM prompt word template construction module specifically designed to guide large language models in generating inference results that conform to TCM semantic norms. This module automatically loads different prompt word templates based on different task scenarios, giving the model a clear role identity, task boundaries, and output structure during inference.

[0034] In summary, this invention constructs a TCM diagnostic question-and-answer system based on knowledge graphs and a large language model. It achieves multi-source knowledge fusion from ancient TCM texts, historical medical records, and modern cases, and utilizes prompt word engineering and semantic embedding techniques to complete structured modeling and intelligent reasoning of TCM diagnostic knowledge. Through a dynamic extraction mechanism of local and global keywords, the system can accurately understand the semantics of user queries and generate standardized answers that conform to TCM diagnostic logic. The introduced TCM-specific prompt word templates further enhance the consistency and professional accuracy of the model's reasoning within the TCM context. This invention significantly improves the performance of the large language model in TCM knowledge understanding and syndrome reasoning tasks, and has significant clinical application value and research promotion significance. Attached Figure Description

[0035] Figure 1 This is a diagram illustrating the overall framework of the TCM diagnostic question-and-answer method based on knowledge graphs and large language models provided by this invention.

[0036] Figure 2 This is a schematic diagram illustrating the TCM predictive processing and segmentation described in the TCM diagnostic question-and-answer method based on knowledge graphs and large language models of this invention.

[0037] Figure 3 This is a schematic diagram illustrating the entity and relation extraction of TCM texts described in the TCM diagnostic question-and-answer method based on knowledge graphs and large language models of this invention.

[0038] Figure 4 This is a schematic diagram illustrating the knowledge graph construction and intelligent retrieval process described in the TCM diagnostic question-and-answer method based on knowledge graphs and large language models of this invention.

[0039] Figure 5This is a schematic diagram of the intelligent diagnostic question-and-answer generation process described in the TCM diagnostic question-and-answer method based on knowledge graphs and large language models of the present invention.

[0040] Figure 6 This invention provides a comparison of the TCM diagnostic question-and-answer method based on knowledge graphs and large language models with different general-purpose large models on a test dataset. Detailed Implementation

[0041] The present invention will be further illustrated below with reference to the accompanying drawings and specific embodiments. It should be understood that these examples are for illustrative purposes only and are not intended to limit the scope of the invention. After reading this invention, any modifications of the invention in various equivalent forms by those skilled in the art will fall within the scope defined by the appended claims.

[0042] Example 1 This embodiment provides a TCM diagnostic question-and-answer method based on knowledge graphs and a large language model. The core of this method is to improve the accuracy and intelligence of TCM diagnostic question-and-answer by segmenting TCM text, extracting semantic knowledge, constructing a knowledge graph, and generating prompt words. Specifically, firstly, based on ancient TCM texts, historical medical records, and modern case data, a segmentation model is used to semantically segment the text to preserve the contextual structural features of TCM diagnosis and treatment. Next, through a large language model combined with prompt word engineering, key medical entities and semantic relationships are automatically extracted from these text blocks to construct a structured representation of TCM diagnostic and treatment knowledge. Subsequently, an embedding model is used to vectorize and encode the extracted entities and relationships, and knowledge graph technology is used to achieve semantic fusion and deduplication of multi-source knowledge, forming a unified TCM knowledge expression space. Furthermore, the introduced TCM-specific prompt word templates enhance the contextual understanding ability of the large language model, making it more consistent with TCM diagnostic logic during the diagnostic reasoning and answer generation stages. Finally, the system integrates the semantics of the prompt words with the knowledge graph retrieval results to generate standardized TCM syndrome answers with greater logical consistency and clinical reference value. Figure 1 As shown, the specific steps include: Step 1: Use a segmentation model to preprocess and segment relevant ancient Chinese medicine books, medical records from various dynasties, and modern outpatient medical records into blocks to obtain segmented text blocks. The method for preprocessing and segmenting TCM text data in step 1: Step 11, Sentence-level segmentation: To address the challenges posed by the complex semantics, non-standard sentence structures, and significant differences in chapter composition in ancient Chinese medicine texts and modern case data, a text segmentation method was first used to preliminarily segment the ancient texts, dividing them into sections based on periods and other semantic pauses. This method divides long texts into semantically coherent basic units by extracting sentence fragments. It can preserve semantic integrity while segmenting long texts into semantically coherent basic units, providing high-quality input for subsequent entity relation extraction and knowledge graph construction.

[0043] Sentence-level segmentation begins by using a text segmenter to initially segment each ancient Chinese medicine text or medical record text according to periods (“.”). One sentence:

[0044] in, Indicates the first One sentence. This indicates the total number of sentences in the original text after it has been divided into periods.

[0045] Step 12, semantic segmentation based on sliding window according to basic semantic units: A dynamic semantic segmentation method based on a sliding window is adopted. After the above segmentation is completed, a fixed-length semantic window is constructed on the sentence set using the sliding window algorithm. The window size is set to... Step size is Calculate the semantic similarity between adjacent sentences; when the similarity value between the semantic embedding vectors of three consecutive sentences is within a preset threshold range, they are merged into a complete semantic block; if the similarity is insufficient, the sentence group is treated as a separate semantic block. Block segmentation and semantic embedding similarity calculation: Ancient Chinese medicine texts were divided into The formula for calculating a semantic block is:

[0046] Each semantic block is denoted as:

[0047] in, Indicates by A set of semantic units consisting of consecutive sentences, where each segment represents a candidate semantic unit. This indicates the total number of sentences after segmentation.

[0048] Semantic similarity calculation and dynamic merging: To ensure the semantic coherence of the segmented text, this method uses a sentence vector embedding model to calculate the semantic similarity between adjacent semantic units. The embedding model is used to semantically encode each sentence segment, and the similarity between any two semantic units is defined as:

[0049] in, and Represents two adjacent semantic units, when When the similarity is within a threshold range, two semantic units are determined to be semantically continuous and merged (in other words, the two semantic units are determined to belong to the same semantic block and merged); if the similarity is below the threshold, they are retained separately (if the similarity is below the threshold, the block is output independently). This method can construct adaptive semantic boundary recognition in different text structures, thereby generating highly consistent text blocks.

[0050] The final output is obtained after the above steps. A text block with high semantic integrity:

[0051] in, It consists of multiple sentences forming independent semantic units, with internal semantic relevance and coherent context, making it well-suited for subsequent knowledge extraction tasks.

[0052] Step 2: Based on the segmented text blocks, extract entities and relationships from them using a large language model combined with prompt words; Step 2, which utilizes a large language model to extract entities and relations from segmented semantic units, includes the following process: Step 21, sentence-level segmentation: As described in step 1, the texts of ancient Chinese medical books, historical medical records, and modern outpatient medical records, after semantic segmentation, are divided into several semantic blocks. Each semantic block maintains a high degree of semantic consistency and contextual integrity. In step 2, the semantic units obtained in step 1 are... The input is fed into a large language model and semantically controlled using structured prompt word templates. Each semantic block... The input is fed into a large language model, and the output is controlled through structured prompt word engineering to achieve entity recognition and relation extraction in traditional Chinese medicine texts.

[0053] Step 22, Define the prompt template: This invention proposes a structured cue word template design method to guide large language models in outputting standardized results for semantic extraction tasks in the field of Traditional Chinese Medicine. Specifically, the cue word template function... The definition is as follows:

[0054] in, Define a function to represent the process of extracting entities and relations from semantic units. Represents semantic units, Represents a collection of entity types. This indicates that the semantic unit block of the input is extracted by the large model. Each entity instance contains a collection of entity types, including categories such as disease, symptom, prescription, and medicinal materials. Represents a set of relation types. Indicates the extracted first The set of relation instances includes semantic relation types such as "treatment", "efficacy", and "correspondence". The prompt words achieve strict semantic constraints on the large language model by clearly defining the model role, task goal, input content and output format, thereby ensuring that the generated entities and relations are all derived from the original text and eliminating fictitious information.

[0055] Step 23, the model outputs a structured definition: The model extraction and structured encoding process, in the prompt word template function Under the constraints, the output of the large language model under the cue word template constraint is defined as:

[0056] in, Represents the semantic reasoning function of a large language model under the constraints of structured cue words; This indicates the encoded output.

[0057] To ensure the interpretability and textual consistency of the generated results, this invention proposes the following output constraints for entities and relations:

[0058] That is: all generated entities It must actually exist in the input text block. In this context, the category must belong to the defined set of entity types. All generated relationships It must be established between entity pairs within the same semantic block, and the relation type must be a set. This constraint ensures the consistency between the model output and the semantic logic of Traditional Chinese Medicine.

[0059] The structured output format is defined as follows: the final structured output generated after the above constraints consists of two parts: an entity set and a relation set. The final output format is as follows:

[0060] in, This represents the final formatted output of the large model. Represents the inference function of a large language model. This represents the vector space in which the output of the large language model resides, where The output vector dimension is used for encoding structured semantics. Represents an entity instance. Indicates the first The set of entity extraction results after processing semantic units by a large language model. Indicates the semantic type of an entity. The semantic type representing the relation. Indicates the first One entity, Indicates the first The semantic type of an entity, This represents the location range of the entity within the text. Indicates the first The total number of entities extracted from each semantic unit. Indicates the first The head entity in the relation, Indicates the first Tail entity in a relation, Indicates the first Entities of relation type in the relationship, Expressing support for the first Textual evidence fragments establishing the relationship are used to enhance the interpretability and verifiability of the relationship extraction results. Indicates the first The total number of relations extracted from each semantic unit.

[0061] Through structured prompt word function Guided by this approach, the large language model can perform precise semantic extraction within the context of Traditional Chinese Medicine (TCM), achieving a structured transformation "from text blocks to knowledge units." Compared to traditional extraction methods based on regular expression matching or shallow neural networks, this method has the following advantages: it improves the model's understanding and constraint generation capabilities of complex TCM semantics; it ensures the traceability and semantic consistency of the extraction results; and it provides a direct input interface for subsequent knowledge graph construction through a standardized JSON output structure.

[0062] Step 3: The segmented text blocks are vectorized using an embedding model. After intelligent deduplication of these entities and relationships using knowledge graph technology, a complete knowledge graph is constructed and stored in the knowledge base.

[0063] Step 3 involves vectorizing the segmented semantic units and constructing a knowledge graph, which includes the following processes: Step 31, Vectorization encoding: In step 2, entities and relationships in the field of Traditional Chinese Medicine have been extracted from text blocks using a large language model. To achieve structured modeling and storage of this semantic information, this invention proposes a vectorization and knowledge graph construction method based on an embedding model. This method includes two stages: (1) semantic block vectorization and storage and (2) entity relationship fusion and knowledge graph generation.

[0064] Semantic block vectorization and database construction begin with the vectorization and encoding of the semantic units (patches) obtained from the block segmentation in step 1. After all semantic blocks have been vectorized, these vectors are standardized, indexed, and stored. The main steps include: Normalization: Normalize all embedding vectors to maintain consistent vector lengths; Similarity index construction: Use a cosine distance-based index structure to establish an efficient retrieval mechanism; Metadata association: In the vector database, the embedded vector is bound to its corresponding semantic block, entity tag and context metadata.

[0065] After the above steps, the final storage structure is as follows:

[0066] in, A unique identifier for a semantic block; For embedding vectors; This corresponds to the original text content; To expand information, such as source literature, chapter location, tags, etc.

[0067] The semantic blocks and entity relationship text extracted in step 2 are embedded. A pre-trained embedding model is used to map the text to a fixed-dimensional vector space. Let the first... The text blocks are:

[0068] Its embedding representation is:

[0069] in, This represents the k-th semantic text block. This represents the i-th basic sentence unit in the original Chinese medicine text. The window length represents the semantic sliding window. Represents the k-th semantic block The semantic vector representation obtained after vectorization model encoding This represents the d-dimensional vector space in which the vector resides. To embed latitude, This is a text vectorization function; Step 32, Similarity calculation and deduplication merging: Intelligent Deduplication of Entities and Relationships and Knowledge Graph Construction: Based on the entity and relation results extracted in step 2, this invention further proposes an intelligent entity deduplication method based on semantic similarity to reduce duplicate nodes and optimize the knowledge graph structure. First, for entities with the same name or similar semantics appearing in different text blocks, cosine similarity is used to calculate the semantic similarity between the entity representation vectors:

[0070] in, Indicates the semantic similarity between entities. Represents an entity, This refers to another entity whose similarity is to be calculated. when When the value exceeds a set threshold, the two entities are determined to have the same semantics and are merged, retaining their original attributes and all associations; that is, when (in When setting a threshold, if two entities are determined to belong to the same semantic category, they are merged, retaining all their attributes and relationship information.

[0071] Step 33, Knowledge Graph Construction: After entity merging is completed, the deduplicated entity set and relation set are linked in a graph structure to construct a Traditional Chinese Medicine knowledge graph:

[0072] in, Represents a knowledge graph of Traditional Chinese Medicine. Represents a set of entity nodes. This represents the set of relation edges. Each node... Each edge possesses attribute information (such as type, source, semantic vector, etc.). This corresponds to the semantic relationship between two nodes, such as "prescription—treatment—syndrome" or "drug—attribution—prescription".

[0073] Step 33, Knowledge Base Storage: A knowledge graph of Traditional Chinese Medicine. Stored in the knowledge base in the form of [database name]. This represents the unique identifier of the k-th knowledge item in the vector knowledge base. This represents the semantic vector representation of the knowledge entry. This represents the original semantic text block content corresponding to the vector. Indicates the first Metadata information of the knowledge, This indicates the index number in the knowledge base.

[0074] The above methods enable efficient structured storage: high-dimensional semantic mapping from text to vectors is achieved through embedding models, providing a foundation for subsequent retrieval and graph reasoning; semantic deduplication optimization: the cosine similarity merging mechanism effectively reduces duplicate entity nodes in the graph, improving the compactness of the graph structure and retrieval efficiency; intelligent knowledge fusion: the constructed knowledge graph can integrate entity relationships from different sources, achieving cross-document semantic fusion and significantly improving the searchability and semantic interpretability of TCM knowledge.

[0075] Step 4: Based on the user's query, local and global keywords are extracted through the big model. After understanding the context of the user's question, the big language model retrieves these keywords from the knowledge base and knowledge graph, and combines the retrieved knowledge with prompt words to return to the big model to generate accurate symptom answers.

[0076] refer to Figure 5 As shown, the method for extracting local and global keywords through a large language model and fusing them to generate symptom-based answers includes the following steps: Step 41, Inputting query information and encapsulating suggestion words: First, the user inputs query information, which may include case description, patient symptoms, tongue and pulse characteristics, four diagnostic methods, or specific TCM diagnostic questions. This input is then encapsulated into a structured question template through prompt word engineering, enabling the large language model to perform keyword recognition and semantic reasoning under clear contextual semantic constraints.

[0077] Step 42, Local Keyword Extraction: For local keyword extraction, the large language model identifies key elements with TCM entity characteristics from the input text based on prompt word templates. For global keyword extraction, the system utilizes the large language model's global semantic understanding capabilities to analyze the query intent within the overall context. The model locates the global semantic domain by calculating the semantic similarity between the input text and the knowledge base topic set, thereby acquiring relevant knowledge at a macro level. Semantic annotation and context-focusing mechanisms determine the semantic dependencies between words, thereby extracting the local entities most closely related to the user's query semantics. Let the input text be... The local keyword set output by the model is The local keyword extraction process is defined as follows:

[0078] in, , It is a collection of entities in traditional Chinese medicine. For the constraints of the prompt word template, This indicates that under the constraint of prompt words, the model outputs keywords. The conditional probability.

[0079] Subsequently, using this local entity as the retrieval center in the knowledge base and knowledge graph, precise retrieval is performed through its direct relational edges (such as "syndrome-symptom" and "drug-efficacy") to achieve rapid location of locally related knowledge. This process can be represented as:

[0080] in, This represents the set of local associations retrieved centered around a local keyword entity. This represents an instance of a relation edge in a knowledge graph. Representing a knowledge graph, This represents the set of relational edges within it.

[0081] Step 43, Global Keyword Extraction: By leveraging the global semantic understanding capabilities of large language models, query intent is analyzed from an overall semantic level. Global topics are located by calculating the semantic similarity between the input text vector and the topic vector of the knowledge base, thereby acquiring relevant knowledge at a macro level.

[0082] Let the knowledge base topic set be The definition of global keyword extraction is:

[0083] in, This represents global keywords extracted from user queries, used for macro-level retrieval within the knowledge base. This represents a text vectorization embedding function. The semantic similarity function is used; during the calculation process, the model represents the global keyword embedding as... Furthermore, by retrieving information about high-level entities and their subordinate nodes related to the topic through the hierarchical structure of the knowledge graph, the aggregation and extraction of globally related knowledge can be achieved.

[0084] Subsequently, a global search is performed in the topic hierarchy of the knowledge graph to locate the high-level entities and subordinate node information related to the topic, thereby obtaining a globally associated knowledge set.

[0085] Step 44, Fusion and Symptom Prediction Generation: After the search results for local and global keywords are returned, the system performs a semantic-aware adaptive fusion operation within the large language model. This fusion process does not use fixed weights or manually set ratios, but rather dynamically adjusts the contribution weights of different semantic sources based on the user query semantics, the hierarchical distribution of retrieved knowledge, and the association structure of the knowledge image, through a parameterized gating function. Let the local and global keyword sets be... and The fusion weights are generated by the following gate function:

[0086] in, For a semantically gated vector with values ​​in the range [0,1], This represents a text semantic embedding function. and These are learnable parameters. Based on the gated vector, a dimension-wise fusion of local and global semantics is performed to obtain a comprehensive semantic representation. The resulting symptom semantic set is then defined as:

[0087] in, This represents the comprehensive semantic representation obtained by fusing local and global keywords. This process is similar to performing a linear projection operation within a frozen, large language model.

[0088] in, This indicates a flattening operation on the semantics of the merged keywords. The linear layer weight matrix, This is a bias term.

[0089] Finally, the model projects the output based on the fused semantics. Standardized TCM "symptom" responses are generated, ensuring that the results balance local contextual accuracy with global semantic integrity, conforming to the logic of TCM syndrome differentiation. The results are then integrated into a large language model. Knowledge graph With knowledge base Execute the inference function (i.e., the final output prediction result is):

[0090] in, This represents the syndrome prediction result ultimately generated by the large language model. Representing a knowledge graph, This represents the completed vectorized TCM knowledge base. This represents the inference function of a large language model optimized with prompt words. The output is a standardized set of "symptom" answers, including the symptom name, main symptoms, and recommended prescriptions, used to assist in traditional Chinese medicine diagnosis and automated question-answering generation.

[0091] Example 2 This embodiment provides a TCM diagnostic question-and-answer system based on knowledge graphs and large language models, including an input unit, a segmentation unit, an entity and relation extraction unit, a knowledge graph construction unit, a query generation unit, and an output unit, wherein: The input unit is used to input relevant ancient Chinese medicine books, medical records from various dynasties, and modern outpatient medical records; it is also used for users to input query information. The segmentation unit uses a segmentation model to preprocess and segment relevant ancient Chinese medicine literature, historical medical records, and modern outpatient medical records into blocks, resulting in segmented text blocks. The segmentation unit includes a sentence-level segmentation processing module, a sliding window-based semantic block segmentation module, a similarity calculation module, and a judgment and merging module, wherein: The sentence-level segmentation module is used to first perform preliminary segmentation of the ancient text using a text segmenter, dividing the entire text into segments according to periods and other semantic pause marks. Sentence fragments are used to obtain computable basic semantic units; The sliding window-based semantic segmentation module employs a dynamic semantic segmentation method based on sliding windows, setting the window size to [value missing]. Step size is The semantic similarity between adjacent sentences is calculated. When the similarity value between the semantic embedding vectors of three consecutive sentences is within a preset threshold range, they are merged into a complete semantic block. If the similarity is insufficient, the sentence group is treated as a separate semantic block.

[0092] The entity and relation extraction unit is used to extract entities and relations from the segmented text blocks by combining a large language model with prompt words. The entity and relation extraction unit includes a sentence-level segmentation processing module, a prompt word template module, and a model output structure module, wherein: The sentence-level segmentation processing module is used to input the semantic units obtained in the step into the large language model, and to perform semantic control in combination with the structured prompt word template; The prompt word template module is used to define prompt word templates as follows:

[0093] in, Define a function to represent the process of extracting entities and relations from semantic units. Represents semantic units, Represents a collection of entity types. This indicates that the semantic unit block of the input is extracted by the large model. Each entity instance contains a set of entity types, including diseases, symptoms, prescriptions, and medicinal materials. Represents a set of relation types. Indicates the extracted first A set of relation instances, with relation types including "treatment", "efficacy", and "correspondence"; The model output structure module is used to define the output of the large language model under the constraint of prompt word templates as follows:

[0094] The model output includes an entity set and a relation set, satisfying:

[0095] The final output format is:

[0096] in, This represents the final formatted output of the large model. Represents the inference function of a large language model. This represents the vector space in which the output of the large language model resides, where The output vector dimension is used for encoding structured semantics. Represents an entity instance. Indicates the first The set of entity extraction results after processing semantic units by a large language model. Indicates the semantic type of an entity. The semantic type representing the relation. Indicates the first One entity, Indicates the first The semantic type of an entity, This represents the location range of the entity within the text. Indicates the first The total number of entities extracted from each semantic unit. Indicates the first The head entity in the relation, Indicates the first Tail entity in a relation, Indicates the first Entities of relation type in the relationship, Expressing support for the first Textual evidence fragments establishing the relationship are used to enhance the interpretability and verifiability of the relationship extraction results. Indicates the first The total number of relations extracted from each semantic unit.

[0097] The knowledge graph construction unit uses an embedding model to vectorize the segmented text blocks, and then uses knowledge graph technology to intelligently deduplicate these entities and relationships to construct a complete knowledge graph and store it in the knowledge base. The knowledge graph construction unit includes a vectorization encoding module, a similarity calculation and deduplication module, a traditional Chinese medicine knowledge graph module, and a knowledge base storage module, wherein: The vectorization encoding module is used to embed the extracted semantic blocks and entity relationship text. It uses a pre-trained embedding model to map the text to a fixed-dimensional vector space. Let the first... The text blocks are:

[0098] Its embedding representation is:

[0099] in, This represents the k-th semantic text block. This represents the i-th basic sentence unit in the original Chinese medicine text. The window length represents the semantic sliding window. Represents the k-th semantic block The semantic vector representation obtained after vectorization model encoding This represents the d-dimensional vector space in which the vector resides. To embed latitude, This is a text vectorization function; The similarity calculation and deduplication module is used to calculate the semantic similarity between entities using cosine similarity. ;when When the threshold is exceeded, the two entities are determined to be semantically identical and are merged, retaining their original attributes and all associated relationships. The TCM knowledge graph module is used to link the deduplicated entity set and relation set in a graph structure to construct a TCM knowledge graph.

[0100] in, Represents a knowledge graph of Traditional Chinese Medicine. Represents a set of entity nodes. Represents the set of relation edges.

[0101] The knowledge base storage module is used to store the TCM knowledge graph. Stored in the knowledge base in the form of [database name]. This represents the unique identifier of the k-th knowledge item in the vector knowledge base. This represents the semantic vector representation of the knowledge entry. This represents the original semantic text block content corresponding to the vector. Indicates the first Metadata information of the knowledge, This indicates the index number in the knowledge base.

[0102] The query generation unit extracts local and global keywords based on the user's query through a large model. After understanding the context of the user's question, the large language model retrieves these keywords from the knowledge base and knowledge graph, and combines the retrieved knowledge with prompt word engineering to return to the large model to generate an accurate symptom answer. The query generation unit includes a prompt word encapsulation module, a local keyword extraction module, a global keyword extraction module, and a fusion and symptom prediction generation module, wherein: The prompt word encapsulation module is used to encapsulate the query information entered by the user into a structured question template through prompt word engineering; The local keyword extraction module is used by the large language model to identify key elements with TCM entity characteristics from the input text based on the prompt word template, and to determine the semantic dependency relationship between words through semantic annotation and context focusing mechanism, thereby extracting the local entities that are most closely related to the semantics of the user's question. Its extraction process is defined as follows:

[0103] in, This represents a local keyword entity extracted from the user query. This represents the query entered by the user. It is a collection of entities in traditional Chinese medicine. For the constraints of the prompt word template, This indicates that under the constraint of prompt words, the model outputs keywords. The conditional probability.

[0104] Subsequently, using this local entity as the retrieval center in the knowledge base and knowledge graph, precise retrieval is performed through its direct relation edges, achieving rapid location of locally related knowledge; this process can be represented as:

[0105] in, This represents the set of local associations retrieved centered around a local keyword entity. This represents an instance of a relation edge in a knowledge graph. Representing a knowledge graph, Represents the set of relational edges within it; The global keyword extraction module utilizes the global semantic understanding capability of the large language model to analyze the query intent from an overall semantic level, and locates the global topic by calculating the semantic similarity between the input text vector and the knowledge base topic vector. The knowledge base topic collection is The definition of global keyword extraction is:

[0106] in, This represents global keywords extracted from user queries, used for macro-level retrieval within the knowledge base. This represents a text vectorization embedding function. It is a semantic similarity function; Subsequently, a global search is performed in the topic hierarchy of the knowledge graph to locate the high-level entities and subordinate node information related to the topic, thereby obtaining a globally associated knowledge set. The fusion and symptom prediction generation module is used to semantically optimize the results after the local and global search results are returned through prompt word engineering, and to perform multi-layer fusion based on weight parameters. The fusion formula is defined as follows:

[0107] in, This represents the comprehensive semantic representation obtained by fusing local and global keywords, with a fusion weight. Generated by the following gate function:

[0108] in, For a semantically gated vector with values ​​in the range [0,1], This represents a text semantic embedding function. and These are learnable parameters. Based on the gated vector, a dimension-by-dimensional fusion of local and global semantics is performed to obtain a comprehensive semantic representation.

[0109] Finally, the large language model was incorporated into the fusion results. Knowledge graph With knowledge base Execute the inference function:

[0110] in, This represents the syndrome prediction result ultimately generated by the large language model. Representing a knowledge graph, This represents the completed vectorized TCM knowledge base. This represents the inference function of a large language model optimized with prompt words. The output unit is used to output the symptom answer.

[0111] Example 3 Reference Figure 6 As an example of the present invention, a verification experiment method for TCM syndrome differentiation question and answer based on knowledge graph and large language model is provided. In order to verify its beneficial effects, a comparative experiment of different model schemes was designed.

[0112] The dataset used in this embodiment comes from manually compiled ancient Chinese medicine documents, modern outpatient medical records, and classic Chinese medicine textbooks. The data covers various disease scenarios and includes fields such as patient basic information, chief complaint, tongue and pulse examination, medical history, syndrome differentiation, symptoms, and pathogenesis. The test data only contains patient basic information, chief complaint, tongue and pulse examination, and medical history. The knowledge stored in the knowledge base mostly comes from Chinese medicine books, in addition to modern medical record data, symptom description tables, and standard Chinese medicine diagnostic terminology, similar in format to the test set. Experimental data comes from anonymized real outpatient medical records. Cases with clear pathogenesis, symptoms, and textual descriptions are selected as the test set. The system generates complete syndrome diagnosis results based on the test data, and the evaluation metric is accuracy. Recall and F1 score are also introduced to compare the model's performance.

[0113] This experiment was conducted within a unified knowledge retrieval and question-answering framework. The testing platform adopted the system framework proposed in this invention, combining knowledge graphs with large language model generation, and its performance was compared with various control models. The experiment included the following four model schemes: This invention uses a retrieval enhancement generation system based on a knowledge graph of traditional Chinese medicine. It retrieves structured knowledge before querying through a large language model and generates syndrome differentiation and prescription reasoning results by combining prompt word templates. We directly use DeepSeek-R1 for natural language reasoning, without relying on the knowledge retrieval module, and generate semantics solely based on model pre-training. The Qwen2.5 general Chinese model was used for open-domain responses to verify the performance of the general model in TCM diagnostic tasks. The HuaTuo-o1 model, pre-trained on a corpus of traditional Chinese medicine, was used as a baseline control for traditional Chinese medicine-specific language models.

[0114] To ensure fairness in the experiment, all question-answering large language models used had a parameter of 7B. The same medical record text was input into each model. The system performs inference based on the designed prompt word template. For versions with retrieval enhancement, the model first performs keyword extraction and knowledge graph retrieval steps, obtaining candidate pathogenesis-symptom-prescription triplet information from the TCM knowledge base, and then generates the final diagnostic result through a fusion mechanism. For versions directly generated by the large language model, generative prediction is performed directly on the input text without external knowledge enhancement. The final output result is compared with the standard reference answer, and the accuracy, recall, and F1 score of the syndrome differentiation prediction are calculated.

[0115] from Figure 6As can be seen, the TCM syndrome differentiation question-answering method based on knowledge graphs and large language models of this invention significantly outperforms other large models in terms of accuracy and recall on the test set. Specifically, the method of this invention exhibits higher overall performance in TCM syndrome recognition tasks. Compared with the control models DeepSeek-R1, Qwen2.5, and HuaTuo-o1, this invention achieves significant improvements in syndrome accuracy, recall, and F1 score.

[0116] The present invention achieves a symptom accuracy of 0.76 and a recall rate of 60%, which is approximately double and 36 percentage points higher than DeepSeek-R1 (accuracy 0.38, recall rate 23.67%), respectively; compared with Qwen2.5 and HuaTuo-o1, the accuracy is improved by approximately 14% to 8%, and the recall rate is improved by approximately 13 to 14 percentage points.

[0117] Although the present invention is basically on par with HuaTuo-o1 in terms of F1 score, its recall rate is significantly improved, indicating that the present invention has a greater advantage in controlling "missed identification" samples and has higher symptom coverage and identification stability.

[0118] This embodiment verifies through real-case testing that the TCM diagnostic question-and-answer method of the present invention significantly improves reasoning accuracy and semantic stability under knowledge enhancement conditions. By combining knowledge graph retrieval and large language model generation capabilities, this method achieves the structured utilization of TCM diagnostic knowledge, providing a scalable technical solution for intelligent TCM question-and-answer and auxiliary diagnosis and treatment systems.

[0119] This invention's system collects data from ancient Chinese medicine texts, historical medical records, and modern outpatient medical records to construct a TCM diagnostic knowledge graph. It then integrates a large language model for language understanding and reasoning, enabling intelligent question-and-answer functionality that simulates TCM diagnostic thinking. Specifically, the system structure includes: a text preprocessing and semantic segmentation module, a large language model entity relation extraction module, a knowledge graph construction module, and a symptom generation module. Through knowledge embedding, similarity calculation, and multi-layered prompt word optimization, the system achieves cross-semantic knowledge integration, efficiently completing the intelligent conversion and reasoning output from TCM text to symptom knowledge.

[0120] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A TCM diagnostic question-and-answer system based on knowledge graphs and large language models, characterized in that, It includes an input unit, a segmentation unit, an entity and relation extraction unit, a knowledge graph construction unit, a query generation unit, and an output unit, wherein: The input unit is used to input relevant ancient Chinese medicine books, medical records from various dynasties, and modern outpatient medical records; it is also used for users to input query information. The segmentation unit uses a segmentation model to preprocess and segment relevant ancient Chinese medicine literature, historical medical records, and modern outpatient medical records into blocks, resulting in segmented text blocks. The entity and relation extraction unit is used to extract entities and relations from the segmented text blocks by combining a large language model with prompt words. The knowledge graph construction unit uses an embedding model to vectorize the segmented text blocks, and then uses knowledge graph technology to intelligently deduplicate these entities and relationships to construct a complete knowledge graph and store it in the knowledge base. The query generation unit extracts local and global keywords based on the user's query through a large model. After understanding the context of the user's question, the large language model retrieves these keywords from the knowledge base and knowledge graph, and combines the retrieved knowledge with prompt word engineering to return to the large model to generate an accurate symptom answer. The output unit is used to output the symptom answer.

2. The TCM diagnostic question-and-answer system based on knowledge graphs and large language models according to claim 1, characterized in that: The segmentation unit includes a sentence-level segmentation processing module, a sliding window-based semantic block segmentation module, a similarity calculation module, and a judgment and merging module, wherein: The sentence-level segmentation module is used to first perform preliminary segmentation of the ancient text using a text segmenter, dividing the entire text into segments according to periods and other semantic pause marks. Sentence fragments are used to obtain computable basic semantic units; The sliding window-based semantic segmentation module employs a dynamic semantic segmentation method based on sliding windows, setting the window size to [value missing]. Step size is The semantic similarity between adjacent sentences is calculated. When the similarity value between the semantic embedding vectors of three consecutive sentences is within a preset threshold range, they are merged into a complete semantic block. If the similarity is insufficient, the sentence group is treated as a separate semantic block.

3. The TCM diagnostic question-and-answer system based on knowledge graphs and large language models according to claim 2, characterized in that: The entity and relation extraction unit includes a sentence-level segmentation processing module, a prompt word template module, and a model output structure module, wherein: The sentence-level segmentation processing module is used to input the semantic units obtained in the step into the large language model, and to perform semantic control in combination with the structured prompt word template; The prompt word template defined in the prompt word template module is as follows: in, Define a function to represent the process of extracting entities and relations from semantic units. Represents semantic units, Represents a collection of entity types. This indicates that the semantic unit block of the input is extracted by the large model. One entity instance, Represents a set of relation types. Indicates the extracted first Instance of a relationship; The model output structure module is used to define the output of the large language model under the constraint of prompt word templates as follows: The model output includes an entity set and a relation set, satisfying: The final output format is: in, This represents the final formatted output of the large model. Represents the inference function of a large language model. This represents the vector space in which the output of the large language model resides. To output the dimension of the vector, Represents an entity instance. Indicates the first The set of entity extraction results after processing semantic units by a large language model. Indicates the semantic type of an entity. The semantic type representing the relation. Indicates the first One entity, Indicates the first The semantic type of an entity, This represents the location range of the entity within the text. Indicates the first The total number of entities extracted from each semantic unit. Indicates the first The head entity in the relation, Indicates the first Tail entity in a relation, Indicates the first Entities of relation type in the relationship, Expressing support for the first A textual evidence fragment establishing the relationship. Indicates the first The total number of relations extracted from each semantic unit.

4. The TCM diagnostic question-and-answer system based on knowledge graphs and large language models according to claim 3, characterized in that: The knowledge graph construction unit includes a vectorization encoding module, a similarity calculation and deduplication module, a traditional Chinese medicine knowledge graph module, and a knowledge base storage module, wherein: The vectorization encoding module is used to embed the extracted semantic blocks and entity relationship text. It uses a pre-trained embedding model to map the text to a fixed-dimensional vector space. Let the first... The text blocks are: Its embedding representation is: in, This represents the k-th semantic text block. This represents the i-th basic sentence unit in the original Chinese medicine text. The window length represents the semantic sliding window. Represents the k-th semantic block The semantic vector representation obtained after vectorization model encoding This represents the d-dimensional vector space in which the vector resides. To embed latitude, This is a text vectorization function; The similarity calculation and deduplication module is used to calculate the semantic similarity between entities using cosine similarity. ;when When the threshold is exceeded, the two entities are determined to be semantically identical and are merged, retaining their original attributes and all associated relationships. The TCM knowledge graph module is used to link the deduplicated entity set and relation set in a graph structure to construct a TCM knowledge graph. in, Represents a knowledge graph of Traditional Chinese Medicine. Represents a set of entity nodes. Represents the set of relation edges; The knowledge base storage module is used to store the TCM knowledge graph. Stored in the knowledge base in the form of [database name]. This represents the unique identifier of the k-th knowledge item in the vector knowledge base. This represents the semantic vector representation of the knowledge entry. This represents the original semantic text block content corresponding to the vector. Metadata information representing the k-th knowledge item. This indicates the index number in the knowledge base.

5. The TCM diagnostic question-and-answer system based on knowledge graph and large language model according to claim 4, characterized in that: The query generation unit includes a prompt word encapsulation module, a local keyword extraction module, a global keyword extraction module, and a fusion and symptom prediction generation module, wherein: The prompt word encapsulation module is used to encapsulate the query information entered by the user into a structured question template through prompt word engineering; The local keyword extraction module is used by the large language model to identify key elements with TCM entity characteristics from the input text based on the prompt word template, and to determine the semantic dependency relationship between words through semantic annotation and context focusing mechanism, thereby extracting the local entities that are most closely related to the semantics of the user's question. The global keyword extraction module utilizes the global semantic understanding capability of the large language model to analyze the query intent from an overall semantic level, and locates the global topic by calculating the semantic similarity between the input text vector and the knowledge base topic vector. The fusion and symptom prediction generation module is used to perform semantic optimization on the results through prompt word engineering after the local and global search results are returned, and to perform multi-layer fusion based on weight parameters to obtain the symptom answer.

6. The TCM diagnostic question-and-answer system based on knowledge graphs and large language models according to claim 5, characterized in that: The extraction process in the local keyword extraction module is defined as follows: in, This represents a local keyword entity extracted from the user query. This represents the query entered by the user. It is a collection of entities in traditional Chinese medicine. For the constraints of the prompt word template, This indicates that under the constraint of prompt words, the model outputs keywords. The conditional probability; Subsequently, using this local entity as the retrieval center in the knowledge base and knowledge graph, precise retrieval is performed through its direct relation edges, achieving rapid location of locally related knowledge; this process can be represented as: in, This represents the set of local associations retrieved centered around a local keyword entity. This represents an instance of a relation edge in a knowledge graph. Representing a knowledge graph, This represents the set of relational edges within it.

7. The TCM diagnostic question-and-answer system based on knowledge graphs and large language models according to claim 6, characterized in that: In the global keyword extraction module, global keyword extraction is defined as follows: in, This represents global keywords extracted from user queries, used for macro-level retrieval within the knowledge base. A collection of topics for the knowledge base. This represents a text vectorization embedding function. It is a semantic similarity function; Subsequently, a global search is performed in the topic hierarchy of the knowledge graph to locate the high-level entities and subordinate node information related to the topic, thereby obtaining a globally associated knowledge set.

8. The TCM diagnostic question-and-answer system based on knowledge graph and large language model according to claim 7, characterized in that: The fusion formula in the fusion and symptom prediction generation model is defined as follows: in, This represents the comprehensive semantic representation obtained by fusing local and global keywords, with a fusion weight. Generated by the following gate function: in, For a semantically gated vector with values ​​in the range [0,1], This represents a text semantic embedding function. and The parameters are learnable; based on the gated vector, the local semantics and global semantics are fused dimension by dimension to obtain a comprehensive semantic representation; Finally, the large language model was incorporated into the fusion results. Knowledge graph With knowledge base Execute the inference function: in, This represents the syndrome prediction result ultimately generated by the large language model. Representing a knowledge graph, This represents the completed vectorized TCM knowledge base. This represents the inference function of a large language model optimized with prompt words, used to integrate multi-source knowledge and produce the final result.

9. A question-answering method for a TCM diagnostic question-answering system based on knowledge graphs and large language models as described in claim 1, characterized in that, Includes the following steps: Step 1: Use a segmentation model to preprocess and segment relevant ancient Chinese medicine books, medical records from various dynasties, and modern outpatient medical records into blocks to obtain segmented text blocks. Step 2: Based on the segmented text blocks, extract entities and relationships from them using a large language model combined with prompt words; Step 3: The above-mentioned segmented text blocks are vectorized using the embedding model. After intelligent deduplication of these entities and relationships using knowledge graph technology, a complete knowledge graph is constructed and stored in the knowledge base. Step 4: Based on the user's query, local and global keywords are extracted through the big model. After understanding the context of the user's question, the big language model retrieves these keywords from the knowledge base and knowledge graph, and combines the retrieved knowledge with prompt words to return to the big model to generate accurate symptom answers.

Citation Information

Cited By

  • A method for fusing large language models and knowledge graphs based on semantic embedding models

    CN122311394A