Skip to main content
SHARC uses state-of-the-art embeddings to understand the semantic meaning of code. This page explains the embedding model, generation process, and optimization techniques.

Embedding Model

Sharc-Embed

SHARC’s embedding model is optimized for code:

Key Features

  1. Code-optimized: Trained on large code corpora
  2. High dimensionality: 4096 dims capture nuanced semantics
  3. Long context: 8K tokens handles large functions

Embedding Generation

Process Overview

Batching Strategy

Embeddings are generated in optimized batches for efficiency. Multiple batches are processed concurrently, enabling fast indexing even for large codebases.

Vector Storage

Full Dimensions

Unlike some implementations that truncate embeddings, SHARC stores the full 4096 dimensions:

Normalization

Vectors are L2-normalized for cosine similarity:
This enables efficient cosine similarity via dot product.

Context Injection

Embeddings capture more than raw code. SHARC injects context:

For Code (AST-parsed)

The embedding now “knows”:
  • This is a method in AuthService
  • It’s in the auth module
  • File is services/auth.ts

With Decorators

For Documentation

Semantic Properties

What Embeddings Capture

Similarity Examples

Indexing Performance

Indexing time depends on codebase size: Subsequent incremental syncs use Merkle diffs and complete near-instantly for unchanged codebases.

Troubleshooting

Slow Embedding Generation

  1. Re-index the codebase if search results look stale.
  2. Ensure your codebase indexing completed successfully.
  3. Retry with a more specific semantic query.