This tutorial will show you how to extract knowledge graph triplets from raw text using the Triplets tool to support GraphRAG based applications.

Introduction

Knowledge Graphs can help to abstract the information available from unstructured text. By extracting relationships from a knowledge base, you can condense the original data to its most salient information to facilitate precise search results.

Anatomy of a Triplet

Relationships in Knowledge Graphs are encoded through (subject, predicate, object) triplets. By indexing these triplets, along with additional ontological information, you can make robust inferences from limited data.

For example, in the triplet (Beatles, performed, ‘Hello, Goodbye’), “Beatles” is the subject, “performed” is the predicate, and “‘Hello, Goodbye’” is the object. Such triplets can be linked and expanded to build a comprehensive knowledge graph.

Extracting Triplets

Navigate to the Triplets tool to get started. Pick a name for your triplet extraction job and upload your data formatted as a text file. Click the “Create” button to process. You’ll then be redirected to the Datasets view where you can see the progress of your triplets job.

Once completed, click the name of your triplets job. You should see a preview of your triplets in a table with four columns like:

SubjectPredicateObjectSource
Beatlesperformed’Hello, Goodbye’In a vibrant performance, the Beatles enchanted the audience with their lively rendition of “Hello, Goodbye.”

Scrolling to the bottom of the view you’ll find the “Download Full Dataset” button to download the triplets. Once downloaded, you can use them to build a knowledge graph to use with GraphRAG based applications.

Build a Knowledge Graph

You can use your triplets in a variety of ways, including building a knowledge graph to query. In this example, we’ll use the llamaindex KnowledgeGraphIndex class to help us do just that. First, make sure you have the following dependencies installed:

Then run this example, updating the fields as indicated with the name of your downloaded triplets csv file and your desired query. If you want to generate a response from your knowlege graph using OpenAI, make sure to set your key as an environment variable.

What’s next?

You’ve extracted triplets from your text data to build a knowledge graph. You can explore other tools in the Remyx Studio like: