diff --git a/package.json b/package.json index 986f8e1..fbf826b 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/scripts/getns.ts b/scripts/getns.ts new file mode 100644 index 0000000..5f525ad --- /dev/null +++ b/scripts/getns.ts @@ -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(); +})();