Intelligent question and answer system for intestinal microorganisms based on knowledge graph and large model

By combining knowledge graphs and large language models using Graph RAG technology, an intelligent question-answering system for gut microbiota was constructed, overcoming the limitations of traditional query methods, achieving richer and more flexible question-answering services, and improving the efficiency and accuracy of gut microbiota research.

CN119226487BActive Publication Date: 2026-03-03SHANGHAI LISHAN BIOPHARMACEUTICAL CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411735666.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2026-03-03
Estimated Expiration
2044-11-29

AI Technical Summary

Technical Problem

Traditional database-based gut microbiome knowledge query methods are fixed in form, unable to achieve flexible and natural language interaction, and difficult to provide intelligent question and answer services. Furthermore, the application of existing RAG technology in the field of gut microbiome has not yet fully utilized its advantages in multi-hop queries and interpretability.

Method used

By combining knowledge graphs and large language models (LLM), and employing Graph RAG technology, an intelligent question-answering system for gut microbiota is constructed. Through a combination of entity recognition, classification, retrieval, and generation, more accurate and interpretable answers are generated.

Benefits of technology

It significantly improves the knowledge coverage and information density of question answering, can handle complex multidisciplinary problems, provides detailed information support, reduces knowledge blind spots, and enhances scientific research applicability and query efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119226487B_ABST
    Figure CN119226487B_ABST
Patent Text Reader

Abstract

The application provides an intelligent question and answer system for intestinal microorganisms based on a knowledge graph and a large model, a constructed scientific intestinal microorganism knowledge base, calling available LLM, and realizing intelligent question and answer in the field of intestinal microorganisms based on Graph RAG technology.In the intelligent question and answer system for intestinal microorganisms, the knowledge richness of question and answer is significantly improved.Through the combination of the knowledge graph and the large language model (LLM), the system can not only provide direct knowledge points, but also supplement context, background information and multi-level scientific explanations, so that the answer content is more rich and comprehensive.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of natural language processing technology, and in particular to a RAG question-answering system based on gut microbiota knowledge graph. Background Technology

[0002] The gut microbiota is a collection of trillions of microorganisms residing in our intestines, including bacteria, viruses, fungi, and protozoa. They form a complex symbiotic relationship with our bodies, and maintaining the balance and diversity of the gut microbiota is crucial for our health. First, the gut microbiota plays a vital role in the digestion and absorption of nutrients. They help break down complex carbohydrates that we cannot digest, producing beneficial substances such as short-chain fatty acids, which can be absorbed and utilized by our bodies. Second, the gut microbiota is closely related to our immune system. They help train and regulate immune cells, enhancing our immunity and preventing infections and inflammatory diseases. Furthermore, the gut microbiota has close connections with our brain and nervous system, influencing our mood, cognition, and behavior by producing neurotransmitters and metabolites. Finally, the gut microbiota is also related to weight management, cardiovascular health, and cancer prevention.

[0003] With the rise and widespread application of high-throughput sequencing technology, the barriers to human microbiome research have been significantly broken down, making multi-omics and clinical research on gut microbiota extremely popular. Numerous studies have conducted detailed experimental verification and in-depth analysis of various associations. However, current findings are still very limited, and many mysteries regarding the specific functional characteristics and mechanisms of action of gut microbiota in the human host remain to be explored and revealed. To gain a deeper understanding of the impact of gut microbiota on human health and disease, researchers should not only rely on traditional but time-consuming and labor-intensive experimental methods, as well as efficient but limited microbiome methods, but also focus more on the mining and application of biomedical big data. By integrating and analyzing massive amounts of biomedical data, we hope to reveal more complex and nuanced relationships between gut microbiota and human health, thereby providing new ideas and strategies for disease prevention, diagnosis, and treatment.

[0004] By constructing a gut microbiome knowledge base, we can acquire knowledge related to gut microbiota more efficiently and accurately, thereby promoting the in-depth development and utilization of gut microbiome resources, improving research efficiency, facilitating cross-institutional collaboration and resource sharing, and strengthening the standardization and normalization of research. However, traditional database-based knowledge retrieval methods have certain limitations; their format is relatively fixed and usually only allows retrieval according to specific formats. To overcome this limitation, we need to combine the knowledge base with a Large Language Model (LLM) to achieve more flexible and natural language interaction, thus providing intelligent question-and-answer services in the field of gut microbiota. This combination will enable researchers to obtain the information they need in a more intuitive and convenient way, further accelerating the progress of gut microbiome research.

[0005] Generative LLMs have made significant progress in recent years. The latest models from companies like OpenAI and Anthropic, such as GPT-4o, OpenAI o1, and Claude 3.5, have demonstrated outstanding performance. Domestic companies such as Baidu, Huawei, and iFlytek have also launched their own LLMs. Meta, through its Llama series, has led the development of open-source LLMs, and is currently updated to version 3.2. Alibaba is also actively involved in open-source LLMs, recently launching the Qwen2.5 model, bringing a new breakthrough to the field of Chinese natural language processing.

[0006] Retrieval Augmented Generation (RAG) is a method that combines retrieval and generation techniques to improve the performance of LLMs when handling specific tasks. Before generating an answer, RAG retrieves information related to the question from a large-scale knowledge base, and then inputs this information along with the question into the LLM to generate a more accurate and interpretable answer.

[0007] Traditional RAGs are based on natural language text segments, while Graph RAG (Graph Retrieval Augmented Generation) is an upgrade of RAG technology, based on the structured knowledge organized by knowledge graphs. First, Graph RAGs can more accurately represent the relationships and contextual information between entities, thereby enhancing the depth and contextual relevance of retrieved information and handling more complex multi-hop queries. Second, based on the explicit structure and relationships of knowledge graphs, Graph RAGs can provide more interpretable answers, and their reasoning process is traceable. Summary of the Invention

[0008] A knowledge graph and large model-based intelligent question-answering system for gut microbiota, based on the gut microbiota knowledge base previously built by the applicant (see CN118506887A), calls available LLMs and uses Graph RAG technology to achieve intelligent question answering in the field of gut microbiota.

[0009] According to CN118506887A, the inventors provided a gut microbiome knowledge graph system, comprising a gut microbiome knowledge base, a gut microbiome small molecule drug therapy association knowledge base, and a clinical medical database, forming a gut microbiome knowledge graph. A multimodal uncertain reasoning system based on this knowledge graph is also described. The system combines and connects the three knowledge bases—the gut microbiome knowledge base, the gut microbiome small molecule drug therapy association knowledge base, and the clinical medical database—aligning small molecules, drugs, and disease entities to obtain the final gut microbiome knowledge graph. The multimodal uncertain reasoning system within this knowledge graph is then used to predict potential associated diseases, drugs, and genes related to gut microbiota. This invention, based on the aforementioned gut microbiome knowledge graph system, establishes a gut microbiome intelligent question-and-answer system based on knowledge graphs and large-scale models.

[0010] Before generating an answer, the RAG retrieves information related to the question from a large-scale knowledge base. This information, along with the question, is then input into the LLM (Large Language Model) to generate a more accurate and interpretable answer. The large-scale knowledge base can be the microbial knowledge graph provided by the inventor in CN118506887A. This invention realizes an intelligent question-answering system in the field of gut microbiota by combining knowledge graphs and large language models (LLMs) based on Graph RAG technology.

[0011] Specifically, the steps include the following:

[0012] (1) After receiving the user's query, retrieve the user's recent dialogue records through the dialogue context, rewrite the query, analyze it, and return a rewritten query string;

[0013] (2) Receive the rewritten query string, call the Large Language Model (LLM) to analyze the complexity of the rewritten query, decompose the query as needed, and return a list containing query questions, with each question as an item in the list;

[0014] (3) Extract the head entity and tail entity, receive the generated question list, identify and extract the head entity and tail entity for each question, perform entity identification, check entity integrity, summarize entity pairs, and return a nested list;

[0015] (4) Determine the entity classification. Based on the predefined knowledge graph classification values, classify and map the extracted head and tail entity lists, mark special entities, and return the nested list.

[0016] (5) Search: For the head and tail entity pairs generated in the previous step, perform keyword and / or embedding search on them to find entities that match or are similar to the entity;

[0017] (6) Classification and generation of Cypher queries: Based on the found matching head and tail entity pairs and classification information, the corresponding query statements are generated using LLM; query parameters are defined according to different entity classifications and these parameters are passed to LLM to generate suitable queries, and finally a list containing Cypher query statements generated for each entity pair is returned.

[0018] (7) Execute queries and integrate results: Connect to the knowledge graph through the GraphDatabase class of the neo4j library, execute the Cypher query statements generated in the previous step one by one, and integrate the query results of each query in Neo4j into a unified structure so as to generate the final answer later;

[0019] (8) The integrated query results and the user's original query are used as context and passed to LLM through Langchain's StrOutputParser module to generate the final query answer.

[0020] In a specific implementation

[0021] The rewrite query is implemented using the ChatOllama interface in the LangChain framework.

[0022] The on-demand decomposition further refers to breaking down a query into multiple simpler questions if it is a complex question, and directly returning the question if it is a simple question.

[0023] The aforementioned entity integrity check refers to the process of calling a web search tool to search for the problem if the head or tail entity of a simple problem cannot be identified, and then passing the search results as supplementary context to the LLM to regenerate the head and tail entities.

[0024] Preferably, the original query can be searched by calling the TavilySearchResults web search tool in the LangChain Community library, and the search results can be passed to the LLM as supplementary context.

[0025] The classification mapping refers to using a predefined knowledge graph classification, and using an LLM called by ChatOllama to classify each pair of head and tail entities. For example, classification can be based on dimensions such as microbial type, disease type, corresponding drug type, intermediate, drug structure, indication, target gene, target protein, biomarker, metabolite, etc., but is not limited to the above classifications.

[0026] The term "marking special entities" refers to the practice of using different methods to mark each head-and-tail entity pair if one of the entities is a category or a semantically expressed category, thereby distinguishing between category entities and specific entities.

[0027] The returned nested list includes a list of head and tail entity pairs and a category list for each entity pair with at least two nested lists.

[0028] The search preferably performs keyword search and / or embedding search on specific entities. In one specific implementation, the search step uses keyword matching to search in the knowledge graph. If the keyword match is successful, the entity is retained and the embedding search is skipped. If the match fails, the embedding search is performed. The embedding search uses a model to match similar entities. In one specific implementation, for category entities, keyword search and embedding search are preferably skipped, and only the original entity is retained. In one specific implementation, if the embedding search does not find a match, a web search tool can be launched as needed to search the original query and pass the results to the LLM.

[0029] The query parameters refer to setting a specific maximum number of hops and / or number of paths based on the classification of each pair of entities.

[0030] The query statement is preferably generated using LLM to generate the corresponding Neo4j Cypher query statement. Furthermore, the Cypher query is generated by calling LLM through a pre-written prompt.

[0031] The integration refers to combining all query results into a unified string or structured data. In a specific implementation, if the query results are complex, integration can be performed by entity pairs or by category blocks as needed. The integrated result can be in JSON, XML, TSV, or other formats.

[0032] The final query response can be text, a list, a paragraph, a link, etc.; furthermore, the response is formatted and output, and finally presented in natural language.

[0033] Beneficial effects

[0034] In the gut microbiome intelligent question-answering system, the richness of knowledge in the questions and answers has been significantly improved. By combining knowledge graphs and large language models (LLM), the system can not only provide direct knowledge points but also supplement them with context, background information, and multi-layered scientific explanations, making the answers richer and more comprehensive. Thanks to the use of Graph RAG technology, the system can cite structured knowledge related to the user's question when answering, and combine it with the text answers generated by the model to provide users with more detailed information support.

[0035] Internal testing shows that, across 100 typical questions, the system's generated answers demonstrate a more than 40% improvement in knowledge coverage and information density compared to traditional methods. This increased knowledge richness significantly enhances the user's knowledge acquisition experience, enabling the system to not only answer simple questions but also provide in-depth and detailed solutions to complex multidisciplinary issues. The system uses LLM to decompose complex problems and iteratively retrieves answers to each sub-question until a termination condition is met. This decompositional reasoning process reduces complexity, supports multi-hop queries, and allows the system to better handle complex problems with strong correlations and multiple levels, such as disease-microbiota, microbiota-metabolites, and metabolites-symptoms. To improve query timeliness, the system combines keyword retrieval and embedded search to quickly match relevant entities in the knowledge graph, avoiding retrieval delays caused by complex document structures. GraphRAG technology, combined with the structured information of the knowledge graph, makes the reasoning path and answer source clearly visible.

[0036] For example, the system can annotate the start and end entities and their corresponding relationships involved in each step of the query in the output, ensuring that each step is traceable. Users can intuitively trace the reasoning path, further enhancing the system's applicability in research environments. By introducing multiple entity classification methods, the system supports the structured management of multidimensional information in the field of gut microbiota.

[0037] For example, the system can label the "drug" category as "Drug*" and use Cypher queries to flexibly match various drug subsets based on this category label. This makes it more adaptable to complex queries, avoiding the need for manual configuration for each specific entity and thus improving query efficiency. If the knowledge base cannot fully answer a user's question, the system can supplement information through web searches (such as TavilySearchResults), passing web data as context to the LLM to provide the user with a comprehensive answer. This strategy ensures the system's coverage and effectively reduces question-answering blind spots caused by limited knowledge base data. Attached Figure Description

[0038] Figure 1 A technology roadmap for intelligent question answering in the field of gut microbiota based on Graph RAG technology Detailed Implementation

[0039] I. The specific computational steps of the intelligent question-answering system for the gut microbiota based on Graph RAG technology involved in this invention are as follows:

[0040] 1. Receive and analyze user queries.

[0041] It receives user input queries to obtain the user's conversation context and retrieves the user's recent conversation records from the database using the user_id.

[0042] (1) Processing flow

[0043] a) Retrieve conversation history: Query the database based on the user's user_id to retrieve the user's most recent conversation history, which will be used as background information to understand the user's current query;

[0044] b) Query Rewriting: Query rewriting will utilize the ChatOllama interface from the LangChain framework. LangChain is a Python framework for building language model-based applications that simplifies interaction with large language models (LLMs). LangChain provides a rich set of tools and interfaces. In LangChain, ChatOllama is an interface class used to interact with the Ollam family of large language models. This call to the large language model rewrites the user-input query to better understand the query intent and make it more explicit and specific. This process leverages the user's conversational context to more accurately generate subsequent query steps.

[0045] (2) Input format

[0046] a) Receive a user's query string, such as "I want to understand the relationship between disease X and drug Y", and obtain the user's dialogue context.

[0047] b) At the same time, user_id is used as a user identifier to retrieve the corresponding conversation records.

[0048] (3) Output format

[0049] Returns a rewritten query string, which will serve as input for subsequent steps. This step will be executed by the StrOutputParser within the LangChain framework. In the LangChain framework, StrOutputParser is a parser used to process the output of language models, helping to convert the text output generated by the model into a usable data format.

[0050] 2. Deconstructing the query

[0051] Receive the rewritten query from the first step and determine its complexity. If the query is a complex problem, break it down into multiple simpler problems; otherwise, return the complete query.

[0052] (1) Processing flow

[0053] a) Analyze query complexity: Use the ChatOllama interface in the LangChain framework to call a Large Language Model (LLM) to analyze the rewritten query and determine its complexity. This can be based on factors such as the query structure and the number of entities involved.

[0054] b) Break down complex queries: If a query is determined to be a complex problem, break it down into several smaller, simpler problems for processing step by step;

[0055] c) Keep simple queries as they are: If a query is determined to be a simple problem, it does not need to be broken down further and is directly output as the problem.

[0056] (2) Input format

