Skip to content

Commit d39a925

Browse files
author
Baransel SAGINDA
committed
details added to steps and reorganized
1 parent 6c0f807 commit d39a925

File tree

5 files changed

+127
-70
lines changed

5 files changed

+127
-70
lines changed
192 KB
Loading
30.3 KB
Loading
16.3 KB
Loading
14.5 KB
Loading

content/guides/genai-rag.md renamed to content/guides/genai-leveraging-rag/index.md

Lines changed: 127 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,16 @@ params:
1111
---
1212

1313

14-
This guide walks you through setting up a powerful AI stack that integrates Retrieval-Augmented Generation (RAG) systems with graph databases. In this guide, you’ll learn how to:
1514

16-
- Set up a GenAI system that enhances language models with real-time data from graph databases
17-
- Use Docker to containerize and deploy the complete GenAI stack, including graph databases and AI models
18-
- Leverage Neo4j for efficient information retrieval and context-aware AI responses
19-
- Inspecting data in the database, ensuring smooth operation for AI-driven applications
15+
## Introduction
2016

17+
Retrieval-Augmented Generation (RAG) is a powerful framework that enhances large language models (LLMs) by integrating information retrieval from external knowledge sources. This guide focuses on a specialized RAG implementation using graph databases like Neo4j, which excel in managing highly connected, relational data. Unlike traditional RAG setups with vector databases, combining RAG with graph databases offers better context-awareness and relationship-driven insights, making it ideal for domains like recommendation systems, compliance tracking, and social networks.
2118

19+
In this guide, you will:
2220

23-
## Introduction to Graph Databases
24-
25-
All NoSQL databases can be grouped under 4 main groups:
26-
27-
* Document-based databases
28-
* Key-value stores
29-
* Column-oriented databases
30-
* Graph-based databases
31-
32-
Being one of the four main groups, graph databases are specialized database systems designed to store and query data where relationships between entities are as important as the entities themselves. Unlike traditional databases, graph databases use nodes (vertices) to store entities and edges to store relationships between these entities, making them ideal for handling highly connected data.
33-
34-
### Graph Databases vs SQL Databases
35-
36-
1. Data Model:
37-
- SQL: Uses tables with rows and columns, relationships expressed through foreign keys
38-
- Graph: Uses nodes and edges, relationships are much more flexible
39-
40-
2. Schema Flexibility:
41-
- SQL: Rigid schema, changes require extra steps
42-
- Graph: Flexible schema, can add new relationships without migrations
43-
44-
3. Use Cases:
45-
- SQL: Structured data with fixed relationships
46-
- Graph: Social networks, recommendation engines, knowledge graphs
21+
- Understand the benefits of integrating graph databases into a RAG system.
22+
- Set up a GenAI stack using Docker, including Neo4j and an AI model.
23+
- Explore a case study demonstrating the system’s effectiveness with real-world queries.
4724

4825

4926
## Understanding RAG (Retrieval-Augmented Generation)
@@ -62,80 +39,102 @@ The system operates as follows:
6239
3. The retrieved data is used to augment the input prompt for the LLM.
6340
4. The LLM generates responses that blend the model's inherent knowledge with the retrieved context.
6441

65-
### When RAG is Effective
66-
67-
1. Knowledge Limitations:
68-
- LLMs have fixed knowledge cutoffs
69-
- Cannot access real-time or specialized information
70-
- May hallucinate or provide outdated information
71-
72-
2. Business Requirements:
73-
- Need for accurate, up-to-date information
74-
- Compliance and auditability
75-
- Domain-specific knowledge integration
42+
To hold this vector information in a efficient manner, we need a special type of database.
7643

77-
3. Cost Efficiency:
78-
- Reduced need for model fine-tuning
79-
- Smaller models can perform well with good context
80-
- Lower computational requirements
8144

45+
## Introduction to Graph Databases
8246

47+
Graph databases, such as Neo4j, are specifically designed for managing highly connected data. Unlike traditional relational databases, graph databases prioritize both the entities and the relationships between them, making them ideal for tasks where connections are as important as the data itself.
8348

49+
In the broader landscape of NoSQL databases, there are four main categories:
8450

85-
## A Case Study in RAG Implementation
51+
* Document-based databases
52+
* Key-value stores
53+
* Column-oriented databases
54+
* Graph-based databases
8655

87-
### What is Apache NiFi?
56+
As one of these core categories, graph databases stand out for their unique approach to data storage and querying. They use nodes (or vertices) to represent entities and edges to represent the relationships between these entities. This structure allows for efficient handling of highly connected data and complex queries, which are difficult to manage in traditional database systems.
8857

89-
Apache NiFi is a powerful data integration tool, but in our context, it serves us as a concept rather than a tool. Since it's a relatively new concept, large language models (LLMs) may have limited or no inherent knowledge about it.
58+
### Graph Databases vs SQL Databases
9059

