From 4d2f6eedb6434ec3135523be9a290d1b696ba2b7 Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Mon, 18 Dec 2023 15:03:35 -0500 Subject: [PATCH 1/2] bump @pinecone-database dependency to support the new global control plane --- package-lock.json | 8 ++++---- package.json | 2 +- src/app/api/crawl/seed.ts | 8 +++++++- src/app/utils/embeddings.ts | 2 +- src/app/utils/pinecone.ts | 4 ++-- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index df8abc3..28c5486 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "dependencies": { "@pinecone-database/doc-splitter": "^0.0.1", - "@pinecone-database/pinecone": "^1.1.0", + "@pinecone-database/pinecone": "^1.1.2-spruceDev.20231214000822", "@types/node": "20.4.0", "@types/react": "18.2.14", "@types/react-dom": "18.2.6", @@ -428,9 +428,9 @@ } }, "node_modules/@pinecone-database/pinecone": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@pinecone-database/pinecone/-/pinecone-1.1.0.tgz", - "integrity": "sha512-THg+D3cSYVCMmphroOEBQOU9UsOhABYcrExZyurcz8cZ3znipDyJuiX9F3CavysnQa5DTzQEZxcH1YmEMGW8mg==", + "version": "1.1.2-spruceDev.20231214000822", + "resolved": "https://registry.npmjs.org/@pinecone-database/pinecone/-/pinecone-1.1.2-spruceDev.20231214000822.tgz", + "integrity": "sha512-9VR3iFc47lVrIMlchaXAokaKe6esC1yEKoOStDkw109NKjJV+beqaSSNgKzzBdRc2Em3M+cGvCc7t0RaXhhfvw==", "dependencies": { "@edge-runtime/types": "^2.2.3", "@sinclair/typebox": "^0.29.0", diff --git a/package.json b/package.json index 8053f15..029f041 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@pinecone-database/doc-splitter": "^0.0.1", - "@pinecone-database/pinecone": "^1.1.0", + "@pinecone-database/pinecone": "^1.1.2-spruceDev.20231214000822", "@types/node": "20.4.0", "@types/react": "18.2.14", "@types/react-dom": "18.2.6", diff --git a/src/app/api/crawl/seed.ts b/src/app/api/crawl/seed.ts index 52feda3..70d96a3 100644 --- a/src/app/api/crawl/seed.ts +++ b/src/app/api/crawl/seed.ts @@ -37,11 +37,17 @@ async function seed(url: string, limit: number, indexName: string, options: Seed // Create Pinecone index if it does not exist const indexList = await pinecone.listIndexes(); - const indexExists = indexList.some(index => index.name === indexName) + const indexExists = indexList.indexes?.some(index => index.name === indexName) if (!indexExists) { await pinecone.createIndex({ name: indexName, dimension: 1536, + spec: { + serverless: { + region: 'us-west-2', + cloud: 'aws', + } + }, waitUntilReady: true, }); } diff --git a/src/app/utils/embeddings.ts b/src/app/utils/embeddings.ts index 29c9d0e..2eb060f 100644 --- a/src/app/utils/embeddings.ts +++ b/src/app/utils/embeddings.ts @@ -12,7 +12,7 @@ export async function getEmbeddings(input: string) { model: "text-embedding-ada-002", input: input.replace(/\n/g, ' ') }) - + const result = await response.json(); return result.data[0].embedding as number[] diff --git a/src/app/utils/pinecone.ts b/src/app/utils/pinecone.ts index 4dc5260..4df4687 100644 --- a/src/app/utils/pinecone.ts +++ b/src/app/utils/pinecone.ts @@ -18,8 +18,8 @@ const getMatchesFromEmbeddings = async (embeddings: number[], topK: number, name } // Retrieve the list of indexes to check if expected index exists - const indexes = await pinecone.listIndexes() - if (indexes.filter(i => i.name === indexName).length !== 1) { + const indexList = await pinecone.listIndexes() + if (indexList.indexes?.filter(i => i.name === indexName).length !== 1) { throw new Error(`Index ${indexName} does not exist`) } From 918aac792ed0bd1f75979ee597ce4ba5165f90b8 Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Tue, 19 Dec 2023 11:11:33 -0500 Subject: [PATCH 2/2] remove PINECONE_ENVIRONMENT from .env.example --- .env.example | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.env.example b/.env.example index fa8aa2d..5d7d345 100644 --- a/.env.example +++ b/.env.example @@ -2,9 +2,8 @@ OPENAI_API_KEY= # Retrieve the following from the Pinecone Console. -# Navigate to API Keys under your Project to retrieve the API key and environment +# Navigate to API Keys under your Project to retrieve the API key PINECONE_API_KEY= -PINECONE_ENVIRONMENT= # Navigate to Indexes under your Project to retrieve the Index name PINECONE_INDEX= \ No newline at end of file