How liyuan551408-bot/smart-context works
Smart Context indexes a target codebase, then retrieves a compact context set for an AI coding agent. The main workflow runs from a developer query through embedding, candidate ranking, and token-budgeted context construction. A separate indexing workflow chunks and embeds repository files, reusing unchanged content. The README also documents adaptive chunking and benchmark/evaluation capabilities; benchmark internals are represented only at directory level. Relationships for unsampled benchmark code are documented rather than inferred from its implementation.
Main entry points: retrieve.py Retrieval CLI · update_index.py Index updater · semantic_chunker.py Adaptive chunking · utils.py Query embedding
Components 19
Context retrieval
- Retrieval CLI
scripts/retrieve.py - Query embedding
scripts/utils.py - Semantic candidates
scripts/retrieve.py - Dependency expansion
scripts/dependency_graph.py - Hybrid reranking
scripts/retrieve.py - Context selection
scripts/retrieve.py
Repository indexing
- Index updater
scripts/update_index.py - Source discovery
scripts/update_index.py - Adaptive chunking
scripts/semantic_chunker.py - Deterministic chunking
scripts/chunker.py - Chunk quality checks
scripts/chunk_quality.py - Embedding generation
scripts/utils.py
Shared infrastructure
- Cached index
cache - Index utilities
scripts/utils.py
Evaluation capabilities
- Benchmark evaluation
benchmarks
Other components
- Developer
- SiliconFlow API
- Coding agent
- GLM boundary service
Connections 20
- Developer → Retrieval CLI: submits query
README.md - Retrieval CLI → Query embedding: embeds query
scripts/retrieve.py - Query embedding → SiliconFlow API: requests embedding
scripts/utils.py - Retrieval CLI → Semantic candidates: retrieves candidates
scripts/retrieve.py - Semantic candidates → Cached index: loads vectors
- Retrieval CLI → Dependency expansion: expands candidates
scripts/retrieve.py - Retrieval CLI → Hybrid reranking: ranks candidates
scripts/retrieve.py - Retrieval CLI → Context selection: selects within budget
scripts/retrieve.py - Context selection → Coding agent: returns context
README.md - Index updater → Source discovery: scans files
scripts/update_index.py - Index updater → Adaptive chunking: chunks changed files
scripts/update_index.py - Adaptive chunking → Deterministic chunking: starts with local chunks
scripts/semantic_chunker.py - Adaptive chunking → Chunk quality checks: checks refinement need
scripts/semantic_chunker.py - Adaptive chunking → GLM boundary service: proposes boundaries
README.md - Index updater → Embedding generation: embeds fresh chunks
scripts/update_index.py - Embedding generation → SiliconFlow API: requests embeddings
scripts/utils.py - Index updater → Cached index: writes index
scripts/update_index.py - Retrieval CLI → Index utilities: loads index
scripts/retrieve.py - Index updater → Index utilities: uses cache and hashes
scripts/update_index.py - Developer → Benchmark evaluation: evaluates retrieval
README.md