Add AST-based chunking for Python files#2
Open
devangpratap wants to merge 6 commits intomainfrom
Open
Conversation
Introduces ast_parser.py which uses Python's built-in ast module to extract functions, classes, and methods as individual chunks. This provides semantically meaningful code units for embedding instead of arbitrary line-based splits.
The indexer now attempts AST-based parsing for .py files before falling back to line-based chunking. Added AST_ENABLED and AST_EXTENSIONS settings to config for easy control.
Show the symbol type and name (function/class) in search results when available from AST parsing. Also increased preview from 5 to 8 lines for better context visibility.
Document the new AST-based parsing step and add ast_parser.py to the project structure section.
6671ed8 to
1d25325
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ast_parser.pythat uses Python's built-inastmodule to extract functions, classes, and module-level code as individual chunksAST_ENABLEDandAST_EXTENSIONSconfig options for easy togglingWhy
Line-based chunking often splits functions in half, producing embeddings that don't represent any coherent code unit. AST-aware chunking ensures each chunk is a complete function, class, or logical block — significantly improving search relevance.
Test plan
python main.py -d .on the Codeseek repo itself and verify chunks map to actual functions/classes