Skip to main content

graph-n4j

Index Python, C and C++ repositories in Neo4j, then ask questions about their symbols, source and relationships. The query pipeline follows the two-agent approach described in CodexGraph: Bridging Large Language Models and Code Repositories via Code Graph Databases.

How indexing works

The indexer selects source files, hashes their contents and parses changed files with Tree-sitter. It stores the extracted symbols and reference sites on the module node so a later run can reuse them. On Windows and Unix, repository-relative graph paths use forward slashes.

The linker looks up imports, owners and names across the selected files. It emits a call edge when it can resolve a reference to one symbol identity. Dynamic dispatch and ambiguous names can leave gaps. The writer groups records by label and relationship type and sends batches to Neo4j. Reindexing also refreshes dependents of changed files.

Graph records Types
Symbols MODULE, CLASS, FUNCTION, METHOD, FIELD, GLOBAL_VARIABLE
Relationships CONTAINS, HAS_METHOD, HAS_FIELD, INHERITS, USES, CALLS, IMPORTS

Release comparison

The benchmark report compares the published Python AST indexer in 0.1.8 with 1.1.0 on pinned sources from Click, Black, cJSON, curl, tinyxml2 and fmt. It includes the exact inputs, indexing and repeat-run times, database writes and graph counts.

Quickstart

1. Install

pip install graph-n4j

2. Start Neo4j

docker run -d --name graph-n4j-db \
  -p 7687:7687 -p 7474:7474 \
  -e NEO4J_AUTH=neo4j/graphn4jtest \
  neo4j:5-community

3. Configure

export NEO4J_URI=bolt://localhost:7687
export NEO4J_USER=neo4j
export NEO4J_PASSWORD=graphn4jtest
export GROQ_API_KEY="gsk_your_key"        # or OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.

4. Index & Ask

graph-n4j index-github bottlepy/bottle --stats
graph-n4j ask "How does routing work?" --repo-id bottlepy/bottle --provider groq

CLI Reference

graph-n4j index ./project --repo-id org/project --stats
graph-n4j index-github jarro2783/cxxopts --stats
graph-n4j ask "Explain Option parsing" --provider openai
graph-n4j cypher "MATCH (c:CLASS) RETURN c.name LIMIT 10"
graph-n4j stats --repo-id bottlepy/bottle                    # graph statistics
graph-n4j repos                                              # list indexed repos

Python API

from graph_n4j import GraphN4J

with GraphN4J.from_env(provider="groq") as g:
    g.index_github("bottlepy/bottle")
    result = g.ask("Where is authentication handled?", repo_id="bottlepy/bottle")
    print(result.answer)

Model providers

Use the provider flag on the ask command. Groq, OpenAI, Anthropic and Gemini read their respective API keys from the environment. Ollama connects to a local server and accepts an OLLAMA_HOST override. Indexing requires a running Neo4j instance. The client opens a model connection on the first question.

Coding applications

CodeChat answers questions, CodeCommenter drafts documentation, CodeDebugger proposes fixes, CodeGenerator drafts features and CodeUnitTester drafts tests. Each passes a task-specific instruction to the retrieval pipeline. Review the returned answer or code before applying it.

Development

Install the project with its dev extras and run pytest. Set GRAPH_N4J_TEST_URI to a disposable Neo4j service for the database integration tests. The benchmark runner and reproduction instructions are in the benchmarks directory.

Metadata

Release files for graph-n4j 1.1.0

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

Built distribution (wheel)

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

Total release size: 115.1 kB

Release files / graph_n4j-1.1.0.tar.gz

Download URL graph_n4j-1.1.0.tar.gz
Size 53.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2310a32b5c0dc50c1d4b78321a592c75e421864c2b74d958db0cbc6c0366353d
BLAKE2b-256 checksum
How to use checksums
143fde21902b54811995a3577a74c21191d00141e3ec462c1ac4d19f9b43096b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / graph_n4j-1.1.0-py3-none-any.whl

Download URL graph_n4j-1.1.0-py3-none-any.whl
Size 61.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a68d51a48453946461cd92106c9e40f2b24583f9f628993334b06e1d0898c41
BLAKE2b-256 checksum
How to use checksums
de28bf1ca9203d0e7667205bbf3af3739007ec2781518ad5418a4e6d2373fd4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for graph-n4j 1.1.0

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