Method for creating knowledge base for LLM
By using user-defined segmentation rules and knowledge extraction strategies, a knowledge graph is built for LLM, which solves the shortcomings of traditional RAG technology in multi-hop reasoning and cross-document association, realizes efficient and automated construction and flexible updating of the knowledge base, and improves the quality and diversity of answers.
Patent Information
- Application Number
- CN202511055190.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-29
- Publication Date
- 2025-11-14
AI Technical Summary
Traditional RAG technology struggles to handle multi-hop reasoning and cross-document associations when retrieving context, resulting in a lack of logical coherence in the generated content. Furthermore, the construction of knowledge graphs relies heavily on the experience of industry experts, which presents a high barrier to entry and leads to significant resource waste.
By using user-defined segmentation rules and knowledge extraction strategies, a knowledge base is built for LLM. The knowledge graph is used to automatically process document fragments, form sub-knowledge graphs, and store them in a graph database, supporting flexible adaptation and incremental updates across multiple knowledge domains.
It lowers the barrier to knowledge graph construction, improves automation and versatility, saves labor costs, and increases the efficiency of knowledge base updates and answer quality.
Smart Images

Figure CN120952125A_ABST
Abstract
Description
Technical Field
[0001] The embodiments in this specification belong to the field of artificial intelligence, and in particular relate to a method for creating a knowledge base for an LLM. Background Technology
[0002] Retrieval-Augmented Generation (RAG) is a technique designed to improve the accuracy and reliability of Large Language Models (LLMs) in answering natural language questions. Based on RAG, when using an LLM to generate answers to user-input questions, it first retrieves question-related information from a large document collection as context. Then, based on the user-input question and the retrieved context, it regenerates prompts to guide the LLM in generating accurate and reliable answers.
[0003] However, traditional RAG techniques typically rely on vector similarity for context retrieval, making it difficult to handle complex queries requiring multi-hop reasoning and cross-document association. Their retrieval results are often limited to locally semantically similar fragments, failing to capture global semantics. Furthermore, traditional RAG techniques usually segment documents into independent text chunks, losing explicit relationships between entities and resulting in a lack of logical coherence in the generated content. Summary of the Invention
[0004] This specification proposes a method for creating a knowledge base for an LLM (Local Management System), wherein the knowledge base created for the LLM includes a knowledge graph constructed based on user-uploaded knowledge documents; the method includes:
[0005] The system retrieves knowledge documents uploaded by users to a target knowledge base; and obtains a first prompt word corresponding to the knowledge domain to which the knowledge document belongs, obtained by the user customizing a first prompt word template corresponding to a preset segmentation rule; wherein the first prompt word describes the segmentation rule customized by the user for the knowledge domain to which the knowledge document belongs; and sends the knowledge document and the first prompt word to an LLM, so that the LLM can segment the knowledge document into multiple document fragments based on the segmentation rule described by the first prompt word.
[0006] Knowledge triples are extracted from the document segments, and sub-knowledge graphs corresponding to the multiple document segments are created based on the extracted knowledge triples, and the sub-knowledge graphs are stored in the knowledge base.
[0007] Optionally, the system acquires knowledge documents uploaded by users to the target knowledge base; and obtains first prompt words corresponding to the knowledge domain of the knowledge documents, obtained by the user through custom modification of a first prompt word template corresponding to a preset segmentation rule, including:
[0008] In response to a knowledge document upload request sent by a client, an upload interface corresponding to the target knowledge base is returned to the client; and a first prompt word template corresponding to a preset segmentation rule is provided so that the client can display the upload interface to the user and output the first prompt word template in the upload interface.
[0009] The system obtains the knowledge document uploaded by the user through the upload interface, and the first prompt word obtained by the user through custom modification of the first prompt word template.
[0010] Optionally, the knowledge extraction strategy used to extract knowledge triples from the document fragments is a user-defined knowledge extraction strategy corresponding to the knowledge domain to which the knowledge document belongs; the knowledge extraction strategy includes prompt words used to describe the knowledge extraction strategy;
[0011] In response to a knowledge document upload request sent by a client, the system returns an upload interface corresponding to the target knowledge base to the client; and a first prompt word template corresponding to a preset segmentation rule is provided for the client to display the upload interface to the user, and the first prompt word template is output in the upload interface, including:
[0012] In response to a knowledge document upload request sent by a client, the system returns to the client an upload interface corresponding to the target knowledge base, a first prompt word template corresponding to a preset segmentation rule, and a second prompt word template corresponding to a preset knowledge extraction strategy, so that the client can display the upload interface to the user and output the first prompt word template and the second prompt word template in the upload interface.
[0013] Acquiring the knowledge document uploaded by the user through the upload interface, and the first prompt word obtained by the user through custom modification of the first prompt word template, including:
[0014] The system retrieves knowledge documents uploaded by users through the upload interface, including the first prompt word obtained by the user customizing the first prompt word template and the second prompt word obtained by the user customizing the second prompt word; wherein the second prompt word describes the knowledge extraction strategy customized by the user for the knowledge domain to which the knowledge document belongs. Knowledge triples are extracted from the document segments, including:
[0015] The document fragments and the second prompt words are sent to the LLM so that the LLM can extract knowledge triples from the document fragments based on the knowledge extraction strategy described by the second prompt words.
[0016] Optionally, storing the sub-knowledge graph in the knowledge base includes:
[0017] Generate the mapping relationship between the entities contained in the sub-knowledge graph and the document fragments corresponding to the sub-knowledge graph;
[0018] A graph structure index corresponding to the sub-knowledge graph is generated based on the attribute information of the sub-knowledge graph; an entity vector index corresponding to the entity is generated based on the attribute information of the entity contained in the sub-knowledge graph; and a relation vector index corresponding to the relation is generated based on the attribute information of the relation contained in the sub-knowledge graph.
[0019] The sub-knowledge graph, the graph structure index, the entity vector index, and the relation vector index are stored in a graph database corresponding to the knowledge base, and the mapping relationship is stored in a relational database corresponding to the knowledge base.
[0020] Optionally, the method further includes:
[0021] In response to an update of any target document fragment contained in the knowledge document, the updated target document fragment uploaded by the user is obtained;
[0022] The target document fragment and the second prompt word are sent to the LLM so that the LLM can re-extract knowledge triples from the target document fragment based on the knowledge extraction strategy described by the second prompt word;
[0023] Based on the extracted knowledge triples, a sub-knowledge graph corresponding to the target document segment is recreated; and, the sub-knowledge graph corresponding to the target document segment is searched in the knowledge base, and based on the recreated sub-knowledge graph corresponding to the target document segment, the searched sub-knowledge graph corresponding to the target document segment is incrementally updated.
[0024] Optionally, searching the knowledge base for the sub-knowledge graph corresponding to the target document fragment includes:
[0025] The mapping relationships stored in the relational database are queried to determine the entities that have a mapping relationship with the target document segment. Furthermore, based on the graph structure index stored in the graph database, a sub-knowledge graph containing the entities is searched in the graph database to serve as the sub-knowledge graph corresponding to the target document segment.
[0026] Optionally, the method further includes:
[0027] Identify the sub-knowledge graphs containing the same entities stored in the graph database, and merge the sub-knowledge graphs containing the same entities to obtain the merged sub-knowledge graph.
[0028] Community clustering is performed on the sub-knowledge graphs stored in the graph database to generate at least one knowledge graph community;
[0029] Based on the attribute information of the at least one knowledge graph community, a community vector index corresponding to the at least one knowledge graph community is generated, and the community vector index is stored in a graph database corresponding to the knowledge base;
[0030] Based on the graph structure index stored in the graph database, the search for a sub-knowledge graph containing the entity in the graph database includes:
[0031] The system searches for a target knowledge graph community that matches the attribute information of the entity from at least one knowledge graph community stored in the graph database, and further searches for a sub-knowledge graph containing the entity in the sub-knowledge graph contained in the target knowledge graph community based on the graph structure index stored in the graph database.
[0032] Optionally, the knowledge triple includes entities and relationships between entities; the knowledge extraction strategy includes a first-stage knowledge extraction strategy and a second-stage knowledge extraction strategy; the first-stage knowledge extraction strategy is used to extract entities contained in the knowledge document; the second-stage knowledge extraction strategy is used to extract entity relationships between entities extracted in the first stage contained in the knowledge document.
[0033] The second prompt word template includes a third prompt word template corresponding to the knowledge extraction strategy of the first stage; and a fourth prompt word template corresponding to the knowledge extraction strategy of the second stage;
[0034] The second prompt word includes a third prompt word obtained by the user customizing the third prompt word template; and a fourth prompt word obtained by the user customizing the fourth prompt word template; wherein, the third prompt word is used to describe the first-stage knowledge extraction strategy customized by the user for the knowledge domain to which the knowledge document belongs; and the fourth prompt word is used to describe the second-stage knowledge prompting strategy customized by the user for the knowledge domain to which the knowledge document belongs.
[0035] Optionally, the method further includes:
[0036] Get user questions input by the user;
[0037] Extract the keywords contained in the user's question and generate a query vector corresponding to the keywords;
[0038] Calculate the vector similarity between the query vector and the entity vector index stored in the graph database, and filter out at least one entity vector index with the highest vector similarity; determine the entity corresponding to the at least one entity vector index, and query the sub-knowledge graph containing the entity in the graph database based on the graph structure index stored in the graph database, and query the mapping relationship stored in the relational database to determine the document fragment that has a mapping relationship with the entity;
[0039] Based on the user question, the sub-knowledge graph containing the entity, and the document fragments that have a mapping relationship with the entity, a question prompt word corresponding to the user question is generated, and the question prompt word is sent to the LLM so that the LLM can generate the answer text corresponding to the user question based on the question prompt word.
[0040] Optionally, calculating the vector similarity between the query vector and the entity vector indexes stored in the graph database, and selecting at least one entity vector index with the highest vector similarity, includes:
[0041] Calculate the vector similarity between the query vector and the community vector index stored in the graph database, and filter out at least one target knowledge graph community with the highest vector similarity;
[0042] Further calculate the vector similarity between the query vector and the entity vector index corresponding to the entity contained in the sub-knowledge graph in the target knowledge graph community, and select at least one entity vector index with the highest vector similarity.
[0043] This specification also proposes a method for creating a knowledge base for an LLM, wherein the knowledge base comprises a knowledge graph constructed based on user-uploaded knowledge documents; the method includes:
[0044] In response to a user's operation of uploading a knowledge document to a target knowledge base, the system retrieves the uploaded knowledge document; and obtains a first prompt word corresponding to the knowledge domain to which the knowledge document belongs, obtained by the user customizing a first prompt word template corresponding to a preset segmentation rule; wherein, the first prompt word is used to describe the segmentation rule customized by the user for the knowledge domain to which the knowledge document belongs;
[0045] The knowledge document and the first prompt word are sent to the server, which then sends them to the LLM (Local Management Module). The LLM then segments the knowledge document into multiple document fragments based on the segmentation rules described by the first prompt word. Knowledge triples are extracted from the document fragments, and sub-knowledge graphs corresponding to the multiple document fragments are created based on the extracted knowledge triples. The sub-knowledge graphs are then stored in the knowledge base.
[0046] This application has the following technical effects:
[0047] On the one hand, by automatically constructing graph knowledge based on knowledge documents as an LLM knowledge base, it can not only greatly reduce the construction threshold of knowledge graph-based knowledge bases and improve the degree of automation in constructing knowledge graph-based knowledge bases, but also save human resources costs.
[0048] On the other hand, the user's ability to flexibly define segmentation rules for knowledge documents in different knowledge domains allows this solution to adapt to different knowledge domains, improving its versatility when building knowledge graph-based knowledge bases. Moreover, by automatically building multiple sub-knowledge graphs as knowledge bases using document fragments as the granularity for LLM, when the content of the knowledge documents used to build the knowledge graph is updated, only the sub-knowledge graphs corresponding to the document fragments whose content has been updated can be incrementally updated. This avoids the waste of resources and time caused by a full reconstruction of the knowledge graph, thus improving the update efficiency of the knowledge base. Attached Figure Description
[0049] To more clearly illustrate the technical solutions of the embodiments in this specification, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0050] Figure 1 This is a flowchart illustrating a method for creating a knowledge base for an LLM, as shown in one embodiment of this specification;
[0051] Figure 2 This is a schematic diagram illustrating an embodiment of the present specification in which a user automatically creates a Graph knowledge base through a client.
[0052] Figure 3 This is a schematic diagram illustrating another example of a user automatically creating a Graph knowledge base via a client, as shown in one embodiment of this specification.
[0053] Figure 4This is a flowchart illustrating another method for creating a knowledge base for an LLM, as shown in one embodiment of this specification;
[0054] Figure 5 This is a schematic structural diagram of an electronic device shown in one embodiment of this specification;
[0055] Figure 6 This is a block diagram of an apparatus for creating a knowledge base for an LLM, as shown in one embodiment of this specification;
[0056] Figure 7 This is a block diagram of an apparatus for creating a knowledge base for an LLM, as shown in one embodiment of this specification. Detailed Implementation
[0057] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this specification, and not all embodiments. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this specification.
[0058] In order to address the technical limitations of traditional RAG technology, GraphRAG technology has been proposed.
[0059] GraphRAG technology is a knowledge graph-based retrieval enhancement and generation technique. By combining knowledge graphs with traditional RAG technology and using the knowledge graph as an LLM knowledge base, it can significantly improve the accuracy and contextual understanding capabilities of LLM in complex queries, multi-step reasoning, and domain-specific tasks.
[0060] Compared to traditional RAG technology, GraphRAG technology has the following core advantages:
[0061] Firstly, it can enhance contextual understanding and global retrieval capabilities.
[0062] GraphRAG technology constructs a knowledge graph as an LLM knowledge base, transforming unstructured text into structured graph data, enabling LLMs to understand complex relationships between entities. Compared to traditional RAG technology that relies on vector similarity retrieval of local fragments, it demonstrates greater comprehensiveness and diversity when processing large-scale datasets.
[0063] Secondly, it can enhance the ability to handle complex problems.
[0064] When handling multi-hop reasoning, cross-document integration, or open-ended queries, GraphRAG technology effectively captures semantic dependencies through the hierarchical structure of knowledge graphs and community layering techniques. For example, in processing large-scale legal or medical datasets, GraphRAG technology demonstrates a deep understanding of complex semantics.
[0065] Third, it can improve the quality and diversity of answers.
[0066] Compared to traditional RAG techniques, GraphRAG achieves semantic aggregation through community detection and hierarchical summarization of knowledge graphs. By generating and summarizing community summaries in parallel, LLM can extract information from different perspectives, avoiding the limitations of traditional keyword matching. This improves the quality and diversity of answers generated by LLM. For example, in complex datasets, the diversity scores of answers generated by GraphRAG often far exceed those of traditional RAG methods.
[0067] However, while GraphRAG technology has the aforementioned technical advantages over traditional RAG technology, the differences in knowledge systems across different knowledge domains mean that the construction of the knowledge base currently relies heavily on the experience of industry experts when building knowledge graph-based knowledge bases for LLM.
[0068] Based on this, this application proposes a technical solution for automatically constructing a knowledge graph as a knowledge base for LLM by segmenting knowledge documents according to user-defined segmentation rules and using the resulting document segments as the granularity.
[0069] Please see Figure 1 , Figure 1 This specification illustrates a flowchart of a method for creating a knowledge base for an LLM; wherein the knowledge base created for the LLM contains a knowledge graph constructed based on user-uploaded knowledge documents; the method includes the following execution process:
[0070] Step 102: Obtain the knowledge document uploaded by the user to the target knowledge base; and obtain the first prompt word corresponding to the knowledge domain to which the knowledge document belongs, obtained by the user customizing the first prompt word template corresponding to the preset segmentation rule; wherein, the first prompt word is used to describe the knowledge extraction strategy customized by the user for the knowledge domain to which the knowledge document belongs; the first prompt word is used to describe the segmentation rule customized by the user for the knowledge domain to which the knowledge document belongs;
[0071] The entity executing the above method can be a server corresponding to a service provider that offers LLM invocation services to users; for example, in practical applications, the service provider can be the LLM operator, and the server can be a service platform that has deployed LLM.
[0072] In practical applications, the server can grant ordinary users the permission to create knowledge bases for LLM, allowing users to create personalized knowledge bases based on their own needs by uploading knowledge documents from different knowledge domains.
[0073] It should be noted that the knowledge base described in this specification specifically refers to a knowledge graph-based knowledge base created within the GraphRAG technical framework, based on user-uploaded knowledge documents. In other words, this user-created knowledge base can specifically contain a knowledge graph built upon user-uploaded knowledge documents.
[0074] When a user needs to create a target knowledge base for an LLM, they can upload the knowledge documents used to create the target knowledge base to the server. For example, the service provider can provide the user with a client for managing the knowledge base, allowing the user to interact with the server through the client to complete operations such as knowledge base creation and daily management.
[0075] In this specification, when creating a knowledge graph as a knowledge base based on user-uploaded knowledge documents, a finer-grained creation process can be adopted, using document fragmentation as the granularity.
[0076] In this scenario, the server obtains the knowledge document uploaded by the user to the target knowledge base. It can then further segment the knowledge document to obtain multiple document fragments.
[0077] The segmentation rules used by the server to segment the knowledge document can be either the server's default segmentation rules or user-defined segmentation rules corresponding to the knowledge domain to which the knowledge document belongs. In other words, in practical applications, the permission to customize segmentation rules can be granted to ordinary users, allowing them to not only upload knowledge documents to the target knowledge base but also to customize the segmentation rules corresponding to the knowledge domain to which the knowledge document belongs.
[0078] It should be noted that the specific form of the above segmentation rules is not specifically limited in this specification. In practical applications, the choice can be made flexibly based on specific needs.
[0079] In some embodiments, the semantic recognition capabilities of LLM can also be used to segment user-uploaded knowledge documents; in this case, the segmentation rules may specifically include prompt words for describing the segmentation rules; that is, user-defined segmentation rules may specifically be strategies in the form of prompt words.
[0080] In this scenario, users can also upload knowledge documents, custom segmentation rules, and custom knowledge extraction strategies to the target knowledge base they wish to create by performing upload operations on the client.
[0081] Please see Figure 2 , Figure 2 This is a schematic diagram illustrating a user-automated creation of a Graph knowledge base via a client, as shown in this specification.
[0082] like Figure 2 As shown, the client can provide an entry point for uploading knowledge documents in the management interface of the target knowledge base (e.g., Figure 2 The "Create New Knowledge Document" button allows users to upload knowledge documents to the target knowledge base. This can be a triggered action (such as a click) on this entry point. Once the client detects this triggered action, it can respond by sending a knowledge document upload request to the server.
[0083] Please continue reading Figure 2 After receiving the knowledge document upload request, the server can respond by returning an upload interface corresponding to the target knowledge base to the client, as well as segmentation rules that the user can select. These selectable segmentation rules may specifically include segmentation rules using LLM (Local Management Model). In addition to the upload interface, the information returned by the server to the client may also include a first prompt word template corresponding to the preset segmentation rules used when segmenting using LLM.
[0084] For example, such as Figure 2 As shown, these selectable segmentation rules can specifically include options such as segmentation by title, custom segmentation, large model segmentation, and automatic segmentation.
[0085] It should be noted that the aforementioned preset segmentation rule may specifically refer to the default knowledge extraction strategy adopted by the server when segmenting knowledge documents; correspondingly, the first prompt word template may specifically refer to the prompt word used to describe the default segmentation rule.
[0086] For example, in practical applications, the aforementioned target knowledge base may specifically be a newly added knowledge group in a knowledge base under a certain knowledge topic that the user has already created, while the aforementioned first prompt word template may specifically be a prompt word template manually configured by industry experts in the knowledge field related to the knowledge topic, based on their experience in that knowledge field.
[0087] Please continue reading Figure 2 After receiving the upload interface and the segmentation rules that the user can choose from from the server, the client can display the upload interface to the user and output the segmentation rules that the user can choose from in the upload interface.
[0088] like Figure 2 As shown, assuming the user has triggered the "large model segmentation" option included in these segmentation rules, the aforementioned second prompt word template can be further output to the user on the upload interface. This output second prompt word template can also be edited.
[0089] After the client displays the upload interface to the user, it can retrieve the knowledge documents uploaded by the user through this interface. In addition, the client can also retrieve the first prompt word obtained by the user through custom modifications to the first prompt word template; specifically, this first prompt word describes the segmentation rules customized by the user for the knowledge domain to which the knowledge document belongs. Then, the client can further upload the retrieved user-uploaded knowledge document and the aforementioned first prompt word to the server.
[0090] Step 104: Send the knowledge document and the first prompt word to the LLM, so that the LLM can divide the knowledge document into multiple document fragments based on the segmentation rules described by the first prompt word;
[0091] After receiving the knowledge document and the aforementioned first prompt word uploaded by the client, when the server needs to perform segmentation processing on the knowledge document, it can further send the knowledge document and the aforementioned first prompt word to the LLM, so that the LLM can segment the knowledge document into multiple document fragments based on the segmentation rules described by the first prompt word.
[0092] Step 106: Extract knowledge triples from the document segments, create sub-knowledge graphs corresponding to the multiple document segments based on the extracted knowledge triples, and store the sub-knowledge graphs in the knowledge base. In some embodiments, the permission to customize knowledge extraction strategies can be granted to ordinary users, allowing users to customize knowledge extraction strategies corresponding to the knowledge domain to which the knowledge document belongs, in addition to uploading knowledge documents to the target knowledge base during the creation of the target knowledge base.
[0093] Specifically, the aforementioned knowledge extraction strategies refer to strategies used to extract knowledge triples from knowledge documents. A knowledge triple is a general representation in knowledge graphs used to describe entities and their relationships. It is an ordered set of three elements: subject, predicate, and object. In knowledge graphs, these three elements are also referred to as entity, relation, and entity.
[0094] In addition to obtaining knowledge documents uploaded by users to the target knowledge base, the server can also obtain knowledge extraction strategies that are user-defined and set to correspond to the knowledge domain to which the knowledge document belongs.
[0095] It should be noted that the specific form of the knowledge extraction strategy described above is not specifically limited in this specification. In practical applications, it can be flexibly selected based on specific needs.
[0096] In some embodiments, the semantic recognition capabilities of LLM can be used to extract knowledge triples from user-uploaded knowledge documents; in this case, the above-mentioned knowledge extraction strategy may specifically include prompts for describing the knowledge extraction strategy; that is, the user-defined knowledge extraction strategy may specifically be a strategy in the form of prompts.
[0097] In this scenario, the service provider can offer users a client for managing the knowledge base. Users can then upload knowledge documents and custom-defined knowledge extraction strategies to the target knowledge base they wish to create using this client.
[0098] Please see Figure 3 , Figure 3 This is an illustration of another method by which a user automatically creates a Graph knowledge base via a client, as shown in this specification.
[0099] like Figure 3 As shown, the client can still provide an entry point for uploading knowledge documents in the management interface of the target knowledge base (e.g., Figure 3 The "Create New Knowledge Document" button allows users to upload knowledge documents to the target knowledge base. This can be a triggered action (such as a click) on this entry point. Once the client detects this triggered action, it can respond by sending a knowledge document upload request to the server.
[0100] Please continue reading Figure 3After receiving the knowledge document upload request, the server can respond to the knowledge document upload request and return to the client the upload interface corresponding to the target knowledge base, the segmentation rules that the user can select, and the second prompt word template corresponding to the preset knowledge extraction strategy.
[0101] These selectable segmentation rules can specifically include segmentation rules using LLM. The information returned by the server to the client, in addition to the upload interface and the first prompt word template corresponding to the preset knowledge extraction strategy, may also include a second prompt word template corresponding to the preset segmentation rules used when segmenting using LLM.
[0102] For example, such as Figure 3 As shown, these selectable segmentation rules can specifically include options such as segmentation by title, custom segmentation, large model segmentation, and automatic segmentation.
[0103] It should be noted that the aforementioned preset segmentation rule may also be the default segmentation rule used by the server when segmenting knowledge documents; correspondingly, the aforementioned second prompt word template may be a prompt word used to describe the default segmentation rule.
[0104] For example, in practical applications, the aforementioned target knowledge base can be a newly added knowledge group in a knowledge base under a certain knowledge topic that the user has already created, while the aforementioned second prompt word template can be a segmentation rule manually configured by industry experts in the knowledge field related to the knowledge topic, based on their experience in that knowledge field.
[0105] Please continue reading Figure 3 After receiving the upload interface, the segmentation rules that the user can choose from, and the second prompt word template returned by the server, the client can display the upload interface to the user and output the segmentation rules and the second prompt word template that the user can choose from in the upload interface.
[0106] like Figure 3 As shown, assuming the user has triggered the "large model segmentation" option included in these segmentation rules, the aforementioned first prompt word template can be further output to the user on the upload interface. This output first prompt word template can also be edited.
[0107] After the client displays the upload interface to the user, it can obtain the knowledge document uploaded by the user through this interface. In addition, the client can also obtain a first prompt word obtained by customizing the first prompt word template, and a second prompt word obtained by customizing the second prompt word. The first prompt word describes the segmentation rules customized by the user for the knowledge domain to which the knowledge document belongs; the second prompt word describes the knowledge extraction strategy customized by the user for the knowledge domain to which the knowledge document belongs. Then, the client can further upload the obtained user-uploaded knowledge document, the aforementioned first prompt word, and the aforementioned second prompt word to the server.
[0108] It should be noted that the specific content of the above knowledge extraction strategies will not be specifically limited in this specification. In practical applications, the specific content of the above knowledge extraction strategies usually depends on the specific strategy.
[0109] In some embodiments, in order to ensure that the above knowledge extraction strategy can have a good knowledge extraction effect, the above knowledge extraction strategy can be designed as a phased extraction strategy, which may specifically include a first-stage knowledge extraction strategy and a second-stage knowledge extraction strategy.
[0110] Specifically, the knowledge extraction strategy in the first stage can be used to extract entities contained in a knowledge document; the knowledge extraction strategy in the second stage can be used to extract the entity relationships between the entities extracted in the first stage. In other words, the first stage extracts the entities contained in the knowledge document, and then, based on the entities extracted in the first stage, the second stage further extracts the relationships between these entities.
[0111] In this scenario, the second prompt word template sent by the server to the client can specifically include a prompt word template corresponding to the knowledge extraction strategy of the first stage (which can be referred to as the third prompt word template); and a prompt word template corresponding to the knowledge extraction strategy of the second stage (which can be referred to as the fourth prompt word template). The second prompt word obtained by the user by modifying this second prompt word template can specifically include a prompt word obtained by the user customizing the prompt word template corresponding to the knowledge extraction strategy of the first stage (which can be referred to as the third prompt word); and a prompt word obtained by the user customizing the prompt word template corresponding to the knowledge extraction strategy of the second stage (which can be referred to as the fourth prompt word). The third prompt word can be used to describe the first-stage knowledge extraction strategy customized by the user for the knowledge domain to which the knowledge document belongs; the fourth prompt word can be used to describe the second-stage knowledge prompt strategy customized by the user for the knowledge domain to which the knowledge document belongs.
[0112] It should be emphasized that in practical applications, when the above knowledge extraction strategy is designed as a phased extraction strategy, the phases included in the knowledge extraction strategy can be expanded based on actual needs.
[0113] For example, in some embodiments, the knowledge extraction strategy of the first stage described above can be further divided into two sub-stages, such as the first sub-stage and the second sub-stage; wherein, the first sub-stage can be used to extract entities of a specific knowledge domain contained in the knowledge document. And the second sub-stage can be used to extract entities of a general knowledge domain contained in the knowledge document.
[0114] In some embodiments, after receiving the knowledge document, the first prompt word, and the second prompt word uploaded by the client, when the server needs to perform segmentation processing on the knowledge document, it can further send the knowledge document and the first prompt word to the LLM, so that the LLM can segment the knowledge document into multiple document fragments based on the segmentation rules described by the second prompt word.
[0115] In some embodiments, after the server divides the knowledge document into multiple document fragments, it can further send each document fragment and the aforementioned second prompt word to the LLM, so that the LLM can extract knowledge triples from the document fragments based on the knowledge extraction strategy described by the second prompt word, and then create sub-knowledge graphs corresponding to each document fragment based on the extracted knowledge triples.
[0116] For example, if the above knowledge extraction strategy includes a first-stage knowledge extraction strategy and a second-stage knowledge extraction strategy, and the above second prompt word includes a third prompt word corresponding to the first-stage knowledge extraction strategy and a fourth prompt word corresponding to the second-stage knowledge extraction strategy, the server can further send each document fragment, the above third prompt word, and the above fourth prompt word to the LLM, so that the LLM can extract entities from the document fragment based on the first-stage knowledge extraction strategy described by the third prompt word, and then further extract the relationship between the entities extracted in the first stage contained in the document fragment based on the second-stage knowledge extraction strategy described by the fourth prompt word.
[0117] Specifically, when creating a sub-knowledge graph corresponding to a document segment based on the knowledge triples extracted from any document segment, the subject and object in each extracted knowledge triple can be used as nodes in the sub-knowledge graph, and the predicate in the knowledge triple can be used as the relationship between the node corresponding to the subject and the node corresponding to the object to generate the sub-knowledge graph.
[0118] It should be noted that in practical applications, the content contained in the aforementioned knowledge document can be multimodal. For example, in fields such as healthcare and finance, the knowledge document may contain multimodal information such as text, tables, and images. In this case, the entities extracted from the knowledge document can include not only text-based entities identified from the text itself, but also text-based entities identified from information contained in tables and images. When the information contained in tables and images cannot be parsed, the tables and images can be treated as a whole as indivisible entities, and treated as independent nodes in the knowledge graph.
[0119] Once the server creates sub-knowledge graphs corresponding to each document fragment based on the extracted knowledge triples, these sub-knowledge graphs can be further stored in the knowledge base.
[0120] Specifically, when the server further stores the sub-knowledge graphs corresponding to each document fragment into the knowledge base, it can first create a hybrid index for the sub-knowledge graph, and then store the sub-knowledge graph and the hybrid index created for the sub-knowledge graph together into the knowledge base.
[0121] For example, in some embodiments, the hybrid index created by the server for the sub-knowledge graph may specifically include a graph structure index corresponding to the sub-knowledge graph, an entity vector index corresponding to the entities contained in the sub-knowledge graph, and a relation vector index corresponding to the relations contained in the sub-knowledge graph.
[0122] In this scenario, when the server further stores the sub-knowledge graph corresponding to any document fragment into the knowledge base, it can first establish a mapping relationship between the entities contained in the sub-knowledge graph and the document fragments corresponding to it. Based on the attribute information of the sub-knowledge graph, a graph structure index corresponding to the sub-knowledge graph is generated; based on the attribute information of the entities contained in the sub-knowledge graph, an entity vector index corresponding to each entity is generated; and based on the attribute information of the relations contained in the sub-knowledge graph, a relation vector index corresponding to each relation is generated. Then, on one hand, the sub-knowledge graph, the graph structure index, the entity vector index, and the relation vector index can be stored in a graph database corresponding to the knowledge base; on the other hand, the mapping relationship can also be stored in a relational database corresponding to the knowledge base.
[0123] Specifically, graph structure indexes can include any form of index built based on attribute information from knowledge graphs, capable of preserving structured relationships between nodes (such as causal relationships and attribute relationships between entities). Entity vector indexes and relation vector indexes typically refer to vectors obtained by vectorizing the attribute information of entities or relations.
[0124] It's important to emphasize that, if compatibility with traditional RAG technology is required, the hybrid index created by the server for the sub-knowledge graph can also include text vector indexes of the document fragments corresponding to that sub-knowledge graph. That is, the vector obtained by vectorizing the entire document fragment. In this case, the server can store this text vector index in a relational database corresponding to the knowledge base.
[0125] It should also be noted that the above mapping relationship usually does not fall under the category of the hybrid index. Establishing this mapping relationship is primarily for the purpose of quickly locating specific document fragments based on entities (such as entity names) during the retrieval phase. Of course, in practical applications, this mapping relationship can also specifically be a mapping relationship between edges contained in a sub-knowledge graph and the corresponding document fragments of that sub-knowledge graph. In this case, establishing this mapping relationship is mainly for the purpose of quickly locating specific document fragments based on edges (such as edge type or name) during the retrieval phase.
[0126] In some embodiments, after storing the created sub-knowledge graphs in the knowledge base, the server, during the routine management of the sub-knowledge graphs contained in the knowledge base, can also identify sub-knowledge graphs containing the same entities stored in the graph database and merge these sub-knowledge graphs to obtain a merged sub-knowledge graph. The specific details of identifying sub-knowledge graphs containing the same entities stored in the graph database and merging them are not detailed in this specification; those skilled in the art can refer to relevant technical descriptions.
[0127] In addition, community clustering can be performed on the sub-knowledge graphs stored in the graph database to generate at least one knowledge graph community. The specific details of community clustering on the sub-knowledge graphs stored in the graph database are not elaborated here; those skilled in the art can refer to relevant technical documents. For example, in practical applications, community discovery algorithms can be used to cluster sub-knowledge graphs with the same or similar semantics into a single knowledge graph community. Multiple document fragments obtained by the server from segmenting user-uploaded knowledge documents can also be returned to the client for centralized maintenance.
[0128] For example, the client can segment these documents into a list and display it to the user through a management interface, allowing the user to maintain it manually.
[0129] In practical applications, users can modify and update these document fragments on a fragment-by-fragment basis according to specific needs. The client can periodically scan these document fragments to identify the target document fragments that have been updated.
[0130] For example, the client can periodically recalculate the digest value (such as hash value) of each document fragment and determine whether the digest value of each document fragment has changed by comparing the recalculated digest value with the previously saved digest value; if the digest value of any target document fragment has changed, it indicates that the target document fragment has been updated.
[0131] When any target document fragment within a knowledge document uploaded by a user is updated, the client can re-upload that target document fragment to the server. After receiving the updated target document fragment re-uploaded by the user, the server can reconstruct the sub-knowledge graph corresponding to that target document fragment according to a similar process, and update the hybrid index and the aforementioned mapping relationship corresponding to that sub-knowledge graph.
[0132] Specifically, the server can re-extract knowledge triples from the updated target document segment based on the same knowledge extraction strategy previously set by the user, and recreate the sub-knowledge graph corresponding to the target document segment based on the extracted knowledge triples.
[0133] The specific details of re-extracting knowledge triples from the updated target document segment and recreating the sub-knowledge graph corresponding to the target document segment based on the extracted knowledge triples will not be elaborated here.
[0134] Once the server recreates the sub-knowledge graph corresponding to the target document segment, it can then further search the knowledge base for the sub-knowledge graph corresponding to the target document segment (that is, the sub-knowledge graph corresponding to the target document segment before the update).
[0135] In some embodiments, when the server searches for the sub-knowledge graph corresponding to the target document segment in the knowledge base, it can first query the above-mentioned mapping relationship stored in the relational database corresponding to the knowledge base to determine the entities that have a mapping relationship with the target document segment; at this time, the entities found are entities extracted from the target document segment before the update.
[0136] Then, based on the graph structure index stored in the graph database, a sub-knowledge graph containing the entity can be searched in the graph database to serve as the sub-knowledge graph corresponding to the target document fragment.
[0137] For example, in some embodiments, when searching for a sub-knowledge graph containing the aforementioned entity in the graph database based on the graph structure index stored in the graph database, specifically, one can first search for a target knowledge graph community that matches the attribute information of the entity from at least one knowledge graph community stored in the graph database; for example, searching for a knowledge graph community that is semantically similar to or the same as the entity; and then, based on the graph structure index stored in the graph database, further searching for a sub-knowledge graph containing the aforementioned entity in the sub-knowledge graph contained in the target knowledge graph community.
[0138] In this way, when the number of sub-knowledge graphs contained in the knowledge base is large, the scope of sub-graph retrieval can be narrowed by first identifying the knowledge graph community where the target sub-knowledge graph belongs, thereby improving retrieval efficiency.
[0139] The process of searching for sub-knowledge graphs containing the entity in the graph database based on the graph structure index will not be detailed in this specification. In practical applications, those skilled in the art can refer to relevant technical records. For example, in practical applications, sub-graph retrieval can be performed based on graph traversal algorithms (such as community detection, shortest path, etc.).
[0140] After the server finds the sub-knowledge graph corresponding to the target document segment in the knowledge base, it incrementally updates the sub-knowledge graph corresponding to the target document segment based on the newly created sub-knowledge graph.
[0141] In some embodiments, when incrementally updating the sub-knowledge graph corresponding to the target document segment based on the recreated sub-knowledge graph corresponding to the target document segment, a mapping relationship between the entities contained in the recreated sub-knowledge graph corresponding to the target document segment and the document segment corresponding to the sub-knowledge graph can be generated. A graph structure index corresponding to the sub-knowledge graph can be regenerated based on the attribute information of the recreated sub-knowledge graph. An entity vector index corresponding to the entity can be regenerated based on the attribute information of the entity contained in the recreated sub-knowledge graph. A relation vector index corresponding to the relation can be regenerated based on the attribute information of the relation contained in the recreated sub-knowledge graph.
[0142] Then, on the one hand, the recreated sub-knowledge graph, the regenerated graph structure index, the regenerated entity vector index, and the regenerated relation vector index can be stored in the graph database corresponding to the knowledge base, so as to update the sub-knowledge graph corresponding to the target document fragment, the graph structure index corresponding to the sub-knowledge graph, the entity vector index corresponding to the entities contained in the sub-knowledge graph, and the relation vector index corresponding to the relations contained in the sub-knowledge graph that are already stored in the graph database. On the other hand, the regenerated mapping relationship can be stored in the relational database corresponding to the knowledge base, so as to update the mapping relationship already stored in the relational database.
[0143] In some embodiments, the server can also generate answers to user-input questions based on structured knowledge stored in the knowledge graph.
[0144] In this scenario, users can input their questions on the server-side service interface corresponding to the LLM model. After receiving the user's input, the server can extract keywords from the question. For example, it can leverage the semantic recognition capabilities of the LLM model to extract keywords from the question by editing prompts. Then, it can generate query vectors corresponding to the extracted keywords.
[0145] After generating the query vector, the vector similarity between the query vector and the entity vector indexes stored in the graph database corresponding to the knowledge base can be further calculated, and at least one entity vector index with the highest vector similarity can be selected; for example, the N entity vector indices with the highest vector similarity can be selected; N is a preset number threshold.
[0146] Then, on the one hand, the entity corresponding to at least one entity vector index mentioned above can be identified, and the sub-knowledge graph containing these entities can be queried in the graph database based on the graph structure index stored in the graph database.
[0147] On the other hand, the mapping relationships stored in the relational database corresponding to the knowledge base can be queried to determine the document fragments that have mapping relationships with these entities;
[0148] Finally, the server can generate question prompts corresponding to the user's question based on the user's input question, the retrieved sub-knowledge graph containing these entities, and the document fragments that have mapping relationships with these entities. These prompts are then sent to the LLM (Local Management Module), which generates the answer text corresponding to the user's question based on them. Since the question prompts encapsulate the sub-knowledge graph containing these entities and the document fragments that have mapping relationships with these entities as the context for generating the answer, the accuracy of the answer text generated by the LLM for the user can be improved.
[0149] In some embodiments, when the server calculates the vector similarity between the query vector and the entity vector indexes stored in the graph database, and selects at least one entity vector index with the highest vector similarity, it may first calculate the vector similarity between the query vector and the community vector indexes stored in the graph database, and select at least one target knowledge graph community with the highest vector similarity; then, it further calculates the vector similarity between the query vector and the entity vector indexes corresponding to the entities contained in the sub-knowledge graphs of the target knowledge graph community, and selects at least one entity vector index with the highest vector similarity.
[0150] In this way, when the number of entity vector indexes is large, the scope of entity vector index filtering can be narrowed by first identifying the knowledge graph community with the highest similarity to the query vector, thereby improving filtering efficiency.
[0151] It should be noted that the processes mentioned in the above embodiments for creating sub-knowledge graphs corresponding to document fragments, as well as the process for incrementally updating the sub-knowledge graphs, can all be implemented in practical applications by creating relevant asynchronous tasks and executing them asynchronously.
[0152] For example, in some embodiments, when the server creates sub-knowledge graphs corresponding to each document fragment based on the extracted knowledge triples, it can specifically generate a first asynchronous task for constructing the sub-knowledge graph and add this first asynchronous task as a task to be executed to a preset task processing queue. Then, the server can periodically read the first asynchronous task from the task processing queue and trigger its execution to perform fragment processing on the knowledge document to obtain multiple document fragments. Based on the aforementioned knowledge extraction strategy, knowledge triples are extracted from each document fragment, and then a sub-knowledge graph corresponding to each document fragment is created based on the extracted knowledge triples.
[0153] In another embodiment, when the server creates a sub-knowledge graph corresponding to a document segment based on the knowledge triples re-extracted from the updated document segment, it can also generate a second asynchronous task for updating the sub-knowledge graph and add this second asynchronous task as a task to be executed to a preset task processing queue. Then, the server can periodically read the second asynchronous task from the task processing queue and trigger its execution. Based on the aforementioned knowledge extraction strategy, it can re-extract knowledge triples from the updated document segment, recreate the sub-knowledge graph corresponding to the document segment based on the extracted knowledge triples, and update the sub-knowledge graph corresponding to the document segment based on the recreated sub-knowledge graph.
[0154] Please see Figure 4 , Figure 4 This specification illustrates a flowchart of a method for creating a knowledge base for an LLM; wherein the knowledge base created for the LLM contains a knowledge graph constructed based on user-uploaded knowledge documents; the method includes the following execution process:
[0155] Step 402: In response to the user's operation of uploading a knowledge document to the target knowledge base, obtain the knowledge document uploaded by the user; and obtain a first prompt word corresponding to the knowledge domain to which the knowledge document belongs, obtained by the user customizing a first prompt word template corresponding to a preset segmentation rule; wherein, the first prompt word is used to describe the knowledge extraction strategy customized by the user for the knowledge domain to which the knowledge document belongs; the first prompt word is used to describe the segmentation rule customized by the user for the knowledge domain to which the knowledge document belongs;
[0156] Step 404: The knowledge document and the first prompt word are sent to the server, so that the server can further send the knowledge document and the first prompt word to the LLM, so that the LLM can divide the knowledge document into multiple document fragments based on the segmentation rules described by the first prompt word; extract knowledge triples from the document fragments, create sub-knowledge graphs corresponding to the multiple document fragments based on the extracted knowledge triples, and store the sub-knowledge graphs in the knowledge base;
[0157] The subject executing the above method can be a client, specifically a client provided by the server to the user for managing the knowledge base. The user can interact with the server through the client to complete operations such as creating and managing the knowledge base.
[0158] In some embodiments, the semantic recognition capabilities of LLM can be used to segment user-uploaded knowledge documents; correspondingly, the segmentation rules can specifically include prompt words to describe the segmentation rules; that is, user-defined segmentation rules can specifically be strategies in the form of prompt words.
[0159] In this scenario, users can upload knowledge documents and custom-defined segmentation rules to the target knowledge base they wish to create by performing an upload operation on the client.
[0160] The client can respond to the user's operation of uploading knowledge documents to the target knowledge base, send a knowledge document upload request to the server, and obtain the upload interface corresponding to the target knowledge base returned by the server in response to the knowledge document upload request; as well as the first prompt word template corresponding to the preset segmentation rule; the client can display the above upload interface to the user and output the above first prompt word template in the upload interface;
[0161] Then, the client can obtain the knowledge document uploaded by the user through the upload interface, as well as the first prompt word obtained by the user through custom modification of the first prompt word template; wherein, the first prompt word is used to describe the segmentation rules customized by the user for the knowledge domain to which the knowledge document belongs;
[0162] Finally, the client can send the acquired knowledge document and the first prompt word to the server, so that the server can segment the knowledge document based on the segmentation rules described by the first prompt word to obtain multiple document segments, extract knowledge triples from these document segments, and then create sub-knowledge graphs corresponding to the multiple document segments based on the extracted knowledge triples.
[0163] In some embodiments, the semantic recognition capabilities of LLM can be used to extract knowledge triples from user-uploaded knowledge documents; correspondingly, the above-mentioned knowledge extraction strategy may specifically include prompt words for describing the knowledge extraction strategy; that is, the user-defined knowledge extraction strategy may specifically be a strategy in the form of prompt words.
[0164] In this scenario, users can also upload knowledge documents, custom segmentation rules, and custom knowledge extraction strategies to the target knowledge base they wish to create by performing upload operations on the client.
[0165] The client can respond to a user's operation of uploading knowledge documents to a target knowledge base by sending a knowledge document upload request to the server and obtaining the upload interface corresponding to the target knowledge base, a first prompt word template corresponding to a preset segmentation rule, and a second prompt word template corresponding to a preset knowledge extraction strategy returned by the server in response to the knowledge document upload request; the client can display the upload interface to the user and output the first prompt word template and the second prompt word template in the upload interface;
[0166] Then, the client can obtain the knowledge document uploaded by the user through the upload interface, the first prompt word obtained by the user through custom modification of the first prompt word template, and the second prompt word obtained by the user through custom modification of the second prompt word; wherein, the first prompt word is used to describe the segmentation rule customized by the user for the knowledge domain to which the knowledge document belongs; the second prompt word is used to describe the knowledge extraction strategy customized by the user for the knowledge domain to which the knowledge document belongs;
[0167] Finally, the client can send the knowledge document, the first prompt word, and the second prompt word to the server. The server then sends the first and second prompt words to the LLM (Local Knowledge Graph). The LLM, based on the segmentation rules described by the first prompt word, segments the knowledge document into multiple document fragments and extracts knowledge triples from the document fragments based on the knowledge extraction strategy described by the second prompt word. Furthermore, it creates sub-knowledge graphs corresponding to each of the multiple document fragments based on the knowledge triples extracted by the LLM. In some embodiments, to ensure that the above knowledge extraction strategy has good knowledge extraction performance, the knowledge extraction strategy can be designed as a staged extraction strategy, specifically including a first-stage knowledge extraction strategy and a second-stage knowledge extraction strategy.
[0168] Specifically, the knowledge extraction strategy in the first stage can be used to extract entities contained in a knowledge document; the knowledge extraction strategy in the second stage can be used to extract the entity relationships between the entities extracted in the first stage. In other words, the first stage extracts the entities contained in the knowledge document, and then, based on the entities extracted in the first stage, the second stage further extracts the relationships between these entities.
[0169] In this scenario, the second prompt word template sent by the server to the client can specifically include a prompt word template corresponding to the knowledge extraction strategy of the first stage (which can be referred to as the third prompt word template); and a prompt word template corresponding to the knowledge extraction strategy of the second stage (which can be referred to as the fourth prompt word template). The first prompt word obtained by the user by modifying the prompt word template can specifically include a prompt word obtained by the user customizing the prompt word template corresponding to the knowledge extraction strategy of the first stage (which can be referred to as the third prompt word); and a prompt word obtained by the user customizing the prompt word template corresponding to the knowledge extraction strategy of the second stage (which can be referred to as the fourth prompt word). The third prompt word can be used to describe the first-stage knowledge extraction strategy customized by the user for the knowledge domain to which the knowledge document belongs; the fourth prompt word can be used to describe the second-stage knowledge prompt strategy customized by the user for the knowledge domain to which the knowledge document belongs.
[0170] It should be emphasized that in practical applications, when the above knowledge extraction strategy is designed as a phased extraction strategy, the phases included in the knowledge extraction strategy can be expanded based on actual needs.
[0171] For example, in some embodiments, the knowledge extraction strategy of the first stage described above can be further divided into two sub-stages, such as the first sub-stage and the second sub-stage; wherein, the first sub-stage can be used to extract entities of a specific knowledge domain contained in the knowledge document. And the second sub-stage can be used to extract entities of a general knowledge domain contained in the knowledge document.
[0172] It needs to be emphasized that, Figure 4 The illustrated method flow is the execution flow from the client's perspective. The implementation details of each step in this method flow are as follows: Figure 1 The method flow is the same as described above, and those skilled in the art can refer to the description of the previous embodiments. It will not be repeated in this embodiment.
[0173] In the above technical solutions, on the one hand, by automatically constructing graph knowledge as an LLM knowledge base based on knowledge documents, it can not only greatly reduce the construction threshold of knowledge base in the form of knowledge graphs and improve the degree of automation in constructing knowledge base in the form of knowledge graphs, but also save human resources costs; for example, it realizes an end-to-end automated pipeline from original knowledge documents → document segmentation → knowledge triple extraction → knowledge graph construction.
[0174] On the other hand, the user-defined segmentation rules for knowledge documents in different knowledge domains allow this solution to adapt to various knowledge domains, improving its versatility in building knowledge graph-based knowledge bases. Furthermore, by automatically constructing multiple sub-knowledge graphs as the knowledge base using document shards as the granularity of LLM, when the content of the knowledge document used to build the knowledge graph is updated, only the sub-knowledge graph corresponding to the updated document shard needs to be incrementally updated. This avoids the resource waste and time consumption of a full reconstruction of the knowledge graph, improving the update efficiency of the knowledge base. For example, when a document shard in a knowledge document is updated, only the sub-knowledge graph and hybrid index need to be reconstructed for the updated document shard.
[0175] Corresponding to the embodiments of the foregoing methods, this specification also provides embodiments of apparatus, electronic devices, and storage media.
[0176] Figure 5 This is a schematic structural diagram of an electronic device provided in an exemplary embodiment. Please refer to... Figure 5At the hardware level, the device includes a processor 502, an internal bus 504, a network interface 506, memory 508, and non-volatile memory 510, and may also include other necessary hardware. One or more embodiments of this specification can be implemented in software, for example, the processor 502 reads the corresponding computer program from the non-volatile memory 510 into memory 508 and then runs it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0177] like Figure 6 As shown, Figure 6 This specification is a block diagram illustrating an apparatus for creating a knowledge base for an LLM according to an exemplary embodiment, the apparatus being operable in, for example... Figure 4 The electronic device shown implements the technical solution of this specification. The knowledge base created for the LLM includes a knowledge graph constructed based on user-uploaded knowledge documents; the device 60 includes:
[0178] The first acquisition module 601 acquires knowledge documents uploaded by users to a target knowledge base; and a first prompt word corresponding to the knowledge domain to which the knowledge document belongs, obtained by the user customizing a first prompt word template corresponding to a preset segmentation rule; wherein, the first prompt word is used to describe the segmentation rule customized by the user for the knowledge domain to which the knowledge document belongs;
[0179] The first sending module 602 sends the knowledge document and the first prompt word to the LLM, so that the LLM can segment the knowledge document into multiple document fragments based on the segmentation rules described by the first prompt word.
[0180] The creation module 602 extracts knowledge triples from the document segments, creates sub-knowledge graphs corresponding to the multiple document segments based on the extracted knowledge triples, and stores the sub-knowledge graphs in the knowledge base.
[0181] like Figure 7 As shown, Figure 7 This is a block diagram illustrating, according to an exemplary embodiment, another apparatus for creating a knowledge base for an LLM, which can operate in, for example... Figure 5 The electronic device shown implements the technical solution of this specification. The knowledge base created for LLM includes a knowledge graph constructed based on user-uploaded knowledge documents; the device 70 includes:
[0182] The second acquisition module 701, in response to the user's operation of uploading a knowledge document to the target knowledge base, acquires the knowledge document uploaded by the user; and obtains a first prompt word corresponding to the knowledge domain to which the knowledge document belongs, obtained by the user customizing a first prompt word template corresponding to a preset segmentation rule; wherein, the first prompt word is used to describe the segmentation rule customized by the user for the knowledge domain to which the knowledge document belongs;
[0183] The second sending module 702 sends the knowledge document and the first prompt word to the server, so that the server can further send the knowledge document and the first prompt word to the LLM, so that the LLM can segment the knowledge document into multiple document fragments based on the segmentation rules described by the first prompt word; extract knowledge triples from the document fragments, create sub-knowledge graphs corresponding to the multiple document fragments based on the extracted knowledge triples, and store the sub-knowledge graphs in the knowledge base.
[0184] Accordingly, this specification also provides an electronic device including a processor; a memory for storing processor-executable instructions; wherein the processor is configured to implement all the steps in the previously described method flow.
[0185] Accordingly, this specification also provides a computer-readable storage medium having stored thereon executable computer program instructions; wherein, when executed by a processor, the instructions implement all the steps in the previously described method flow.
[0186] Accordingly, this specification also provides a computer program product having executable computer program instructions stored thereon; wherein, when the computer program instructions are executed by a processor, they implement all the steps in the previously described method flow.
[0187] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0188] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, ASICs, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0189] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or physical entities, or by products with certain functions. A typical implementation device is a server system. Of course, this application does not exclude the possibility that, with the future development of computer technology, the computer implementing the functions of the above embodiments can be, for example, a personal computer, a laptop computer, an in-vehicle human-machine interaction device, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.
[0190] While one or more embodiments of this specification provide the operational steps of the methods described in the embodiments or flowcharts, more or fewer operational steps may be included based on conventional or non-inventive means. The order of steps listed in the embodiments is merely one possible order of execution among many steps and does not represent the only possible order. In actual device or end product execution, the methods shown in the embodiments or drawings may be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed data processing environment). The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitations, the presence of other identical or equivalent elements in the process, method, product, or apparatus that includes the elements is not excluded. For example, the use of terms such as "first," "second," etc., is to denote names and does not indicate any particular order.
[0191] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, when implementing one or more of these specifications, the functions of each module can be implemented in one or more software and / or hardware components, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.
[0192] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0193] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0194] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0195] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0196] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0197] Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0198] Those skilled in the art will understand that one or more embodiments of this specification can be provided as a method, system, or computer program product. Therefore, one or more embodiments of this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0199] One or more embodiments of this specification can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a particular task or implement a particular abstract data type. One or more embodiments of this specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0200] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, system embodiments are basically similar to method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. In the description of this specification, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0201] The above description is merely an embodiment of one or more embodiments of this specification and is not intended to limit the scope of this specification. Various modifications and variations can be made to the one or more embodiments of this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims.
Claims
1. A method for creating a knowledge base for an LLM, wherein, The knowledge base created for LLM contains a knowledge graph built based on user-uploaded knowledge documents; the method includes: The system retrieves knowledge documents uploaded by users to a target knowledge base; and obtains a first prompt word corresponding to the knowledge domain to which the knowledge document belongs, obtained by the user customizing a first prompt word template corresponding to a preset segmentation rule; wherein the first prompt word describes the segmentation rule customized by the user for the knowledge domain to which the knowledge document belongs; and sends the knowledge document and the first prompt word to an LLM, so that the LLM can segment the knowledge document into multiple document fragments based on the segmentation rule described by the first prompt word. Knowledge triples are extracted from the document segments, and sub-knowledge graphs corresponding to the multiple document segments are created based on the extracted knowledge triples, and the sub-knowledge graphs are stored in the knowledge base.
2. The method as described in claim 1, The process includes: acquiring knowledge documents uploaded by users to a target knowledge base; and obtaining first prompt words corresponding to the knowledge domain of the knowledge documents, obtained by the user through custom modification of a first prompt word template corresponding to a preset segmentation rule. In response to a knowledge document upload request sent by the client, an upload interface corresponding to the target knowledge base is returned to the client; In addition, a first prompt word template corresponding to a preset segmentation rule is provided so that the client can display the upload interface to the user and output the first prompt word template in the upload interface. The system obtains the knowledge document uploaded by the user through the upload interface, and the first prompt word obtained by the user through custom modification of the first prompt word template.
3. The method as described in claim 2, wherein the knowledge extraction strategy used to extract knowledge triples from the document fragments is a user-defined knowledge extraction strategy corresponding to the knowledge domain to which the knowledge document belongs; The knowledge extraction strategy includes prompt words used to describe the knowledge extraction strategy; In response to a knowledge document upload request sent by the client, the system returns an upload interface corresponding to the target knowledge base to the client. In addition, a first prompt word template corresponding to a preset segmentation rule is provided, which is displayed to the user by the client on the upload interface, and the first prompt word template is output on the upload interface, including: In response to a knowledge document upload request sent by a client, the system returns to the client an upload interface corresponding to the target knowledge base, a first prompt word template corresponding to a preset segmentation rule, and a second prompt word template corresponding to a preset knowledge extraction strategy, so that the client can display the upload interface to the user and output the first prompt word template and the second prompt word template in the upload interface. Acquiring the knowledge document uploaded by the user through the upload interface, and the first prompt word obtained by the user through custom modification of the first prompt word template, including: The system obtains a knowledge document uploaded by a user through the upload interface, a first prompt word obtained by the user customizing the first prompt word template, and a second prompt word obtained by the user customizing the second prompt word; wherein, the second prompt word is used to describe the knowledge extraction strategy customized by the user for the knowledge domain to which the knowledge document belongs; Extracting knowledge triples from the document fragments includes: The document fragments and the second prompt words are sent to the LLM so that the LLM can extract knowledge triples from the document fragments based on the knowledge extraction strategy described by the second prompt words.
4. The method of claim 3, wherein storing the sub-knowledge graph in the knowledge base comprises: Generate the mapping relationship between the entities contained in the sub-knowledge graph and the document fragments corresponding to the sub-knowledge graph; A graph structure index corresponding to the sub-knowledge graph is generated based on the attribute information of the sub-knowledge graph; an entity vector index corresponding to the entity is generated based on the attribute information of the entity contained in the sub-knowledge graph; and a relation vector index corresponding to the relation is generated based on the attribute information of the relation contained in the sub-knowledge graph. The sub-knowledge graph, the graph structure index, the entity vector index, and the relation vector index are stored in a graph database corresponding to the knowledge base, and the mapping relationship is stored in a relational database corresponding to the knowledge base.
5. The method of claim 4, further comprising: In response to an update of any target document fragment contained in the knowledge document, the updated target document fragment uploaded by the user is obtained; The target document fragment and the second prompt word are sent to the LLM so that the LLM can re-extract knowledge triples from the target document fragment based on the knowledge extraction strategy described by the second prompt word; Based on the extracted knowledge triples, a sub-knowledge graph corresponding to the target document fragment is recreated; In addition, the sub-knowledge graph corresponding to the target document segment is searched in the knowledge base, and the searched sub-knowledge graph corresponding to the target document segment is incrementally updated based on the newly created sub-knowledge graph corresponding to the target document segment.
6. The method of claim 5, wherein searching the knowledge base for a sub-knowledge graph corresponding to the target document fragment, includes: The mapping relationships stored in the relational database are queried to determine the entities that have a mapping relationship with the target document segment. Furthermore, based on the graph structure index stored in the graph database, a sub-knowledge graph containing the entities is searched in the graph database to serve as the sub-knowledge graph corresponding to the target document segment.
7. The method of claim 6, further comprising: Identify the sub-knowledge graphs containing the same entities stored in the graph database, and merge the sub-knowledge graphs containing the same entities to obtain the merged sub-knowledge graph. Community clustering is performed on the sub-knowledge graphs stored in the graph database to generate at least one knowledge graph community; Based on the attribute information of the at least one knowledge graph community, a community vector index corresponding to the at least one knowledge graph community is generated, and the community vector index is stored in a graph database corresponding to the knowledge base; Based on the graph structure index stored in the graph database, the search for a sub-knowledge graph containing the entity in the graph database includes: The system searches for a target knowledge graph community that matches the attribute information of the entity from at least one knowledge graph community stored in the graph database, and further searches for a sub-knowledge graph containing the entity in the sub-knowledge graph contained in the target knowledge graph community based on the graph structure index stored in the graph database.
8. The method as described in claim 3, wherein the knowledge triple includes entities and relationships between entities; and the knowledge extraction strategy includes a first-stage knowledge extraction strategy and a second-stage knowledge extraction strategy. The knowledge extraction strategy in the first stage is used to extract entities contained in the knowledge document; the knowledge extraction strategy in the second stage is used to extract entity relationships between entities extracted in the first stage from the knowledge document. The second prompt word template includes a third prompt word template corresponding to the knowledge extraction strategy of the first stage; And, the fourth prompt word template corresponding to the knowledge extraction strategy of the second stage; The second prompt word includes a third prompt word obtained by the user customizing the third prompt word template; and a fourth prompt word obtained by the user customizing the fourth prompt word template; wherein, the third prompt word is used to describe the first-stage knowledge extraction strategy customized by the user for the knowledge domain to which the knowledge document belongs; The fourth prompt word is used to describe the second-stage knowledge prompting strategy customized by the user for the knowledge domain to which the knowledge document belongs.
9. The method of claim 7, further comprising: Get user questions input by the user; Extract the keywords contained in the user's question and generate a query vector corresponding to the keywords; Calculate the vector similarity between the query vector and the entity vector index stored in the graph database, and filter out at least one entity vector index with the highest vector similarity; determine the entity corresponding to the at least one entity vector index, and query the sub-knowledge graph containing the entity in the graph database based on the graph structure index stored in the graph database, and query the mapping relationship stored in the relational database to determine the document fragment that has a mapping relationship with the entity; Based on the user question, the sub-knowledge graph containing the entity, and the document fragments that have a mapping relationship with the entity, a question prompt word corresponding to the user question is generated, and the question prompt word is sent to the LLM so that the LLM can generate the answer text corresponding to the user question based on the question prompt word.
10. The method of claim 9, wherein calculating the vector similarity between the query vector and the entity vector indexes stored in the graph database, and selecting at least one entity vector index with the highest vector similarity, comprises: Calculate the vector similarity between the query vector and the community vector index stored in the graph database, and filter out at least one target knowledge graph community with the highest vector similarity; Further calculate the vector similarity between the query vector and the entity vector index corresponding to the entity contained in the sub-knowledge graph in the target knowledge graph community, and select at least one entity vector index with the highest vector similarity.
11. A method for creating a knowledge base for an LLM, wherein, The knowledge base contains a knowledge graph constructed based on user-uploaded knowledge documents; the method includes: In response to a user's operation of uploading a knowledge document to a target knowledge base, the system retrieves the uploaded knowledge document; and obtains a first prompt word corresponding to the knowledge domain to which the knowledge document belongs, obtained by the user customizing a first prompt word template corresponding to a preset segmentation rule; wherein, the first prompt word is used to describe the segmentation rule customized by the user for the knowledge domain to which the knowledge document belongs; The knowledge document and the first prompt word are sent to the server, which then sends them to the LLM (Local Management Module). The LLM then segments the knowledge document into multiple document fragments based on the segmentation rules described by the first prompt word. Knowledge triples are extracted from the document fragments, and sub-knowledge graphs corresponding to the multiple document fragments are created based on the extracted knowledge triples. The sub-knowledge graphs are then stored in the knowledge base.
12. An electronic device, characterized in that, include: processor; A memory for storing processor-executable instructions; wherein the processor implements the steps of the method as described in any one of claims 1-11 by executing the executable instructions.
13. A computer-readable storage medium, characterized in that, It stores computer instructions that, when executed by a processor, implement the steps of the method as described in any one of claims 1-11.
14. A computer program product, characterized in that, Includes a computer program / instructions that, when executed by a processor, implement the steps of the method as described in any one of claims 1-11.
Citation Information
Cited By
Automatic revision method and system for track traffic rules and regulations based on knowledge base and LLM
CN121766418A
