Dev.to AI 🤖 Ai 👁 0 📖 2 min read

How I built Ask the Repo: AST chunking vs fixed-size chunking for code RAG

I'm a self-taught AI engineer, and I wanted to build something I could actually measure instead of just following a tutorial. The result is Ask the Repo: paste a public Python repo from GitHub, ask a question, and get an

I'm a self-taught AI engineer, and I wanted to build something I could actually measure instead of just following a tutorial. The result is Ask the Repo: paste a public Python repo from GitHub, ask a question, and get an answer with exact file:line citations that link to the real code.

Live demo: https://aryan-ask-the-repo.streamlit.app/
Code: https://github.com/kaseraaryan5-star/ask-the-repo

The problem

Generic code chatbots give answers that sound right, but I can't verify them. I wanted every claim to point to a specific place in the repo, so I could click through and check.

How it works

  1. Clone the repo and split the Python files into chunks.
  2. Embed the chunks with Gemini embeddings and store them in Qdrant.
  3. For a question, retrieve the closest chunks, pass them to Gemini, and ask for an answer that cites the chunks it used.
  4. Each chunk keeps its file path and line range, so every citation becomes a link to those exact lines on GitHub.

The stack: Python, FastAPI, Qdrant, Gemini, and Streamlit for the frontend.

The interesting part: how you chunk code

The usual approach is fixed-size chunks (for example, N characters with some overlap). For code, that cuts functions in half and mixes unrelated code into one chunk.

Instead, I used the Python AST to split code along its natural boundaries: one chunk per function or class. Each chunk is a complete, meaningful unit, and its line range is exact, which also makes the citations precise.

Does it actually help?

I wrote a small test set of 17 questions about repos, and measured top-1 retrieval accuracy (does the first retrieved chunk contain the answer?):

Chunking Top-1 accuracy
Fixed-size 53%
AST-based 71%

Limitations (being honest)

  • The test set is small (17 questions), so treat these numbers as a signal, not a benchmark.
  • The live demo shares one index between visitors, so indexing a new repo replaces the previous one.
  • It supports Python repos only, because the chunker uses Python's AST.
  • The demo runs on free hosting and Gemini's free tier. It can take about 30 seconds to wake up and may occasionally be busy.

What I'd do next

Per-user indexes, support for more languages, and a larger evaluation set.

If you try it on a repo and it gets something wrong, I'd love to hear about it. The code is open source, and feedback is very welcome.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.