Skip to main content
Search code using natural language queries. Two-stage retrieval: vector search (fast, broad) + GPU reranking (precise).
Push your code with morph.git.push() first (see Repo Storage). Embedding takes 3-8 seconds in background.

Installation

npm install @morphllm/morphsdk

Quick Start

  • Anthropic
  • OpenAI
  • Vercel AI SDK
  • Direct
import Anthropic from '@anthropic-ai/sdk';
import { createCodebaseSearchTool } from '@morphllm/morphsdk/tools/codebase-search/anthropic';

const anthropic = new Anthropic();
const tool = createCodebaseSearchTool({ repoId: 'my-project' });

const response = await anthropic.messages.create({
  model: "claude-sonnet-4-5-20250929",
  tools: [tool],
  messages: [{ 
    role: "user", 
    content: "Find the authentication code" 
  }]
});

How It Works

Two-stage retrieval (~230ms total):
  1. Vector search (~50ms) - HNSW index retrieves top 50 candidates
  2. GPU rerank (~150ms) - morph-rerank-v3 scores for precision
  3. Returns top 10 most relevant
Why two stages? Vector search is fast but imprecise. Reranking is slow but accurate. Together = fast + accurate.

Direct Usage

const results = await morph.codebaseSearch.search({
  query: "Where is JWT validation implemented?",
  repoId: 'my-project',
  target_directories: [], // Empty = all, or ["src/auth"]
  limit: 10
});

console.log(`Found ${results.results.length} matches in ${results.stats.searchTimeMs}ms`);
results.results.forEach(r => {
  console.log(`${r.filepath} - ${(r.rerankScore * 100).toFixed(1)}% match`);
  console.log(r.content);
});

Search Tips

Good queries:
  • “Where is JWT validation implemented?”
  • “Show database error handling”
  • “Find the login flow”
Avoid:
  • Single words (“auth”)
  • Too vague (“code”)
  • Too broad (“everything”)

API

Input:
{
  query: string,              // Natural language question
  repoId: string,             // Repository ID
  target_directories: string[], // Filter paths, or [] for all
  limit?: number              // Max results (default: 10)
}
Returns:
{
  success: boolean,
  results: [{
    filepath: string,         // "auth.ts::login@L5-L20"
    content: string,          // Code chunk
    rerankScore: number,      // 0-1 relevance (use this!)
    language: string,
    startLine: number,
    endLine: number
  }],
  stats: { searchTimeMs: number }
}