Skip to main content
Code chunking is critical for semantic search quality. SHARC uses a tiered strategy that matches chunking approach to content type.

Tiered Chunking Strategy

Different content needs different treatment:

Tier 1: AST-Based Chunking

For languages with AST support, code is split at semantic boundaries.

Supported Languages

How It Works

Context Injection

Each chunk receives context about its location, including parent classes, modules, and decorators/annotations:

Decorator/Annotation Context

SHARC extracts decorators and annotations, embedding them in the context for better semantic understanding:
Supported decorator syntax:
  • TypeScript/JavaScript: @Decorator(), @decorator
  • Python: @decorator, @decorator(args)
  • Java: @Annotation, @Annotation(value)
  • C#: [Attribute], [Attribute(args)]
  • Rust: #[attribute], #[derive(...)]
  • Scala: @annotation

Container Nodes

These nodes provide context but aren’t chunked separately:
  • Classes
  • Interfaces
  • Modules
  • Namespaces
  • Impl blocks (Rust)

Leaf Nodes

These are extracted as individual chunks:
  • Functions
  • Methods
  • Arrow functions
  • Property assignments

Tier 2: Documentation Chunking

For markdown and text files:
Chunking result:
  • Smaller chunks (1500 chars)
  • 150 char overlap preserves context
  • Section headers kept with content

Why Overlap?

Documentation flows between sections. Overlap ensures:

Tier 3: Configuration Chunking

For JSON, YAML, TOML:
Chunking behavior:
  • Groups related keys together
  • 100 char overlap for context
  • Preserves structure

Tier 4: Other Code

For languages without AST support:
Chunking behavior:
  • Character-based splitting
  • 100 char overlap
  • May split mid-function

File Context

All chunks include file information:

Size Limits

Per-Chunk Limits

Per-File Limits

  • Maximum file size: 1MB
  • Files larger than this are skipped
  • Prevents indexing minified bundles

Custom Extensions

Add file types during indexing:
These use Tier 4 chunking (LangChain).

Ignore Patterns

Skip files/directories:

Default Ignores

Always skipped:
Custom ignorePatterns use glob semantics, so patterns like static/**, *.tmp, and private/** behave as expected. Optional team-dependent patterns such as vendor/**, third_party/**, and generated/** are opt-in.

Chunking Quality

Good Chunks

Bad Chunks (Avoided)

Debugging Chunks

To see how your code is chunked: