• Embeds and stores an entire directory in SurrealDB.

    This is the complete end-to-end function that:

    1. Chunks the directory structure
    2. Generates embeddings using OpenAI's batch API
    3. Stores everything in SurrealDB with graph relations

    Parameters

    • filePath: string

      Absolute path to the directory to embed and store

    • options: DirectoryStructureOptions & {
          delimiter?: RegExp;
      } & ChunkStatsOptions & EmbedOptions & {
          costLimit?: number;
          deleteExisting?: boolean;
      } = {}

      Combined options for all stages

    Returns Promise<EmbedAndStoreResult>

    Object containing embedded directory, stats, and storage stats

    // Embed and store MDX files only
    const result = await embed_and_store_directory('/path/to/docs', {
    fileExtensions: ['.mdx'],
    costLimit: 0.50,
    model: 'text-embedding-3-small',
    dimensions: 1536
    });
    console.log(`Project: ${result.storageStats.projectId}`);
    console.log(`Stored: ${result.storageStats.chunksCreated} chunks`);
    console.log(`Embeddings: ${result.storageStats.embeddingsCreated} new, ${result.storageStats.embeddingsReused} reused`);
    // Embed and store TypeScript files
    const result = await embed_and_store_directory('/path/to/src', {
    fileExtensions: ['.ts', '.tsx'],
    costLimit: 2.0,
    delimiter: /\n{3,}/g,
    deleteExisting: true
    });