DatabricksDaniel LidenBenchmark
Building a knowledge assistant over code
Summary
Building a knowledge assistant over code requires more careful chunking than indexing ordinary business documents, because code has nested structure, cross-file dependencies, and multiple file formats. The comparison built three Databricks Knowledge Assistants over the Casper’s Kitchens repository: fixed-size character chunks, LangChain language-aware splitting, and AST-based splitting with structure and metadata headers. The AST approach used ASTChunk to preserve units such as functions, classes, or statement blocks and prepend file paths plus class/function hierarchies to chunks. MLflow GenAI evaluation ran 46 questions with retrieval sufficiency, groundedness, and custom answer-correctness judges; AST chunking achieved 89% retrieval sufficiency and 70% fully correct answers, versus 85% and 59% for the naive baseline. The advantage was strongest for disambiguating structurally similar code, while value lookups and complete definition retrieval were comparable across methods.
Context
The evaluation used the Casper’s Kitchens demo repository, which simulates a ghost kitchen business on Databricks. Its mixed Python, notebook, Markdown, and YAML files, cross-file dependencies, and domain-specific patterns provide a varied codebase for testing retrieval.
Approach / What changed
Three Knowledge Assistants used separate chunking strategies: fixed-size character chunks with overlap, LangChain’s language-aware RecursiveCharacterTextSplitter, and AST-based splitting with ASTChunk. The AST method chunked semantic units and added metadata headers containing the file path and class/function hierarchy, while MLflow GenAI evaluation compared retrieval and answer quality across 46 questions.
Takeaways
AST-based chunking produced 70% fully correct answers, compared with 59% for fixed-size chunks and 61% for the language-aware splitter.
Retrieval sufficiency was high for every strategy: 85% for the naive baseline, 87% for language-aware splitting, and 89% for AST-based chunking.
AST-based chunking helped most with disambiguating structurally similar code across modules; value lookups and complete definition retrieval were comparable across strategies.
FAQ
Why did AST-based chunking help with code disambiguation?
Its chunks preserved semantic units and included metadata headers with the file path and class/function hierarchy. That context strengthened matches for queries involving similar code in different modules.
How were the chunking strategies evaluated?
The comparison used 46 questions covering values, definitions, system flows, application comparisons, and framework patterns. MLflow GenAI evaluation scored retrieval sufficiency, groundedness, and custom answer correctness.
Did the simpler chunking methods still retrieve useful context?
Yes. Retrieval sufficiency was at least 85% for all three strategies, and nearly every question received at least a partially correct answer.
Source and freshness
- Source
- databricks.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.