Setting Up a Neo4j GenAI Environment on Fedora
In this article, we will walk through the steps to set up a Neo4j GenAI Python environment on a Fedora system using Ansible automation. This setup will enable you to deploy a Retrieval-Augmented Generation (RAG) system that integrates with a Neo4j graph database and utilizes OpenAI’s language models for interactive data retrieval and analysis.
Prerequisites
Before starting, ensure you have:
- A Fedora system with root access.
- Ansible installed on your control machine.
- Access to the OpenAI API and a valid API key.
- Credentials and URI for your Neo4j database.
Additionally, we will be using the Northwind dataset to populate our Neo4j database. For more information on importing the Northwind dataset into Neo4j, refer to the [Northwind Dataset Guide](https://neo4j.com/docs/getting-started/appendix/tutorials/guide-import-relational-and-etl/).
Step-by-Step Setup
1. Create an Ansible Playbook
Create a file named setup_neo4j_genai.yml with the following content:
```yaml
---
- name: Set up Neo4j GenAI Python environment on Fedora
hosts: all
become: true
tasks:
- name: Install necessary system packages
ansible.builtin.dnf:
name:
- python3
- python3-pip
state: present
update_cache: true
- name: Install necessary Python packages using pip
ansible.builtin.pip:
name:
- neo4j
- neo4j_genai
- openai
state: present
executable: /usr/bin/pip3
- name: Set OpenAI API key as environment variable
ansible.builtin.lineinfile:
path: /etc/environment
line: "OPENAI_API_KEY={{ openai_key }}"
create: true
state: present
mode: '0644'
- name: Source environment file to apply changes
ansible.builtin.shell: source /etc/environment
- name: Create configuration file for Neo4j connection
ansible.builtin.copy:
dest: /etc/neo4j_genai_config.py
content: |
from neo4j import GraphDatabase
URI = "{{ neo4j_uri }}"
AUTH = ("{{ neo4j_auth.split(':')[0] }}", "{{ neo4j_auth.split(':')[1] }}")
driver = GraphDatabase.driver(URI, auth=AUTH)
mode: '0644'
- name: Create application directory
ansible.builtin.file:
path: /opt/neo4j_genai
state: directory
mode: '0755'
- name: Copy Python application to the server
ansible.builtin.copy:
src: files/application.py
dest: /opt/neo4j_genai/application.py
mode: '0755'
- name: Run the Neo4j GenAI application
ansible.builtin.command: python3 /opt/neo4j_genai/application.py
environment:
OPENAI_API_KEY: "{{ openai_key }}"
NEO4J_URI: "{{ neo4j_uri }}"
NEO4