System Architecture

CodeSageZ employs a 7-stage ingestion pipeline designed to preserve the structural relationships of source code.

The 7-Stage Ingestion Pipeline

1. Clone

Shallow clone of the GitHub repository into a temporary workspace.

2. Parse AST

Tree-sitter extracts function boundaries, classes, and all identifiers.

3. Call Graph

NetworkX builds a directed graph connecting callers to callees.

4. Chunking

Functions are embedded as discrete chunks to maintain semantic integrity.

5. Embedding

A deterministic lexical hash encoder turns each chunk into a normalized vector for reproducible local retrieval.

6. Vector Store

ChromaDB stores embeddings with graph metadata attached to each document.

7. Graph RAG

At query time, vector hits are expanded by 1-hop using graph edges.

The Problem with Naive RAG

Standard RAG chunks source files arbitrarily. If you ask a question about a function that relies on three other internal helpers, a naive retriever might only fetch the top-level function. The LLM is forced to hallucinate the missing implementations.

By storing the Abstract Syntax Tree (AST) relationships in a NetworkX graph alongside our vector database, CodeSageZ can perform a 1-hop expansion. It retrieves the semantically similar chunk, and then immediately fetches exactly what it calls, and who calls it.

# 1. Vector Search finds Seed Node
seed_nodes = vector_db.query("How does auth work?")
// returns: validate_token() [similarity: 0.85]

# 2. Graph Expansion fetches exact structural context
for node in seed_nodes:
    context.append( graph.get_callers(node) )
    context.append( graph.get_callees(node) )
    
// Context now contains:
// - authenticate() [caller]
// - validate_token() [seed]
// - decode_jwt() [callee]

Fine-Tuning on Bug Fixes

Our underlying playground models are fine-tuned via QLoRA on the CommitPack dataset. We filter for surgical, single-file bug fixes (under 30 lines) and train the model to predict the exact diff required to fix a given error message.

10,000
Training Samples
4-bit
QLoRA Quantization
A100
Training Hardware