60+
1. Data Model:
61+
- SQL: Uses tables with rows and columns, relationships expressed through foreign keys
62+
- Graph: Uses nodes and edges, relationships are much more flexible
9163

64+
2. Schema Flexibility:
65+
- SQL: Rigid schema, changes require extra steps
66+
- Graph: Flexible schema, can add new relationships without migrations
9267

93-
Question: What is Apache Nifi?
94-
RAG: Disabled
68+
3. Use Cases:
69+
- SQL: Structured data with fixed relationships
70+
- Graph: Social networks, recommendation engines, knowledge graphs
9571

96-
Hello! I'm here to help you with your question about Apache NiFi. Unfortunately, I don't know the answer to that question. I'm just an AI and my knowledge cutoff is December 2022, so I may not be familiar with the latest technologies or software. Can you please provide more context or details about Apache NiFi? Maybe there's something I can help you with related to it.
9772

98-
Question: What is Apache Nifi?
99-
RAG: Enabled
10073

101-
Answer:
10274

103-
Apache NiFi is an open-source, distributed data processing system that allows you to collect, transform, and transport data across various sources and sinks. It provides a graphical user interface for designing and managing data flows, as well as a set of APIs for integrating with other systems.
75+
## Practical Implementation: A Case Study in RAG Effectiveness
10476

105-
According to this Stack Overflow question, the free Neo4J JDBC driver doesn't understand SQL, only Cypher, so you would need to use a non-free BI Connector to connect to Neo4j from Apache Drill.
77+
To illustrate the power of RAG systems in practice, let's examine a real-world implementation using Apache NiFi as our subject matter. This case study demonstrates how RAG can enhance an AI's ability to provide accurate, contextual information about specialized technical topics.
10678

107-
Additionally, this Stack Overflow question suggests that Apache POI does work in a Neo4j User Defined Function. However, there may be an unknown glitch in the standalone UDF mentioned in the initial question.
10879

109-
To export data from Neo4j to Excel using APOC Extended procedures, you can use apoc.export.xls.query which takes a Cypher query and exports the results to an Excel file.
11080

111-
References:
81+
## A Case Study in RAG Implementation
11282

113-
How to connect and query Neo4j Database on Apache Drill?
114-
Is a Neo4j UDF compatible with Apache POI?
83+
### Teaching AI About New Technologies
11584

85+
Apache NiFi serves as an excellent example of the limitations of traditional LLMs and how RAG can overcome them. As a relatively recent technology, many LLMs have limited or outdated knowledge about it, making it a perfect candidate for demonstrating RAG's capabilities.
11686

87+
Without RAG, the LLM may provide broad responses or acknowledge its limited knowledge when asked about information that is beyond its cutoff date.
11788

11889

11990
## Setting Up GenAI Stack with GPU Acceleration on Linux
12091

121-
To set up and run the GenAI stack on a Linux host with GPU acceleration, execute the following command:
92+
To set up and run the GenAI stack on a Linux host, execute the following command:
93+
94+
### GPU powered
12295

12396
```bash
97+
git clone https://github.com/docker/genai-stack
12498
docker compose --profile linux-gpu up -d
99+
mv env.example .env
100+
nano .env
101+
```
102+
Make sure following lines are commented out. Set your own credentials for security
103+
104+
NEO4J_URI=neo4j://database:7687
105+
NEO4J_USERNAME=neo4j
106+
NEO4J_PASSWORD=password
107+
OLLAMA_BASE_URL=http://llm-gpu:11434
108+
109+
110+
111+
### CPU powered
112+
113+
```bash
114+
git clone https://github.com/docker/genai-stack
115+
docker compose --profile linux up -d
116+
mv env.example .env
117+
nano .env
125118
```
119+
Make sure following lines are commented out. Set your own credentials for security
120+
121+
NEO4J_URI=neo4j://database:7687
122+
NEO4J_USERNAME=neo4j
123+
NEO4J_PASSWORD=password
124+
OLLAMA_BASE_URL=http://llm:11434
125+
126126

127127
### Setting Up on Other Platforms
128128

