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.7

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.7
File Size Uploaded Provenance Actions
graph_n4j-0.1.7.tar.gz 45.8 kB Without provenance Details for graph_n4j-0.1.7.tar.gz

Built distribution (wheel)

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

Total release size: 99.7 kB

Release files / graph_n4j-0.1.7.tar.gz

Download URL graph_n4j-0.1.7.tar.gz
Size 45.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4b54fc303cc0c0e06c2c050469a3bff547f176d6721aff8f2fe5fe47ecbd400d
BLAKE2b-256 checksum
How to use checksums
43623778c37f7a384c5de71f08a4f46192d78262a29a7bcc71ebf803e1897661
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.7-py3-none-any.whl

Download URL graph_n4j-0.1.7-py3-none-any.whl
Size 54.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfa85b359ea68ba20e99408367c829095aad93176a3ef813caaf7fa7fff0f090
BLAKE2b-256 checksum
How to use checksums
c9310bb026d8d4d47f4574120b3fe5ddebd0c9837fa8cd1d8e128d3bcc2436a1
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.7

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