agentleFS
Goodnight77Goodnight77/rag-skills/skills/data-type-handling/rag-for-code-documentation/SKILL.md

rag-for-code-documentation

Skill8 starsChanged 7 months agoMITView on GitHub

Handle code-aware retrieval by preserving symbols, file structure, and API context.

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
  1. Distinctive:

    Use embeddings designed for code or augment text embeddings with code-aware features.

    line 40
  2. Distinctive:

    Search with code-specific considerations.

    line 50
  3. Distinctive:

    When users query code syntax, APIs, or programming concepts

    line 63
  4. Distinctive:

    When building technical documentation with code examples

    line 65
  5. Distinctive:

    When code structure isn't important for retrieval

    line 70
  6. Distinctive:

    When embedding code-specific models is not feasible

    line 72

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.