A knowledge graph query method, device, equipment and storage medium

By constructing vector databases and model fine-tuning, combined with thinking chain construction and context design, the problem that traditional knowledge graph query methods cannot understand the intent of natural language query is solved, efficient and accurate knowledge graph query is achieved, and the scope of application is expanded.

CN118760775BActive Publication Date: 2025-03-14INSPUR YUNZHOU (SHANDONG) IND INTERNET CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411238323.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-05
Publication Date
2025-03-14
Estimated Expiration
2044-09-05

AI Technical Summary

Technical Problem

Traditional knowledge graph query methods cannot accurately understand the intention of the user's natural language query statement, resulting in the accuracy and efficiency of the search results that need to be improved, and it is impossible to query related content based on the user's natural language semantics.

Method used

By constructing a vector database based on knowledge graph and word embedding algorithms, a pre-trained large model is obtained and the model is fine-tuned, the inference ability of the large model is activated by using thinking chain construction and context design, and finally reconstructing the query statement based on the vector database to improve query accuracy.

Benefits of technology

The speed and accuracy of knowledge graph query are optimized, the convenience of query is improved, and the scope of application of knowledge graphs is expanded, so that the entities in user's natural language query can match existing knowledge in the knowledge graph on a semantic level.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118760775B_ABST
    Figure CN118760775B_ABST
Patent Text Reader

Abstract

The present application discloses a knowledge graph query method, device, equipment and storage medium, which relates to the field of intelligent search technology, including: constructing a vector database based on the corresponding knowledge graph and word embedding algorithm to obtain a target vector database; obtaining an initial large model and a preset data set that have been pre-trained; wherein the preset data set includes a corresponding natural language query statement and a corresponding knowledge graph query statement; fine-tuning the initial large model based on the preset data set and model fine-tuning parameters to obtain a target large model; performing corresponding thought chain construction and context design on the knowledge graph query statement generation task of the target large model to activate the context learning ability of the target large model when performing reasoning; performing query statement reconstruction processing on the target large model based on the target vector database, so as to use the processed target large model to perform knowledge graph query and obtain query results. Effectively improve the accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of intelligent search technology, and in particular to a knowledge graph query method, device, equipment and storage medium. Background Art

[0002] Knowledge graph is a structured information storage method that represents entities and their relationships in the form of a graph. Traditional knowledge graph query methods are usually based on keyword search or specific graph query languages, which are not user-friendly. In addition, this query method cannot accurately understand the true intention of the query statement, so the accuracy and efficiency of the retrieval results need to be improved. In addition, traditional knowledge graph query methods cannot query related content based on the semantics of the user's natural language.

[0003] However, after the big models gradually emerged with language understanding capabilities, existing methods can use natural corpora and Cypher QL (Cypher Query Language, a data query language provided by graph databases) syntax to pre-train the big models, allowing the big models to generate corresponding Cypher QL statements based on user query semantics. However, this method is limited by the discrete representation of entities and relationships in the knowledge graph. The entities in the Cypher QL statements generated by the big model may not be aligned with the entity names in the knowledge graph, resulting in low query accuracy. Summary of the invention

[0004] In view of this, the purpose of the present invention is to provide a knowledge graph query method, device, equipment and storage medium, which can effectively optimize the query speed, improve the convenience and accuracy of knowledge graph query, and expand the application of knowledge graph. The specific scheme is as follows:

[0005] In a first aspect, the present application provides a knowledge graph query method, comprising:

[0006] Construct a vector database based on the corresponding knowledge graph and word embedding algorithm to obtain the corresponding target vector database;

[0007] Obtaining a pre-trained initial large model and a corresponding preset data set; wherein the preset data set includes a corresponding natural language query statement and a corresponding knowledge graph query statement;

[0008] Fine-tune the initial large model based on the preset data set and the corresponding model fine-tuning parameters to obtain a target large model after fine-tuning;

[0009] By constructing a corresponding thought chain for the knowledge graph query statement generation task of the target large model, and performing context design based on the obtained thought chain, the context learning ability of the target large model is activated when performing reasoning;

[0010] Based on the target vector database, the target big model is subjected to corresponding query statement reconstruction processing, so as to use the processed target big model to perform knowledge graph query and obtain corresponding query results.

[0011] Optionally, the constructing of a vector database based on a corresponding knowledge graph and a word embedding algorithm to obtain a corresponding target vector database includes:

[0012] Obtaining each entity in the corresponding knowledge graph and the corresponding entity attribute information, and the relationship information between the entities;

[0013] Based on the word embedding algorithm and the entity attributes information of each entity and the corresponding entity, and the relationship information between the entities, low-dimensional dense vector mapping is performed to obtain a corresponding mapping result;

[0014] Obtain an initial vector database, and configure and create a vector database instance in the vector database according to relevant documents;

[0015] Each vector in the mapping result is inserted into the vector database instance in the vector database to obtain a corresponding target vector database.

[0016] Optionally, the method further includes:

[0017] During the vector insertion process, the corresponding vector ID information is configured to obtain the target vector ID information corresponding to each target vector.

[0018] Optionally, fine-tuning the initial large model based on the preset data set and the corresponding model fine-tuning parameters to obtain a target large model after fine-tuning, includes:

[0019] The initial large model is fine-tuned based on the preset data set and the learning rate and number of training rounds in the corresponding model fine-tuning parameters, and the model parameters are updated based on the cross entropy loss function during the fine-tuning process to obtain the target large model that completes the number of training rounds.

[0020] Optionally, the step of constructing a corresponding thinking chain for the knowledge graph query statement generation task of the target large model and performing context design based on the obtained thinking chain to activate the context learning ability of the target large model when performing reasoning includes:

[0021] Extract all entities, corresponding entity attribute information and relationship information between entities in the current natural language query statement through the target big model, and guide the process of expressing all entities, entity attribute information and relationship information based on the knowledge graph query statement to obtain the corresponding thinking chain;

[0022] The corresponding few-shot context is designed through the thinking chain, and the standard answers and corresponding reasoning processes of the corresponding number of query statement conversions are added to the model prompts of the target large model to activate the context learning ability of the target large model when performing reasoning.

[0023] Optionally, before constructing a corresponding thought chain for the knowledge graph query statement generation task of the target large model, the method further includes:

[0024] By designing corresponding initial prompts, the task definition of the knowledge graph query statement generation task is explained for the target large model.

[0025] Optionally, the performing corresponding query statement reconstruction processing on the target large model based on the target vector database so as to perform knowledge graph query using the processed target large model includes:

[0026] Extracting target entities, corresponding target entity attribute information, and target relationship information between the target entities in the query statement generated by the target macro model;

[0027] Performing word embedding on the target entity, the corresponding target entity attribute information, and the target relationship information between the target entities to obtain a corresponding word embedding result;

[0028] Performing a vector query on the target vector database based on the word embedding result to obtain a corresponding query result;

[0029] Acquire a target vector based on the query result, and acquire target text information corresponding to the target vector from the knowledge graph;

[0030] By using the target text information to replace the text information in the query statement, the corresponding query statement reconstruction processing is completed, and the corresponding processed target big model is obtained, so that after saving the knowledge graph based on the preset graph database, the search engine of the preset graph database and the processed target big model can be used for query.

[0031] In a second aspect, the present application provides a knowledge graph query device, comprising:

[0032] The database construction module is used to construct a vector database based on the corresponding knowledge graph and word embedding algorithm to obtain the corresponding target vector database;

[0033] A data set acquisition module, used to acquire a pre-trained initial large model and a corresponding preset data set; wherein the preset data set includes a corresponding natural language query statement and a corresponding knowledge graph query statement;

[0034] A model fine-tuning module, used to perform model fine-tuning on the initial large model based on the preset data set and the corresponding model fine-tuning parameters to obtain a target large model after fine-tuning;

[0035] A thinking chain construction module is used to construct a corresponding thinking chain by generating a task of querying a knowledge graph of the target large model, and to design a context based on the obtained thinking chain, so as to activate the context learning ability of the target large model when performing reasoning;

[0036] The statement reconstruction module is used to perform corresponding query statement reconstruction processing on the target large model based on the target vector database, so as to use the processed target large model to perform knowledge graph query and obtain corresponding query results.

[0037] In a third aspect, the present application provides an electronic device, including:

[0038] Memory, used to store computer programs;

[0039] A processor is used to execute the computer program to implement the steps of the aforementioned knowledge graph query method.

