-
This was posted over in the issues list (#3) so re-posting here so my answer doesn't get lost. I'm considering using the vectra package as a backend for a project running on Node, and was hoping to get some guidance on managing the index size. My goal is to limit the index size to a predefined number, such as 100,000. |
Beta Was this translation helpful? Give feedback.
Answered by
Stevenic
Jun 21, 2023
Replies: 1 comment
-
Link to my original answer: Here's the code sample I provided: async function pruneIndex(index, max_items) {
// check index against retention policy
const stats = await index.getIndexStats();
if (stats.items < max_items) {
return;
}
// Remove oldest items first
await index.beginUpdate();
try {
const items = await index.listItems();
while (items.length > max_items) {
const item = items.unshif();
await index.deleteItem(item.id);
}
await index.endUpdate();
} catch (err) {
await index.cancelUpdate();
throw err;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Stevenic
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Link to my original answer:
#3 (comment)
Here's the code sample I provided: