Get Started With GraphRAG
Vijaya Kumar Pabothu
Senior Manager and Certified Architect(L1) at Capgemini | AWS Solutions Architect (Gen AI) | AWS ? GEN AI ? Data Engineering ? Cloud Migration ? Data Platforms ? AI ? ML? HADOOP ? SPARK ? Big Data Technologies
GraphRAG Overview
Retrieval-Augmented Generation (RAG) is a technique to search for information based on a user query and provide the results as reference for an AI answer to be generated. This technique is an important part of most LLM-based tools and the majority of RAG approaches use vector similarity as the search technique.
GraphRAG uses LLM-generated knowledge graphs to provide substantial improvements in question-and-answer performance when conducting document analysis of complex information.
With the rise of Generative AI the ability for an application to provide comprehensive and explainable results has become critical. While architectures such as Retrieval Augmented Generation (RAG) have become popular ways to help mitigate these issues, combining them with knowledge graphs, using a technique called GraphRAG, has proven to be a valuable tool for getting better results.
Vector and graph queries each add value in RAG.This is distinct from “vector-only RAG,” which is strictly based on similarity with embeddings based on words in text.
GraphRAG Pattern
Fundamentally, GraphRAG is RAG, where the Retrieval path includes a knowledge graph. As you can see below, the core GraphRAG pattern is straightforward. It’s basically the same architecture as RAG with vectors but with a knowledge graph layered into the picture
For us, it’s a set of RAG patterns that leverage a graph structure for retrieval. Each pattern demands a unique data structure, or graph pattern, to function effectively.
Here, you see a graph query being triggered. It can optionally include a vector similarity component. You can choose to store your graphs and vectors either separately in two distinct databases, or use a graph database like Amazon Neptune which also supports vector search.
One of the common patterns for using GraphRAG is as follows:
Patterns vary by use case, and like everything else in AI today, GraphRAG is proving to be a rich space, with new discoveries emerging every week.
GraphRAG Lifecycle
A GenAI application that uses GraphRAG follows the same pattern as any RAG application, with an added “create graph” step at the start:
Creating a graph is analogous to chunking documents and loading them into a vector database. Advances in tooling have made graph creation literally that easy. The good news is threefold:
Benefits of GraphRAG
The benefits we are seeing from GraphRAG relative to vector-only RAG fall into three main buckets:
Knowledge Graph
A knowledge graph model is especially suitable for representing both structured and unstructured data with connected elements. Unlike traditional databases, they do not require a rigid schema but are more flexible in the data model. The graph model allows efficient storage, management, querying, and processing of the richness of real-world information. In a RAG system, the knowledge graph serves as the flexible memory companion to the language skills of LLMs, such as summarization, translation, and extraction.
In a knowledge graph, facts and entities are represented as nodes with attributes connected with typed relationships, which also carry attributes for qualification. This graph model can scale from a simple family tree to the complete digital twin of a company encompassing employees, customers, processes, products, partnerships, and resources, with millions or billions of connections.
Graph structures can originate from various sources, from a structured business domain, (hierarchical) document representations, and signals computed by graph algorithms.
When we dive into retrieval patterns, we notice how the most advanced techniques rely on the connections within the data. Whether it’s metadata filtering, like searching for articles by a specific author or on a particular topic, or parent-child retrievers, which navigate back to the parent of a text chunk to provide breadth to the LLM for context-enriched answers, these methods leverage the relationships between the data to be retrieved.
Typically, these implementations rely heavily on client-side data structures and extensive Python code connecting the different pieces of information. However, in a graph database, establishing real relationships and querying them with simple patterns is much more efficient.
In the graph pattern of almost every pattern, you will see the entities or domain nodes that represent your application domain domain relationships document nodes that represent the unstructured documents ingested into the graph.
Natural language querying allows users to interact with computer systems using everyday human language, rather than having to learn and use structured query languages or complex programming commands. This capability enables users to ask questions or provide instructions in their native tongue, and the system can then process this input to understand the user's intent and provide relevant information or perform the requested action.
However, in many real-world applications, it is not safe or appropriate to allow users to ask completely open-ended questions of a data set. For example, in a banking application, you may want to give users the ability to ask about their own transactions and account balance, but you certainly wouldn't want to allow them to inquire about other users' financial information.
To address these types of use cases, we can leverage a technique called Knowledge Graph Retrieval. Here, a large language model (LLM) is used to extract key entities from the user's natural language question. These extracted entities are then used as the parameters for a pre-defined, templated query. This approach gives the application developer the freedom to create optimized, secure queries with appropriate data access controls, while still providing users with a natural language interface on top of the underlying data.
Chunking
Text documents can be short (a social sedia post or comment) or very long (a book).
As longer text documents cover many different topics in sequential order (sometimes with references), it is desireable to structure them into smaller pieces that are semantically coherent and focus on one topic.
This process of splitting up documents into smaller pieces is called Chunking.
There are a number of different chunking strategies, listed below.
Extracting Nodes and Relationships
The next step is constructing knowledge from text chunks. For this use case, we use an LLM to extract structured information in the form of nodes and relationships from the text. You can examine the LLM prompt the authors used in the paper. They have LLM prompts where we can predefine node labels if needed, but by default, that’s optional. Additionally, the extracted relationships in the original documentation don’t really have a type, only a description. I imagine the reason behind this choice is to allow the LLM to extract and retain richer and more nuanced information as relationships. But it’s difficult to have a clean knowledge graph with no relationship-type specifications (the descriptions could go into a property).
GraphRAG-Amazon Bedrock with Neptune
Amazon Bedrock Knowledge Bases offers fully-managed, end-to-end Retrieval-Augmented Generation (RAG) workflows to create highly accurate, low latency, and custom Generative AI applications by incorporating contextual information from your company's data sources. Amazon Bedrock Knowledge Bases now offers a fully-managed GraphRAG capability with Amazon Neptune Analytics.
Previously, customers faced challenges in conducting exhaustive, multi-step searches across disparate content. By identifying key entities across documents, GraphRAG delivers insights that leverage relationships within the data, enabling improved responses to end users. For example, users can ask a travel application for family-friendly beach destinations with direct flights and good seafood restaurants.
Developers building Generative AI applications can enable GraphRAG in just a few clicks by specifying their data sources and choosing Amazon Neptune Analytics as their vector store when creating a knowledge base. This will automatically generate and store vector embeddings in Amazon Neptune Analytics, along with a graph representation of entities and their relationships.
GraphRAG with Amazon Neptune is built right into Amazon Bedrock Knowledge Bases, offering an integrated experience with no additional setup or additional charges beyond the underlying services
Amazon Bedrock Knowledge Bases offers a fully managed GraphRAG feature with Amazon Neptune. This functionality uses Retrieval Augmented Generation (RAG) techniques combined with graphs to enhance generative AI applications so that end users can get more accurate and comprehensive responses.
GraphRAG automatically identifies and uses relationships between related entities and structural elements (such as section titles) across documents that are ingested into Amazon Bedrock Knowledge Bases. This means that generative AI applications can deliver more relevant responses in cases where connecting data and reasoning across multiple document chunks is needed.
Amazon Bedrock Knowledge Bases automatically manages the creation and maintenance of the graphs from Amazon Neptune, so you can provide relevant responses to your end users, without relying on expertise in graph techniques.
Amazon Bedrock Knowledge Bases with GraphRAG offers the following benefits:
Using graphs with Amazon Neptune just got a whole lot simpler with Langchain and LLMs! Customers use graphs with Amazon Neptune for use cases like detecting fraud, customer 360, and security posture assessment. They also use Amazon Neptune to build knowledge graphs that connect disparate data sources.
领英推荐
Implementing GraphRAG offers a powerful approach to using the strengths of both LLMs and structured knowledge bases. Integrating the natural language understanding capabilities of language models with the factual and contextual information contained within knowledge graphs, GraphRAG enables the generation of highly accurate and informative responses. Amazon Bedrock and Amazon Neptune to facilitate the implementation of GraphRAG and increase the capabilities of generative artificial intelligence (AI)-powered applications.
GraphRAG- databases
A graph database allows you to model, store and query your data in the form of a graph, or network structure. Graphs and graph databases are ideal for applications where you need to understand the connections between things, the nature or semantics of those connections, and the strength, weight or quality of each connection.
Which are purpose-built to store and navigate relationships - have emerged as a better-fit data store for identity graph solutions. Graph databases are easy to model for highly connected data, treat relationships as “first class citizens,” have flexible schemas, and provide higher performance for graph query traversals. Using a graph database for an identity graph enables you to link identifiers and update profiles with more easily and query at ultra-low latency — enabling faster updates and more accurate, up-to-date profile data for ad targeting, personalization, analytics, and ad attribution.
With a graph database you can identify patterns of connected data, follow paths that connect entities, identify indirect and transitive relationships that might not otherwise be apparent on the data, and analyze the communities to which entities belong, and the relative importance or influence of different entities within a connected structure.
Example graph database workloads include:
Introducing Amazon Neptune Amazon Neptune is a fast, reliable, and fully managed graph database service for building and running applications with highly connected datasets, such as knowledge graphs, fraud graphs, identity graphs, and security graphs.
Amazon Neptune provides two different engine offerings, Neptune Database and Neptune Analytics. You can use with this notebook however some differences may apply for certain cells.
Neptune Database is a serverless graph database designed for superior scalability and availability. Neptune Database provides built-in security, continuous backups, and integrations with other AWS services. Neptune Global Database offers cross-region data replication for low-latency reads and writes, disaster recovery, and scalability for globally distributed applications.
Neptune Analytics is an analytics database engine for quickly analyzing large volumes of graph data to get insights and find trends from data stored in Amazon S3 buckets or a Neptune database. Neptune Analytics uses built-in algorithms, vector search, and in-memory computing to run queries on data with tens of billions of relationships in seconds. With Neptune Analytics, you can get insights and find trends by processing large amounts of graph data in seconds. To analyze graph data quickly and easily, Neptune Analytics stores large graph datasets in memory. It supports a library of optimized graph analytic algorithms, low-latency graph queries, and vector search capabilities within graph traversals.
GraphRAG-Indexing
GraphRAG-Retrieval
Natural Language Querying(NLQ)
Natural Language Querying (NLQ) is an emerging technology that allows users to interact with databases and knowledge graphs using plain language instead of rigid query languages like SQL. NLQ systems use advanced natural language processing and machine learning models to understand the intent behind a user's query and translate it into the appropriate database operations. This provides a more intuitive and user-friendly way for non-technical users to access and analyze data.
One prominent query language designed for knowledge graphs is openCypher. openCypher is a declarative graph query language that allows for powerful graph pattern matching and traversal operations. openCypher queries express what information should be retrieved from the graph, rather than how to retrieve it, making it more accessible than lower-level graph APIs. The combination of NLQ and openCypher is a compelling approach for enabling flexible, natural interactions with complex connected data.
However, it's important to recognize the inherent nature of large language models (LLMs) - they will not always generate the correct query, even if the original natural language question was clear. When the generated query does not produce the expected results, we'll need to employ below techniques such as query validation, prompt tuning, and query rewriting to troubleshoot and refine the process and to mitigate some of the challenges you are likely to run into when using LLMs to generate natural language queries.
By combining these techniques together we can start to improve our query generation capabilities. However, we are still giving customers direct access to our graph so additional process safeguards, such as limiting users to read only access, need to be included to prevent misuse.
LLM Frameworks
LangChain is an open source framework for building Generative AI applications and provides key components to combine Large Language Models (LLMs) with external data.
Amazon Neptune with LangChain's NeptuneOpenCypherQAChain and Amazon Bedrock for the LLM.
LangChain's NeptuneOpenCypherQAChain provides a powerful way to enable natural language querying on top of a graph database like Amazon Neptune. The process works as follows:
This approach allows non-technical users to interact with complex graph data using plain language questions, without needing to learn the specifics of the openCypher query language. The LLM handles the translation from natural language to the appropriate graph traversal and pattern matching operations. This makes it easier for a wider range of users to derive insights from highly connected datasets stored in a graph database like Amazon Neptune.
LlamaIndex is a data structure and tooling designed to create and interact with large language model indexes. It facilitates the storage, searching, and querying of textual data using advanced vector database techniques in conjunction with large language models like GPT. This enables efficient and effective retrieval of relevant information from extensive text corpora.
LlamaIndex is the Framework for Context-Augmented LLM Applications and LlamaIndex imposes no restriction on how you use LLMs. You can use LLMs as auto-complete, chatbots, agents, and more. It just makes using them easier.
Below are the Tools in Llama Index
GraphRAG-Usage in Network and IT operations
Graph databases can be used to map complex network relationships, visualize network topologies, and perform root-cause analysis for outages
Graph databases can help telecommunications businesses become more agile by leveraging their connected data
Telecommunications is all about connections. Graph databases are, therefore, an excellent fit for modeling, storing and querying telecommunications data of all kinds. Whether managing increasingly complex network structures, ever-more-diverse product lines and bundles, or customer satisfaction and retention in today’s competitive environments, graph databases enable businesses to become more agile by leveraging their connected data.
From the network graph, to the social graph, to the call center graph, and the master data graph, telcos around the world have begun to use graph databases to achieve competitive advantage. Neo4j provides thousand-fold performance improvements and massive agility benefits over relational databases, enabling new levels of performance and insight.
Telecom inventory management tracks detailed information about physical and logical network components, including, for example, cell towers, cables, switches, routers, antennas and network devices.
References
Referred some existing Blogs and added few points based on my requirement .