-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Purge cached docs and remove docs from all workspaces on vectorDB/emb…
…edder changes (#2819) * wip remove all docs clear vector db on embedder/vector db change * purge all cached docs and remove docs from workspaces on vectordb/embedder change * lint * remove unneeded console log * remove reset vector stores endpoint and move to server side updateENV with postUpdate check * reset embed module * remove unused import * simplify deletion process rescoped document deletion to be more general for speed, everything needs to be reset anyway fixed issue where unembedded docs not in any workspaces, but cached, were not removed * add back missing readme file update warning text modals --------- Co-authored-by: timothycarambat <[email protected]>
- Loading branch information
1 parent
d145602
commit ae51061
Showing
8 changed files
with
153 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const { Workspace } = require("../../models/workspace"); | ||
const { Document } = require("../../models/documents"); | ||
const { DocumentVectors } = require("../../models/vectors"); | ||
const { EventLogs } = require("../../models/eventLogs"); | ||
const { purgeEntireVectorCache } = require("../files"); | ||
const { getVectorDbClass } = require("../helpers"); | ||
|
||
/** | ||
* Resets all vector database and associated content: | ||
* - Purges the entire vector-cache folder. | ||
* - Deletes all document vectors from the database. | ||
* - Deletes all documents from the database. | ||
* - Deletes all vector db namespaces for each workspace. | ||
* - Logs an event indicating the reset. | ||
* @param {string} vectorDbKey - The _previous_ vector database provider name that we will be resetting. | ||
* @returns {Promise<boolean>} - True if successful, false otherwise. | ||
*/ | ||
async function resetAllVectorStores({ vectorDbKey }) { | ||
try { | ||
const workspaces = await Workspace.where(); | ||
purgeEntireVectorCache(); // Purges the entire vector-cache folder. | ||
await DocumentVectors.delete(); // Deletes all document vectors from the database. | ||
await Document.delete(); // Deletes all documents from the database. | ||
await EventLogs.logEvent("workspace_vectors_reset", { | ||
reason: "System vector configuration changed", | ||
}); | ||
|
||
console.log( | ||
"Resetting anythingllm managed vector namespaces for", | ||
vectorDbKey | ||
); | ||
const VectorDb = getVectorDbClass(vectorDbKey); | ||
for (const workspace of workspaces) { | ||
try { | ||
await VectorDb["delete-namespace"]({ namespace: workspace.slug }); | ||
} catch (e) { | ||
console.error(e.message); | ||
} | ||
} | ||
|
||
return true; | ||
} catch (error) { | ||
console.error("Failed to reset vector stores:", error); | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = { resetAllVectorStores }; |