Neo4j GraphRAG and LangChain: Python setup tutorial

Learn to query a knowledge graph with a LangChain agent using Neo4j 5 in Docker, ports 7474 and 7687, and an OpenAI API key.

Player not loading? Watch on YouTube

This tutorial builds a Python AI agent that answers questions using a Neo4j knowledge graph. The speaker recommends GraphRAG for data and queries with many relationships, especially questions that require several hops between entities. He favors classic vector RAG for text similarity and simple document retrieval, and notes that maintaining a graph can be costly when data changes frequently.

The setup runs Neo4j 5 on localhost through Docker Compose, with port 7474 for the web interface and 7687 for Bolt connections. It requires Docker and Docker Compose already installed; the tutorial does not cover their installation. The speaker also describes desktop, package manager and managed database options. Although the database is self-hosted, the demonstrated model calls use OpenAI and require an API key in a .env file. This is not an offline model setup.

The Python example creates nodes and relationships with MERGE, describes the graph schema, and connects Neo4j GraphRAG's text-to-Cypher retriever to a LangChain tool. The agent uses GPT-4o mini. A question links a channel owner to the operating system he uses and then to its creator's country. The speaker reports Finland as the result and streams the agent's steps to inspect its queries. A larger example adds graph data and demonstrates a single generated Cypher query that returns Amsterdam.