Learn how to remove documents from your VectoriaDB index.
Remove Single Document
// Returns true if document was found and removed
const removed = await toolIndex . remove ( ' users:list ' );
if ( removed ) {
console . log ( ' Document removed ' );
} else {
console . log ( ' Document not found ' );
}
Remove Multiple Documents
// Returns count of documents actually removed
const removedCount = await toolIndex . removeMany ([
' users:list ' ,
' billing:charge ' ,
' nonexistent:id ' , // Silently skipped if not found
]);
console . log ( ` Removed ${ removedCount } documents ` );
Clear All Documents
// Remove all documents from the index
await toolIndex . clear ();
console . log ( ` Index now contains ${ toolIndex . size () } documents ` ); // 0
clear() is irreversible and removes all documents. Make sure to save important data before calling it.
Remove by Filter
VectoriaDB doesn’t have a built-in “remove by filter” method. Use this pattern:
// Get IDs of documents matching filter
const deprecatedDocs = toolIndex . filter (( m ) => m . deprecated === true );
const idsToRemove = deprecatedDocs . map (( doc ) => doc . id );
// Remove them
const removed = toolIndex . removeMany ( idsToRemove );
console . log ( ` Removed ${ removed } deprecated documents ` );
Safe Removal Pattern
async function safeRemove ( id : string ) {
// Check if exists first
const doc = toolIndex . get ( id );
if (! doc ) {
console . log ( ` Document ${ id } not found ` );
return false ;
}
// Log what we're removing
console . log ( ` Removing: ${ doc . metadata . toolName } ` );
// Remove
return toolIndex . remove ( id );
}
HNSW Index Updates
When using HNSW indexing, remove operations update the index structure:
const db = new VectoriaDB ({
useHNSW : true ,
});
// Removal updates HNSW graph
await db . remove ( ' doc-id ' );
// Search immediately reflects the removal
const results = await db . search ( ' query ' );
Storage Considerations
Removing documents doesn’t automatically update persistent storage:
src/remove-with-storage.ts
// Remove document
await db . remove ( ' doc-id ' );
// Save updated state to storage
await db . saveToStorage ();
For file or Redis storage, call saveToStorage() after batch removals to persist the changes.
Adding Documents Add documents
Updating Documents Update documents