[0057] It receives a rewritten query string, such as "I want to know the relationship between disease X and drug Y".

[0058] (3) Output format

[0059] Returns a list containing one or more query questions, each question as an item in the list. For example, for a complex query, the output might be [simple question 1, simple question 2, ...]; for a simple query, the output might be [simple question]. The output format is constrained by the `BaseModel` class and the `Field` helper function from the `pydantic` library. `pydantic` is a Python library specifically designed for data validation and data model definition, helping developers easily define and validate structured data formats in Python. `BaseModel` is a core class, typically used as the base class for data models. By inheriting from `BaseModel`, developers can define data models with type constraints, and `pydantic` automatically validates the type and format of the input data to ensure they conform to the definition. `Field` is a helper function provided by `pydantic` to further refine the constraints of fields. Through `Field`, developers can specify default values, descriptions, maximum or minimum lengths, numeric ranges, and other constraints for fields.

[0060] 3. Extract the head and tail entities

[0061] Receive the list of simple questions generated in step two, identify and extract the head and tail entities for each question. For questions where the head and tail entities cannot be identified, use a web search tool to supplement the information, obtain the relevant context, and pass it to the LLM.

[0062] (1) Processing flow

[0063] a) Entity recognition: For each simple problem, use the ChatOllama interface to call LLM to identify the head entity (the main starting point) and tail entity (the main target).

[0064] b) Check entity integrity: If the head or tail entity of a simple problem cannot be identified, call the web search tool to search for the problem and pass the search results as supplementary context to LLM to regenerate the head and tail entities;

[0065] c) Summarize entity pairs: Output the head and tail entities of each simple problem as pairs.

[0066] (2) Input format

[0067] The input is a list of simple questions output from the second step, such as [simple question 1, simple question 2, ...].

[0068] (3) Output format

[0069] Returns a nested list containing the head and tail entities for each simple problem. For example, [[head entity 1, tail entity 1], [head entity 2, tail entity 2], …]. The output format here will be constrained by the BaseModel class and Field helper functions of the pydantic library.

[0070] 4. Determine entity classification

[0071] Based on the head and tail entities extracted in step three, determine the classification of each pair of entities. Classification must be based on predefined knowledge graph classification values ​​(e.g., Disease, Drug, Human Gene, Human Protein). Classification values ​​will be stored in a YAML file. If an entity is itself a category (e.g., Drug) or semantically represents a category (e.g., drug category), then the entity's classification will be marked as Drug*, indicating that it is a category label, not a specific entity.

[0072] (1) Processing flow

[0073] a) Classification Mapping: Uses predefined knowledge graph classification, and uses the LLM called by ChatOllama to classify each pair of head and tail entities. Specific classification values ​​include Disease, Drug, Human Gene and Human Protein.

[0074] b) Labeling Special Entities: For each head-tail entity pair, if one of the entities is itself a category (e.g., Drug) or semantically represents a category (e.g., drug category), it is labeled Drug*. For example, if the tail entity is of the category "drug", its classification should be Drug*. Specifically, an entity such as "aspirin" should be labeled Drug to represent the specific entity.

[0075] c) Output classification results: Summarize each pair of head and tail entities and their corresponding classification information to form two lists: one is a list of head and tail entity pairs, and the other is a list of corresponding classifications.

[0076] (2) Input format

[0077] The input is a list of head and tail entity pairs output from step 3, for example, [[head entity 1, tail entity 1], [head entity 2, tail entity 2], … ].

[0078] (3) Output format

[0079] a) Returns two nested lists: one is a list of head and tail entity pairs, such as [[head entity1, tail entity1], [head entity2, tail entity2], … ].

[0080] b) Another is a list of categories for each pair of entities, such as [[Disease, Drug], [Human Gene, HumanProtein], …], or [[Disease, Drug*], [Human Gene, HumanProtein], …] if categorical entities are included. This output format will be constrained by the BaseModel class and Field helper functions of the pydantic library.

[0081] 5 Search

[0082] For the head and tail entity pairs generated in step four, perform keyword and embedding searches on the entities not marked with an asterisk (*) to find matching entities. If no match is found through keyword search, embedding search is used to find similar items in the knowledge graph. For entities marked with an asterisk (*), skip the keyword and embedding search for that entity, but continue searching for other entities in the entity pair.

[0083] (1) Processing flow

[0084] a) Skip entities marked with *: For any entity in each pair of head and tail entities, if that entity is marked with * (indicating it is a category entity, tagged with a category label), skip the keyword and embedding search for that entity, and only retain the original entity. In this case, only the other unmarked entity is matched;

[0085] b) Keyword Search: For entities without an asterisk (*), first attempt to find the corresponding entity in the knowledge graph using keyword matching. If the keyword match is successful, retain the entity and skip the embedding search; if no keyword match is found, proceed to the next step.

[0086] c) Embedding Search: When no results are found for keyword matching, use the OpenAIEmbeddings class, or call the embedding model through ChatOllama to generate embeddings for entities and search for the entity with the most similar embedding in the knowledge graph;

[0087] d) Embedded search will return the top y matching entities with a similarity to the target entity that is higher than a set threshold x, where the specific values ​​of x and y need to be defined according to the actual application;

