Knowledge graph construction system and method based on cue words

Through a knowledge graph construction system based on prompt words, a knowledge graph is automatically constructed using a large language model and a vector database, which solves the problems of high data labeling costs and redundancy of graphs, and achieves efficient and accurate knowledge graph construction and information acquisition.

CN119443253AInactive Publication Date: 2025-02-14XIAN XINCHUANG ELECTRONIC TECH CO LTD

Patent Information

Application Number
CN202510038116.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-10
Publication Date
2025-02-14
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The prior art requires a lot of manpower and material resources to mark data when building a knowledge graph, and traditional methods make the content of the graph huge and redundant, increasing the difficulty of users to screen and extract effective information during use.

Method used

Provide a knowledge graph construction system based on prompt words, using the context understanding ability and problem analysis ability of the large language model, and automatically identify key information in the text through vector databases and intelligent reasoning and execution modules, without additional labeling data or further Training to achieve efficient knowledge graph construction.

Benefits of technology

Reliance on labeled data is reduced, labor costs are reduced, efficient and accurate knowledge graph construction is achieved, information redundancy is avoided, and users are improved in the efficiency of obtaining target information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119443253A_ABST
    Figure CN119443253A_ABST
Patent Text Reader

Abstract

The invention provides a knowledge graph construction system and method based on cue words, and the method comprises the steps: determining a mapping relation corresponding to an obtained unstructured document set through a data collection module, and transmitting the mapping relation to a vector data storage module; sending the obtained rule extraction file to an automatic cue word generation module to obtain a target template, and distributing the target template to a problem auditing module and a cue word judgment module; the vector data storage module obtains vectorized data based on the mapping relation and stores the vectorized data to a vector database; the problem auditing module audits a drawing instruction input by a user according to the template, and if the auditing is passed, the drawing instruction is sent to the cue word judgment module, so that the cue word judgment module inputs the corresponding template and the drawing instruction into the intelligent reasoning and executing module, the drawing instruction is embedded into the template and then is transmitted into a preset large language model, the drawing instruction is disassembled, and the drawing instruction is sent to the intelligent reasoning and executing module. And according to a disassembling result, querying a vector database and calling related tools, so that efficient and accurate knowledge graph construction is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a system and method for constructing a knowledge graph based on prompt words. Background Art

[0002] With the rapid development of the Internet, information is growing explosively. News reports, social media posts, blog articles, etc. appear in large numbers in our lives. These contents contain a lot of valuable information, but because the format of these information is mostly irregular, complex and unstructured, traditional database query methods cannot be directly applied. Knowledge graphs and information extraction technologies have emerged.

[0003] Traditional relational databases mainly store and organize data based on table structures, which are very suitable for processing structured data. However, unstructured data usually does not have a fixed structure or pattern, and the flexibility of traditional relational database data structures is insufficient. The knowledge graph is a graph structure composed of nodes (representing entities) and edges (representing the relationships between entities). It can graphically display concepts in knowledge and describe the relationship between things in the real world. Simply put, it is like a large, structured knowledge base that contains various entities and the relationships between them. This structured representation can clearly show the relationships and hierarchical structures between entities, allowing machines to better understand and reason about complex information in the real world.

[0004] At present, the application of knowledge graphs in the service field shows significant potential and value. As a structured knowledge representation method, knowledge graphs can associate multiple entities, attributes and relationships and present them in a graphical manner. However, when building knowledge graphs in specific fields, it is usually necessary to invest a lot of manpower and material resources in data annotation to train models, which makes it difficult for small and medium-sized enterprises or teams to quickly build the required knowledge graphs. In addition, traditional knowledge graph construction methods often integrate various information together, which may make the graph content large and redundant, thereby increasing the difficulty for users to filter and extract effective information during use. Summary of the invention

[0005] In order to solve the above problems existing in the prior art, the present invention provides a knowledge graph construction system and method based on prompt words, which specifically include: In a first aspect, the present invention provides a knowledge graph construction system based on prompt words, comprising: The data collection module is used to obtain the unstructured document collection and the rule extraction file; determine the mapping relationship between the document content and the metadata attribute value corresponding to each document in the unstructured document collection according to the preset metadata; send the mapping relationship between the document content and the metadata attribute value corresponding to each document to the vector data storage module; send the rule extraction file to the prompt word automatic generation module; The vector data storage module is used to clean and cut the document content of each document based on the mapping relationship between the document content and the metadata attribute value corresponding to each received document to obtain multiple text blocks; determine the vectorized data corresponding to each text block; and construct a vector database according to the mapping relationship between the document content and the metadata attribute value corresponding to each document, each text block and the corresponding vectorized data; The prompt word automatic generation module is used to extract the rule data in the rule extraction file; embed the rule data into the preset initial prompt word review template and the initial prompt word reasoning template to obtain the target prompt word review template and the target prompt word reasoning template; send the target prompt word review template to the question review module; send the target prompt word reasoning template to the prompt word judgment module; the rule data includes domain information and relationship type; The problem review module is used to receive and store the drawing instructions input by the user with the user identity identifier; review the drawing instructions according to the target prompt word review template, and if the review fails, a reminder message is issued to remind the user to input a compliant drawing instruction; if the review passes, the target data is sent to the prompt word judgment module according to the drawing instruction; The prompt word judgment module is used to write the received target prompt word reasoning template into the prompt word unit of the intelligent reasoning and execution module, and after receiving the target data, input the target data into the intelligent reasoning and execution module; The intelligent reasoning and execution module is used to embed the target data into the target prompt word template in the prompt word unit and then pass it into the large language model with intelligent agent function; disassemble the entity elements from the target data through the large language model; search for the knowledge graph related to each entity element in the graph database according to the user identity carried by the drawing instruction and the disassembled entity elements. If found, the found knowledge graph is returned to the user; if not found, the vector database is queried according to each entity element to obtain the candidate text block related to the target data, and the entity relationship of the candidate text block is extracted through the large language model, and a set of entity relationship triples is constructed according to the extraction results. According to the set of entity relationship triples, a target knowledge graph is constructed, and the target knowledge graph is named with the user identity and stored in the graph database, and the target knowledge graph is returned to the user.

[0006] In a second aspect, the present invention also provides a method for constructing a knowledge graph based on prompt words, comprising: Obtain unstructured document collections and rule extraction files; Determine the mapping relationship between the document content and the metadata attribute value corresponding to each document in the unstructured document collection according to the preset metadata; Based on the mapping relationship between the document content and the metadata attribute value corresponding to each document, the document content of each document is cleaned and cut into pieces to obtain multiple text blocks, and the vectorized data corresponding to each text block is determined. According to the mapping relationship between the document content and the metadata attribute value corresponding to each document, each text block and the corresponding vectorized data, a vector database is constructed; Extract rule data from the rule extraction file, the rule data includes domain information and relationship type; Embed the rule data into a preset initial prompt word review template and an initial prompt word reasoning template to obtain a target prompt word review template and a target prompt word reasoning template; In response to a drawing instruction input by a user carrying a user identity identifier, the drawing instruction is reviewed according to a target prompt word review template. If the review fails, a reminder message is issued to remind the user to input a compliant drawing instruction. If the review passes, target data is determined according to the drawing instruction. Based on the preset large language model with intelligent agent function, the template is inferred according to the target data and the target prompt words to disassemble the entity elements from the target data; According to the user identity carried by the drawing instruction and the disassembled entity elements, the knowledge graph related to each entity element is searched in the graph database. If found, the found knowledge graph is returned to the user. If not found, the vector database is queried according to each entity element to obtain candidate text blocks related to the target data. The candidate text blocks are extracted from entity relationships through a large language model, and a set of entity relationship triples is constructed based on the extraction results. Based on the set of entity relationship triples, a target knowledge graph is constructed, and the target knowledge graph is named with the user identity and stored in the graph database, and the target knowledge graph is returned to the user.

[0007] Beneficial effects of the present invention: The knowledge graph construction system and method based on prompt words provided by the present invention, with the help of the generalization ability of the large language model, alleviate the influence of subjective factors to a certain extent, and also greatly reduce labor costs. "Prompt words" are the only input instructions received by the large language model, guiding the model to understand the user's intentions and make relevant responses. At the same time, by introducing vector databases and execution tools, not only the generation of model hallucinations is reduced, but also the model can keep knowledge updated without training. The conversation mode is used to dynamically construct and enrich the knowledge graph. With the problem understanding and behavior planning capabilities of the large language model, the content related to the user's drawing instructions can be accurately located and extracted, realizing efficient and accurate knowledge graph construction.

[0008] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] Figure 1 A schematic diagram of the architecture of a knowledge graph construction system based on prompt words provided by the present invention; Figure 2 A schematic diagram of the internal working mechanism of a prompt word automatic generation module provided by the present invention; Figure 3 A schematic diagram of the flow of a method for constructing a knowledge graph based on prompt words provided by the present invention. DETAILED DESCRIPTION

[0010] The present invention is further described in detail below with reference to specific embodiments, but the embodiments of the present invention are not limited thereto.

[0011] In order to cope with the problems existing in the prior art, the present invention provides a method and system for constructing a knowledge graph based on prompt words. The present invention cleverly utilizes the two core advantages of the large language model (LLM): context understanding ability and problem analysis ability. These advantages are due to the model's learning of language rules and accumulation of world knowledge in the pre-training stage. By combining the preset template and the call of external tools, the present invention can guide the large language model to disassemble the key entity elements, accurately focus on the core content of the task, and realize the structured processing of relevant information through entity relationship extraction. In particular, it can automatically identify the key information in the text, and can directly and efficiently extract the required knowledge from the text without additional annotation data or retraining. This innovation significantly reduces the dependence on annotation data and greatly reduces the labor cost in the knowledge extraction task. At the same time, the present invention also introduces a dialogue interaction method to quickly locate the topic of user concern according to the user's questions and input prompt information, thereby guiding the graph construction to revolve around these core information, and dynamically adjust according to the user's needs to ensure that the content of the constructed knowledge graph is more refined and focused, thereby avoiding the interference of irrelevant information. Through this dialogue-driven construction method, the knowledge graph is no longer a huge static data set, but a knowledge network that can be dynamically adjusted and continuously refined according to user needs. This construction method effectively reduces information redundancy, allowing users to obtain the target information they are concerned about more efficiently and intuitively, and enhancing the practical application value of the knowledge graph.

[0012] Figure 1 A schematic diagram of the architecture of a knowledge graph construction system based on prompt words provided by the present invention, such as Figure 1As shown, the system includes a data collection module 11, a vector data storage module 12, a prompt word automatic generation module 13, a question review module 14, a prompt word judgment module 15 and an intelligent reasoning and execution module 16. The intelligent reasoning and execution module 16 has a built-in large language model with intelligent agent functions, a graph database and a prompt word unit. The vector data storage module 12 has a built-in vector database. The above modules can be set on the same electronic device or on multiple electronic devices, and there is no specific limitation on this.

[0013] like Figure 1 As shown, the data collection module 11 is used to obtain an unstructured document collection and a rule extraction file; determine the mapping relationship between the document content corresponding to each document in the unstructured document collection and the metadata attribute value based on the preset metadata; send the mapping relationship between the document content corresponding to each document and the metadata attribute value to the vector data storage module 12, and send the rule extraction file to the prompt word automatic generation module 13.

[0014] Optionally, the data collection module 11 is specifically used to parse the corresponding documents according to the format of each document in the unstructured document collection to obtain the document content of each document; determine the metadata attribute value corresponding to each document according to the preset metadata and the document content of each document, and obtain the mapping relationship between the document content corresponding to each document and the metadata attribute value.

[0015] In a possible implementation, the data collection module 11 parses the corresponding documents according to the format of each document in the unstructured document collection to obtain the document content of each document, including: the data collection module 11 calls the corresponding parser to obtain the document content according to the format of each document in the unstructured document collection.

[0016] Exemplarily, the document format is automatically identified through the file extension (such as .txt, .pdf, .docx), file header information or open source library, and the corresponding parser is called to obtain the document content. For example, for PDF files, tools such as PyPDF2 or pdfminer are used for parsing; for Word documents, python-docx or other libraries are used for parsing.

[0017] Furthermore, metadata is usually additional information related to the document, such as the document title, author, publication date, abstract, etc. Metadata helps to conduct more efficient subsequent search and analysis. Metadata does not directly participate in similarity calculations, but plays a role in filtering, sorting, classifying and enhancing query results in subsequent retrieval.

[0018] Exemplarily, the metadata types of the document are shown in Table 1: Table 1 Document metadata types

[0019] The vector data storage module 12 is used to clean and segment the document content of each document based on the mapping relationship between the received document content of each document and the metadata attribute value, obtain multiple text blocks, determine the vectorized data corresponding to each text block, and construct a vector database according to each text block and the corresponding vectorized data.

[0020] Optionally, the vector data storage module 12 is specifically used to perform data cleaning on the document content of each document based on the mapping relationship between the received document content of each document and the metadata attribute value, to obtain the corresponding cleaned document; according to the preset segmentation rules, segment each cleaned document into text segments; perform word segmentation on each of the segmented text segments, and perform stop word processing on the word segmentation result; construct each text block according to the stop word processing result; perform vectorization processing on each text block through an embedding model to obtain the vectorized data corresponding to each text block.

[0021] Exemplarily, the vector data storage module 12 is used to perform the following operation steps S11 - S17: S11. Perform data cleaning on the document content of each document, remove special characters, Hyper Text Markup Language (HTML) tags, redundant spaces, and other noise information in the document, to obtain the corresponding cleaned document.

[0022] This process helps to eliminate unnecessary interference factors and ensure the effectiveness of the text content.

[0023] S12. Segment each cleaned document into text segments according to a fixed length, specific structure, or semantics.

[0024] The segmentation method can be flexibly selected according to the task requirements, such as sentence - based segmentation, sliding window segmentation, or topic - based segmentation, etc. Try to avoid breaking in the middle of a sentence or paragraph during segmentation to ensure sufficient context information is retained; if the segmentation is too fragmented, it may lead to overly sparse representation information of the vector, affecting the subsequent retrieval effect.

[0025] S13. Select a suitable word segmentation tool according to the text characteristics, such as jieba, HanLP, etc., and perform word segmentation on each of the segmented text segments.

[0026] After this processing, it is convenient to remove stop words later.

[0027] S14. Perform stop word processing on the word segmentation result, and remove words that do not carry substantial information, such as "de", "shi", "zai", etc.

[0028] It is understandable that the word segmentation result corresponds to multiple words.

[0029] Specifically, we can dynamically filter out low-importance words based on statistical methods such as term frequency-inverse document frequency (TF-IDF) values. The specific steps are as follows: First, calculate the TF-IDF value of each word obtained by word segmentation in the document to evaluate the importance of the word.

[0030] , , , in, Indicates the word frequency corresponding to the target vocabulary, represents the inverse document frequency corresponding to the target vocabulary, Represents a logarithmic function.

[0031] Specifically, Refers to the number of times a word appears in a document; It is used to measure the general importance of the word in the entire document collection; TF-IDF is used to comprehensively consider the frequency of occurrence of the word in the document and the distribution of the word in the entire document collection to measure the importance of the word.

[0032] Secondly, the TF-IDF value distribution of all words is analyzed, and the distribution is visualized through histograms and other methods. The threshold is dynamically adjusted according to the distribution, so as to filter out those words that appear frequently in the text fragments but have low information content.

[0033] S15, merging the processed word-granularity texts into text blocks.

[0034] S16. Each text block is vectorized through an embedding model such as text-embedding-ada-002 and Bidirectional Encoder Representations from Transformers (BERT) to obtain vectorized data corresponding to each text block.

[0035] This operation can map words or phrases in the text into a high-dimensional space, thereby capturing the semantic features of the text for efficient processing in subsequent tasks.

[0036] S17. Store each text block and the corresponding vectorized data in a vector database. The vector database may be ChromaDB, Qdrant, Milvus, etc.

