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

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

Built distribution (wheel)

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

Total release size: 99.5 kB

Release files / graph_n4j-0.1.6.tar.gz

Download URL graph_n4j-0.1.6.tar.gz
Size 45.7 kB
Tags Source
SHA-256 checksum
How to use checksums
11acf3d0361d71d8e6bda2eb49051c70830fb6fb6a438cae5b86109ba34e22ae
BLAKE2b-256 checksum
How to use checksums
45ff899fee7797672e74e8664b1bfef6ab8d99871bd0ac347856871a2c6e5b4e
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.6-py3-none-any.whl

Download URL graph_n4j-0.1.6-py3-none-any.whl
Size 53.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db4f8e0b14a48d6134fc8429be283b6a1cb817588801587eeaaf3c0ffe461df2
BLAKE2b-256 checksum
How to use checksums
7af0ac3909372eafd55cbef7c2b8a1a405b11e8d90ebc8006a0d14ff04c86ec9
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.6

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