Skip to content

Commit

Permalink
chore: update example snippets for mvi count items (#1115)
Browse files Browse the repository at this point in the history
Add example snippets for MVI countItems in both the Web and Node.js vector index examples.

Because the cache examples sdk dependencies were out of date for latest leaderboard changes, we also updated those.
  • Loading branch information
malandis authored Jan 24, 2024
1 parent 128a141 commit 338125b
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 158 deletions.
110 changes: 31 additions & 79 deletions examples/nodejs/cache/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/nodejs/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"typescript": "4.4.3"
},
"dependencies": {
"@gomomento/sdk": "^1.58.0"
"@gomomento/sdk": "^1.60.0"
},
"engines": {
"node": ">=10.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DeleteVectorIndex,
ListVectorIndexes,
PreviewVectorIndexClient,
VectorCountItems,
VectorIndexConfigurations,
VectorSearch,
VectorSearchAndFetchVectors,
Expand Down Expand Up @@ -61,6 +62,15 @@ async function example_API_DeleteIndex(vectorClient: PreviewVectorIndexClient) {
}
}

async function example_API_CountItems(vectorClient: PreviewVectorIndexClient) {
const result = await vectorClient.countItems('test-index');
if (result instanceof VectorCountItems.Success) {
console.log(`Found ${result.itemCount()} items`);
} else if (result instanceof VectorCountItems.Error) {
throw new Error(`An error occurred while counting items: ${result.errorCode()}: ${result.toString()}`);
}
}

async function example_API_UpsertItemBatch(vectorClient: PreviewVectorIndexClient) {
const result = await vectorClient.upsertItemBatch('test-index', [
{
Expand Down Expand Up @@ -142,6 +152,7 @@ async function main() {
example_API_InstantiateVectorClient();
await example_API_CreateIndex(vectorClient);
await example_API_ListIndexes(vectorClient);
await example_API_CountItems(vectorClient);
await example_API_UpsertItemBatch(vectorClient);
await example_API_Search(vectorClient);
await example_API_SearchAndFetchVectors(vectorClient);
Expand Down
58 changes: 29 additions & 29 deletions examples/nodejs/vector-index/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 338125b

Please sign in to comment.