Learn how to update documents in your VectoriaDB index.
Metadata-only updates are instant and don’t trigger re-embedding:
await toolIndex . updateMetadata ( ' users:list ' , {
id : ' users:list ' ,
toolName : ' list ' ,
owner : ' users ' ,
tags : [ ' read ' , ' user-management ' , ' legacy ' ],
risk : ' safe ' ,
deprecated : true ,
});
Use updateMetadata when only changing metadata fields. It’s significantly faster than a full update since no embedding regeneration is required.
Update Text and Metadata
When text changes, VectoriaDB re-embeds the document:
await toolIndex . update ( ' users:list ' , {
text : ' Updated description for user listing ' ,
metadata : {
id : ' users:list ' ,
toolName : ' list ' ,
owner : ' users ' ,
tags : [ ' read ' ],
risk : ' safe ' ,
},
});
Smart Re-embedding
The update method only re-embeds when necessary:
// Only updates metadata (no re-embed)
await db . update ( ' id ' , {
metadata : newMetadata ,
});
// Re-embeds because text changed
await db . update ( ' id ' , {
text : ' New text content ' ,
metadata : newMetadata ,
});
// Force re-embed even if text unchanged
await db . update ( ' id ' , {
text : existingText ,
metadata : newMetadata ,
}, { forceReembed : true });
Batch Updates
const result = await toolIndex . updateMany ([
{
id : ' users:list ' ,
text : ' New description ' ,
metadata : { /* ... */ },
},
{
id : ' billing:charge ' ,
metadata : { deprecated : true }, // Metadata-only update
},
]);
console . log ( ` Updated: ${ result . updated } , Re-embedded: ${ result . reembedded } ` );
Return Value
updateMany returns statistics:
updated: Total documents updated
reembedded: Documents that required re-embedding
Upsert Pattern
VectoriaDB doesn’t have a built-in upsert. Use this pattern:
async function upsertDocument ( id : string , text : string , metadata : T ) {
if ( db . has ( id )) {
await db . update ( id , { text , metadata });
} else {
await db . add ( id , text , metadata );
}
}
To update only some metadata fields:
// Get existing document
const existing = db . get ( ' users:list ' );
if (! existing ) throw new Error ( ' Not found ' );
// Merge updates
await db . updateMetadata ( ' users:list ' , {
... existing . metadata ,
deprecated : true ,
tags : [... existing . metadata . tags , ' legacy ' ],
});
Error Handling
import { DocumentNotFoundError , DocumentValidationError } from ' vectoriadb ' ;
try {
await db . update ( id , updates );
} catch ( error ) {
if ( error instanceof DocumentNotFoundError ) {
console . log ( ` Document ${ error . documentId } not found ` );
} else if ( error instanceof DocumentValidationError ) {
console . log ( ` Validation failed: ${ error . message } ` );
}
}
Adding Documents Add new documents
Removing Documents Remove documents
Search Query updated documents