A graph database dimension reduction method and device, electronic equipment and storage medium
By filtering shared edges and vertices in the graph database for dimensionality reduction, the query pressure problem of graph databases when querying the vertex relationships of four-hop graphs is solved, and the query efficiency is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI SHIZHUANG INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2022-11-10
- Publication Date
- 2026-05-29
AI Technical Summary
Existing graph databases experience significant query pressure when querying the vertex relationships in a four-hop graph, resulting in long query times.
By determining whether the number of edges traversed from the first vertex to the second vertex in the graph database meets the preset conditions (the number is greater than a threshold and includes shared edges), and by performing dimensionality reduction based on shared edges and vertices, a dimensionality-reduced database is constructed, reducing the query path.
It effectively reduces the query pressure on graph databases, decreases query time, and improves query response speed.
Smart Images

Figure CN115658977B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of graph databases and data processing, and more specifically, to a graph database dimensionality reduction method, apparatus, electronic device, and storage medium. Background Technology
[0002] Current graph databases offer good performance support for one-hop and two-hop graph vertex relationships (i.e., the number of edges traversed between two vertices). For example, in graph databases like Neo4j, queries for vertices where the number of edges traversed between two vertices is within two hops respond quickly. However, in practice, it has been found that querying four-hop graph vertex relationships results in extremely high query pressure on the graph database. Therefore, current graph databases generally have long query times. Summary of the Invention
[0003] The purpose of this application is to provide a graph database dimensionality reduction method, apparatus, electronic device, and storage medium to improve the problem of long query time in graph databases.
[0004] This application provides a graph database dimensionality reduction method, including: obtaining multiple edges traversed from a first vertex to a second vertex in the graph database; determining whether the multiple edges traversed from the first vertex to the second vertex meet preset conditions, the preset conditions including: the number of multiple edges is greater than a preset threshold, and the multiple edges include shared edges; if so, then performing dimensionality reduction on the graph database based on the shared edges, the first vertex, and the second vertex to obtain a dimensionality-reduced database. In the implementation of the above scheme, by performing dimensionality reduction on the graph database based on the shared edges, the first vertex, and the second vertex when the number of multiple edges traversed from the first vertex to the second vertex in the graph database is greater than a preset threshold and the multiple edges include shared edges, the query pressure on the graph database is reduced, effectively reducing the query time of the dimensionality-reduced database.
[0005] Optionally, in this embodiment, dimensionality reduction of the graph database based on shared edges, the first vertex, and the second vertex includes: filtering out shared edges from multiple edges that traverse from the first vertex to the second vertex; and constructing a dimensionality-reduced database based on the first vertex, the second vertex, and the shared edges, wherein the number of edges traversed from the first vertex to the second vertex in the dimensionality-reduced database is less than the number of edges traversed from the first vertex to the second vertex in the graph database. In the implementation of the above scheme, by filtering out shared edges from multiple edges that traverse from the first vertex to the second vertex and constructing a dimensionality-reduced database based on the first vertex, the query pressure on the graph database is reduced, effectively decreasing the query time of the dimensionality-reduced database.
[0006] Optionally, in this embodiment, after obtaining the dimensionality reduction database, the method further includes: obtaining a query request, the query request including: a first vertex and a hop count, the query request being used to query vertices whose number of edges originating from the first vertex is less than or equal to the hop count; determining whether the hop count is greater than a preset threshold; if so, querying the vertices in the dimensionality reduction database whose number of edges originating from the first vertex is less than or equal to the preset threshold. In the implementation of the above scheme, by querying the vertices in the dimensionality reduction database whose number of edges originating from the first vertex is less than or equal to the preset threshold when the hop count is greater than the preset threshold, the query pressure on the graph database is reduced, effectively reducing the query time of the dimensionality reduction database.
[0007] Optionally, in this embodiment, after determining whether the hop count is greater than a preset threshold, the method further includes: if the hop count is less than or equal to the preset threshold, then querying the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the hop count. In the implementation of the above scheme, by querying the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the hop count when the hop count is less than or equal to the preset threshold, the graph database is only allowed to perform query operations where the hop count is less than or equal to the preset threshold, thus reducing the query pressure on the graph database and effectively reducing the query time of the dimensionality reduction database.
[0008] Optionally, in this embodiment of the application, querying the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops includes: determining whether the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to a preset threshold is less than a vertex threshold; if so, querying the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops.
[0009] Optionally, in this embodiment, after determining whether the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to a preset threshold is less than a vertex threshold, the method further includes: if the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to the preset threshold is greater than or equal to the vertex threshold, then the graph database is dimensionality reduced based on the first vertex. In the implementation of the above scheme, by directly querying ordinary nodes instead of dense nodes (i.e., vertices whose number of edges originating from the first vertex is less than or equal to the preset threshold and whose number of edges originating from the first vertex is greater than or equal to the vertex threshold) when the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to the preset threshold is less than the vertex threshold, the query pressure on the graph database is reduced, effectively reducing the query time of the dimensionality-reduced database.
[0010] Optionally, in this embodiment of the application, the graph database includes Nebula or Neo4j.
[0011] This application embodiment also provides a graph database dimensionality reduction device, including: a graph vertex edge acquisition module, used to acquire multiple edges traversed from a first vertex to a second vertex in the graph database; a preset condition judgment module, used to judge whether the multiple edges traversed from the first vertex to the second vertex meet preset conditions, the preset conditions including: the number of multiple edges is greater than a preset threshold, and the multiple edges include shared edges; and a graph database dimensionality reduction module, used to perform dimensionality reduction on the graph database based on shared edges, the first vertex, and the second vertex if the multiple edges traversed from the first vertex to the second vertex meet the preset conditions, to obtain a dimensionality-reduced database.
[0012] Optionally, in this embodiment of the application, the graph database dimensionality reduction module includes: a graph edge filtering submodule, used to filter out the common edges traversed from the first vertex to the second vertex from multiple edges; and a dimensionality reduction construction submodule, used to construct a dimensionality reduction database based on the first vertex, the second vertex, and the common edges, wherein the number of edges traversed from the first vertex to the second vertex in the dimensionality reduction database is less than the number of edges traversed from the first vertex to the second vertex in the graph database.
[0013] Optionally, in this embodiment of the application, the graph database dimensionality reduction device further includes: a query request acquisition module, used to acquire a query request, the query request including: a first vertex and a hop count, the query request being used to query vertices whose number of edges originating from the first vertex is less than or equal to the hop count; a preset threshold judgment module, used to determine whether the hop count is greater than a preset threshold; and a dimensionality reduction vertex query module, used to query vertices in the dimensionality reduction database whose number of edges originating from the first vertex is less than or equal to the preset threshold if the hop count is greater than the preset threshold.
[0014] Optionally, in this embodiment of the application, the graph database dimensionality reduction device further includes: a graph database query module, used to query the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops if the number of hops is less than or equal to a preset threshold.
[0015] Optionally, in this embodiment of the application, the graph database query module includes: a vertex threshold judgment submodule, used to determine whether the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to a preset threshold is less than the vertex threshold; and a graph database query submodule, used to query the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops if the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to the preset threshold is less than the vertex threshold.
[0016] Optionally, in this embodiment of the application, the graph database query module further includes: a graph database dimensionality reduction submodule, used to reduce the dimensionality of the graph database based on the first vertex if the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to a preset threshold is greater than or equal to a vertex threshold.
[0017] Optionally, in this embodiment of the application, the graph database includes Nebula or Neo4j.
[0018] This application also provides an electronic device, including a processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and the machine-readable instructions, when executed by the processor, perform the method described above.
[0019] This application also provides a computer-readable storage medium storing a computer program that is executed by a processor to perform the methods described above.
[0020] Other features and advantages of embodiments of this application will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing embodiments of this application. Attached Figure Description
[0021] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 The diagram shown is a flowchart illustrating the graph database dimensionality reduction method provided in an embodiment of this application.
[0023] Figure 2 The diagram shown is a partial representation of the graph database provided in an embodiment of this application.
[0024] Figure 3 The diagram shown is a partial data representation of the dimensionality reduction database provided in an embodiment of this application.
[0025] Figure 4 The diagram shown is a flowchart illustrating the process of querying a dimensionality-reduced database provided in an embodiment of this application.
[0026] Figure 5 The diagram shown is a structural schematic of the graph database dimensionality reduction device provided in an embodiment of this application. Detailed Implementation
[0027] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. The components of the embodiments of this application described and shown in the accompanying drawings can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed embodiments of this application, but merely represents selected embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of the embodiments of this application.
[0028] It is understood that the terms "first" and "second" in the embodiments of this application are used to distinguish similar objects. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that the terms "first" and "second" are not necessarily different.
[0029] Before introducing the graph database dimensionality reduction method provided in the embodiments of this application, let's first introduce some concepts involved in the embodiments of this application:
[0030] Graph databases (GDBs), also known as knowledge graphs, are methods or tools that connect knowledge according to certain rules and can be displayed in the form of graphs. In the library and information science field, they are called knowledge domain visualization knowledge domain mapping maps. They are a series of different graphics that show the development process and structural relationships of knowledge. They use visualization technology to describe knowledge resources and their carriers, and to mine, analyze, construct, draw and display knowledge and the interrelationships between them.
[0031] It should be noted that the graph database dimensionality reduction method provided in this application can be executed by an electronic device. Here, an electronic device refers to a device terminal or server with the function of executing computer programs. Device terminals include, for example, smartphones, personal computers, tablets, personal digital assistants, or mobile internet devices. A server refers to a device that provides computing services through a network. Servers include, for example, x86 servers and non-x86 servers. Non-x86 servers include, for example, mainframes, minicomputers, and UNIX servers.
[0032] The following describes the applicable scenarios for this graph database dimensionality reduction method. These scenarios include, but are not limited to: using this graph database dimensionality reduction method to optimize the functionality of graph databases such as Neo4j or Nebula, and reducing the query pressure on graph databases. Specifically, this graph database dimensionality reduction method can be used to reduce the dimensionality of graph databases such as Neo4j or Nebula based on shared edges, thereby reducing the query time of the dimensionality-reduced database.
[0033] Please see Figure 1 The diagram illustrates a flowchart of a graph database dimensionality reduction method provided in this application embodiment. The main idea of this method is to reduce the dimensionality of the graph database based on the shared edges when the number of edges traversed from a first vertex to a second vertex exceeds a preset threshold, thereby reducing the query pressure on the graph database. Implementation methods of the above-described graph database dimensionality reduction method may include:
[0034] Step S110: Obtain the multiple edges traversed from the first vertex to the second vertex in the graph database.
[0035] A graph database (GDB), also known as a knowledge graph, refers to a method or tool that connects knowledge according to certain rules and can display it in the form of a graph. It uses visualization technology to describe knowledge resources and their carriers. The graph database in this application embodiment can specifically use, but is not limited to, Neo4j or Nebula, etc.
[0036] Please see Figure 2 The illustration shows a partial diagram of the graph database provided in this application embodiment; an example of the implementation of step S110 above is as follows: Figure 2 In the graph database, users A, B, C, and D are all vertices (also called nodes). Assuming user A is the first vertex and user B is the second vertex, user A can reach user B via two routes, each involving only one edge: the device A edge and the device B edge. The device A edge indicates that device A has been used by both user A and user B, and similarly, the device B edge indicates that device B has been used by both user A and user B. Similarly, Figure 2 In the graph database, the phone number, network address 1, and network address 2 are also vertices. User C can reach user B via three routes. The first and second routes start from user C's vertex, successively reaching network address 1 and user A, then following the two routes from user A to user B. It's easy to calculate that the first and second routes both require 3 edges. Finally, the third route starts from user C's vertex, reaches the phone number node, and then reaches user B. It's easy to calculate that the third route only requires 2 edges. The multiple edges traversed to reach the second vertex from the first vertex in the graph database can include: the edge between user C's vertex and the phone number vertex, or the edge between user B's vertex and the phone number vertex, etc.
[0037] Step S120: Determine whether the multiple edges traversed from the first vertex to the second vertex meet the preset conditions. The preset conditions include: the number of multiple edges is greater than a preset threshold, and the multiple edges include shared edges.
[0038] A shared edge refers to an edge or a vertex and edge that are used together by two vertices of the same type. For example, if user B and user C are two user vertices of the same type, and both user B and user C use the same mobile phone number (i.e., the vertex of the mobile phone number in the graph database), then the shared edge that user B traverses to reach user C is the shared edge mentioned above.
[0039] Understandably, assuming the preset threshold is 4, the total number of edges for the three routes from user C to user B is 6. That is, the number of edges for the three routes from user C to user B is greater than the preset threshold of 4. Furthermore, two edges in the third route from user C to user B are shared edges.
[0040] Step S130: If the multiple edges traversed from the first vertex to the second vertex satisfy the preset conditions, then the graph database is dimensionality reduced based on the shared edges, the first vertex, and the second vertex to obtain a dimensionality-reduced database.
[0041] Please see Figure 3 The diagram illustrates a portion of the data in the dimensionality-reduced database provided in this embodiment. It can be understood that during the dimensionality reduction of the graph database, intermediate vertices (or nodes) in shared edges can be represented as edge relationships. For example, if both user B and user C use vertices representing phone numbers in the graph database, the shared phone number edges can be used to represent the relationship between user B and user C sharing phone numbers after dimensionality reduction. In the dimensionality-reduced database, user C can reach user B via three routes. Using a similar calculation method as described above, it can be determined that the sum of the three routes from user C to user B is four edges, which is equal to the aforementioned preset threshold. Therefore, this portion of the data can be further dimensionality-reduced.
[0042] In the above implementation process, when the number of multiple edges traversed from the first vertex to the second vertex in the graph database is greater than a preset threshold, and the multiple edges include shared edges, the graph database is dimensionality reduced based on the shared edges, the first vertex, and the second vertex, which reduces the query pressure on the graph database and effectively reduces the query time of the dimensionality-reduced database.
[0043] As an optional implementation of step S130 above, the implementation of dimensionality reduction of the graph database based on shared edges, the first vertex, and the second vertex may include:
[0044] Step S131: Select the shared edges that the first vertex passes through to reach the second vertex from the multiple edges.
[0045] Step S132: Construct a dimension-reduced database based on the first vertex, the second vertex, and the shared edges. The number of edges traversed from the first vertex to the second vertex in the dimension-reduced database is less than the number of edges traversed from the first vertex to the second vertex in the graph database.
[0046] The implementation of steps S131 to S132 above is as follows: Copy all vertices from the graph database and create a new dimensionality-reduced database based on all vertices in the graph database. Then, construct the edge between the first vertex and the second vertex based on the shared edge traversed from the first vertex to the second vertex. Specifically, from the six edges in the graph database showing three possible routes from user C to user B, select two edges from the third possible route: the edge between user C's vertex and the vertex with the phone number, or the edge between user B's vertex and the vertex with the phone number. Then, replace these two edges with the edge sharing the phone number, i.e., connect the vertices of user C and user B through the edge sharing the phone number. Figure 3 The dimensionality reduction process for the shared network address 1 edge between users A and C, and the dimensionality reduction process for the shared network address 2 edge between users B and D, follows a similar technical principle and will not be elaborated further. Once all dimensionality-reducible processes in the graph database are completed, the edge relationships in the dimensionality-reduced database are constructed, thus obtaining the dimensionality-reduced database.
[0047] Please see Figure 4 The illustrated flowchart shows a process for querying a dimensionality-reduced database according to an embodiment of this application. As an optional implementation of the above-described graph database dimensionality reduction method, after obtaining the dimensionality-reduced database, it can also be queried. This implementation may include:
[0048] Step S210: Obtain a query request. The query request includes: the first vertex and the number of hops. The query request is used to query vertices whose number of edges originating from the first vertex is less than or equal to the number of hops.
[0049] An example implementation of step S210 above is as follows: A user uses a terminal device to send a query request to an electronic device via Transmission Control Protocol (TCP) or User Datagram Protocol (UDP). This query request may contain a query statement for the Neo4j or Nebula database. After receiving the query request sent by the user through the terminal device via TCP or UDP, the electronic device can parse the user A's vertices and hop count (which can be set by the user, for example, to 2 or 4, etc.) from the query request.
[0050] Step S220: Determine whether the number of jumps is greater than the preset threshold.
[0051] For example, the implementation of step S220 above involves using an executable program compiled or interpreted in a preset programming language to determine whether the number of jumps is greater than a preset threshold. The preset threshold is a pre-set limit threshold that can be set according to specific circumstances, such as 2, 4, or 5. Programming languages that can be used include C, C++, Java, BASIC, JavaScript, LISP, Shell, Perl, Ruby, Python, and PHP, etc.
[0052] Step S230: If the number of hops is greater than the preset threshold, then query the vertices in the dimensionality reduction database whose number of edges originating from the first vertex is less than or equal to the preset threshold.
[0053] An example implementation of step S230 above: Assuming the hop count is 4 and the preset threshold is 2, then the hop count 4 is greater than the preset threshold 2. Since the dimensionality reduction database is a database after pre-reducing the dimensionality of the graph database (i.e., reducing the dimensionality from 4 hops to a level where only 2 hops are needed to complete the original 4-hop query), it is possible to query vertices in the dimensionality reduction database whose number of edges originating from the first vertex is less than or equal to the preset threshold 2. It is understandable that graph databases such as Neo4j or Nebula provide good support for 2-hop queries and have fast response times. Therefore, using a dimensionality reduction database to query vertices whose number of edges originating from the first vertex is less than or equal to the preset threshold can effectively improve query response speed.
[0054] As an optional implementation of the above-mentioned graph database dimensionality reduction method, after determining whether the number of hops is greater than a preset threshold, it may further include:
[0055] Step S240: If the number of hops is less than or equal to a preset threshold, then query the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops.
[0056] For example, in implementing step S240 above: assuming the hop count is 2 and the preset threshold is 2, then the hop count of 2 is equal to the preset threshold of 2. Since graph databases such as Neo4j or Nebula have good support for 2-hop queries and fast response speeds, in this case, we can directly query the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the hop count; that is, we can directly query the graph database for vertices whose number of edges originating from the first vertex is less than or equal to 2 hops. The query process and technical principle for a hop count of 1 are similar, so they will not be described in detail here.
[0057] As an optional implementation of step S240 above, querying the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops includes:
[0058] Step S241: Determine whether the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to a preset threshold is less than the vertex threshold.
[0059] Understandably, in graph databases, when the number of vertices within a preset threshold hop count from the first vertex is greater than or equal to a vertex threshold, the first vertex can be called a dense vertex or dense node. Since graph databases like Neo4j or Nebula have relatively few dense vertices, when querying non-dense nodes (i.e., the number of vertices within a preset threshold hop count from the first vertex is less than the vertex threshold), the query operation can be directly performed using the graph database. When querying dense nodes, a dimensionality reduction operation can be triggered, reducing the dense node to a dimensionality-reduced database. This allows subsequent queries on that dense node to be executed directly in the dimensionality-reduced database, effectively improving the query speed for that dense node.
[0060] Step S242: If the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to a preset threshold is less than the vertex threshold, then query the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops.
[0061] For example, the implementation of steps S241 to S242 above is as follows: Assuming the first vertex is user C, and the preset threshold is 4, and the vertex threshold is 10, it can be calculated that the number of vertices in the graph database with the number of edges originating from user C less than or equal to 4 is 6. Then it can be determined that the number of vertices 6 is less than the vertex threshold of 10. At this time, it is possible to directly query the graph database for vertices with the number of edges originating from user C less than or equal to the number of hops 4.
[0062] As an optional implementation of step S240 above, after determining whether the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to a preset threshold is less than a vertex threshold, the method further includes:
[0063] Step S243: If the number of edges originating from the first vertex in the graph database is less than or equal to the preset threshold and the number of vertices is greater than or equal to the vertex threshold, then the graph database is dimensionality reduced based on the first vertex.
[0064] The implementation of step S243 above includes: when querying a dense node, a dimensionality reduction operation on the dense node can be triggered, that is, the dense node is reduced to a dimensionality-reduced database, so that subsequent query operations on the dense node are directly executed in the dimensionality-reduced database, thereby effectively improving the query speed of the dense node. For example: assuming the first vertex is user C, and the preset threshold is 4, and the vertex threshold is 5, it can be calculated that the number of vertices in the graph database with edges originating from user C less than or equal to 4 is 6. Then it can be determined that the number of vertices 6 is greater than the vertex threshold 5. At this time, dimensionality reduction can be performed on the graph database based on user C. The specific dimensionality reduction process is similar to that above, so it will not be repeated.
[0065] In the implementation of the above scheme, as an optional implementation method of the graph database dimensionality reduction method, the graph database in this application embodiment includes, but is not limited to, Nebula or Neo4j. By allowing the graph database to directly query ordinary nodes when the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to a preset threshold is less than the vertex threshold, instead of allowing the graph database to query dense nodes (i.e., vertices whose number of edges originating from the first vertex is less than or equal to the preset threshold and whose number of vertices is greater than or equal to the vertex threshold), the query pressure on graph databases such as Nebula or Neo4j is reduced, and the query time of the dimensionality reduction database is effectively reduced.
[0066] Please see Figure 5 The diagram shown is a structural schematic of a graph database dimensionality reduction device provided in an embodiment of this application. This application provides a graph database dimensionality reduction device 300, including:
[0067] The graph vertex edge acquisition module 310 is used to acquire the multiple edges traversed from the first vertex to the second vertex in the graph database.
[0068] The preset condition judgment module 320 is used to determine whether the multiple edges traversed from the first vertex to the second vertex meet the preset conditions. The preset conditions include: the number of multiple edges is greater than a preset threshold, and the multiple edges include shared edges.
[0069] The graph database dimensionality reduction module 330 is used to reduce the dimensionality of the graph database based on the shared edges, the first vertex, and the second vertex if the multiple edges traversed from the first vertex to the second vertex meet preset conditions, thereby obtaining a dimensionality-reduced database.
[0070] Optionally, in this embodiment of the application, the graph database dimensionality reduction module includes:
[0071] The graph edge filtering submodule is used to filter out the shared edges that the first vertex passes through to reach the second vertex from multiple edges.
[0072] The dimensionality reduction construction submodule is used to construct a dimensionality reduction database based on the first vertex, the second vertex, and shared edges. The number of edges traversed from the first vertex to the second vertex in the dimensionality reduction database is less than the number of edges traversed from the first vertex to the second vertex in the graph database.
[0073] Optionally, in this embodiment of the application, the graph database dimensionality reduction device further includes:
[0074] The query request acquisition module is used to acquire query requests, which include the first vertex and the number of hops. The query request is used to find vertices whose number of edges originating from the first vertex is less than or equal to the number of hops.
[0075] The preset threshold judgment module is used to determine whether the number of jumps is greater than the preset threshold.
[0076] The dimension reduction vertex query module is used to query the dimension reduction database for vertices whose number of edges originating from the first vertex is less than or equal to the preset threshold if the number of hops is greater than the preset threshold.
[0077] Optionally, in this embodiment of the application, the graph database dimensionality reduction device further includes:
[0078] The graph database query module is used to query the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops if the number of hops is less than or equal to a preset threshold.
[0079] Optionally, in this embodiment of the application, the graph database query module includes:
[0080] The vertex threshold determination submodule is used to determine whether the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to a preset threshold is less than the vertex threshold.
[0081] The graph database query submodule is used to query the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops if the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to a preset threshold is less than the vertex threshold.
[0082] Optionally, in this embodiment of the application, the graph database query module further includes:
[0083] The graph database dimensionality reduction submodule is used to reduce the dimensionality of the graph database based on the first vertex if the number of edges originating from the first vertex in the graph database is less than or equal to a preset threshold and the number of vertices is greater than or equal to a vertex threshold.
[0084] Optionally, in this embodiment of the application, the graph database includes Nebula or Neo4j.
[0085] It should be understood that this device corresponds to the above-described graph database dimensionality reduction method embodiment and is capable of performing the various steps involved in the above method embodiment. The specific functions of this device can be found in the description above, and detailed descriptions are omitted here to avoid repetition. The device includes at least one software functional module that can be stored in memory or embedded in the device's operating system (OS) in the form of software or firmware.
[0086] An electronic device provided in this application includes a processor and a memory. The memory stores machine-readable instructions that can be executed by the processor. When the machine-readable instructions are executed by the processor, the method described above is performed.
[0087] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the method described above. The computer-readable storage medium can be implemented using any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0088] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For apparatus embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0089] It should be understood that the disclosed apparatus and methods can also be implemented in other ways, as provided in the embodiments of this application. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in the flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the accompanying drawings. For example, two consecutive blocks may actually be executed substantially in parallel, or they may sometimes be executed in reverse order, depending primarily on the functions involved.
[0090] Furthermore, the functional modules of each embodiment in this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part. In addition, in the description of this specification, the reference to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., means that the specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. Furthermore, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0091] The above description is only an optional implementation of the embodiments of this application, but the protection scope of the embodiments of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the embodiments of this application should be covered within the protection scope of the embodiments of this application.
Claims
1. A method for dimensionality reduction of graph databases, characterized in that, include: Retrieve the number of edges traversed from the first vertex to the second vertex in the graph database; Determine whether the multiple edges traversed by the first vertex to reach the second vertex meet the preset conditions. The preset conditions include: the number of multiple edges is greater than a preset threshold, and the multiple edges include shared edges. A shared edge refers to an edge that has a shared relationship between two vertices of the same type or a vertex and edge that are used together. If so, the graph database is dimensionality reduced based on the shared edges, the first vertex, and the second vertex to obtain a dimensionality-reduced database; After obtaining the dimensionality reduction database, the process also includes: Obtain a query request, the query request including: the first vertex and the number of hops, the query request is used to query vertices whose number of edges originating from the first vertex is less than or equal to the number of hops; Determine whether the number of hops is greater than the preset threshold; If so, then query the dimensionality reduction database for vertices whose number of edges originating from the first vertex is less than or equal to the preset threshold; If not, then query the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops; The step of reducing the dimensionality of the graph database based on the shared edge, the first vertex, and the second vertex to obtain a dimensionality-reduced database includes: From the plurality of edges, select the edge through which the first vertex reaches the second vertex; The dimensionality reduction database is constructed based on the first vertex, the second vertex, and the shared edge, and the intermediate vertices or nodes in the shared edge are converted into edge relationships to represent the relationship. The number of edges traversed from the first vertex to the second vertex in the dimensionality reduction database is less than the number of edges traversed from the first vertex to the second vertex in the graph database.
2. The method according to claim 1, characterized in that, The step of querying the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops includes: Obtain the number of vertices in the graph database whose number of edges originating from the first vertex is less than or equal to the preset threshold; Determine whether the number of vertices is less than a vertex threshold, where the vertex threshold refers to a preset vertex number threshold; If so, then query the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops.
3. The method according to claim 2, characterized in that, After determining whether the number of vertices is less than the vertex threshold, the process also includes: If the number of vertices is greater than or equal to the vertex threshold, then the graph database is dimensionality reduced based on the first vertex.
4. The method according to any one of claims 1-3, characterized in that, The graph databases include Nebula or Neo4j.
5. A graph database dimensionality reduction device, characterized in that, include: The graph vertex and edge acquisition module is used to obtain the multiple edges traversed from the first vertex to the second vertex in the graph database; The preset condition judgment module is used to determine whether the multiple edges traversed by the first vertex to reach the second vertex meet the preset conditions. The preset conditions include: the number of multiple edges is greater than a preset threshold, and the multiple edges include shared edges. The shared edges refer to edges that have a shared usage relationship between two vertices of the same type or vertices and edges that are used together. The graph database dimensionality reduction module is used to reduce the dimensionality of the graph database based on the shared edges, the first vertex, and the second vertex if the multiple edges traversed by the first vertex to reach the second vertex meet preset conditions, thereby obtaining a dimensionality-reduced database. A query request acquisition module is used to acquire a query request, the query request including: the first vertex and the number of hops, the query request being used to query vertices whose number of edges originating from the first vertex is less than or equal to the number of hops; A preset threshold determination module is used to determine whether the number of jumps is greater than the preset threshold; The dimension reduction vertex query module is used to query the dimension reduction database for vertices whose number of edges originating from the first vertex is less than or equal to the preset threshold if the number of hops is greater than the preset threshold. The graph database query module is used to query the graph database for vertices whose number of edges originating from the first vertex is less than or equal to the number of hops if the number of hops is less than or equal to the preset threshold. Specifically, the graph database dimensionality reduction module is used to filter out the shared edges from the multiple edges that lead from the first vertex to the second vertex; construct the dimensionality reduction database based on the first vertex, the second vertex, and the shared edges; and convert the intermediate vertices or nodes in the shared edges into edge relationships. The number of edges that lead from the first vertex to the second vertex in the dimensionality reduction database is less than the number of edges that lead from the first vertex to the second vertex in the graph database.
6. An electronic device, characterized in that, include: A processor and a memory, the memory storing machine-readable instructions executable by the processor, which, when executed by the processor, perform the method as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the method as described in any one of claims 1 to 4.