Knowledge graph storage method and device, storage medium and electronic equipment
By storing the attribute data of the knowledge graph in a structured database and graph structure data in a graph database, and using transaction coordination mechanism and database encapsulation, the performance bottleneck problem during knowledge graph writing and query is solved, and efficient storage is achieved and query.
Patent Information
- Application Number
- CN202310656014.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-05
- Publication Date
- 2024-12-06
AI Technical Summary
In the prior art, the high coupling between entity, relationship and attribute data during writing and querying knowledge graphs lead to bottleneck in performance of graph databases, which cannot respond to requests in a timely and accurate manner, affecting efficiency.
Store the attribute data of the knowledge graph in a structured database with indexing function, store the graph structure data in the graph database, and reduce coupling and improve write and query efficiency through transaction coordination mechanism and database encapsulation.
It effectively shortens the knowledge graph query time, improves query efficiency, avoids writing bottlenecks, and hides database language differences under different scenario requirements, giving full play to the ultimate performance of each database.
Smart Images

Figure CN119088977A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a storage method, device, storage medium and electronic device for a knowledge graph. Background Art
[0002] At present, in order to realize the functions of writing and querying knowledge graphs, the entities, relationship attributes and graph structure data of knowledge graphs are stored in graph databases. However, the information coupling degree of knowledge graphs stored in graph databases is high. When the number of writing and querying requests is large, the performance of graph databases may affect the response to requests in a timely and accurate manner, that is, the graph database has a performance bottleneck.
[0003] For example, when writing to the knowledge graph, the coupling degree between the attribute data of entities is high, and the coupling degree between relationships and the attribute data of the start entity, end entity, and relationship is high. When an entity and / or relationship has multiple attribute data, performance bottlenecks are prone to occur in the graph database when multiple attribute data of the entity and / or relationship are written. When there are many attribute query requests in the knowledge graph, the related entities or relationships are found by querying the attribute values in the graph database, and then the entities or relationships associated with the entities or relationships are further found. Due to the high coupling degree between entities, relationships, and attributes, the performance requirements of the graph database are extremely high to avoid performance bottlenecks.
[0004] Therefore, how to improve the efficiency of knowledge graph writing, querying and other functions is an urgent problem that needs to be solved. Summary of the invention
[0005] In view of the above problems, the present application provides a knowledge graph storage method, device, storage medium and electronic device, which solves the problem of how to improve the efficiency of knowledge graph writing, query and other functions.
[0006] In order to solve the above technical problems, this application proposes the following solutions:
[0007] In a first aspect, the present application provides a method for storing a knowledge graph, the method comprising: extracting attribute data and graph structure data of the knowledge graph, the attribute data comprising attribute information of entities and attribute information of relationships in the knowledge graph, and the graph structure data comprising associations between entities and relationships; storing the attribute data in a first database indicating an indexing function; and storing the graph structure data in a graph database.
[0008] Since the attribute data in the knowledge graph can be organized as structured data, structured data is data that is logically expressed and implemented by a two-dimensional table structure, while graph structure data is unstructured data, which is data with an irregular or incomplete data structure and no predefined data model, and is not convenient to be represented by a two-dimensional logical table in the database. Therefore, the attribute data can be stored in the first database, and the graph structure data can be stored in the graph database to reduce the coupling between entities, relationships and attribute data in the knowledge graph, and improve the efficiency of writing or querying the knowledge graph. Since the first database is a database with an indexing function, it can be used to deal with scenarios where data query requests are frequent and have high requirements for response time, so it can effectively shorten the time for knowledge graph queries and improve query efficiency.
[0009] In combination with the first aspect, in a possible implementation, a first identifier of a configuration entity in attribute data is the same as a second identifier of the entity in graph structure data; a third identifier of a configuration relationship in attribute data is the same as a fourth identifier in graph structure data.
[0010] The attribute data and the graph structure data are associated through the identifiers of entities and / or relationships. That is, when writing data in the knowledge graph, the identifiers of the same entity and the same relationship are configured to be consistent in the attribute data and the graph structure data. When querying, the information of the target entity and / or relationship can be queried in both the first database and the graph database through the identifier.
[0011] In combination with the first aspect, in another possible implementation, the attribute data is synchronously stored in the first database according to the transaction coordination mechanism, and the graph structure data is stored in the graph database.
[0012] The transaction coordination mechanism includes a strong consistency scheme and an eventual consistency scheme. The strong consistency scheme is used to control the knowledge graph to be written into the first database and the graph database at the same time. The eventual consistency scheme is used to control the knowledge graph to be written into the first database and the graph database within one transaction cycle. The transaction coordination mechanism can be selected according to the different scenario requirements of the knowledge graph. The present application can write entities, relationships and their attribute data into multiple types of databases at the same time and in parallel, thereby reducing the performance requirements for different types of databases, and can also effectively improve the storage efficiency of the knowledge graph to avoid knowledge graph writing bottlenecks.
[0013] In combination with the first aspect, in another possible implementation manner, the first database and the graph database are encapsulated separately.
[0014] Since the same type of database can have different database languages, different knowledge graphs have different scenario requirements, and different scenario requirements correspond to different database languages, encapsulating the first database and the graph database can avoid learning different database languages under different scenario requirements, hide the specific storage details of the knowledge graph, and give full play to the ultimate performance of various types of databases, so that they can perform their respective functions, work together, and complement each other to achieve an efficient storage state.
[0015] In a second aspect, the present application provides a storage device for a knowledge graph, and the storage device for the knowledge graph includes: an extraction unit and a storage unit.
[0016] The extraction unit is used to extract the attribute data and graph structure data of the knowledge graph. The attribute data includes the attribute information of the entities and the attribute information of the relationships in the knowledge graph, and the graph structure data includes the association relationships between entities and relationships.
[0017] The storage unit is used to store the attribute data in a first database indicating an indexing function; and store the graph structure data in a graph database.
[0018] Since the attribute data in the knowledge graph can be organized as structured data, structured data is data that is logically expressed and implemented by a two-dimensional table structure, while graph structure data is unstructured data, which is data with an irregular or incomplete data structure and no predefined data model, and is not convenient to be represented by a two-dimensional logical table in the database. Therefore, the attribute data can be stored in the first database, and the graph structure data can be stored in the graph database to reduce the coupling between entities, relationships and attribute data in the knowledge graph, and improve the efficiency of writing or querying the knowledge graph. Since the first database is a database with an indexing function, it can be used to deal with scenarios where data query requests are frequent and have high requirements for response time, so it can effectively shorten the time for knowledge graph queries and improve query efficiency.
[0019] In combination with the second aspect, in a possible implementation, the extraction unit is also used to configure the first identifier of the entity in the attribute data to be the same as the second identifier of the entity in the graph structure data; and to configure the third identifier of the relationship in the attribute data to be the same as the fourth identifier in the graph structure data.
[0020] The attribute data and the graph structure data are associated through the identifiers of entities and / or relationships. That is, when writing data in the knowledge graph, the identifiers of the same entity and the same relationship are configured to be consistent in the attribute data and the graph structure data. When querying, the information of the target entity and / or relationship can be queried in both the first database and the graph database through the identifier.
[0021] In combination with the second aspect, in another possible implementation, the storage unit is further used to synchronously store the attribute data in the first database and store the graph structure data in the graph database according to the transaction coordination mechanism.
[0022] The transaction coordination mechanism includes a strong consistency solution and an eventual consistency solution. The strong consistency solution is used to control the knowledge graph to be written into the first database and the graph database at the same time. The eventual consistency solution is used to control the knowledge graph to be written into the first database and the graph database within one transaction cycle. The transaction coordination mechanism can be selected according to the different scenario requirements of the productized graph. Since the knowledge graph can be written into multiple types of databases at the same time and in parallel, the performance requirements for different types of databases can be reduced, and the storage efficiency of the knowledge graph can be effectively improved to avoid the knowledge graph writing bottleneck.
[0023] In combination with the second aspect, in another possible implementation, the storage device of the knowledge graph also includes an encapsulation unit, and the encapsulation unit is used to encapsulate the first database and the graph database respectively.
[0024] Since the same type of database can have different database languages, different knowledge graphs have different scenario requirements, and different scenario requirements correspond to different database languages, encapsulating the first database and the graph database can avoid learning different database languages under different scenario requirements, hide the specific storage details of the knowledge graph, and give full play to the ultimate performance of various types of databases, so that they can perform their respective functions, work together, and complement each other to achieve an efficient storage state.
[0025] In order to achieve the above-mentioned purpose, according to the third aspect of the present application, a storage medium is provided, which includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the knowledge graph storage method of the first aspect mentioned above.
[0026] In order to achieve the above-mentioned purpose, according to the fourth aspect of the present application, an electronic device is provided, which includes at least one processor, and at least one memory and a bus connected to the processor; wherein the processor and the memory communicate with each other through the bus; the processor is used to call the program instructions in the memory to execute the knowledge graph storage method of the first aspect mentioned above.
[0027] By means of the above technical solution, the technical solution provided by this application has at least the following advantages:
[0028] The present application provides a method, device, storage medium and electronic device for storing a knowledge graph. The present application can store attribute data in a first database and store graph structure data in a graph database to reduce the coupling between entities, relationships and attribute data in the knowledge graph and improve the efficiency of writing or querying the knowledge graph. Since the first database is a database with an indexing function, it can be used to deal with scenarios where data query requests are frequent and the response time requirements are high, so it can effectively shorten the time for knowledge graph query and improve query efficiency.
[0029] This application can also reduce the performance requirements for different types of databases through a transaction coordination mechanism, effectively improving the storage efficiency of the knowledge graph to avoid knowledge graph writing bottlenecks.
[0030] The present application can also avoid learning different database languages under different scenario requirements by encapsulating the first database and the graph database, hiding the specific storage details of the knowledge graph, and improving storage efficiency.
[0031] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0033] Figure 1 A schematic diagram of a system architecture provided by an embodiment of the present application is shown;
[0034] Figure 2 A schematic diagram of a process for storing a knowledge graph provided in an embodiment of the present application is shown;
[0035] Figure 3 A schematic diagram of a knowledge graph provided in an embodiment of the present application is shown;
[0036] Figure 4 A schematic diagram of graph structure data provided by an embodiment of the present application is shown;
[0037] Figure 5 A block diagram showing a composition of a knowledge graph storage device provided in an embodiment of the present application is shown;
[0038] Figure 6A schematic diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0039] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0040] In the embodiments of the present application, the terms "first" and "second" do not have a logical or temporal dependency, nor do they limit the quantity and execution order. It should also be understood that although the following description uses the terms first, second, etc. to describe various elements, these elements should not be limited by the terms. These terms are only used to distinguish one element from another element.
[0041] In the embodiments of the present application, the term "at least one" means one or more, and the term "plurality" means two or more.
[0042] It should also be understood that the term "if" may be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting." Similarly, the phrase "if it is determined that ..." or "if [a stated condition or event] is detected" may be interpreted as "upon determining that ..." or "in response to determining that ..." or "upon detecting [a stated condition or event]" or "in response to detecting [a stated condition or event]," depending on the context.
[0043] To facilitate understanding of the solutions of the present application, a brief introduction to the relevant concepts is first given as follows.
[0044] Knowledge Graph (KG): is a graph-based data structure consisting of nodes and edges. Each node represents an "entity" and each edge represents a "relationship" between entities. Entities can be things in the real world, such as people, places, companies, telephones, animals, etc.; relationships are used to express the associations between different entities.
[0045] Search (index) database: It is based on the inverted index and evolved from the traditional relational database. It is used to deal with scenarios where data queries are frequent and have high requirements for response time. It makes up for the slow query of relational databases when the data volume is large.
[0046] Graph database: A data management system based on nodes and edges as storage units, designed with the principle of efficient storage and query of graph data. The graph data structure directly stores the dependencies between nodes. Graph database stores the associations between data as part of the data, and labels, directions, and attributes can be added to the associations.
[0047] The implementation of the embodiments of the present application will be described in detail below with reference to the accompanying drawings.
[0048] Figure 1 A schematic diagram of a system architecture provided for this application. The system architecture diagram is an example of a computer device. Figure 1 , the computer device 100 includes a processor 110 and a memory 120 .
[0049] Processor 110 is used to extract attribute data and graph structure data of the knowledge graph, the attribute data includes attribute information of entities and attribute information of relationships in the knowledge graph, and the graph structure data includes the association relationship between entities and relationships; store the attribute data to a first database indicating an indexing function; and store the graph structure data to a graph database.
[0050] The memory 120 is used to store the attribute data and graph structure data of the knowledge graph.
[0051] The system architecture of the present application includes a graph service, a software development kit (SDK) package, a database, and a transaction coordination mechanism. The graph service is used to add, read, update, and delete entities, relationships, and / or attributes. The SDK package is used to hide the attributes and implementation details of the database, and only discloses the interface to the outside. In the embodiment of the present application, the outside refers to the caller on the database. The abstracted data and behavior (or function) are combined to form an organic whole. In the present application, the database includes an index database, a graph database, and a relational database. The index database includes but is not limited to Elastic Search and Solr. The graph database includes but is not limited to Neo4j and Janus Graph. The relational database includes but is not limited to PostgreSQL, MySQL, Oracle, and SQLite. The transaction coordination mechanism is a guarantee mechanism introduced to cope with the need to have the "transaction" feature when writing graph data in different usage scenarios. For example, the control attribute data and graph structure data are all written to the corresponding database at the end of a transaction, or when an exception occurs, none of them are written to the database.
[0052] The system architecture of the present application can also be a computer cluster, in which there are multiple computer devices to store the knowledge graph. For example, there are a first computer device and a second computer device in the computer cluster, the first computer device is used to extract the attribute data and graph structure data of the knowledge graph, and store the attribute data in the first database, and the second computer device is used to store the graph structure data in the graph database.
[0053] The system architecture of the present application can also be an example of a server or a server cluster. The present application embodiment does not limit the specific form of the system architecture, and the above is only an exemplary description. In the following embodiments, only the system architecture is a computer device 100 as an example for description.
[0054] The system architecture and application scenarios described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. A person of ordinary skill in the art can appreciate that with the evolution of the system architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of the present application are equally applicable to similar technical problems.
[0055] Next, the storage method of the knowledge graph is described in detail with reference to the accompanying drawings. Figure 2 A schematic diagram of a knowledge graph storage method provided in this application. Figure 1 The processor 110 and the memory 120 shown in FIG. 1 are used as an example for explanation.
[0056] Step 210: The processor extracts attribute data and graph structure data of the knowledge graph.
[0057] The knowledge graph includes entities, relationships, and attributes. In the embodiment of the present application, an entity refers to a real physical thing in the objective world, or a concept that is abstractly summarized for the convenience of research. For example, a certain person, a certain thing, a certain noun concept, etc. Entity is the most basic element in the knowledge graph, and different entities have different associations. In the embodiment of the present application, a relationship refers to a real association between entities, or an abstract association introduced for the convenience of research. Attributes are characteristic descriptions of entities or relationships. The attributes of an entity are descriptions of the characteristics of an entity. For example, a person's name, date of birth, blood type, etc., or the explanation, keywords, and characteristics of a certain noun concept. The attributes of a relationship are characteristic descriptions of the association between entities. For example, symmetric relationships, existence time, occurrence time, and occurrence location.
[0058] In an embodiment of the present application, the knowledge graph is expressed in the form of an attribute graph.
[0059] The property graph model uses nodes to represent entities and edges to represent the relationships between entities. At the same time, entities and their relationships have associated attributes. Attributes can be any attributes that provide detailed information about data entities or relationships, that is, points and edges can be associated with any number of attributes and attribute values in the form of key-value pairs. Nodes and edges in the property graph are identified by their internal structure, including their unique identifiers and attributes. Any node or edge can contain attributes that represent data attributes as key-value pairs. In the property graph model, relationships are mentioned to a degree as important as the entities themselves.
[0060] In the embodiment of the present application, the graph model of the knowledge graph is taken as an example of a property graph. According to the characteristics of the property graph model, entities and relationships can have any number of attributes and attribute values. Since the attributes and attribute values are in the form of key-value pairs, that is, tuples, the attribute data of entities and relationships can be organized as structured data. The association relationship between entities, relationships, and attributes is in the form of a graph structure, so the graph structure data is unstructured data. The attribute data and graph structure data of the knowledge graph are extracted to separate the unstructured data and the structured data, thereby reducing the coupling degree of the attribute data and the graph structure data of the knowledge graph, avoiding the problem of traversing the knowledge graph when writing or querying a certain attribute and attribute value of an entity or relationship, avoiding performance bottlenecks, and improving the efficiency of writing or querying the knowledge graph.
[0061] Furthermore, the attribute data and the graph structure data are associated through the identifiers of entities and / or relationships. That is, when writing data in the knowledge graph, the identifiers of the same entity and the same relationship are configured to be consistent in the attribute data and the graph structure data. When querying, the information of the target entity and / or relationship can be queried in both the first database and the graph database through the identifier.
[0062] In other words, the identifier of the entity and the identifier of the relationship are like the foreign key in a relational database. The foreign key is used to establish the relationship between two tables. In layman's terms, a foreign key is one or more fields in a table whose values correspond to the field values in another table and are used to represent the relationship between the two tables. A foreign key is defined in a relational database as: a relationship pointer defined on a column in a parent table and a child table. In addition to quickly performing association lookups, it also helps to indicate reference integrity.
[0063] For example, Figure 3 A schematic diagram of a knowledge graph provided for this application. Figure 3It can be seen that in this knowledge graph, entity 1 is Zhang San, whose attribute is person; entity 2 is Li Si, whose attribute is also person; the relationship between entity 1 and entity 2 is friend. The attribute data of entity 1 is shown in Table 1, the attribute data of entity 2 is shown in Table 2, and the attribute data of the relationship is shown in Table 3.
[0064] Table 1
[0065] Name Zhang San gender male height 180cm
[0066] Table 1 is the attribute information of an entity 1 provided in this application. The first attribute of entity 1 is name, and its attribute value is Zhang San; the second attribute is gender, and its attribute value is male; the third attribute is height, and its attribute value is 180cm;
[0067] Table 2
[0068] Name Li Si gender female height 160cm
[0069] Table 2 is the attribute information of an entity 2 provided in this application, which is similar to Table 1 and will not be elaborated here.
[0070] Table 3
[0071] Knowing time 2021-04-08 Get to know the place Coffee Shop Relationship Type Symmetrical relationship
[0072] Table 3 is the attribute information of a relationship provided in this application. According to Table 3, it can be seen that entity 1 and entity 2 met in a coffee shop on 2021-04-08. Since entity 1 and entity 2 are friends with each other, the relationship type is a symmetric relationship.
[0073] The processor extracts attribute data of the knowledge graph, and the attribute data are shown in Tables 4 and 5. Table 4 is a logical diagram of entity attribute data storage of an entity provided by the present application, and Table 5 is attribute data of a relationship provided by the present application.
[0074] Table 4
[0075] Logo Name gender height E-1 Zhang San male 180cm E-2 Li Si female 160cm
[0076] Table 5
[0077] Logo Get to know the place Knowing time Relationship Type R-1 2021-04-08 Coffee Shop Symmetrical relationship
[0078] The graph structure data of the knowledge graph extracted by the processor is as follows Figure 4 As shown, Figure 4 A schematic diagram of graph structure data provided for this application.
[0079] according to Figure 4 It can be seen that the relationship between entity 1 Zhang San and entity 2 Li Si is a friend relationship. The attribute of entity 1 is person, marked as E-1, the attribute of entity 2 is person, marked as E-2, and the attribute of the relationship is friend, marked as R-1.
[0080] When the query request is the height of entity 1, the height can be obtained by querying attribute data table 4 without traversing the graph structure data, thereby realizing the decoupling of the attribute data and graph structure data of the knowledge graph. In addition, by identifying the attribute data and graph structure data of the associated knowledge graph, when writing data, the entity identifier and the relationship identifier can be controlled to have the same value in the two types of databases, thereby effectively improving the query efficiency.
[0081] Step 220: The memory stores the attribute data in the first database, and stores the graph structure data in the graph database.
[0082] According to the above example description, the attribute data and graph structure data of the knowledge graph based on the attribute graph model have different structure types, so the attribute data and graph structure data can be stored in two different types of databases.
[0083] Specifically, because graph structured data is different from general data structures and is not a two-dimensional table, graph structured data needs to reflect the geometric and topological relationships between the elements (i.e. entities) corresponding to the data. Therefore, graph structured data is stored in a graph database.
[0084] A graph database is a data management system that uses nodes and edges as storage units and is designed to efficiently store and query graph data. A graph database can be used to store data with complex data relationships or data structure graphs. A graph database can make up for the problem that other types of databases are slow in multi-hop queries. In an embodiment of the present application, the graph database may be Neo4j, ArangoDB, or Tiger Graph.
[0085] Neo4j is a high-performance NOSQL graph database that stores structured data on the network instead of in tables. It is an embedded, disk-based, fully transactional Java persistence engine, but it stores structured data on the network instead of in tables. Therefore, Neo4j can also be seen as a high-performance graph engine that has all the features of a mature database.
[0086] Arango DB: Arango DB is a free, open source, native multi-model database system. The database system supports three data models through a database core and a unified query language AQL, including key / value pairs, graphs, and document data models. It provides a unified database query language covering the three data models and allows the three models to be mixed in a single query. Based on its native integrated multi-model features, high-performance programs can be built, and all three data models support horizontal expansion.
[0087] Tiger Graph: Tiger Graph is a "real-time native parallel graph database" that can be deployed in the cloud or locally, supports vertical and horizontal expansion, can automatically partition graph data in the cluster, follows ACID standards, and provides built-in data compression. It uses a messaging architecture that has parallelism that can scale with data growth.
[0088] The attribute data of the knowledge graph is structured data, which is logically expressed and implemented by a two-dimensional table structure. In addition, the knowledge graph product has many functions, and the most frequently used one is the attribute query function of the knowledge graph. Therefore, the attribute data of the knowledge graph is stored in the first database with an indexing function to reduce the coupling between entities, relationships and attribute data in the knowledge graph, and improve the efficiency of writing or querying the knowledge graph.
[0089] In one embodiment, the first database may be an index database, which is usually used to deal with scenarios where data queries are frequent and the response time requirements are relatively high. It is based on the inverted index and evolved from traditional relational databases. The index database makes up for the problem that relational databases have slow queries when the amount of data is large. In the embodiment of the present application, the index database may be Elastic Search or Solr.
[0090] Elastic Search provides near real-time search and analysis for all types of data. Elastic Search can efficiently store and index data in a way that allows for fast searches.
[0091] Solr is an independent enterprise-level search application server. Users can submit XML files in a certain format to the search engine server through a hypertext transfer protocol request to generate an index; they can also make a search request through an Http Get operation and get the result in XML format. Solr is configurable and extensible, optimizes query performance, and provides a complete functional management interface.
[0092] Furthermore, storing the knowledge graph will generate system data to maintain the information of the knowledge graph. The system data is a relatively regular two-dimensional table. Therefore, the system data can be stored in a relational database.
[0093] Relational databases are usually used for system data persistence, storing relatively regular two-dimensional table data. In the embodiment of the present application, the relational database can be PostgreSQL, MySQL, Oracle, or SQLite.
[0094] The attribute data and graph structure data of the knowledge graph are separated and stored, and an index-type database is selected for the attribute data. Therefore, when querying entity and relationship attributes, it will hit the entity or relationship corresponding to the attribute faster than other types of databases, shorten the query time, and improve the query efficiency.
[0095] In another embodiment, since the attribute data of the knowledge graph is structured data, the first database may also be a relational database, and the attribute data of the knowledge graph and the system data are stored in the relational database at the same time.
[0096] Furthermore, since the same type of database can have different database languages, different knowledge graphs have different scenario requirements, and different scenario requirements correspond to different database languages, SDK encapsulation is performed on top of different types of database layers.
[0097] There is no unified description for graph database (GDB). There are two popular ones: one is Cypher Query Language (CQL), which mainly describes query operations such as vertex, edge, attribute query and graph traversal in the graph. It was first proposed by Neo4j and is now an Open Cypher standard language; the other is Gremlin query language, which is now defined by Apache Tinker Pop specification.
[0098] For search (index) databases, the Domain Specific Language (DSL) used by Elastic Search is a typical example. For relational databases, the database language generally refers to the Structured Query Language (SQL). Although it is called a query language, it does not only have query functions, but also manipulation functions.
[0099] Structured data query languages can be divided into two categories: Database Definition Language (DDL), which refers to the "definition" language of libraries, tables, fields, etc. in the database; Database Manipulation Language (DML), which refers to the "manipulation" language of querying, inserting, modifying, and deleting data in database tables.
[0100] For example, there are multiple computer devices in a computer cluster to store knowledge graphs. There are a first computer device, a second computer device, and a third computer device in the computer cluster. The first computer device deploys an index database Elastic Search or an index database Solr, the second computer device deploys a graph database Neo4j, and the third computer device deploys a relational database MySQL. SDK packaging is performed on the first computer device, the second computer device, and the third computer device respectively.
[0101] Encapsulating the database can shield the differences in database languages between databases of the same type at the database layer, that is, the differences between the index database Elastic Search and the index database Solr. Encapsulating the database can also hide the specific storage details of the knowledge graph, give full play to the ultimate performance of various types of underlying databases, and enable different types of databases to work together to achieve efficient storage and use.
[0102] In the embodiment of the present application, the SDK encapsulation can provide a unified external capability interface service based on different database languages, shielding the differences in the underlying databases. Therefore, the query and write advantages of various databases can be maximized. The combination, separation and coordination between various databases are guaranteed.
[0103] In another embodiment, a transaction coordination mechanism is introduced, and the transaction coordination mechanism includes a strong consistency scheme and an eventual consistency scheme. The strong consistency scheme is used to control the knowledge graph to be written into the first database and the graph database at the same time. The eventual consistency scheme is used to control the knowledge graph to be written into the first database and the graph database within a transaction cycle. The transaction coordination mechanism can be selected according to the different scenario requirements of the knowledge graph. In the application scenario where transactions are required, it can be ensured that the knowledge graph data has transaction characteristics when it is written into various types of databases at the database layer. Transaction characteristics include: atomicity, consistency, isolation, and persistence. Atomicity means that a transaction is an indivisible unit of work, and all operations included in the transaction are done or not done. Consistency means that the transaction must change the database from one consistent state to another consistent state. Isolation means that the execution of a transaction cannot be interfered with by other transactions. That is, the operations and data used within a transaction are isolated from other concurrent transactions, and the concurrently executed transactions cannot interfere with each other. Persistence means that once a transaction is committed, its changes to the data in the database should be permanent, and subsequent other operations or failures should not have any impact on it.
[0104] Since the transaction coordination mechanism can coordinate data to be written into multiple types of databases in parallel, it can reduce the performance requirements for different types of databases and effectively improve the storage efficiency of the knowledge graph to avoid knowledge graph writing bottlenecks.
[0105] It is understandable that in order to implement the functions in the above embodiments, the computer device includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and method steps of each example described in the embodiments disclosed in this application, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application scenario and design constraints of the technical solution.
[0106] Furthermore, as a response to the above Figure 2 The implementation of the method embodiment shown in the figure, the embodiment of the present application provides a storage device for a knowledge graph, which is used to store a knowledge graph. The embodiment of the device corresponds to the aforementioned method embodiment. For ease of reading, this embodiment will no longer repeat the details of the aforementioned method embodiment one by one, but it should be clear that the device in this embodiment can correspond to all the contents of the aforementioned method embodiment. Specifically, Figure 5 As shown, the storage device 500 of the knowledge graph includes:
[0107] The extraction unit 510 is used to extract the attribute data and graph structure data of the knowledge graph. The knowledge graph includes entities, relationships and attributes. The attribute data is used to indicate the attribute information of the entity and the attribute information of the relationship. The graph structure data is used to indicate the association relationship between the entity and the relationship.
[0108] The storage unit 520 is used to store the attribute data in a first database, where the first database is used to indicate a database with an indexing function; and store the graph structure data in a graph database.
[0109] Further, such as Figure 5 As shown, the extraction unit 510 is also used to: configure the first identifier of the entity in the attribute data to be the same as the second identifier in the graph structure data; configure the third identifier of the relationship in the attribute data to be the same as the fourth identifier in the graph structure data.
[0110] Further, such as Figure 5 As shown, the storage unit 520 is also used to: synchronously store attribute data to the first database according to the transaction coordination mechanism, and store graph structure data to the graph database.
[0111] Further, such as Figure 5 As shown, the device also includes an encapsulation unit 530, and the encapsulation unit 530 is used to encapsulate the first database and the graph database respectively.
[0112] Furthermore, an embodiment of the present application also provides an electronic device, the electronic device includes a processor and a memory, the extraction unit 510, the storage unit 520 and the encapsulation unit 530 are all stored in the memory as program units, and the processor executes the program units stored in the memory to implement corresponding functions. The processor includes a kernel, and the kernel retrieves the corresponding program unit from the memory.
[0113] An embodiment of the present application provides a storage medium on which a program is stored, and when the program is executed by a processor, the storage method of the knowledge graph is implemented.
[0114] An embodiment of the present application provides a processor, which is used to run a program, wherein the program executes the storage method of the knowledge graph when it is running.
[0115] The present application embodiment provides a device 600, such as Figure 6 As shown, the device 600 includes at least one processor 601 , and at least one memory 602 and a bus 603 connected to the processor 601 ; wherein the processor 601 and the memory 602 communicate with each other via the bus 603 .
[0116] The bus 603 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0117] Among them, the processor 601 can be a central processing unit (CPU), and the processor 601 is used to call the program instructions in the memory 602 to execute the above-mentioned knowledge graph storage method.
[0118] The memory 602 may include a volatile memory, such as a random access memory (RAM). The memory 602 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a HDD or a SSD. The memory 602 stores an executable code, and the processor 601 executes the executable code to execute the aforementioned knowledge graph storage method.
[0119] The devices in this article can be servers, PCs, PADs, mobile phones, etc.
[0120] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having the following method steps: extracting attribute data and graph structure data of a knowledge graph, the knowledge graph including entities, relationships and attributes, the attribute data being used to indicate attribute information of entities and attribute information of relationships, the graph structure data being used to indicate the association relationship between entities and relationships, storing the attribute data in a first database, the first database being used to indicate a database having an indexing function; and storing the graph structure data in a graph database.
[0121] Furthermore, after extracting the attribute data and graph structure data of the knowledge graph, the method also includes: configuring the first identifier of the entity in the attribute data to be the same as the second identifier in the graph structure data; configuring the third identifier of the relationship in the attribute data to be the same as the fourth identifier in the graph structure data.
[0122] Furthermore, storing the attribute data in the first database and storing the graph structure data in the graph database includes: synchronously storing the attribute data in the first database and storing the graph structure data in the graph database according to a transaction coordination mechanism.
[0123] Furthermore, the method also includes: encapsulating the first database and the graph database respectively.
[0124] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0125] In a typical configuration, the device includes one or more processors (CPU), memory and bus. The device may also include input / output interface, network interface and the like.
[0126] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip. The memory is an example of a computer-readable medium.
[0127] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. 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 technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0128] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity 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, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0129] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt 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.) that contain computer-usable program code.
[0130] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A method for storing knowledge graphs. It is characterized in that The method comprises: Extracting attribute data and graph structure data of a knowledge graph, wherein the knowledge graph includes entities, relationships, and attributes, wherein the attribute data is used to indicate attribute information of the entities and attribute information of the relationships, and the graph structure data is used to indicate associations between the entities and the relationships; storing the attribute data in a first database, where the first database is used to indicate a database with an indexing function; The graph structure data is stored in a graph database.
2. The method according to claim 1, It is characterized in that After extracting the attribute data and graph structure data of the knowledge graph, the method further includes: Configuring a first identifier of the entity in the attribute data to be the same as a second identifier in the graph structure data; The third identifier for configuring the relationship in the attribute data is the same as the fourth identifier in the graph structure data.
3. The method according to claim 1, It is characterized in that Storing the attribute data in a first database and storing the graph structure data in a graph database includes: The attribute data is synchronously stored in the first database and the graph structure data is stored in the graph database according to the transaction coordination mechanism. The transaction coordination mechanism is used to control the writing of the attribute data and / or the graph structure data in different scenarios, and has transaction characteristics, and the transaction characteristics include atomicity, consistency, isolation and persistence.
4. The method according to any one of claims 1 to 3, It is characterized in that The method further comprises: The first database and the graph database are encapsulated respectively, and the encapsulation is used to eliminate the difference between different database languages of the same type of databases.
5. A storage device for a knowledge graph, It is characterized in that The device comprises: An extraction unit, used to extract attribute data and graph structure data of a knowledge graph, wherein the knowledge graph includes entities, relationships and attributes, wherein the attribute data is used to indicate attribute information of the entities and attribute information of the relationships, and the graph structure data is used to indicate associations between the entities and the relationships; a storage unit, used to store the attribute data in a first database, wherein the first database is used to indicate a database having an indexing function; and The graph structure data is stored in a graph database.
6. The device according to claim 5, It is characterized in that The extraction unit is also used for: Configuring a first identifier of the entity in the attribute data to be the same as a second identifier in the graph structure data; The third identifier for configuring the relationship in the attribute data is the same as the fourth identifier in the graph structure data.
7. The device according to claim 5, It is characterized in that The storage unit is also used for: The attribute data is synchronously stored in the first database and the graph structure data is stored in the graph database according to the transaction coordination mechanism. The transaction coordination mechanism is used to control the writing of the attribute data and / or the graph structure data in different scenarios, and has transaction characteristics, and the transaction characteristics include atomicity, consistency, isolation and persistence.
8. The device according to any one of claims 5 to 7, It is characterized in that The device also includes an encapsulation unit, which is used to encapsulate the first database and the graph database respectively, and the encapsulation is used to eliminate the differences between different database languages of the same type of databases.
9. A storage medium, It is characterized in that The storage medium includes a stored program, wherein, when the program is running, the device where the storage medium is located is controlled to execute the knowledge graph storage method as described in any one of claims 1-4.
10. An electronic device, It is characterized in that The device includes at least one processor, and at least one memory and a bus connected to the processor; wherein the processor and the memory communicate with each other through the bus; the processor is used to call program instructions in the memory to execute the knowledge graph storage method as described in any one of claims 1-4.
Citation Information
Patent Citations
Knowledge graph system and graph server thereof
CN109670089A
A hybrid storage method and system for knowledge graph data relation separation
CN109710618A
Data storage method and device and data retrieval method and device
CN112445889A
Distributed transaction processing method and device based on independent transaction coordinator and medium
CN114528073A
High-performance storage query method and device for power grid security and stability situation knowledge graph
CN116126978A
Cited By
Entity extraction, storage and retrieval method based on LLM and multiple databases
CN120316265A