[0037] The prompt word automatic generation module 13 is used to extract the rule data in the rule extraction file; embed the rule data into the preset initial prompt word review template and the initial prompt word reasoning template to obtain the target prompt word review template and the target prompt word reasoning template; send the target prompt word review template to the question review module; send the target prompt word reasoning template to the prompt word judgment module; the rule data includes domain information and relationship type.

[0038] Optionally, the prompt word automatic generation module 13 is specifically used to respond to the received rule extraction file and select a file parser according to the format of the rule extraction file; parse the file content of the rule extraction file through the selected file parser; and extract rule data from the parsed file content through the rule extractor.

[0039] Exemplarily, the internal working mechanism of the prompt word automatic generation module 13 is as follows: Figure 2 As shown, see Figure 2 The prompt word automatic generation module 13 is used to perform the following operation steps S21-S23: S21. In response to the received rule extraction file, the document format of the rule extraction file is identified according to the file extension, file header information or open source library, and the corresponding parser is called according to the document format to obtain the document content of the rule extraction file.

[0040] For example, use a JavaScript Object Notation (JSON) parser to process .json files, an Extensible Markup Language (XML) parser to process .xml files, and a Comma-Separated Values ​​(CSV) parser to process .csv files to ensure that the documents are parsed correctly.

[0041] S22. After the file content is successfully parsed, specific rule data, such as domain information and relationship types, are extracted from the parsed data through a rule extractor.

[0042] S23. After the rule data is extracted, the rule data such as domain information and relationship type are embedded into the preset initial prompt word review template and initial prompt word reasoning template to obtain the target prompt word review template and target prompt word reasoning template, and transmit them between modules.

[0043] This method can constrain the domain of knowledge graphs that can be drawn.

[0044] The problem review module 14 is used to receive and store the drawing instructions input by the user and carry the user identity identification; the drawing instructions are reviewed according to the target prompt word review template. If the review fails, a reminder message is issued to remind the user to enter a compliant drawing instruction. If the review passes, the target data is sent to the prompt word judgment module 15 according to the drawing instruction.

[0045] It is understandable that the drawing instruction contains information that can reflect the user's needs and the topics that the user is concerned about, for example, which aspect of the knowledge graph the user needs to draw, whether the user needs a knowledge graph or triples and other data.

[0046] The user identity can reflect the user's identity, and the user identity can limit the user's query or drawing scope. If the current system can draw the medical field, when the user issues a drawing instruction to draw a knowledge graph related to historical events, the drawing instruction will be judged as an illegal drawing instruction.

[0047] The question review module is specifically used to store the drawing instruction into the internal cache unit, and according to the user identity carried by the drawing instruction; obtain the historical dialogue data from the cache unit, determine the drawing instruction and the historical dialogue data as the target data; and send the target data to the prompt word judgment module 15.

[0048] For example, when a user starts a conversation, the drawing instruction is sent to the question review module 14. The module reviews the drawing instruction in combination with the content of the target prompt word review template. If the question does not meet the preset task content, the user will be reminded to enter a compliant drawing instruction and temporarily exit the working state. If the question passes the review, the drawing instruction is passed to the prompt word judgment module 15.

[0049] For example, the user may be reminded to input a compliant drawing instruction in any manner such as text, image, light, sound, etc.

[0050] By adopting a conversational model to dynamically construct and enrich the knowledge graph, it helps to focus on the core concerns of users and efficiently construct the knowledge graph.

[0051] The prompt word judgment module 15 is used to write the received target prompt word reasoning template into the prompt word unit of the intelligent reasoning and execution module 16, and input the target data into the intelligent reasoning and execution module 16 after receiving the target data.

[0052] Exemplarily, when the prompt word judgment module 15 receives the target prompt word reasoning template, it will write it into the prompt word unit of the intelligent reasoning and execution module 16. After completing this operation, the module will wait for the question review module 14 to pass the drawing instruction. When the drawing instruction is received, the drawing instruction is passed to the intelligent reasoning and execution module 16 as input.

[0053] The intelligent reasoning and execution module 16 is used to embed the target data into the target prompt word template in the prompt word unit and then pass it to the large language model with intelligent agent function; disassemble the entity elements from the target data through the large language model; search for the knowledge graph related to each entity element in the graph database according to the user identity carried by the drawing instruction and the disassembled entity elements, if found, the found knowledge graph is returned to the user, if not found, query the vector database according to each entity element, obtain the candidate text block related to the target data, extract the entity relationship of the candidate text block through the large language model, and construct the entity relationship triple set according to the extraction result, and construct the target knowledge graph according to the entity relationship triple set, and store the target knowledge graph in the graph database after naming it with the user identity, and return the target knowledge graph to the user.

[0054] By embedding the target data into the target prompt word template in the prompt word unit, a "prompt word" closely related to the user's drawing instruction is formed. This "prompt word" is the only input instruction received by the large language model, which can guide the model to better understand the user's intention and make a correct response.

[0055] Optionally, the intelligent reasoning and execution module 16 is specifically used to perform semantic analysis on the target data through a preset large language model with intelligent agent functions, and disassemble the entity elements in the target data; determine the dependency relationship between the disassembled entity elements; determine the acquisition order and acquisition method of each entity element based on the determined dependency relationship; determine the search and information acquisition plan based on the acquisition order and acquisition method of each entity element, the search and information acquisition plan includes query strategies for graph databases and vector databases, and the query strategy for the vector database includes vector retrieval methods, similarity thresholds, data sources and tool selection rules; based on the search and information acquisition plan, according to the acquisition method of each entity element, call the corresponding tool to query the vector database to obtain text blocks related to the target data as candidate text blocks.

