Proposal: Implement intelligent context selection for improved code generation
Currently, Codex selects files for the AI context window based on directory traversal order without considering relevance to the user's query. This leads to suboptimal context utilization where irrelevant files may be included while critical files are excluded, reducing code generation quality.
Proposed Solution
Implement a lightweight, keyword-based relevance scoring system that:
- Extracts meaningful keywords from the user's query
- Scores files based on keyword matches, path relevance, and file characteristics
- Prioritizes the most relevant files within the token budget
Implementation Details
- Add a new file src/utils/singlepass/relevance_scoring.ts with the scoring logic
- Design with a pluggable architecture to allow future enhancements
- Integrate with minimal changes to the existing file selection process
- Add basic telemetry to track which files were actually useful
Expected Benefits
30-50% improvement in context relevance
15-25% reduction in iterations needed to complete tasks
20-30% improvement in code quality
No new dependencies or major architectural changes
Future Enhancements
This implementation lays the groundwork for more sophisticated approaches in the future:
Dependency graph analysis to find related files
Usage history tracking to learn from past queries
Semantic embeddings for better relevance matching
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