Graph Embeddings 101: Key Terms, Concepts and AI Applications
In Gartner’s Emerging Tech Impact Radar for 2024, only two technologies fall into the “High Impact, Right Now” category: generative AI (GenAI) and knowledge graphs. You’re probably very familiar with GenAI by now, as it’s found its way into our everyday search engine, customer support and online shopping experiences. You’re probably even implementing GenAI applications within your business to improve productivity or to create innovative new customer experiences.
You might not be as familiar with knowledge graphs and graph databases. Knowledge graphs are data sets composed of things (aka “nodes” or “entities”) and their relationships to one another (“edges”). Read on to learn the fundamentals of knowledge graph-assisted AI and how graph embeddings enhance various generative AI and semantic search use cases.
What Are Knowledge Graphs?
A popular example of a knowledge graph is your professional network, which includes you related to your current and former employers, which connects you indirectly to those employers’ current and past employees and their current and past employers, and so on. Graph databases such as Aerospike and Neo4j facilitate storing and searching knowledge graphs.
Historically, graphs have been widely used in social networks, e-commerce recommendation engines, fraud detection, computing network analysis and security and other technologies. They’ve also been instrumental in the evolution of natural language processing and internet search at Google.
With the soaring popularity of GenAI, knowledge graphs are becoming increasingly important. When integrated into AI applications, the information knowledge graphs contain about explicit relationships has been shown to increase the accuracy and completeness of GenAI responses.
What Is a Graph Embedding?
Embeddings, or vectors, are data items that represent complex pieces of information like legal documents or images. They are generated by AI models that convert the original information into a set of coordinates that place the information in a multidimensional space (like a chart with hundreds or thousands of axes). Embeddings that are closer to each other in that n-dimensional space, known as “nearest neighbors,” are similar in meaning or appearance, in the case of images.
Graph embedding is a technique that transforms elements of a graph — such as nodes, edges or entire subgraphs — into a continuous vector space while preserving the graph’s structural and relational properties. The resulting vectors, known as graph embeddings, capture the essential features and relationships of the original graph elements in a way that makes them suitable for use in various machine learning and data analysis tasks.
Why Are Graph Embeddings Useful?
Graph embeddings provide a powerful way to transform complex graph structures into continuous vector spaces, enabling more efficient analysis and processing. Capturing the essential structural and relational information of the graph in this way makes the knowledge graph accessible for generative AI, semantic search and other machine learning and data analysis tasks. This transformation facilitates various applications, such as node classification, link prediction and clustering, by allowing traditional algorithms to operate on graph data more effectively.
Furthermore, graph embeddings enable the integration of graph data with other data types, enhancing the ability to derive insights and make informed decisions across diverse domains, including social network analysis, recommendation systems, bioinformatics and fraud detection. By simplifying the complexity of graph data and making it more manageable, graph embeddings play a crucial role in advancing the capabilities of AI and other data-driven initiatives.
How Are Graph Embeddings Created?
The process of creating graph embeddings typically involves the following steps:
- Feature extraction: Identify features that capture the structural and attribute-based information of the graph elements (nodes, edges, subgraphs).
- Embedding generation: Use algorithms such as Node2Vec, DeepWalk or GraphSAGE to generate low-dimensional vector representations of the graph elements.
- Optimization: Train the embedding model to ensure that similar nodes (e.g., nodes with similar roles or in similar neighborhoods) have similar vector representations.
What Are the Key Terms to Know?
Basic concepts and terminology in graph embeddings include:
- Node embeddings: Represent individual nodes, stored and queried through the vector model.
- Edge embeddings: Represent connections between nodes, derived from node embeddings and stored similarly.
- Graph-level embeddings: Represent entire subgraphs or the entire graph, facilitating graph-wide analytics.
- Random walks and aggregation: Techniques used during the embedding generation process, leveraging the graph model to capture structural patterns.
How Are Graph Embeddings Stored and Searched?
As mentioned earlier, graph databases are used to store knowledge graphs. But what about graph embeddings, which are a different data type? The good news is that several graph databases add the ability to store and search vector data.
With your graphs and graph embeddings stored in a database, you can perform nearest-neighbor searches, which return the graph embeddings that represent the graphs that are most similar in structure or meaning to the search target. The graph embeddings can include links to their corresponding graphs for easy retrieval of the source graphs.
For example, given a graph containing information related to a banking customer, you can ask the database to find the 10 graph embeddings that represent the customer graphs most similar to that customer. This is a much easier way to find possible fraudulent identities versus traditional methods of performing searches based on comparisons of individual bits of customer and transaction data.
Combining graph embeddings (and other vectors) with knowledge graphs into a single database simplifies managing and processing graph embedding data. As knowledge graphs are created or changed, their corresponding graph embeddings can be searched or updated instantly and without having to write software to search or synchronize data across separate graph and vector databases.
How Do Graph Embeddings Enhance AI Applications?
Once you’ve created graph embeddings and stored them in a database, you can put them to work in your AI applications. With a database of graph embeddings, you can make it much easier to perform complex searches and analyses, such as:
- Bank fraud and money laundering prevention: When a person applies for a bank account, the bank forms a knowledge graph of the person’s identity: their name, address, known relatives, accounts, etc. The bank can transform this knowledge graph into a graph embedding and quickly search the database for other graph embeddings that are so similar that they might be linked to the same person and indicate identity fraud.
- Recommendation engines: As a shopper browses an e-commerce site, graph embedding searches reveal similar product catalog items (graphs!) to display to the user, thus increasing the probability they’ll make a purchase.
- Social network analysis: User relationships are stored as graphs from which graph embeddings are generated. The embeddings can be searched to identify influencers or predict new connections.
- Bioinformatics: Protein interaction networks can be transformed into graph embeddings and used to discover new drug targets by analyzing graph-structured biological data with embeddings.
Graph embeddings can also help increase the accuracy and completeness of any GenAI application. GenAI is used to formulate new content, such as answers to questions, marketing copy and even application source code. Queries are passed to large language models (LLMs), which return responses based on the knowledge they were trained on.
The relevance of the response can be increased via retrieval-augmented generation (RAG). With RAG, you submit the user query to the LLM along with some relevant contextual content the model can draw from while composing a response.
For example, in a customer-support–bot application, you might submit to the LLM one or more relevant product support articles, thus enabling it to generate a response based on specific, relevant information. However, the LLM will have to infer the most relevant parts of the article from which to create its response. If the support article supplied with the query includes multiple causes or resolutions to the customer issue, the LLM will make its best guess at the most useful parts of the supplied articles.
If you have a database of graphs and graph embeddings, you can find graphs of support issues, symptoms and resolutions related to the support question and pass those to the LLM with the query. Unlike textual support articles alone, the support knowledge graphs can make relationships between symptoms, causes and fixes explicitly clear. This, in turn, allows the LLM to return a more complete and accurate answer to the user.
Wrap Up
If you’re building GenAI applications and seeking ways to improve the quality and accuracy of your AI system output, I urge you to look into knowledge graphs and graph embeddings. Early research shows that they’re effective in significantly increasing the accuracy and completeness of GenAI responses and associated business outcomes in customer support applications and others.
The technology curves you’ll want to climb include graph data modeling, and very likely, graph databases. There are a number of resources available — online courseware, meetups, graph database vendors and others — to help you master those topics. It’s not a hard climb, but definitely worth it if you want to create differentiated GenAI solutions that meet or exceed the expectations of your project stakeholders.
When vector search is combined with other search methods, it can greatly improve AI applications. Hear experts from Aerospike and Forrester explain how to combine vector search, knowledge graphs and key-value queries in different database application architectures including RAG and GraphRAG.