GitRAG: Using AST Parsing to Make Codebase Q&A No Longer a Guesswork

The developer has open-sourced GitRAG, a GitHub code repository Q&A system based on AST syntax tree parsing. Through hybrid retrieval (BM25 + semantic vectors) and re-ranking, it can accurately pinpoint file paths and line numbers, supports 15 programming languages, and completely solves the hallucination problem of traditional RAG in code comprehension.
GitRAG: Making Codebase Q&A No Longer a Shot in the Dark with AST Parsing
A developer recently shared his new project GitRAG on Reddit — paste any GitHub repository URL, directly ask questions about the codebase, and the system will return answers precise to file path and line number — no guesswork.
This is not yet another ChatGPT wrapper toy. Its core lies in using Abstract Syntax Tree (AST) parsing to understand code structure, combined with hybrid retrieval and re-ranking, elevating code Q&A from “probably like this” to “exactly at line 327” level precision.
Why Code Q&A Is So Hard
Traditional RAG systems have a fatal flaw when handling code: they treat code as plain text. They split by line count, by character count, completely ignoring semantic boundaries in code. The result is that a single function can be split into three fragments scattered across different chunks, making it impossible to reconstruct its complete logic during retrieval.
What’s worse, pure semantic vector search often fails miserably in code scenarios. If you ask “where is the getUserData function called,” the vector model might return a bunch of semantically similar but completely irrelevant code snippets, because it doesn’t understand how important exact function name matching is.
The author of GitRAG clearly ran into these pitfalls. His solution is to fix it from the ground up: use an AST parser to understand code structure, then perform hybrid indexing at the retrieval layer.
AST Parsing: Cutting Code by Semantic Boundaries

The first step GitRAG takes after cloning a repository is to process each file with an AST parser. AST (Abstract Syntax Tree) is a data structure used by compilers to understand code structure, capable of identifying boundaries of semantic units like classes, functions, and variable declarations.
Specific approach:
- If a class or function is smaller than 1,500 characters, treat it as a whole chunk
- If it exceeds 1,500 characters, split into multiple chunks by function granularity
- Each chunk retains complete context information (owning class, namespace, import dependencies, etc.)
Chunks cut this way are semantically complete. When you retrieve a function definition, its parameters, return values, and internal logic are all in the same chunk — avoiding situations where “function signature is in chunk A, implementation in chunk B.”
GitRAG supports AST parsing for 15 languages: Python, JavaScript/TypeScript, C#, Java, Go, Rust, C/C++, Swift, Kotlin, Dart, Ruby, PHP, Vue, Svelte, Shell — covering most mainstream development scenarios.
Hybrid Retrieval: Dual Safeguards of Semantics + Keywords
Good chunking alone isn’t enough — retrieval strategy must match. GitRAG uses hybrid indexing:
Dense Vector Index: Uses OpenAI’s text-embedding-3-small model to convert each chunk into a vector and store it in ChromaDB. This layer handles semantic understanding, matching conceptual queries like “user authentication logic.”
BM25 Keyword Index: A traditional TF-IDF improvement specialized in exact matching. When you ask “where was FileNotFoundException thrown,” BM25 can directly locate code containing that exception name.
During queries, both indices return candidate results, then Reciprocal Rank Fusion (RRF) merges and sorts them. RRF’s advantage is it doesn’t require weight tuning — it calculates combined scores based on each result’s rank position in both lists, automatically balancing semantic relevance and keyword match accuracy.
This design is practical — pure vector search misses exact matches, pure keyword search misses semantic understanding. Combined, they complement each other. The author noted this was his proudest part, and it’s understandable — many open-source RAG projects still use a single retrieval strategy, resulting in significantly poorer performance.
Re-ranking: Compressing from 20 Candidates to 5
After hybrid retrieval, you get about 20 candidate chunks — but you can’t feed them all to the LLM — too long a context dilutes important information and wastes tokens.
GitRAG uses Cohere’s rerank-v3.5 model here. Rerankers are trained specifically to re-score retrieval results, deeply understanding query-chunk relevance, compressing 20 candidates down to the most relevant 5.
This step is a game-changer. I’ve tested RAG systems without rerankers, and often the most relevant chunk is ranked 7th or 8th, getting pushed out of the context window. With a reranker, top-5 accuracy can jump from 60% to over 90%.
Generation: Groq-accelerated Llama 3.3
The final step is sending the 5 selected chunks along with the user’s question to the LLM to generate the answer. GitRAG uses Groq-hosted llama-3.3-70b.
Groq is a hardware company specializing in LLM inference acceleration — their LPU (Language Processing Unit) can push Llama 70B inference speeds over 500+ tokens/s, 5–10x faster than regular GPUs. For real-time Q&A systems, this speed advantage is crucial.
Llama 3.3 70B itself has strong code understanding — scoring over 80% accuracy on benchmarks like HumanEval. Combined with the preceding precise retrieval, it can basically ensure reliable answers.
Tech Stack and Architecture
GitRAG’s full tech stack:
- Backend: FastAPI (Python async framework, suited for I/O-intensive RAG scenarios)
- Vector Database: ChromaDB (lightweight, supports local deployment)
- Embedding Model: OpenAI text-embedding-3-small (1536 dimensions, cost-effective)
- Reranker: Cohere rerank-v3.5 (among the strongest open rerankers)
- LLM: Groq-hosted Llama 3.3 70B (fast, cost-controllable)
- Frontend: React + Vite (modern standard frontend stack)
The whole system is a standard RAG pipeline, but every step is optimized for code scenarios. From AST parsing to hybrid retrieval to re-ranking, each step addresses the core issue: “Code isn’t ordinary text.”
Real-world Effectiveness and Limitations
From Reddit discussions, GitRAG performs well for small-to-medium repositories (under 10k files). Users reported it accurately answered:
- “Where is this API’s authentication logic implemented?”
- “Where is the
processPaymentfunction called?” - “Where is this error code defined?”
These are questions traditional search or pure LLMs struggle to answer precisely.
But there are clear limitations:
Scale Issues: For ultra-large repositories (hundreds of thousands of files), index build time becomes lengthy, and retrieval performance drops. The author notes Sweep AI handled 2M+ files using distributed indexing — GitRAG hasn’t implemented this optimization yet.
Cross-file Reasoning: If answers require information across multiple files (e.g., “What’s the call chain for this interface”), current chunk-based retrieval may miss some. This would require introducing code graphs or call chain analysis.
Dynamic Behavior: AST can only analyze static code structure — it’s powerless for runtime behavior (e.g., “What’s this config’s value in production”).
More Potential for AST in Code RAG
GitRAG’s AST-based chunking is just the start. Academia and industry are exploring deeper AST use:
Structured Query: Convert natural language questions into AST patterns, directly match structures on the syntax tree. For example, asking “where are exceptions unhandled” can be translated to an AST query “find all try-catch blocks where catch is empty.” Tools like ast-grep already do this.
Code Graphs: Build function call graphs, class inheritance diagrams, and data flow graphs from AST, turning the codebase into a knowledge graph — retrieval can then return relevant code along with upstream/downstream dependencies.
Hybrid Representation Learning: Encode AST structural info into vectors. For example, the AstBERT model considers node positional relationships in AST when embedding, increasing similarity for semantically and structurally close code.
Automatic Program Repair: Combine AST and LLMs to not only locate bugs but generate syntax-compliant fix patches. Models like CodeT5 and InCoder are exploring this area.
Open-source Tool Ecosystem
If you want to build your own code RAG, these tools are worth attention:
tree-sitter: Incremental syntax parser supporting 40+ languages, widely used by Neovim, GitHub, etc. It can parse code changes in real time, suitable for IDE integration.
ast-grep: Code search tool based on tree-sitter, supporting structured search using code-like patterns. For example, searching foo($$$) matches all calls to function foo, regardless of arguments.
Bloop: Open-source code search engine using a local embedding model (sentence-transformers/all-MiniLM-L6-v2, only 22MB) for vectorization — suited for offline use.
Sweep AI: Commercial product for codebase Q&A — their technical blog details how AST was used to handle large-scale indexing of 2M+ files.
Final Thoughts
GitRAG isn’t the first project to tackle code Q&A, but it gets the key points — AST parsing, hybrid retrieval, re-ranking — all right. More importantly, the author open-sourced the full implementation, enabling other developers to build on and improve it.
Code understanding is harder than text understanding — it requires semantic understanding (what does this function do), structural understanding (where is it called), and exact matching (what’s the variable name exactly). Traditional RAG has weaknesses in all three dimensions, while AST + hybrid retrieval can cover them.
If you’re building AI applications involving code, GitRAG’s architecture is worth referencing. If you just want to quickly search a codebase, it’s also a solid tool — certainly more reliable than hunting around GitHub for hours.
References
- Reddit original post: GitRAG project intro — Author’s detailed explanation of technical implementation and design thinking
- Multi-language, multi-granularity precise codebase retrieval based on tree-sitter — In-depth analysis of AST parsing in code retrieval
- Understanding RAG Applications — AI-assisted Software Engineering Practices — Systematic overview of various chunking strategies in code scenarios