[0088] e) Invoking a web search tool (if needed): If no match is found either in the embedded search, the original query is searched using the TavilySearchResults web search tool from the LangChain Community library. The search results are then passed to the LLM as supplementary context to help it identify and understand entities. The primary role of the TavilySearchResults class or interface is to process the results obtained from the Tavily search engine. Typically, LangChain can use Tavily for real-time searches when the language model needs to reference external data sources (e.g., to find specific information or documents). TavilySearchResults standardizes and formats the raw data returned by Tavily for easier model processing or application use.

[0089] (2) Input format

[0090] The input consists of two lists output from step four: a list of head and tail entity pairs (e.g., [[head entity 1, tail entity 1], [head entity 2, tail entity 2], …]) and a list of categories (e.g., [[Disease, Drug], [Human Gene, Human Protein], …] or [[Disease, Drug*], [Human Gene, Human Protein], …]).

[0091] (3) Output format

[0092] a) Returns a nested list containing the found matching entity pairs (potentially multiple matches). For example, if multiple matching entities are found, the output might be: [[head entity 1.a, tail entity 1.a], [head entity 1.b, tail entity 1.b], [head entity 2.a, tail entity 2.a], … ];

[0093] b) Returns a corresponding list of categories, such as [ [Disease, Drug], [Disease, Drug], [Human Gene, Human Protein], …]. The output format will be constrained by the BaseModel class and Field helper functions of the pydantic library.

[0094] 6. Classification and Cypher Query Generation

[0095] Based on the matching head and tail entity pairs and classification information found in step 5, the corresponding Neo4jCypher query statement is generated using LLM. Limits on the maximum number of hops and paths are defined according to different entity classifications, and these parameters are passed to LLM to generate suitable queries.

[0096] (1) Processing flow

[0097] a) Define query parameters: Set specific maximum hop count and path count for each entity pair based on its classification. For example: for entity pairs classified as [Human Gene, Human Protein], set the maximum hop count to 5 and the maximum path count to 20; for entity pairs classified as [Disease, Drug], set the maximum hop count to 3 and the maximum path count to 15; for entity pairs classified as [Disease, Drug*], set the maximum hop count to 2 and the maximum path count to 100.

[0098] b) Generate Cypher queries: Using these parameters and the classification information of the entity pairs, generate Cypher queries by calling the LLM through a pre-written prompt;

[0099] c) Handling Category-Labeled Entities: If one of the head or tail entity pairs is a category label (i.e., marked with *), then that category label is used as the matching condition when generating the Cypher query. For example, if the tail entity is a category label Drug*, then the Cypher query will target the specific head entity, while the tail entity can be any value within that category.

[0100] (2) Input format

[0101] The input consists of two lists output from step 5: a list of matching entity pairs (e.g., [[head entity 1.a, tail entity 1.a], [head entity 1.b, tail entity 1.b], [head entity 1.b, tail entity 1.b], … ]) and a list of categories (e.g., [[Disease, Drug], [Disease, Drug], [Human Gene, Human Protein], … ]).

[0102] (3) Output format

[0103] Returns a list containing the Cypher queries generated for each entity pair. For example, [cypher1, cypher2, cypher3, … ], where each query corresponds to an entity pair and its category. The output format will be constrained by the BaseModel class and Field helper functions from the pydantic library.

[0104] 7. Execute the query and integrate the results.

[0105] By connecting to the knowledge graph through the GraphDatabase class in the neo4j library, the Cypher query statements generated in step six are executed one by one, and the query results of each query in Neo4j are integrated into a unified structure so that the final answer can be generated later.

[0106] (1) Processing flow

[0107] a) Execute Cypher queries: For each Cypher query statement generated in step six, execute them one by one in the Neo4j database and retrieve the query results. The information returned by each query will be temporarily stored for later processing;

[0108] b) Integrate query results: Combine all query results into a unified string or structured data (such as JSON format). If the query results are complex, you can choose to integrate them by entity pairs or categories to facilitate reading and understanding;

[0109] c) Error handling: If a query fails during the query process (such as timeout or no results), the error message is logged and other queries are processed to ensure that the final result is as complete as possible.

[0110] (2) Input format

[0111] The input is the Cypher query list generated in step six, for example, [cypher1, cypher2, cypher3, … ].

[0112] (3) Output format

[0113] The Langchain PromptTemplate module and the pydantic library define and return an integrated string or structured data containing all the queried information. For example: {"results": [ { "query": "cypher1", "data": "result 1"}, { "query": "cypher2", "data": "result 2"}, ... ]}.

[0114] 8. Generate the final result

[0115] The query results integrated in step seven, along with the user's original query, are passed to the LLM using Langchain's StrOutputParser module to generate the final query answer. The LLM then generates a natural language answer or explanation based on the query results and the user's original intent.

[0116] In the LangChain framework, StrOutputParser is a parser used to process the output of language models, helping to convert the text output generated by the model into a usable data format.

[0117] (1) Processing flow

[0118] a) Passing contextual information: The integrated query results and the user's original query are passed as input to the LLM. The LLM will then generate the final answer based on the query results and contextual information.

[0119] b) Generating Answers: Based on the context and the user's query, LLM generates clear and coherent answers. These answers can be simple conclusions and detailed explanations, or summaries of information from multiple parts.

[0120] c) Formatted Output: Depending on specific needs, the answers generated by LLM can be output in various formats such as text, lists, and paragraphs. Formatted output is used to ensure ease of understanding and use, if necessary.

[0121] (2) Input format

