Skip to content

Commit

Permalink
get namespaces script
Browse files Browse the repository at this point in the history
  • Loading branch information
dissorial committed Jun 3, 2023
1 parent 85eb457 commit 877d644
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lint": "eslint --ignore-path .gitignore \"**/*.+(ts|js|tsx)\"",
"format": "prettier --ignore-path .gitignore \"**/*.+(ts|js|tsx)\" --write",
"delete-namespace": "tsx -r dotenv/config scripts/delete-namespace.ts",
"getns": "tsx -r dotenv/config scripts/getns.ts",
"lang": "tsx -r dotenv/config scripts/lang.ts"
},
"dependencies": {
Expand Down
34 changes: 34 additions & 0 deletions scripts/getns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { pinecone } from '@/utils/pinecone-client';

type NamespaceSummary = {
vectorCount: number;
};

export const run = async () => {
const targetIndex = process.env.PINECONE_INDEX_NAME ?? '';

try {
const index = pinecone.Index(targetIndex);

const describeIndexStatsQuery = {
describeIndexStatsRequest: {
filter: {},
},
};

const res = await index.describeIndexStats(describeIndexStatsQuery);
const namespaces = Object.keys(
res.namespaces as { [key: string]: NamespaceSummary },
);
console.log('Namespaces:', namespaces);

console.log('Namespaces:', namespaces);
} catch (error) {
console.log('error', error);
throw new Error('Failed to delete your namespace');
}
};

(async () => {
await run();
})();

0 comments on commit 877d644

Please sign in to comment.