[0040] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the steps of the aforementioned knowledge graph query method.

[0041] It can be seen that in the present application, a vector database is constructed based on the corresponding knowledge graph and word embedding algorithm to obtain a corresponding target vector database; an initial large model that has been pre-trained and a corresponding preset data set are obtained; wherein the preset data set includes corresponding natural language query statements and corresponding knowledge graph query statements; the initial large model is fine-tuned based on the preset data set and the corresponding model fine-tuning parameters to obtain the target large model after fine-tuning; a corresponding thinking chain is constructed by generating a knowledge graph query statement for the target large model, and a context design is performed based on the obtained thinking chain to activate the context learning ability of the target large model during reasoning; the target large model is subjected to corresponding query statement reconstruction processing based on the target vector database, so as to use the processed target large model to perform knowledge graph query and obtain corresponding query results. That is, in this application, by converting the entities, relationships and attributes in the knowledge graph into vector form and storing them in the form of a vector database, the query speed can be effectively optimized; after fine-tuning the model, a thinking chain aligned with the large model reasoning is designed for the knowledge graph sentence generation task, guiding the large model to obtain more accurate results in the sentence generation task, thereby improving the accuracy of the query results output by the model; the semantic features of word embedding are used to expand the discrete representation of the traditional knowledge graph into semantics in a continuous space, so that the entities in the user's natural language query can be matched with the existing knowledge in the knowledge graph at the semantic level, thereby improving the convenience and accuracy of knowledge graph queries and expanding the application of knowledge graphs. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0043] Figure 1 A flow chart of a knowledge graph query method provided for this application;

[0044] Figure 2 A specific knowledge graph query method flow chart provided for this application;

[0045] Figure 3 A schematic diagram of the structure of a knowledge graph query device provided in this application;

[0046] Figure 4 A structural diagram of an electronic device provided for this application. DETAILED DESCRIPTION

[0047] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0048] However, after the big model gradually emerged with language understanding capabilities, the existing methods can use natural corpus and Cypher QL syntax to pre-train the big model, allowing the big model to generate corresponding Cypher QL statements based on user query semantics, but this method is limited by the discrete representation of entities and relationships in the knowledge graph. The entities in the CypherQL statements generated by the big model may not be aligned with the entity names in the knowledge graph, resulting in low query accuracy. To this end, the present application provides a knowledge graph query solution that can effectively optimize the query speed, improve the convenience and accuracy of knowledge graph queries, and expand the application of knowledge graphs.

[0049] See also Figure 1 As shown, the embodiment of the present invention discloses a knowledge graph query method, including:

[0050] Step S11: construct a vector database based on the corresponding knowledge graph and word embedding algorithm to obtain a corresponding target vector database.

[0051] In this embodiment, it should be understood that in the process of building a word embedding database from a knowledge graph, all entities, their attributes and relationships are first extracted from the knowledge graph, and all entities, their attributes and relationships are obtained by selecting a node and traversing the entire knowledge graph. After that, all the above entities, attributes and relationships are mapped to low-dimensional dense vectors using word embedding technology (Word2Vec, GloVe, FastText or BERT). Then create a vector database for word embedding, select a vector database (such as Faiss, Milvus, Annoy or Elastic Search), configure and create a vector database instance according to the relevant documents, and insert the vectors of entities, attributes and relationships into the database. That is, the construction of the vector database based on the corresponding knowledge graph and the word embedding algorithm to obtain the corresponding target vector database includes: obtaining each entity in the corresponding knowledge graph and the corresponding entity attribute information, and the relationship information between each entity; performing low-dimensional dense vector mapping based on the word embedding algorithm and each entity and the corresponding entity attribute information, and the relationship information between each entity to obtain the corresponding mapping result; obtaining the initial vector database, and configuring and creating a vector database instance in the vector database according to the relevant documents; inserting each vector in the mapping result into the vector database instance in the vector database to obtain the corresponding target vector database. Among them, GloVe, namely Global Vectors for Word Representation, is also called the word embedding of global vectors; Word2Vec, namely Word toVector, is a related model used to generate word vectors; BERT, namely Bidirectional Encoder Representations from Transformers, is a bidirectional encoder representation from transformers. Faiss is a library developed by Facebook Artificial Intelligence; Annoy, namely Approximate Nearest Neighbors Oh Yeah, is an open source library for approximate nearest neighbors in high-dimensional space.