[0122] The input consists of the integrated query results in JSON format from step seven, and the user's original query.

[0123] (3) Output format

[0124] Returns a final natural language answer, explaining the query results and fulfilling the user's original needs. For example: "Based on your query, the relationship between disease X and drug Y is as follows: ...".

[0125] II. Comparison of Dialogue Examples

[0126] The following example problem demonstrates the comprehensiveness of the answers provided by the Graph RAG intelligent question answering system of the present invention to user questions, and compares them with the answers provided by ordinary question answering systems that do not include the Graph RAG computing language of the present invention.

[0127] The following only shows Chinese and English Q&A, but is not limited to English. Any language that a computer can process is within the protection scope and can present the same Q&A effect.

[0128] (1) "Which small molecules does the HSD17B4 gene regulate?"

[0129] Answer (based on Graph RAG):

[0130] The HSD17B4 gene regulates several small molecules, including sodium valproate, ribose-5-triphosphate compounds, a certain benzamide variant, and glucocorticoids (a drug metabolite of prednisone).

[0131] Upon examining the provided background, it became clear that the HSD17B4 gene interacts with a variety of small molecules. These include sodium valproate, a compound used to treat epilepsy and bipolar disorder. It also interacts with ribose-5-triphosphate, a molecule that plays a crucial role in a variety of biological processes, including RNA synthesis and energy metabolism. Furthermore, it interacts with a type of benzamide, an organic compound that typically acts as a building block in organic synthesis. Finally, it interacts with glucocorticoids, steroid hormones that reduce inflammation and suppress the immune system. This particular glucocorticoid is a metabolite of prednisone, a drug commonly used to treat inflammation such as arthritis and severe allergies.

[0132] Answer (not based on Graph RAG):

[0133] The HSD17B4 gene regulates small molecules called steroids, particularly the metabolism of sex hormones such as testosterone and estradiol.

[0134] (2) 'HSD17B4 gene regulates which small molecules?'

[0135] ANS_WITH_Graph RAG:

[0136] The HSD17B4 gene regulates several small molecules, including thesodium salt of valproic acid, a ribose 5-triphosphate compound, a certainbenzamide variant, and a glucocorticoid which is a drug metabolite ofprednisone.

[0137] Upon examining the provided context, it is evident that the HSD17B4gene interacts with a variety of small molecules. These include the sodiumsalt of valproic acid, a compound involved in the treatment of epilepsy andbipolar disorder. It also interacts with a ribose 5-triphosphate compound, amolecule that plays a significant role in several biological processes,including RNA synthesis and energy metabolism. Additionally, it interactswith a certain type of benzamide, which is an organic compound that oftenserves as a building block in organic synthesis. Lastly, it interacts with aglucocorticoid, a type of steroid hormone that can reduce inflammation andsuppress the immune system. This particular glucocorticoid is a drugmetabolite of prednisone, a medication commonly used to treat inflammatoryconditions like arthritis and severe allergies.

[0138] ANS_WITHOUT_Graph RAG:

[0139] The HSD17B4 gene regulates small molecules known as steroids, specifically regulating the metabolism of sex hormones such as testosterone and estradiol.

[0140] (3) "What diseases are associated with the ACE2 gene?"

[0141] Answer (based on Graph RAG):

[0142] The ACE2 gene is associated with a variety of diseases, including liver cancer, hepatocellular carcinoma, myocardial cancer, infarction, leiomyomas, early pregnancy problems, and squamous cell carcinoma.

[0143] Referring to the provided background: The ACE2 gene shows interactions with other genes, such as SLC7A8 and SLC43A2, and has been identified as a biomarker for diseases including hepatocellular carcinoma, myocardial infarction, leiomyomas, early pregnancy-related problems, and squamous cell carcinoma. Other related genes such as ECE2, ACOT2, and ACE are also associated with a variety of diseases, including cervical malignancies, cervical cancer, colorectal cancer, type 2 diabetes, pneumonia, parenchymal lung inflammation, granulomatous polyangiitis, focal segmental glomerulosclerosis, color blindness, DEUTAN series and arthritis, and adolescents. Meanwhile, the CES2 gene shows interactions with PTGDR and is associated with diseases such as rhinitis, allergies, and central neuroblastoma.

[0144] Answer (not based on Graph RAG):

[0145] The ACE2 gene is associated with a variety of diseases. Most notably, it plays a crucial role in Covid-19 because the virus uses ACE2 as a receptor to enter cells. Furthermore, variations in the ACE2 gene are linked to cardiovascular diseases, particularly hypertension, and diabetes.

[0146] (4) 'what are the disease associated with gene ACE2?'

[0147] ANS_WITH_Graph RAG:

[0148] The ACE2 gene has been associated with a variety of diseases,including Carcinoma, Hepatocellular, Myocardial Infarction, Leiomyoma, earlypregnancy issues, and Carcinoma, Squamous Cell.

[0149] Upon referring to the provided context: The gene ACE2 showsinteraction with other genes such as SLC7A8 and SLC43A2 and has beenidentified as a biomarker in diseases including Hepatocellular Carcinoma,Myocardial Infarction, Leiomyoma, issues related to early pregnancy, andSquamous Cell Carcinoma. Other connected genes such as ECE2, ACOT2, and ACEare also associated with various diseases, including Malignant tumor ofcervix, Cervix carcinoma, Colorectal Cancer, Diabetes Mellitus, Type 2,Pneumonitis, Pneumonia, Granulomatosis With Polyangiitis, Focal SegmentalGlomerulosclerosis, COLORBLINDNESS, DEUTAN SERIES, and Arthritis, Juvenile.Meanwhile, gene CES2 shows interaction with PTGDR and is associated withdiseases like Rhinitis, Allergic, and Central neuroblastoma, among others.

