rag-for-code-documentation
Skill8 starsChanged 7 months agoMITView on GitHub
Handle code-aware retrieval by preserving symbols, file structure, and API context.
In this repository39 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rag-skillsSkill
- choosing-a-chunking-frameworkSkill
- contextual-chunk-headersSkill
- hierarchical-chunkingSkill
- semantic-chunkingSkill
- chunkingSkill
- sliding-window-chunkingSkill
- rag-for-multimodal-contentSkill
- data-type-handlingSkill
- index-versioning-and-reindexingSkill
- production-rag-deploymentSkill
- deploymentSkill
- generation-evaluation-metricsSkill
- rag-evaluation-frameworksSkill
- retrieval-evaluation-metricsSkill
- evaluation-metricsSkill
- optimize-retrieval-latencySkill
- performance-optimizationSkill
- agentic-rag-routingSkill
- multi-agent-rag-orchestrationSkill
- rag-agentsSkill
- adaptive-retrievalSkill
- context-enrichment-windowSkill
- crag-corrective-ragSkill
- explainable-retrievalSkill
- graph-ragSkill
- hybrid-search-bm25-denseSkill
- hyde-hypothetical-document-embeddingsSkill
- hype-hypothetical-prompt-embeddingsSkill
- multi-pass-retrieval-with-rerankingSkill
- query-transformation-strategiesSkill
- raptor-hierarchical-retrievalSkill
- self-ragSkill
- retrieval-strategiesSkill
- choosing-vector-db-by-datatypeSkill
- qdrant-for-production-ragSkill
- qdrant-setup-ragSkill
- vector-databasesSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 40
Use embeddings designed for code or augment text embeddings with code-aware features.
- Distinctive: line 50
Search with code-specific considerations.
- Distinctive: line 63
When users query code syntax, APIs, or programming concepts
- Distinctive: line 65
When building technical documentation with code examples
- Distinctive: line 70
When code structure isn't important for retrieval
- Distinctive: line 72
When embedding code-specific models is not feasible
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Overview
RAG for code documentation requires specialized handling due to code's structured nature, syntax-specific patterns, and the importance of preserving function signatures, imports, and contextual relationships. This skill covers embedding code snippets, handling API references, and retrieving code-aware context.
Problem Statement
Generic RAG approaches struggle with code-related queries:
- Standard chunking breaks function/class structures mid-signature
- Language models don't understand code syntax and semantics as well as natural language
- Code requires preserving structural relationships (imports, dependencies, inheritance)
- API queries need exact matches alongside semantic understanding
- Code examples need context to be useful (imports, dependencies)
Key Concepts
- Code-Aware Chunking: Preserving function/class boundaries and syntactic units
- Code-Specific Embeddings: Models trained on code (CodeBERT, StarCoder) vs. general embeddings
- Syntax Preservation: Maintaining formatting, indentation, and structure
- Context Tracking: Following import chains and dependency relationships
- Hybrid Search for Code: Combining semantic search with AST-based matching
Implementation Guide
Step 1: Code-Aware Document Parsing
Parse code files into structured chunks that preserve syntactic units.
Why: AST-based parsing preserves code structure that would be lost with generic text chunking.
Step 2: Code-Specific Embedding
Use embeddings designed for code or augment text embeddings with code-aware features.
Why: Code-specific embeddings capture semantic meaning in code (function relationships, patterns) that general embeddings miss.
Step 2.5: Store Code Chunks in Vector DB
Store code chunks with rich metadata for effective retrieval.
Why: Rich metadata enables filtering by language, type, file path, and other code-specific attributes.
Step 3: Implement Code-Aware Search
Search with code-specific considerations.
Why: Code-aware search combines semantic understanding with precise filtering for programming-specific use cases.
Step 4: Handle API Documentation
Specialized handling for API reference queries.
Why: API queries often require exact matching (function/class names) rather than pure semantic search.
Practical references include the CodeBERT paper, GraphCodeBERT paper, StarCoder paper, and GitHub code search.
When to Use This Skill
- Building code search or documentation assistants
- When users query code syntax, APIs, or programming concepts
- For IDE integrations and code completion systems
- When building technical documentation with code examples
- For troubleshooting programming queries
When NOT to Use This Skill
- For natural language-only content (use general RAG)
- When code structure isn't important for retrieval
- For very simple codebases where grep suffices
- When embedding code-specific models is not feasible
Related Skills
- Semantic Chunking - For document chunks
- Choosing Vector DB by Datatype - Database selection
- Hierarchical Chunking - For nested code structures
Metrics & Success Criteria
- Code Retrieval Accuracy: Exact matches for function/class names > 90%
- Semantic Understanding: NDCG@10 for code-related queries > 0.7
- Context Preservation: Relevant imports included > 80% of time
- Syntax Preservation: Code formatting maintained 100%
- Query Latency: < 200ms for typical code queries
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

