• Embeds an entire directory with cost limit protection.

    This is the recommended high-level function for embedding a directory. It performs the following steps with safety checks:

    1. Chunks the directory structure
    2. Calculates statistics and estimated cost
    3. Checks cost against limit (aborts if over limit)
    4. Generates embeddings using batch API

    Parameters

    Returns Promise<EmbedDirectoryResult>

    Object containing embedded directory, chunk stats, and embed stats

    Error if estimated cost exceeds cost limit

    // Embed directory with default $1 limit
    try {
    const result = await embed_directory('/path/to/project');
    console.log(`Success! Generated ${result.embedStats.successfulEmbeddings} embeddings`);
    console.log(`Actual batches used: ${result.embedStats.totalBatches}`);
    } catch (error) {
    console.error('Embedding failed:', error.message);
    }
    // Custom cost limit and file filtering
    const result = await embed_directory('/path/to/src', {
    costLimit: 0.10, // 10 cents max
    fileExtensions: ['.ts', '.tsx'],
    delimiter: /\n{3,}/g
    });
    // Use larger model with custom dimensions
    const result = await embed_directory('/path/to/project', {
    costLimit: 5.0,
    model: 'text-embedding-3-large',
    dimensions: 512,
    costPerToken: 0.00000013 // Update for larger model pricing
    });