[0150] ANS_WITHOUT_Graph RAG:

[0151] The ACE2 gene has been associated with several diseases. Mostnotably, it is significant in Covid-19 as the virus uses ACE2 as a receptor to enter cells. Additionally, variations in the ACE2 gene have been implicated in cardiovascular disease, particularly hypertension, as well as diabetes.

[0152] (5) "Which genes are associated with high blood pressure?"

[0153] Answer (based on Graph RAG):

[0154] Several genes are associated with hypertension, including EDN2 (endothelin 2), RELA (RELA proto-oncogene, NF-κB subunit), PITX2 (paired homeo domain 2), MAZ (MYC-associated zinc finger protein), HSF1 (heat shock transcription factor 1), COMT (catechol-O-methyltransferase), SNCA (synuclein α), SNAP29 (synaptosome-associated protein 29), SNAP25 (synaptosome-associated protein 25), SNAP23 (synaptosome-associated protein 23), and WNK4 (WNK... Lysine-deficient protein kinase 4), COA3 (cytochrome c oxidase assembly factor 3), SLC12A3 (solute carrier family 12 member 3), SGK1 (serum / glucocorticoid-regulated kinase 1), RUNX1 (dwarf-associated transcription factor 1), ALOX12 (arachidonic acid 12-lipoxygenase, 12S type), SLC27A5 (solute carrier family 27 member 5), PRMT1 (protein arginine methyltransferase 1), PLB1 (phospholipase B1), and PLA2G4B (phospholipase A2 group IVB).

[0155] Answer (not based on Graph RAG):

[0156] Various genes are believed to be associated with hypertension, including genes for AGT (angiotensinogen), ACE (angiotensin-converting enzyme), NOS3 (nitric oxide synthase 3), and various sodium channels. The exact roles and effects of these genes on hypertension may vary and are often involved in complex interactions with environmental factors.

[0157] (6) 'Which genes are involved in hypertension?'

[0158] ANS_WITH_Graph RAG:

[0159] Several genes have been associated with hypertension, including EDN2(endothelin 2), RELA (RELA proto-oncogene, NF-kB subunit), PITX2 (paired likehomeodomain 2), MAZ (MYC associated zinc finger protein), HSF1 (heat shocktranscription factor 1), COMT (catechol-O-methyltransferase), SNCA (synucleinalpha), SNAP29 (synaptosome associated protein 29), SNAP25 (synaptosomeassociated protein 25), SNAP23 (synaptosome associated protein 23), WNK4 (WNKlysine deficient protein kinase 4), COA3 (cytochrome c oxidase assemblyfactor 3), SLC12A3 (solute carrier family 12 member 3), SGK1 (serum / glucocorticoid regulated kinase 1), RUNX1 (runt related transcription factor1), ALOX12 (arachidonate 12-lipoxygenase, 12S type), SLC27A5 (solute carrierfamily 27 member 5), PRMT1 (protein arginine methyltransferase 1), PLB1(phospholipase B1), and PLA2G4B (phospholipase A2 group IVB).

[0160] ANS_WITHOUT_Graph RAG:

[0161] Various genes are thought to be involved in hypertension including AGT (angiotensinogen), ACE (angiotensin-converting enzyme), NOS3 (nitricoxide synthase 3), and genes for various sodium channels. The exact role and impact of these genes on hypertension can vary and often involves complexinteraction with environmental factors.

[0162] We compare the level of knowledge provided in the above answers based on the following three aspects:

[0163] (1) The types and number of entities as a measure of richness: Especially in the fields of bioinformatics and medicine, the diversity of entities (such as genes, drugs, diseases, small molecules, etc.) can often indicate the depth and breadth of the answer;

[0164] (2) Number and diversity of relationships: The more relationships between entities (e.g., gene-disease, gene-drug relationship), the richer the answer is in describing biological networks or interactions. Different types of relationships (e.g., "regulation", "metabolic action") also increase the richness of the answer. A deep learning-based model (RoBERTa) will be used for evaluation, which performs well on NER tasks and is particularly suitable for recognizing specialized terms in customized domains (e.g., biology, medicine). Named Entity Recognition (NER) is a natural language processing technique used to identify specific entities (e.g., names of people, places, times, organizations, genes, diseases, etc.) from text.

[0165] (3) Depth of Knowledge Levels: Analyze the depth of information levels in the answers. For example, basic information level (such as "gene A regulates molecule B") and extended information level (such as "the specific function or therapeutic use of molecule B"). Depth Scoring: Some answers will explain the function, metabolic process or pharmacological effect of an entity in depth. If an answer delves into more detailed biological processes, mechanisms of action or molecular functions, it indicates that it can provide a deeper level of knowledge.

Claims

1. An intelligent question and answer system for intestinal microorganisms based on a knowledge graph and a large model, comprising the following steps, (1) After accepting the user's query, the user's recent dialogue record is recalled and rewritten through the dialogue context, and the rewritten query string is returned by the StrOutputParser in the LangChain framework; (2) receiving the rewritten query string, based on the structure of the query and the number of entities involved, using the ChatOllama interface in the LangChain framework to call a large language model (LLM) to analyze the complexity of the rewritten query, and if the query is a complex problem, it is disassembled into multiple simple problems; If it is a simple question, the question is directly returned; Finally, a list containing one or more query questions is returned, and each question is an item in the list; (3) Extract the head entity and tail entity, receive the generated question list, identify the head entity and tail entity of each question using the ChatOllama interface to call the LLM, if the head entity or tail entity of a simple question cannot be identified, call the network search tool to search the question, and pass the search result as supplementary context to the LLM to re-generate the head and tail entity; (4) Determine the entity classification, based on the pre-defined knowledge graph classification item, use the LLM called by ChatOllama to classify and map each pair of head and tail entity; If one of the entities is a category or semantically expressed in a certain category, use the corresponding different method for marking, so as to distinguish the category entity and the specific entity; Summarize each pair of head and tail entity and its corresponding classification information, return two nested lists, one is the list of head and tail entity pairs, and the other is the classification list of each entity pair; (5) Search: For specific entities, perform keyword search and / or embedding search, use keyword matching to search in the knowledge graph, if the keyword matching is successful, keep the entity and skip the embedding search, if the matching fails, perform embedding search, which uses the model to match similar entities; For category entities, skip keyword search and embedding search, and continue to search for other entities of the entity pair; (6) Define query parameters: define the maximum hop and path number according to different entity classification: Generate Cypher query: use these parameters and the classification information of the entity pair to generate a Cypher query by calling the LLM through a pre-written prompt; Process category label entity: if one of the head and tail entity pairs is a category label marked with *, the category label is used as a matching condition when generating the Cypher query; If the tail entity is a category label Drug*, the Cypher query will be for a specific head entity, and the tail entity can be any value in the category; (7) Execute the query and integrate the results: connect to the knowledge graph through the GraphDatabase class of the neo4j library, execute the Cypher query generated in the last step one by one, and integrate the query results in Neo4j into a unified string or structured data; (8) Pass the integrated query results and the user's original query as context to the LLM through the StrOutputParser module of Langchain to generate the final output answer.

2. The knowledge graph and large model-based intelligent question answering system for intestinal microorganisms according to claim 1, wherein the rewritten query in step (1) is implemented using the ChatOllama interface in the LangChain framework to interact with large language models in the Ollama series.

3. The knowledge graph and large model-based intelligent question answering system for intestinal microorganisms according to claim 1, wherein the output format in step (2) is constrained by the BaseModel class and the Field auxiliary function of the pydantic library, and through the Field, the developer can specify more constraint conditions for the field, such as default value, description, maximum or minimum length, numerical range.

4. The knowledge graph and large model-based intelligent question answering system for intestinal microorganisms according to claim 1, wherein step (3) further comprises outputting the head entity and tail entity of each simple question in pairs, returning a nested list containing the head entity and tail entity of each simple question, and the output format is constrained by the BaseModel class and the Field auxiliary function of the pydantic library.

5. The knowledge graph and large model-based intelligent question answering system for intestinal microorganisms according to claim 1, wherein step (4) comprises classifying each pair of head and tail entities according to classification items including Disease, Drug, Human Gene, and Human Protein, and the classification items are stored in a yaml file; and the final output format is constrained by the BaseModel class and the Field auxiliary function of the pydantic library.

6. The knowledge graph and large model-based intelligent question answering system for intestinal microorganisms according to claim 1, wherein if the embedded search does not find a matching item in step (5), the network search tool TavilySearchResults of the LangChain Community library is called to search the original query, the original data returned by Tavily is standardized and formatted, and the search results are passed to the LLM as supplementary context to assist it in identifying and understanding entities; the embedded search refers to using the OpenAIEmbeddings class or calling the embedding model through ChatOllama to generate embeddings for entities, finding the most similar entities in the knowledge graph, and the embedded search will return the top y matching entities with a similarity higher than the set threshold x to the target entity. ​ 7. The knowledge graph and large model-based intelligent question answering system for intestinal microorganisms according to claim 1, in step (6), when defining the maximum number of hops and the maximum number of paths: for entity pairs classified as [Human Gene, Human Protein], set the maximum number of hops to 5 and the maximum number of paths to 20; for entity pairs classified as [Disease, Drug], set the maximum number of hops to 3 and the maximum number of paths to 15; for entity pairs classified as [Disease, Drug*], set the maximum number of hops to 2 and the maximum number of paths to 100; further, for the two input and output lists, return a list containing the Cypher query statements generated by each entity pair, and the output format will be constrained by the BaseModel class and the Field auxiliary function of the pydantic library.

8. The knowledge graph and large model-based intelligent question answering system for intestinal microorganisms according to claim 1, in step (7), if the query result is relatively complex, choose to integrate by entity pair or classification block, and if a query fails during the query process, record the error information and continue processing other queries, and through the PromptTemplate module of Langchain and the pydantic library, define and return an integrated string or structured data containing all the information queried.

Citation Information

Patent Citations

  • Intestinal microorganism knowledge graph system

    CN118506887A

  • Knowledge graph construction method and device and readable storage medium

    CN116955634A

  • Bridge management and cultivation question-answering method based on cooperation of large model and knowledge graph

    CN118410145A