feat(index): add mapping_fn param to build_index#10
Merged
Conversation
build_index was hardcoded to regex_mapping, giving callers no way to plug in the embedding, LLM, or composed strategies added in v0.5/v0.6. The new keyword-only mapping_fn param accepts any strategy callable with the standard (events, symbols) signature and defaults to None, which preserves the existing regex_mapping behavior unchanged.
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.
Why
build_indexwas hardcoded toregex_mapping, giving callers no wayto use the composable strategies added in v0.5 (
embedding_mapping,compose_mappings) and v0.6 (llm_mapping). The README explicitlyrecommends stacking strategies ("regex first, embedding to fill gaps,
LLM for the long tail"), but there was no way to wire that stack into
the index. This closes the gap.
What
pm_rag/index.py: adds a keyword-onlymapping_fn: MappingFn | Noneparameter to
build_index. Defaults toNone, which preserves theexisting
regex_mappingbehavior unchanged. Also exportsMappingFnas a type alias for documentation purposes.
tests/test_index.py: adds 4 new tests covering the new parameter:custom mapping function is used, default
Nonematches explicitregex_mapping,compose_mappingsworks as the mapping_fn, andexplicit
Nonefalls back to regex.Tests
python -m pytest -q: 83 passed (was 79 before this PR).ruff check: all checks passed.test_build_index_custom_mapping_fn_is_used,test_build_index_default_matches_regex_mapping,test_build_index_with_composed_strategy,test_build_index_mapping_fn_none_uses_regex.Self-merge gate
pm_rag/__init__.pynot touched;build_indexsignature is backward-compatible (new keyword-only optional param)tests/test_index.pyGenerated by Claude Code