[0052] In addition, in this embodiment, when inserting vectors, a unique ID (Identity document) needs to be specified for each vector. This ID can be the name of an entity, attribute or relationship, or a unique digital ID. That is, it also includes: in the process of vector insertion, corresponding vector ID information configuration is performed to obtain target vector ID information corresponding to each target vector.

[0053] Step S12: Obtain an initial large model that has been pre-trained and a corresponding preset data set; wherein the preset data set includes a corresponding natural language query statement and a corresponding knowledge graph query statement.

[0054] Specifically, in this embodiment, before starting model fine-tuning, corresponding preparations need to be made. First, it is necessary to select a pre-trained model for the base, and select a large model that has been pre-trained. You can choose open source large models such as GLM4 (General Language Model 4, the fourth generation base large language model), GPT3 (General Pretrained Transformer-3, a computational model for natural language processing), and T5 (Text-to-Text Transfer Transformer, a Transformer-based NLP model for text-to-text transfer). Among them, the NLP model is the Natural Language Processing model, that is, the natural language processing model.

[0055] After that, prepare a dataset containing natural query input and corresponding knowledge graph query, such as Cypher QL statements. For example, if the input is "find all actors born in New York", the corresponding Cypher QL statement may be "MATCH (a:Actor) WHERE a.BirthPlace='New York' RETURN a". Finally, set the parameters for model fine-tuning, including learning rate, batch size, number of training rounds, etc. These parameters can be adjusted in real time according to the aforementioned dataset size and computing resources.

[0056] Step S13: fine-tune the initial large model based on the preset data set and the corresponding model fine-tuning parameters to obtain a target large model after fine-tuning.

[0057] Specifically, in this embodiment, after obtaining the initial large model that has been pre-trained and the corresponding preset data set, model fine-tuning can be started. Because during the fine-tuning process, the model will learn how to generate correct Cypher QL statements based on the input. Therefore, the cross-entropy loss function is used to measure the gap between the output of the model and the actual Cypher QL statement, and the parameters of the model are updated through back propagation and optimizer. That is, the initial large model is fine-tuned based on the preset data set and the corresponding model fine-tuning parameters to obtain the target large model after fine-tuning, including: the initial large model is fine-tuned based on the learning rate and the number of training rounds in the preset data set and the corresponding model fine-tuning parameters, and the model parameters are updated based on the cross-entropy loss function during the fine-tuning process to obtain the target large model that completes the number of training rounds.

[0058] In addition, in this embodiment, after obtaining the target large model, the model performance of the target large model obtained after fine-tuning can be evaluated. Specifically, the model can be run on an independent test set and a certain evaluation index, such as accuracy or F1-Score (an evaluation standard that comprehensively considers precision and recall), to obtain the corresponding model performance test results, so as to check whether the model performance meets the requirements. If not, fine-tuning can be performed again until it is satisfied.

[0059] Step S14: construct a corresponding thinking chain for the knowledge graph query statement generation task of the target large model, and perform context design based on the obtained thinking chain to activate the context learning ability of the target large model when performing reasoning.

[0060] Specifically, in this embodiment, in order to activate the context learning ability of the target large model when performing reasoning, before that, it is necessary to design an initial prompt to explain the definition of the Cypher QL statement generation task to the large model. That is, before the knowledge graph query statement generation task of the target large model performs the corresponding thought chain construction, it also includes: by designing the corresponding initial prompt, explaining the task definition of the knowledge graph query statement generation task to the target large model.

[0061] It should be understood that in this embodiment, the corresponding thinking chain is constructed for the knowledge graph query statement generation task of the target large model, and the context design is performed based on the obtained thinking chain to activate the context learning ability of the target large model when reasoning, including: extracting all entities, corresponding entity attribute information and relationship information between entities in the current natural language query statement through the target large model, and guiding the process of expressing all entities, entity attribute information and relationship information based on the knowledge graph query statement to obtain the corresponding thinking chain; designing the corresponding few-shot context through the thinking chain, adding the corresponding number of standard answers for query statement conversion and the corresponding reasoning process in the model prompt of the target large model to activate the context learning ability of the target large model when reasoning. That is to say, in the process of activating the ability, the thinking chain is constructed for the Cypher QL statement generation task, and the generation task is decomposed into several steps to guide the large model to reason according to the idea of ​​the thinking chain. First, let the large model extract all important entities and their attributes in the user query, then extract the mutual relationship between the entities, and finally guide the large model to use Cypher QL statements to represent the aforementioned entities and their attributes and relationships. Combine the above-mentioned thinking chain to design a few-shot context, and add 10-100 (depending on actual needs) standard answers and their thinking chain processes for the "input-Cypher QL statement" conversion into the prompts of the large model to activate the contextual learning ability during model reasoning.

[0062] Step S15: reconstruct the target big model based on the target vector database to perform corresponding query statement processing, so as to use the processed target big model to perform knowledge graph query and obtain corresponding query results.

[0063] Specifically, in this embodiment, after activating the model capability, the constructed target vector database is used to reconstruct the Cypher QL statements generated by the target large model. First, extract the entities and their attributes and relationships in the Cypher QL statements generated by the large model. Since the Cypher QL statement is a relatively structured language, this step can be implemented using a rule-based matching method. Then, the extracted entities and their attributes and relationships are word-embedded, using the same word embedding technology as in step S11 to ensure the consistency of the word embedding space of the user's query and the word embedding space of the knowledge graph. Afterwards, query the created target vector database for the vector with the highest similarity to the entities and their attributes and relationships in the Cypher QL statement generated by the large model, and replace the text in the Cypher QL statement generated by the large model with the text represented by the vector with the highest similarity in the knowledge graph.

[0064] After completing the above processing, in a specific implementation, the knowledge graph can be stored using a graph database such as Neo4j, and the search engine of these graph databases and the processed target large model can be used to execute the final CypherQL statement query and return the query results to the user.

[0065] In summary, in this embodiment, 1) word embedding based on knowledge graph: by converting entities, relations and attributes in the knowledge graph into vector form, their semantic information can be captured and represented in a low-dimensional space. This representation method has good scalability and can handle large-scale knowledge graphs. 2) Fine-tuning of pre-trained models: using pre-trained large models (such as GLM or GPT), natural language queries can be converted into knowledge graph query languages, such as Cypher QL. By fine-tuning the Cypher QL statement generation task, the model can understand and generate complex query statements. 3) Constructing thought chains: by constructing thought chains, the large model can be guided to generate Cypher QL statements, helping the model understand complex query tasks and improving the accuracy of queries. 4) Reconstructing query statements using word embedding databases: by reconstructing query statements using vectors in word embedding databases, words outside the vocabulary can be processed to improve the accuracy of queries. This step also enables the current system to adapt to new queries that did not appear in the original training data.

[0066] It can be seen that in the embodiment of the present application, a vector database is constructed based on the corresponding knowledge graph and word embedding algorithm to obtain a corresponding target vector database; an initial large model that has been pre-trained and a corresponding preset data set are obtained; wherein the preset data set includes corresponding natural language query statements and corresponding knowledge graph query statements; the initial large model is fine-tuned based on the preset data set and the corresponding model fine-tuning parameters to obtain the target large model after fine-tuning; a corresponding thinking chain is constructed by generating a knowledge graph query statement for the target large model, and a context design is performed based on the obtained thinking chain to activate the context learning ability of the target large model when reasoning; the target large model is subjected to corresponding query statement reconstruction processing based on the target vector database, so as to use the processed target large model to perform knowledge graph query and obtain corresponding query results. That is, in this application, by converting the entities, relationships and attributes in the knowledge graph into vector form and storing them in the form of a vector database, the query speed can be effectively optimized; after fine-tuning the model, a thinking chain aligned with the large model reasoning is designed for the knowledge graph sentence generation task, guiding the large model to obtain more accurate results in the sentence generation task, thereby improving the accuracy of the query results output by the model; the semantic features of word embedding are used to expand the discrete representation of the traditional knowledge graph into semantics in a continuous space, so that the entities in the user's natural language query can be matched with the existing knowledge in the knowledge graph at the semantic level, thereby improving the convenience and accuracy of knowledge graph queries and expanding the application of knowledge graphs.

[0067] As can be seen from the previous embodiment, the query statement of the target large model is reconstructed by using the constructed target vector database in this application. To this end, this embodiment will describe the query statement reconstruction process in detail. Figure 2 As shown, the embodiment of the present invention discloses a knowledge graph query method, including:

[0068] Step S21: extract the target entities, the corresponding target entity attribute information, and the target relationship information between the target entities in the query statement generated by the target macro model.

[0069] Step S22: word embedding is performed on the target entity, the corresponding target entity attribute information, and the target relationship information between the target entities to obtain a corresponding word embedding result.

[0070] Step S23: perform a vector query on the target vector database based on the word embedding result to obtain a corresponding query result.

[0071] Step S24: Obtain a target vector based on the query result, and obtain target text information corresponding to the target vector from the knowledge graph.

[0072] Step S25: Replace the text information in the query statement with the target text information to complete the corresponding query statement reconstruction process and obtain the corresponding processed target big model, so that after saving the knowledge graph based on the preset graph database, query can be performed using the search engine of the preset graph database and the processed target big model.

[0073] Among them, the specific process of the above steps S21 to S25 can refer to the corresponding content disclosed in the above embodiments, and will not be repeated here.

[0074] It can be seen that in the embodiment of the present application, query statements based on the constructed target vector database and word embedding technology reconstruction model, such as Cypher QL query statements, are used. By using the semantic features of word embedding, the discrete representation of the traditional knowledge graph is expanded into semantics in a continuous space, so that the entities in the user's natural language query can be matched with the existing knowledge in the knowledge graph at the semantic level, thereby effectively improving the convenience and accuracy of knowledge graph queries and expanding the application of knowledge graphs.

[0075] See also Figure 3 As shown, the embodiment of the present application also discloses a knowledge graph query device, including:

[0076] A database construction module 11 is used to construct a vector database based on the corresponding knowledge graph and word embedding algorithm to obtain a corresponding target vector database;

[0077] The data set acquisition module 12 is used to acquire the pre-trained initial large model and the corresponding preset data set; wherein the preset data set includes the corresponding natural language query statement and the corresponding knowledge graph query statement;

[0078] A model fine-tuning module 13 is used to perform model fine-tuning on the initial large model based on the preset data set and the corresponding model fine-tuning parameters to obtain a target large model after fine-tuning;

[0079] A thinking chain construction module 14 is used to construct a corresponding thinking chain by generating a task of querying a knowledge graph of the target large model, and to design a context based on the obtained thinking chain, so as to activate the context learning ability of the target large model when performing reasoning;

[0080] The statement reconstruction module 15 is used to perform corresponding query statement reconstruction processing on the target large model based on the target vector database, so as to use the processed target large model to perform knowledge graph query and obtain corresponding query results.

[0081] Among them, for more specific working processes of the above-mentioned modules, please refer to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0082] It can be seen that in this application, by converting the entities, relationships and attributes in the knowledge graph into vector form and storing them in the form of a vector database, the query speed can be effectively optimized; after fine-tuning the model, a thinking chain aligned with the large model reasoning is designed for the knowledge graph sentence generation task, guiding the large model to obtain more accurate results in the sentence generation task, thereby improving the accuracy of the query results output by the model; the semantic features of word embedding are used to expand the discrete representation of the traditional knowledge graph into semantics in a continuous space, so that the entities in the user's natural language query can be matched with the existing knowledge in the knowledge graph at the semantic level, thereby improving the convenience and accuracy of knowledge graph queries and expanding the application of knowledge graphs.

[0083] In some specific embodiments, the database construction module 11 may specifically include:

[0084] An information acquisition unit, used to acquire each entity in the corresponding knowledge graph and the corresponding entity attribute information, and the relationship information between the entities;

[0085] A mapping result acquisition unit, configured to perform low-dimensional dense vector mapping based on a word embedding algorithm and the entity attributes information corresponding to each entity and the relationship information between each entity, so as to obtain a corresponding mapping result;

[0086] A database instance creation unit, used to obtain an initial vector database, and configure and create a vector database instance in the vector database according to relevant documents;

[0087] The vector database construction unit is used to insert each vector in the mapping result into the vector database instance in the vector database to obtain a corresponding target vector database.

[0088] In some specific embodiments, the knowledge graph query device may further include:

[0089] The ID information acquisition unit is used to perform corresponding vector ID information configuration during the vector insertion process to obtain target vector ID information corresponding to each target vector.

[0090] In some specific embodiments, the model fine-tuning module 13 may specifically include:

[0091] A model parameter updating unit is used to perform model fine-tuning on the initial large model based on the preset data set and the learning rate and number of training rounds in the corresponding model fine-tuning parameters, and to update the model parameters based on the cross entropy loss function during the fine-tuning process to obtain a target large model that completes the number of training rounds.

[0092] In some specific embodiments, the thought chain construction module 14 may specifically include:

[0093] A thought chain construction unit is used to extract all entities, corresponding entity attribute information and relationship information between entities in the current natural language query statement through the target large model, and guide the process of expressing all entities, entity attribute information and relationship information based on the knowledge graph query statement to obtain a corresponding thought chain;

[0094] The capability activation unit is used to design a corresponding few-shot context through the thinking chain, and add a corresponding number of standard answers for query statement conversion and the corresponding reasoning process in the model prompt of the target large model to activate the context learning capability of the target large model when performing reasoning.

[0095] In some specific embodiments, the statement reconstruction module 15 may specifically include:

[0096] The initial prompt design unit is used to interpret the task definition of the knowledge graph query statement generation task for the target large model by designing a corresponding initial prompt.

[0097] In some specific embodiments, the knowledge graph query device may further include:

[0098] An information extraction unit, used to extract target entities, corresponding target entity attribute information, and target relationship information between the target entities in the query statement generated by the target macro model;

[0099] A word embedding unit, used for performing word embedding on the target entity, the corresponding target entity attribute information and the target relationship information between the target entities to obtain a corresponding word embedding result;

[0100] A database query unit, configured to perform a vector query on the target vector database based on the word embedding result to obtain a corresponding query result;

[0101] A text information acquisition unit, configured to acquire a target vector based on the query result, and acquire target text information corresponding to the target vector from the knowledge graph;

[0102] An information replacement unit is used to replace the text information in the query statement by using the target text information, complete the corresponding query statement reconstruction processing, and obtain the corresponding processed target big model, so that after saving the knowledge graph based on the preset graph database, the search engine of the preset graph database and the processed target big model can be used for query.

[0103] Furthermore, the present application also discloses an electronic device. Figure 4 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be regarded as any limitation on the scope of use of the present application.

[0104] Figure 4 A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the knowledge graph query method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0105] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0106] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0107] The operating system 221 is used to manage and control the hardware devices and computer program 222 on the electronic device 20, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the knowledge graph query method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.

[0108] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned disclosed knowledge graph query method is implemented. The specific steps of the method can be referred to the corresponding contents disclosed in the aforementioned embodiments, and will not be repeated here.

[0109] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0110] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0111] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0112] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0113] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A knowledge graph query method, characterized in that: include: Construct a vector database based on the corresponding knowledge graph and word embedding algorithm to obtain the corresponding target vector database; Obtaining a pre-trained initial large model and a corresponding preset data set; wherein the preset data set includes a corresponding natural language query statement and a corresponding knowledge graph query statement; Fine-tune the initial large model based on the preset data set and the corresponding model fine-tuning parameters to obtain a target large model after fine-tuning; By constructing a corresponding thought chain for the knowledge graph query statement generation task of the target large model, and performing context design based on the obtained thought chain, the context learning ability of the target large model is activated when performing reasoning; Reconstructing the target macromodel based on the target vector database to perform query statement processing, so as to perform knowledge graph query using the processed target macromodel and obtain corresponding query results; The step of reconstructing the target large model based on the target vector database to perform corresponding query statement processing so as to perform knowledge graph query using the processed target large model includes: Extracting target entities, corresponding target entity attribute information, and target relationship information between the target entities in the query statement generated by the target macro model; Performing word embedding on the target entity, the corresponding target entity attribute information, and the target relationship information between the target entities to obtain a corresponding word embedding result; Performing a vector query on the target vector database based on the word embedding result to obtain a corresponding query result; Acquire a target vector based on the query result, and acquire target text information corresponding to the target vector from the knowledge graph; By using the target text information to replace the text information in the query statement, the corresponding query statement reconstruction processing is completed, and the corresponding processed target big model is obtained, so that after saving the knowledge graph based on the preset graph database, the search engine of the preset graph database and the processed target big model can be used for query.

2. The knowledge graph query method according to claim 1, characterized in that: The vector database is constructed based on the corresponding knowledge graph and word embedding algorithm to obtain the corresponding target vector database, including: Obtaining each entity in the corresponding knowledge graph and the corresponding entity attribute information, and the relationship information between the entities; Based on the word embedding algorithm and the entity attributes information of each entity and the corresponding entity, and the relationship information between the entities, low-dimensional dense vector mapping is performed to obtain a corresponding mapping result; Obtain an initial vector database, and configure and create a vector database instance in the vector database according to relevant documents; Each vector in the mapping result is inserted into the vector database instance in the vector database to obtain a corresponding target vector database.

3. The knowledge graph query method according to claim 2, characterized in that: Also includes: During the vector insertion process, the corresponding vector ID information is configured to obtain the target vector ID information corresponding to each target vector.

4. The knowledge graph query method according to claim 1, characterized in that: The fine-tuning of the initial large model based on the preset data set and the corresponding model fine-tuning parameters to obtain a target large model after fine-tuning includes: The initial large model is fine-tuned based on the preset data set and the learning rate and number of training rounds in the corresponding model fine-tuning parameters, and the model parameters are updated based on the cross entropy loss function during the fine-tuning process to obtain the target large model that completes the number of training rounds.

5. The knowledge graph query method according to claim 1, characterized in that: The method of constructing a corresponding thinking chain for the knowledge graph query statement generation task of the target large model and performing context design based on the obtained thinking chain to activate the context learning ability of the target large model when performing reasoning includes: Extract all entities, corresponding entity attribute information and relationship information between entities in the current natural language query statement through the target big model, and guide the process of expressing all entities, entity attribute information and relationship information based on the knowledge graph query statement to obtain the corresponding thinking chain; The corresponding few-shot context is designed through the thinking chain, and the standard answers and corresponding reasoning processes of the corresponding number of query statement conversions are added to the model prompts of the target large model to activate the context learning ability of the target large model when performing reasoning.

6. The knowledge graph query method according to claim 1, characterized in that: Before constructing a corresponding thinking chain for the knowledge graph query statement generation task of the target large model, it also includes: By designing corresponding initial prompts, the task definition of the knowledge graph query statement generation task is explained for the target large model.

7. A knowledge graph query device, characterized in that: include: The database construction module is used to construct a vector database based on the corresponding knowledge graph and word embedding algorithm to obtain the corresponding target vector database; A data set acquisition module, used to acquire a pre-trained initial large model and a corresponding preset data set; wherein the preset data set includes a corresponding natural language query statement and a corresponding knowledge graph query statement; A model fine-tuning module, used to perform model fine-tuning on the initial large model based on the preset data set and the corresponding model fine-tuning parameters to obtain a target large model after fine-tuning; A thinking chain construction module is used to construct a corresponding thinking chain by generating a task of querying a knowledge graph of the target large model, and to design a context based on the obtained thinking chain to activate the context learning ability of the target large model when performing reasoning; A statement reconstruction module, used to perform corresponding query statement reconstruction processing on the target large model based on the target vector database, so as to use the processed target large model to perform knowledge graph query and obtain corresponding query results; Wherein, the statement reconstruction module includes: An information extraction unit, used to extract target entities, corresponding target entity attribute information, and target relationship information between the target entities in the query statement generated by the target macro model; A word embedding unit, used for performing word embedding on the target entity, the corresponding target entity attribute information and the target relationship information between the target entities to obtain a corresponding word embedding result; A database query unit, configured to perform a vector query on the target vector database based on the word embedding result to obtain a corresponding query result; A text information acquisition unit, configured to acquire a target vector based on the query result, and acquire target text information corresponding to the target vector from the knowledge graph; An information replacement unit is used to replace the text information in the query statement by using the target text information, complete the corresponding query statement reconstruction processing, and obtain the corresponding processed target big model, so that after saving the knowledge graph based on the preset graph database, the search engine of the preset graph database and the processed target big model can be used for query.

8. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, used to execute the computer program to implement the knowledge graph query method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: Used to store a computer program, which, when executed by a processor, implements the knowledge graph query method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Auxiliary retrieval method fusing knowledge graph and large language model

    CN117633252A

  • A ship test training scenario question and answer method, system, device and medium

    CN118113855A