[0056] Exemplarily, the intelligent reasoning and execution module 16 is used to perform the following operation steps S31-S37: S31 . Perform semantic analysis on the drawing instruction input by the user to extract entity elements involved in the drawing instruction.

[0057] For example, identify the entity elements involved such as diseases, foods, and medicines.

[0058] S32. Analyze the dependencies between the entity elements according to the disassembled entity elements, so as to infer the acquisition order and acquisition method of each entity element.

[0059] For example, some entity features may depend on the attributes of other entity features, or when querying, it is necessary to first obtain a certain entity feature and then infer other related information.

[0060] S33. Develop a specific search and information acquisition plan based on the inferred acquisition order and method.

[0061] Specifically, it is necessary to plan the query strategy of the vector database, including which vector retrieval method to choose, how to set the similarity threshold, which data sources or tools to choose, etc., to ensure that the most relevant information to the query is retrieved.

[0062] S34. The large language model with intelligent agent functions reviews and reflects on the planned search strategy to ensure that there is a corresponding action plan for the acquisition of each entity element, check whether there are any missing entity elements or acquisition paths, and supplement the missing parts in time to ensure the integrity of the strategy.

[0063] S35. After reflection, the formulated search plan is executed. According to the acquisition method of each entity element, the corresponding tool is called to perform vector database query to obtain the text block related to the target data and use it as a candidate text block.

[0064] S36. Based on the target prompt word inference template, entity relationship extraction is performed on the returned candidate text block, and a set of entity relationship triples is constructed according to the extraction results.

[0065] Exemplarily, a set of entity-relationship triples such as (entity 1, relationship, entity 2) is constructed.

[0066] S37. If the drawing instruction indicates that the user requires drawing a knowledge graph, the graph drawing tool is called to parse the extracted entity relationship triple set and construct the corresponding knowledge graph; if the user has no graph drawing requirements, the extracted entity relationship triple set is directly returned to the user.

[0067] Closely combining the drawing instructions input by the user and querying related data can improve the accuracy and availability of the query results, while also improving the query efficiency and the efficiency of knowledge graph drawing.

[0068] Furthermore, if the user needs to continue to expand on the basis of the existing graph, the stored graph can be queried according to the user identity and continue to expand or update.

[0069] The knowledge graph construction system based on prompt words provided by the present invention reduces the influence of subjective factors to a certain extent with the help of the generalization ability of the large language model, and also greatly reduces labor costs. "Prompt words" are the only input instructions received by the large language model, guiding the model to understand the user's intentions and make relevant responses. At the same time, by introducing vector databases and execution tools, not only the generation of model hallucinations is reduced, but also the model can keep knowledge updated without training. The conversation mode is used to dynamically construct and enrich the knowledge graph. With the problem understanding and behavior planning capabilities of the large language model, the content related to the user's drawing instructions can be accurately located and extracted, realizing efficient and accurate knowledge graph construction.

[0070] For ease of understanding, the present invention also provides a set of examples, which are as follows: Taking the field of medical diagnosis and treatment as an example, the knowledge graph is automatically constructed through dialogue.

[0071] Large language models can use OpenAI's generative pre-trained model (Generative Pre-trained Transformer, GPT), LLaMA (Large Language Model Meta AI) model, etc.

[0072] This method does not rely on annotated data sets, but uses the dialogue question-answering method to extract the key entity elements in the question through the question analysis and task decomposition capabilities of the large language model. With the key elements as the core, the entity relationship extraction task is automatically performed, and finally the construction and display of the knowledge graph centered on the key elements is completed.

[0073] 1. Example of rule extraction file When processing medical diagnosis and treatment information, we first need to clarify the key information types and relationship categories that the system is concerned about. For example, the medical field involves a variety of relationship types related to diagnosis and treatment, which generally include but are not limited to the following: Susceptible population: refers to those groups of people who are more likely to be infected or suffer from a certain disease, such as the elderly, children, or people with a specific genetic background.

[0074] Symptoms: include various clinical manifestations related to the disease, such as fever, cough, headache, etc. These symptoms are the key to diagnosis.

[0075] Medication: refers to the information about drugs used to treat a certain disease, including drug name, dosage, frequency of use, etc.

[0076] Treatment cycle: refers to the time frame or course of treatment for a disease, helping doctors determine the duration of treatment and whether the treatment plan needs to be adjusted.

[0077] Beneficial foods: List the foods that are helpful for the patient's recovery, which have a positive effect on enhancing immunity or alleviating symptoms.

[0078] Avoided foods: Include the foods that should be avoided, usually because certain foods may react with medications or exacerbate symptoms.

[0079] To ensure that information can be effectively extracted and meet the actual needs of the medical field, these key relationship types need to be listed in detail and organized into a standardized rule extraction file. This rule extraction file can exist in JSON format, containing the specific definitions, extraction criteria, and corresponding examples for each relationship type. The formulation of the rule extraction file will provide clear guidance for subsequent document processing.

[0080] 2. Example of the processing of the data collection module for unstructured documents Related medical literature, case reports, treatment guidelines and other documents will be uploaded to the data collection module. This module first parses the document content and assigns a unique identifier to each document. According to the preset metadata, such as author information, title, content summary, etc., the corresponding metadata attribute values are extracted from the document, and then the mapping relationship between the document content and the metadata attribute values is constructed and passed into the vector data storage module.

[0081] 3. Example of the processing of the vector data storage module In the vector data storage module, first, data cleaning operations are performed to remove invalid information and noise data in the document, such as punctuation marks, special characters, meaningless spaces, etc. This can ensure that the text is cleaner and more standardized during subsequent processing.

[0082] Next, text chunking is performed to divide the document into multiple small chunks, and each text chunk contains information or a topic of a specific category. This step can effectively organize the document structure and improve the efficiency of subsequent retrieval. For example, for a long document, it can be divided into multiple shorter paragraphs or topic chunks, making each chunk independent and easier to manage and search.

[0083] Then, each text chunk is tokenized to split out words or phrases. The tokenized text will further undergo stop word removal processing. This step is to remove some high-frequency words with low contribution in semantic analysis, such as common function words like "de" (的) and "le" (了), thereby reducing noise and improving the accuracy of subsequent analysis.

[0084] After the stop words are removed, the text blocks are merged into a processed standard form and then input into the embedding model for vectorization. In this process, the embedding model converts the text blocks into vector representations, allowing the text data to be efficiently stored and retrieved in the computer. This vector representation will provide the necessary support for subsequent text analysis and retrieval tasks.

[0085] Finally, a vector database is constructed based on the mapping relationship between the document content and metadata attribute values ​​corresponding to each document, each text block and the corresponding vectorized data.

[0086] 4. Example of prompt word review template A customized filter is introduced into the prompt word review template to identify whether the user's drawing instruction is related to the preset field, or whether there is an attempt to tamper with the prompt word review template. An example of the prompt word review template is shown in Table 2.

[0087] Table 2 Example of prompt word review template

[0088] It should be noted that the system constraints corresponding to the target prompt word review template include embedded rule data.

[0089] When the user enters a drawing instruction in the dialog window, the system will analyze the drawing instruction in combination with the target prompt word review template. If it meets the requirements, it will be passed to the prompt word judgment module. Otherwise, the user is reminded to enter a compliant drawing instruction. The dialog example is shown in Table 3.

[0090] Table 3 Dialogue examples

[0091] 5. Example of prompt word reasoning template Introducing thinking chains and execution tools into the prompt word reasoning template and linking internal thinking with external information can better assist large language models in reasoning and decision-making on complex issues and realize the construction of knowledge graphs. The basic structure of the prompt word reasoning template is shown in Table 4.

[0092] Table 4 Example of prompt word inference template

[0093] Taking the entity relationship extraction task in the field of medical diagnosis and treatment as an example, the field is medical diagnosis and treatment. The role of the large language model is the intelligent generation assistant of the medical diagnosis and treatment knowledge graph. The parsed relationship types include susceptible population, symptoms, medication, treatment cycle, beneficial food, and taboo food. The domain information extracted from the rule extraction file is filled in the area position of the prompt word reasoning template, and the relationship type description is filled in the extract_content position, as shown in Table 5.

[0094] Table 5 Examples of inference templates for prompt words in the field of medical diagnosis and treatment

[0095] The generation process of the prompt word reasoning template specifically includes the following steps: 1) Record all the documents and available tools required for the query in the prompt word reasoning template.

[0096] Exemplarily, the required tools include: file parsing tools, code generation tools, graph drawing tools, etc.

[0097] The details are shown in Table 6: Table 6 Limiting the scope of queries and the scope of use of tools / commands

[0098] At the same time, in order to ensure the consistency of the large language model reasoning process, it is necessary to regulate that only one tool is called for each decision, but it can be called multiple times. And the called instructions or tools used must be in the given tool list.

[0099] 2) Record the constraints of the interactive behavior in the prompt word reasoning template.

[0100] Exemplary constraints on interactive behavior include: strict control over the legality of answers to ensure that the generated content does not contain any illegal or infringing information; if the execution of an instruction or tool call fails, try to adjust the parameters or parameter format and call it again; avoid repeated queries for information that has already been obtained; remind large language models to refer to historical conversation records to reduce the waste of computing resources; when generating natural language queries, be sure to include all known information to prevent unsatisfactory query results due to missing key information; and avoid asking questions to users and autonomously reasoning to solve problems.

[0101] 3) Constrain the reasoning process and record it in the prompt word reasoning template.

[0102] Exemplarily, the constraints of the reasoning process include: if the task involves composite concepts or entities, the clear values ​​should be recorded after the key concepts; next, the key concepts in the task are split into a series of sub-entity elements to be queried, and these sub-elements are arranged in a hierarchical structure; combined with the executed records, the rationality of the execution method of the entity elements is judged; then, step by step, consider whether the query results of each key concept or entity element are accurate, which entity elements cannot be obtained, and whether there are dependencies between the entity elements, and then infer the way to obtain the entity element; rationality mainly includes whether there is exhaustive behavior in this process. If such behavior exists, a more efficient method should be given, and the entire reflection process must rely on available real data to avoid using any assumptions; if the last plan failed, check whether the input contains a clear definition of each concept or entity element, and try to refine the description of the query.

[0103] 4) Record the execution process control in the prompt word reasoning template, as shown in Table 7.

[0104] Table 7 Example of executing process control

[0105] Figure 3 A schematic diagram of a process for constructing a knowledge graph based on prompt words provided by the present invention, such as Figure 3 As shown, the method includes: S41. Obtain an unstructured document collection and rule extraction files.

[0106] The unstructured document collection includes multiple unstructured documents. Unstructured documents are mainly text files, such as papers, reports, books, etc., and can also be HTML web pages, etc.

[0107] S42: Determine, according to preset metadata, a mapping relationship between the document content and the metadata attribute value corresponding to each document in the unstructured document collection.

[0108] In a possible implementation, a mapping relationship between document content and metadata attribute values ​​corresponding to each document in an unstructured document collection is determined based on preset metadata, including: parsing corresponding documents according to the formats of each document in the unstructured document collection to obtain the document content of each document; determining the metadata attribute values ​​corresponding to each document based on the preset metadata and the document content of each document to obtain the mapping relationship between the document content and metadata attribute values ​​corresponding to each document.

[0109] S43. Based on the mapping relationship between the document content and the metadata attribute value corresponding to each document, the document content of each document is cleaned and cut into pieces to obtain multiple text blocks, and the vectorized data corresponding to each text block is determined. A vector database is constructed according to the mapping relationship between the document content and the metadata attribute value corresponding to each document, each text block and the corresponding vectorized data.

[0110] In a possible implementation, based on the mapping relationship between the document content corresponding to each document and the metadata attribute value, the document content of each document is cleaned and segmented to obtain multiple text blocks and determine the vectorized data corresponding to each text block, including: based on the mapping relationship between the document content corresponding to each received document and the metadata attribute value, the document content of each document is cleaned to obtain the corresponding cleaned document; according to a preset segmentation rule, each cleaned document is segmented into text segments; each text segment obtained by segmentation is segmented, and stop word processing is performed on the result of the word segmentation processing; text blocks are constructed according to the stop word processing result; and each text block is vectorized through an embedding model to obtain the vectorized data corresponding to each text block.

[0111] S44, extracting rule data from the rule extraction file.

[0112] Rule data includes domain information and relationship types.

[0113] In a possible implementation, extracting rule data from a rule extraction file includes: selecting a file parser according to a format of the rule extraction file; extracting content from the rule extraction file by the selected file parser; and extracting rule data from the content of the parsed file by the rule extractor.

[0114] S45, embedding the rule data into the preset initial prompt word review template and the initial prompt word reasoning template to obtain the target prompt word review template and the target prompt word reasoning template.

[0115] S46. In response to the drawing instruction input by the user carrying the user identity identifier, the drawing instruction is reviewed according to the target prompt word review template. If the review fails, a reminder message is issued to remind the user to input a compliant drawing instruction. If the review passes, the target data is determined according to the drawing instruction.

[0116] S47. Based on a preset large language model with intelligent agent functions, the template is inferred according to the target data and the target prompt words to disassemble the entity elements from the target data.

[0117] S48. According to the user identity carried by the drawing instruction and the disassembled entity elements, the knowledge graph related to each entity element is searched in the graph database. If found, the found knowledge graph is returned to the user. If not found, the vector database is queried according to each entity element to obtain candidate text blocks related to the target data. The candidate text blocks are extracted from the entity relationship through the large language model, and a set of entity relationship triples is constructed according to the extraction results. According to the set of entity relationship triples, a target knowledge graph is constructed, and the target knowledge graph is named with the user identity and stored in the graph database, and the target knowledge graph is returned to the user.

[0118] As for the method embodiment, since it is basically similar to the system embodiment, the description is relatively simple, and the specific contents and beneficial effects and other related matters can be referred to the partial description of the system embodiment.

[0119] The above contents are further detailed descriptions of the present invention in combination with specific preferred embodiments, and it cannot be determined that the specific implementation of the present invention is limited to these descriptions. For ordinary technicians in the technical field to which the present invention belongs, several simple deductions or substitutions can be made without departing from the concept of the present invention, which should be regarded as falling within the protection scope of the present invention.

Claims

1. A knowledge graph construction system based on prompt words, characterized in that: include: Data collection module, used to obtain unstructured document collection and rule extraction files; According to the preset metadata, the mapping relationship between the document content and the metadata attribute value corresponding to each document in the unstructured document set is determined; the mapping relationship between the document content and the metadata attribute value corresponding to each document is sent to the vector data storage module; the rule extraction file is sent to the prompt word automatic generation module; The vector data storage module is used to clean and cut the document content of each document based on the mapping relationship between the document content and the metadata attribute value corresponding to each document, so as to obtain multiple text blocks; determine the vectorized data corresponding to each text block; and construct a vector database according to the mapping relationship between the document content and the metadata attribute value corresponding to each document, each text block and the corresponding vectorized data; The prompt word automatic generation module is used to extract the rule data in the rule extraction file; Embedding the rule data into a preset initial prompt word review template and an initial prompt word reasoning template to obtain a target prompt word review template and a target prompt word reasoning template; Sending the target prompt word review template to the question review module; Sending the target prompt word reasoning template to the prompt word judgment module; the rule data includes domain information and relationship type; The problem review module is used to receive and store the drawing instruction input by the user and carrying the user identity identifier; review the drawing instruction according to the target prompt word review template, and if the review fails, send a reminder message to remind the user to input a compliant drawing instruction; if the review passes, send the target data to the prompt word judgment module according to the drawing instruction; The prompt word judgment module is used to write the received target prompt word reasoning template into the prompt word unit of the intelligent reasoning and execution module, and after receiving the target data, input the target data into the intelligent reasoning and execution module; The intelligent reasoning and execution module is used to embed the target data into the target prompt word template in the prompt word unit and then pass it into a large language model with intelligent agent function; disassemble entity elements from the target data through the large language model; search for knowledge graphs related to each entity element in the graph database according to the user identity carried by the drawing instruction and the disassembled entity elements, if found, return the found knowledge graph to the user, if not found, query the vector database according to each entity element to obtain candidate text blocks related to the target data, extract entity relationships from the candidate text blocks through the large language model, and construct an entity relationship triple set according to the extraction results, construct a target knowledge graph according to the entity relationship triple set, store the target knowledge graph in the graph database after naming it with the user identity, and return the target knowledge graph to the user.

2. The system according to claim 1, characterized in that The data collection module is specifically used to parse the corresponding documents according to the format of each document in the unstructured document collection to obtain the document content of each document; determine the metadata attribute value corresponding to each document according to the preset metadata and the document content of each document, and obtain the mapping relationship between the document content corresponding to each document and the metadata attribute value.

3. The system according to claim 2, characterized in that The vector data storage module is specifically used to perform data cleaning on the document content of each of the documents based on the mapping relationship between the document content corresponding to each of the received documents and the metadata attribute value to obtain the corresponding cleaned document; according to the preset segmentation rules, each of the cleaned documents is segmented into text segments; each of the text segments obtained by segmentation is segmented, and stop word processing is performed on the word segmentation results; each of the text blocks is constructed according to the stop word processing results; each of the text blocks is vectorized through the embedding model to obtain the vectorized data corresponding to each of the text blocks.

4. The system according to claim 3, characterized in that The prompt word automatic generation module is specifically used to respond to the received rule extraction file and select a file parser according to the format of the rule extraction file; parse the file content of the rule extraction file through the selected file parser; and extract rule data from the content of the parsed file through the rule extractor.

5. The system according to claim 4, characterized in that The question review module is specifically used to store the drawing instruction into an internal cache unit, and according to the user identity carried by the drawing instruction; obtain historical conversation data from the cache unit, determine the drawing instruction and the historical conversation data as the target data; and send the target data to the prompt word judgment module.

6. The system according to claim 5, characterized in that The intelligent reasoning and execution module is specifically used to perform semantic analysis on the target data through the preset large language model with intelligent agent function, and disassemble the entity elements in the target data; determine the dependency relationship between the disassembled entity elements; determine the acquisition order and acquisition method of each entity element according to the determined dependency relationship; determine the search and information acquisition plan according to the acquisition order and acquisition method of each entity element, and the search and information acquisition plan includes the query strategy of the graph database and the vector database, and the query strategy of the vector database includes the vector retrieval method, similarity threshold, data source and tool selection rule; based on the search and information acquisition plan, according to the acquisition method of each entity element, call the corresponding tool to query the vector database to obtain the text block related to the target data as the candidate text block.

7. A method for constructing a knowledge graph based on prompt words, characterized in that: include: Obtain unstructured document collections and rule extraction files; Determining, according to the preset metadata, a mapping relationship between the document content corresponding to each document in the unstructured document set and the metadata attribute value; Based on the mapping relationship between the document content corresponding to each of the documents and the metadata attribute value, the document content of each of the documents is cleaned and cut into pieces to obtain a plurality of text blocks, and the vectorized data corresponding to each of the text blocks is determined, and a vector database is constructed according to the mapping relationship between the document content corresponding to each of the documents and the metadata attribute value, each of the text blocks and the corresponding vectorized data; Extracting rule data from the rule extraction file, wherein the rule data includes domain information and relationship type; Embedding the rule data into a preset initial prompt word review template and an initial prompt word reasoning template to obtain a target prompt word review template and a target prompt word reasoning template; In response to a drawing instruction input by a user carrying a user identity identifier, the drawing instruction is reviewed according to the target prompt word review template, and if the review fails, a reminder message is issued to remind the user to input a compliant drawing instruction, and if the review passes, target data is determined according to the drawing instruction; Based on a preset large language model with intelligent agent function, entity elements are disassembled from the target data according to the target data and the target prompt word inference template; According to the user identity carried by the drawing instruction and the disassembled entity elements, the knowledge graph related to each entity element is searched in the graph database. If found, the found knowledge graph is returned to the user. If not found, the vector database is queried according to each entity element to obtain candidate text blocks related to the target data. The candidate text blocks are subjected to entity relationship extraction through the large language model, and a set of entity relationship triples is constructed according to the extraction results. According to the set of entity relationship triples, a target knowledge graph is constructed, and the target knowledge graph is named with the user identity and stored in the graph database, and the target knowledge graph is returned to the user.

8. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; The processor is used to implement the method described in claim 7 when executing the program stored in the memory.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to claim 7 is implemented.

10. A program product, characterized in that The program product comprises computer program instructions, and when the computer program instructions are executed, the method according to claim 7 can be implemented.

Citation Information

Patent Citations

  • Intelligent question and answer method and system based on tourism knowledge graph

    CN113535917A

  • Knowledge graph construction method and device based on pre-trained large language model

    CN117851610A

  • Data integration method based on knowledge graph

    CN118333059A

  • Management and control method and system for intelligent viewing terminal equipment

    CN118714408A

  • Intelligent question answering method based on vertical domain knowledge

    CN118820444A

Cited By

  • Intelligent operation and maintenance aid decision-making method and device based on large language model, and medium

    CN119739797A

  • Teaching design generation, optimization and reflection method and system based on AI chain driving

    CN119886737A

  • Large model prompt design method for social governance knowledge graph construction based on CoT chain thinking

    CN119918677A

  • Large Model Prompt Design Method for Constructing a Social Governance Knowledge Graph Based on Chain of Thought

    CN119918677B

  • Travel text label cloud-icon collaborative visualization method based on LLM analysis

    CN120597836A