Absolute path to the directory to embed
Options for chunking, stats, and embedding
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
});
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: