Skip to main content

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:

  1. 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.
  2. 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.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graph-n4j 0.1.8
File Size Uploaded Provenance Actions
graph_n4j-0.1.8.tar.gz 45.8 kB Without provenance Details for graph_n4j-0.1.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for graph-n4j 0.1.8
File Interpreter ABI Platform Actions
graph_n4j-0.1.8-py3-none-any.whl Python 3 none any Details for graph_n4j-0.1.8-py3-none-any.whl

Total release size: 99.7 kB

Release files / graph_n4j-0.1.8.tar.gz

Download URL graph_n4j-0.1.8.tar.gz
Size 45.8 kB
Tags Source
SHA-256 checksum
How to use checksums
83dbcb466d85fa393fb80abdaab37e71d803cb18c7410fec42b27ee3fb3f32eb
BLAKE2b-256 checksum
How to use checksums
5b8cad0c4c82c1cae3d9326731a9dd65303d268a8756ba42582c3776865a346e
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.8-py3-none-any.whl

Download URL graph_n4j-0.1.8-py3-none-any.whl
Size 54.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f032e39640785e61f8e78d73f901be8ff97ca44c09cf8add9b0096287da4cd0
BLAKE2b-256 checksum
How to use checksums
b5eef026702190c24db4a90fb4540fbfb113f5477174074db81f4235a7bccdae
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.8

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page