You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Knowledge Graphs (KGs) combined with Large Language Models (LLMs) offer powerful solutions for data-driven applications. This guide showcases practical examples of how to integrate LLMs with Knowledge Graphs using tools like Virtuoso and Apache Jena.
8
+
Knowledge Graphs (KGs) combined with Large Language Models (LLMs) offer powerful solutions for data-driven applications.
9
+
This guide showcases practical examples of how to integrate LLMs with Knowledge Graphs using tools like **Virtuoso and Apache Jena**.
10
+
11
+
The examples use **Llama** (an open-source LLM), but you can also use OpenAI models if you have an API key.
9
12
10
13
---
11
14
12
15
## Example 1: Querying Knowledge Graphs with LLMs
13
16
14
17
<details>
15
18
16
-
### Overview
19
+
### **Overview**
20
+
21
+
In this example, we demonstrate how to **query a Virtuoso Knowledge Graph using a Large Language Model (LLM)** to retrieve meaningful insights from structured data.
17
22
18
-
In this example, we demonstrate how to query a Virtuoso Knowledge Graph using a Large Language Model (LLM) to retrieve meaningful insights from structured data. The core idea is to bridge the gap between natural language queries and structured data stored in RDF format within Virtuoso.The integration leverages `llama_index`, an interface that connects LLMs to structured data sources like SPARQL endpoints.
23
+
The key idea is to **bridge the gap between natural language queries and structured data stored in RDF format within Virtuoso**.
24
+
The integration leverages `llama_index`, an interface that connects LLMs to structured data sources like **SPARQL endpoints**.
19
25
20
26
---
21
27
22
-
## Prerequisites
28
+
## **Prerequisites**
23
29
24
-
### System Requirements:
30
+
### **System Requirements**
25
31
26
-
-**Python 3.x** installed.
27
-
-**Virtuoso Server** running with SPARQL authentication enabled.
32
+
-**Python 3.x** installed
33
+
-**Virtuoso Server** running with SPARQL authentication enabled
28
34
29
-
### Required Installations:
35
+
### **Required Installations**
30
36
31
-
1.**Uninstall existing LlamaIndex (if any):**
37
+
####**1️⃣ Install LlamaIndex and Dependencies**
32
38
33
-
```bash
34
-
pip uninstall llama_index -y
35
-
```
39
+
```bash
40
+
pip uninstall llama_index -y # Remove old versions
When the code is executed, we expect the output to provide an insightful answer extracted from the Knowledge Graph:
149
+
## **Expected Output**
159
150
160
151
```bash
161
152
Ken thinks about his identity, purpose, and the meaning of life, reflecting on his role beyond just being a supporting character.
162
153
```
163
154
164
-
This response is generated based on the RDF triples extracted from the Virtuoso knowledge graph.
155
+
This response is generated based on RDF triples extracted from the Virtuoso knowledge graph.
165
156
166
157
---
167
158
168
-
## Key Concepts
159
+
## **Key Concepts**
169
160
170
161
-**Virtuoso Integration:** The example connects to a Virtuoso SPARQL endpoint for querying RDF data.
171
-
-**LLM Query Processing:** LLM enhances the query with natural language understanding, making it user-friendly.
162
+
-**LLM Query Processing:**The LLM enhances the query with natural language understanding, making it user-friendly.
172
163
-**Knowledge Graph Indexing:** The Knowledge Graph Index improves retrieval efficiency by organizing data into meaningful chunks.
173
164
174
-
---
175
-
176
-
## Troubleshooting Tips
177
-
178
-
-**Connection Errors:** Ensure Virtuoso is running and accessible via the specified SPARQL endpoint.
179
-
-**Authentication Issues:** Verify that the provided `USER` and `PASSWORD` have the necessary SPARQL access rights.
180
-
-**API Key Errors:** Confirm that the OpenAI API key is correctly set in the environment variables.
165
+
</details>
181
166
182
167
---
183
168
184
-
## Expanding the Dataset
185
-
186
-
You can modify the SPARQL queries to explore more data points. For example:
187
-
188
-
```python
189
-
response_graph_rag = kg_rag_query_engine.query("Who is Barbie?")
190
-
print(str(response_graph_rag))
191
-
```
192
-
193
-
### Expected Output:
194
-
195
-
```bash
196
-
Barbie is a character who thinks about becoming human and living in the real world. She also contemplates what it means to be human.
197
-
```
198
-
199
-
</details>
200
-
201
-
## Example 2: Extracting Triples from Text Using LLMs
169
+
## **Example 2: Extracting Triples from Text Using LLMs**
202
170
203
171
<details>
204
172
205
-
### Overview
173
+
### **Overview**
174
+
175
+
This example demonstrates how to **automatically extract structured knowledge from unstructured text**.
176
+
Using **Llama**, we transform plain text into **triples (subject, predicate, object)** suitable for **building Knowledge Graphs**.
206
177
207
-
In this example, we showcase how to automatically extract structured knowledge (in the form of triples: subject, relation, object) from unstructured text using a Large Language Model (LLM). The goal is to transform plain text into a format suitable for building knowledge graphs, which can later be queried using SPARQL or integrated with systems like Virtuoso or Apache Jena.
0 commit comments