import { readFile, writeFile } from 'node:fs/promises';
import { INDEX_PATH } from './constants.js';
export const loadEmbeddingIndex = async (indexPath = INDEX_PATH) => {
    const raw = await readFile(indexPath, 'utf-8');
    const parsed = JSON.parse(raw);
    if (!Array.isArray(parsed.chunks)) {
        throw new Error('Invalid embedding index: missing chunks array');
    }
    return parsed;
};
export const saveEmbeddingIndex = async (index, indexPath = INDEX_PATH) => {
    const payload = JSON.stringify(index, null, 2);
    await writeFile(indexPath, payload, 'utf-8');
};
//# sourceMappingURL=storage.js.map