install neo4j and try knowledge graphs

Motivation

So far, we have built RAG system using FAISS and BM25. Although vector search is relatively easy to construct, there are cases where the necessary information is not found in “k” documents, and I was looking for ways to improve the accuracy. I happened to read this article and became interested in the knowledge graph and decided to try it myself.

In this post, I will summarize the process of installing nao4j in my local environment and trying to use it from a browser in order to use the knowledge graph.

Sources

  1. Increasing the Accuracy of RAG Applications with the Knowledge Graph The article that led me to know about the Knowledge Graph.
  2. Knowledge Graph: Technical Overview and Applications An article by the author of the above article explaining the Knowledge Graph.
  3. neo4j The home page of neio4j. You can use the cloud service “neo4j auraDB” from “Get Started for Free” on this page.
  4. Getting started with Neo4j in Docker The introduction part of Docker in the documentation page.
  5. dockerhub The dockerhub page that provides Docker Officaial Image of neo4j. There is also a link in the introduction document page above.
  6. Neo4j Licensing Explains the license of Neo4j, which is available in Community Edition and Enterprise Edition. Community Edition is licensed under GPL v3.
  7. [Simple Graph Database Setup with Neo4j and Docker Compose](https://medium.com/@matthewghannoum/simple-graph-database-setup-with-neo4j- and-docker-compose-061253593b5a) I used the Docker Compose on this page to start the container.

Launch containers

docker-compose.yml

I created docker-compose.yml under $HOME directory as follows, referring to the source 7.

$ pwd
/home/kenji/workspace/neo4j
$ cat docker-compose.yml
services:
  neo4j:
    container_name: neo4j
    image: neo4j:latest
    ports:
      - 7474:7474
      - 7687:7687
    environment:
      - NEO4J_AUTH=neo4j/password
      - NEO4J_apoc_export_file_enabled=true
      - NEO4J_apoc_import_file_enabled=true
      - NEO4J_apoc_import_file_use__neo4j__config=true
      - NEO4J_PLUGINS=["apoc", "graph-data-science"]
    volumes:
      - ./neo4j_db/data:/data

Start neo4j

$ pwd
/home/kenji/workspace/neo4j
$ sudo docker compose up -d

Connecting to neo4j from the local environment

Type “http://localhost:7474/” in a browser on the machine where the neo4j container is running to connect to neo4j.

The first time you connect, you will be asked to enter a password, so set a password and change “password” in docker-compose.yml.

Connect to neo4j from another machine

From a browser on another machine connected to the network, type “http://192.168.11.8:7474/” to connect to neo4j. Of course, change the “192.168.11.8” part according to your environment.

Try using neo4j from a browser

Try Neo4j with live data

First, start the container on the neo4j server. Start neo4j as described in “Starting neo4j”.

Connect to neo4j from a browser as described in “Connect to neo4j from thelocal environment/another machine”.

neo4j

Click on “Open guide” under “Try Neo4j with live data” in the center to try it out.

When the side menu opens, click “Next” to proceed one by one. Click the Cypher query box in the side menu, and the query will be copied to the prompt line on the right side.

It took me about 30 minutes to an hour to try the whole process.

The future

Cypher is similar to SQL in atmosphere, but it is different and I don’t understand it, but I can get an idea of what it is like by trying it out as described above.

I would like to build a RAG system with it in the future.