graph-n4j
Bridge LLM agents with code repositories via Neo4j graph databases. Based on the CodexGraph NAACL 2025 paper.
graph-n4j builds a highly structured code graph (AST, inheritance, composition, calls) into Neo4j and uses a dual-agent LLM pipeline to let you chat with your entire codebase with perfect accuracy and drastically reduced token consumption.
Prerequisites
To use graph-n4j, you need two things running/available:
-
Neo4j Database: You need a running Neo4j instance.
- Quickest way (Docker):
docker run -d -p 7474:7474 -p 7687:7687 -e NEO4J_AUTH=neo4j/password neo4j:latest - Cloud option: You can also use a free Neo4j AuraDB instance.
- Quickest way (Docker):
-
Groq API Key: You need an API key from Groq to power the LLM agents.
Installation
pip install graph-n4j
Setup & Configuration
Configure the package using environment variables. You can set them in your terminal or create a .env file in the directory where you run your commands:
# Required: Groq API Key
GROQ_API_KEY=gsk_your_api_key_here
# Optional: Set the model (Defaults to llama-3.3-70b-versatile)
GROQ_MODEL=llama-3.3-70b-versatile
# B5 optimization: Use a cheaper/faster model for translation to save costs
GROQ_MODEL_TRANSLATION=llama-3.1-8b-instant
# Neo4j connection (These are the defaults)
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=password
CLI Usage
The package installs a handy command-line tool graph-n4j:
# 1. Index a local Python repository
graph-n4j index /path/to/your/python/repo
# OR Clone and index a GitHub repository directly
graph-n4j index-github pallets/click
# 2. Chat with your indexed codebase!
graph-n4j ask "How does the command line parsing work in this repo?"
# Check graph statistics
graph-n4j stats
# List all indexed repos
graph-n4j repos
Python API Usage
You can also use it programmatically in your own apps:
import os
from graph_n4j import GraphN4J
# Set up environment or let it load from .env
os.environ["GROQ_API_KEY"] = "gsk_your_api_key_here"
# Initialize the API
g = GraphN4J.from_env()
# Index a repository
g.index("./my-project")
# Chat with the codebase
result = g.ask("What does the UserManager class do and what does it inherit from?")
print(result.answer)
Features
- B1-B7 Token Efficiency: Implements all 7 token optimizations from the CodexGraph paper (Skeleton caching, Context pruning, Early-stopping, etc.)
- Multi-repo support: Seamlessly index and query across multiple isolated repositories.
- AST Parsing: Highly accurate edge extraction for classes, functions, globals, fields, and inheritance.
Metadata
Release files for graph-n4j 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| graph_n4j-0.1.1.tar.gz | 44.9 kB | Without provenance | Details for graph_n4j-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graph_n4j-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for graph_n4j-0.1.1-py3-none-any.whl |
Total release size: 97.9 kB
Release files / graph_n4j-0.1.1.tar.gz
| Download URL | graph_n4j-0.1.1.tar.gz |
|---|---|
| Size | 44.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61c80f097ab725dfd61723ab5891e056f1c8d77d19e8a38a478d3990435ffb08
|
|
BLAKE2b-256 checksum How to use checksums |
0f63e0299dec45b98f594654e7a46be83bd676f02ca8c548c3569163a738fcd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / graph_n4j-0.1.1-py3-none-any.whl
| Download URL | graph_n4j-0.1.1-py3-none-any.whl |
|---|---|
| Size | 53.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
397ec2ea47acf76803f2888f6b6e7d2c51d93690a5d70244774e4ba74e78ce8c
|
|
BLAKE2b-256 checksum How to use checksums |
99102fe6a200a04c04af5081fc5b60276cdd285dce11825ae3c9d81e24bc37c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Security for graph-n4j 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.