your-papa / papa-ts

This library exposes PAPA, your Personal Assistant powered by Private AI, which can be used in any browser environment and completely offline
GNU Affero General Public License v3.0
33 stars 9 forks source link

There is a bug in the restore function, which seems to cause the plugin to fail to initialize normally. #27

Open ZDFX opened 3 weeks ago

ZDFX commented 3 weeks ago
// src/VectorStore.ts>OramaStore
    async restore(vectorStoreBackup: VectorStoreBackup) {
        Log.debug('Restoring vectorstore from backup');
        // vectorStoreBackup is an object and not an array for some reason
        const docs = Object.keys(vectorStoreBackup.docs).map((key) => vectorStoreBackup.docs[key]);
        await this.create(vectorStoreBackup.indexName, vectorStoreBackup.vectorSize);
        await insertMultiple(this.db, docs);// plugin:smart-second-brain:30 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'length')
        Log.info('Restored vectorstore from backup');
        Log.debug(this.db.data.docs.docs);
    }

Can I fix the error like this?

async restore(vectorStoreBackup: VectorStoreBackup) {
    Log.debug('Restoring vectorstore from backup');
    const docs = Object.keys(vectorStoreBackup.docs).map((key) => vectorStoreBackup.docs[key]);
    await this.create(vectorStoreBackup.indexName, vectorStoreBackup.vectorSize);

    if (docs.length > 0) {
        await insertMultiple(this.db, docs);
    } else {
        Log.info('No documents to restore');
    }

    Log.info('Restored vectorstore from backup');
    Log.debug(this.db.data.docs.docs);
}
Leo310 commented 2 weeks ago

I will take a look at this 👍