129129
For instructions on how to set up the stack on other platforms, refer to [this page](https://github.com/docker/genai-stack).
130130

131131
---
132+
### Initial Startup
132133

133-
### Notes
134-
135-
- **Initial Startup**: The first startup may take some time because the system needs to download a large language model (LLM).
136-
- **Monitoring Progress**: We can monitor the download and initialization progress by viewing the logs.
134+
The first startup may take some time because the system needs to download a large language model (LLM).
137135

138-
Run the following command to view the logs:
136+
### Monitoring Progress
137+
We can monitor the download and initialization progress by viewing the logs. Run the following command to view the logs:
139138

140139
```bash
141140
docker compose logs
@@ -153,19 +152,30 @@ Wait for specific lines in the logs indicating that the download is complete and
153152
You can now access the interface at [http://localhost:8501/](http://localhost:8501/) to ask questions. For example, you can try the sample question:
154153

155154

156-
What is Apache Nifi?
155+
When we see those lines in the logs, web apps are ready to be used.
156+
157+
Since our goal is to teach AI about things it does not yet know, we begin by asking it a simple question about Nifi at
158+
[http://localhost:8501/](http://localhost:8501/).
159+
![alt text](image.png)
160+
157161

162+
Question: What is Apache Nifi?
163+
RAG: Disabled
164+
165+
Hello! I'm here to help you with your question about Apache NiFi. Unfortunately, I don't know the answer to that question. I'm just an AI and my knowledge cutoff is December 2022, so I may not be familiar with the latest technologies or software. Can you please provide more context or details about Apache NiFi? Maybe there's something I can help you with related to it.
158166

159-
The response should be similar to the following:
160167

168+
As we can see, AI does not know anything about this subject because it did not exist during the time of its training, also known as the information cutoff point.
161169

162-
... I'm just an AI and my knowledge cutoff is December 2022...
170+
Now it's time to teach the AI some new tricks. First, connect to [http://localhost:8502/](http://localhost:8502/). Instead of using the "neo4j" tag, change it to the "apache-nifi" tag, then click the **Import** button.
163171

164172

165-
Now it's time to teach the AI some new tricks. First, connect to [loader-1](http://localhost:8502/). Instead of using the "neo4j" tag, change it to the "apache-nifi" tag, then click the **Import** button. After the import is successful, access Neo4j to verify the data.
173+
![alt text](image-1.png)
166174

167175

168176

177+
After the import is successful, we can access Neo4j to verify the data.
178+
169179
After logging in to [http://localhost:7474/](http://localhost:7474/) using the credentials from the `.env` file, you can run queries on Neo4j. Using the Neo4j Cypher query language, you can check for the data stored in the database.
170180

171181
To count the data, run the following query:
@@ -177,6 +187,11 @@ RETURN DISTINCT labels(n) AS NodeTypes, count(*) AS Count
177187
ORDER BY Count DESC;
178188
```
179189

190+
To execute this query, write in the box on the top and click the blue run button.
191+
192+
![alt text](image-2.png)
193+
194+
Results will appera below. What we are seeing here is the information system downloaded from Stack Overflow and saved in the graph database. RAG will utilize this information to enhance its responses.
180195

181196
You can also run the following query to visualize the data:
182197

@@ -190,8 +205,32 @@ To check the relationships in the database, run the following query:
190205
CALL db.relationshipTypes()
191206
```
192207

208+
209+
193210
Now, we are ready to enable our LLM to use this information. Go back to [http://localhost:8501/](http://localhost:8501/), enable the **RAG** checkbox, and ask the same question again. The LLM will now provide a more detailed answer.
194211

212+
![alt text](image-3.png)
213+
214+
The system delivers comprehensive, accurate information by pulling from current technical documentation.
215+
216+
Question: What is Apache Nifi?
217+
RAG: Enabled
218+
219+
Answer:
220+
221+
Apache NiFi is an open-source, distributed data processing system that allows you to collect, transform, and transport data across various sources and sinks. It provides a graphical user interface for designing and managing data flows, as well as a set of APIs for integrating with other systems.
222+
223+
According to this Stack Overflow question, the free Neo4J JDBC driver doesn't understand SQL, only Cypher, so you would need to use a non-free BI Connector to connect to Neo4j from Apache Drill.
224+
225+
Additionally, this Stack Overflow question suggests that Apache POI does work in a Neo4j User Defined Function. However, there may be an unknown glitch in the standalone UDF mentioned in the initial question.
226+
227+
To export data from Neo4j to Excel using APOC Extended procedures, you can use apoc.export.xls.query which takes a Cypher query and exports the results to an Excel file.
228+
229+
References:
230+
231+
How to connect and query Neo4j Database on Apache Drill?
232+
Is a Neo4j UDF compatible with Apache POI?
233+
195234
Keep in mind that new questions will be added to Stack Overflow, and due to the inherent randomness in most AI models, the answers may vary and won't be identical to those in this example.
196235

197236
Feel free to start over with another [Stack Overflow tag](https://stackoverflow.com/tags). To drop all data in Neo4j, you can use the following command in the Neo4j Web UI:
@@ -204,3 +243,21 @@ DETACH DELETE n;
204243

205244
For optimal results, choose a tag that the LLM is not familiar with.
206245

246+
247+
### When RAG is Effective
248+
249+
1. Knowledge Limitations:
250+
- LLMs have fixed knowledge cutoffs
251+
- Cannot access real-time or specialized information
252+
- May hallucinate or provide outdated information
253+
254+
2. Business Requirements:
255+
- Need for accurate, up-to-date information
256+
- Compliance and auditability
257+
- Domain-specific knowledge integration
258+
259+
3. Cost Efficiency:
260+
- Reduced need for model fine-tuning
261+
- Smaller models can perform well with good context
262+
- Lower computational requirements
263+

0 commit comments

Comments
 (0)