Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PineconeClient: Project name not set. Call init() first #12

Closed
ediardo opened this issue Feb 25, 2023 · 51 comments
Closed

PineconeClient: Project name not set. Call init() first #12

ediardo opened this issue Feb 25, 2023 · 51 comments
Labels
bug Something isn't working

Comments

@ediardo
Copy link

ediardo commented Feb 25, 2023

Hi!

First day using Pinecone. I followed the steps at https://docs.pinecone.io/docs/node-client but I'm getting an error.

Version: 0.0.8

Code:

 const pinecone = new PineconeClient();
  await pinecone.init({
    environment: "us-east1-gcp",
    apiKey: "SECRET",
  });

  const index = pinecone.Index("websites");

  try {
    const res = await index.upsert({
      upsertRequest: {
        vectors: [
          {
            id: "1",
            values: vector,
          },
        ],
      },
    });
....

Error:

Error: PineconeClient: Project name not set. Call init() first.
    at PineconeClient.Index (./node_modules/@pinecone-database/pinecone/dist/index.js:172:19)
    at insertToVectorCollection (embeddings.js:50:28)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async createIndex (index.js:77:9)

I tried setting the projectName right before the init() but didn't make a difference:

const pinecone = new PineconeClient();
pinecone.projectName = "websites";
await pinecone.init({...

What can I do to fix problem?

Thank you.

@NCKLS
Copy link

NCKLS commented Feb 25, 2023

I'm also receiving this error. It looks like I'm getting a
PineconeClient: Error getting project name: ReferenceError: fetch is not defined
error.

Quickly looking through the source code it seems it's trying to use the jsdom version of fetch and isn't using node-fetch or axios?

@JoshuaPerk
Copy link

+1

It looks like the PineconeClient.prototype.Index function checks for an apiKey, projectName, and environment to assemble the URL for indexConfigurationParameters.

But when init'ing, that projectName key is stripped away:

await pinecone.init({
    environment: process.env.PINECONE_ENVIRONMENT,
    apiKey: process.env.PINECONE_API_KEY,
    projectName: 'Project Name Here'
})

👆🏼 This will not working. I'm going to use http requests directly until this is fixed.

P.S. The documentation says to call pinecone.index(process.env.PINECONE_INDEX) but it's worth nothing the i in index needs to be capitalized.

@rschwabco
Copy link
Contributor

@ediardo , @NCKLS , @JoshuaPerk - what Node version are you using? This is most likely an issue with using a version of Node that doesn't support fetch natively.

@rschwabco
Copy link
Contributor

rschwabco commented Feb 26, 2023

I've added an engines version specification to ensure this issue doesn't resurface:

  "engines": {
    "node": ">=18.0.0"
  },

@drob
Copy link

drob commented Feb 26, 2023

I'm running v16.19 in prod and unfortunately can't upgrade, so this would force me to fork or switch to a different library.

Would strongly prefer an approach like the one in rileytomasek/pinecone-client, i.e. allow older versions of node via a fetch polyfill. If you wanted to make it extra user friendly, you could detect the absence of native fetch and warn about it.

@rschwabco
Copy link
Contributor

@drob as you suggested this PR add the cross-fetch polyfill.

@junhyeokkwak
Copy link

Seems like this issue was resolved at 0.0.10 but was then reintroduced in 0.0.11?

@Thushan96
Copy link

i use Node.js v18.15.0 , i also get the same error

@markwwd
Copy link

markwwd commented Mar 23, 2023

I use Node 16.17.1 and get the same error..

"Error: PineconeClient: Project name not set. Call init() first."

anyone?

@rschwabco rschwabco reopened this Mar 23, 2023
@rschwabco
Copy link
Contributor

@markwwd @junhyeokkwak @Thushan96 - Can you please provides steps for a repro?

@markwwd
Copy link

markwwd commented Mar 24, 2023

@rschwabco I solved it by using the latest NodeJS version. Though, it's giving a warning that it's an experimental feature and it might get replaced in the future (the fetch method).

@joschan21
Copy link

Having the same issue.
"PineconeClient: Error getting project name: ReferenceError: fetch is not defined"

@stephenkalnoske-sans
Copy link

Also had this issue. Reverting back to version 0.0.10 fixed it for me.

@jlancaster7
Copy link

Also having this issue on node v16.19.1. Reverting to 0.0.10 worked for me.

@gdj0nes gdj0nes added the bug Something isn't working label Mar 28, 2023
@rschwabco
Copy link
Contributor

rschwabco commented Mar 28, 2023

There was a build issue that resulted in the cross-fetch polyfill to be dropped from the build. The error was corrected in 0.0.12. The issue stems from a mistake where tests were pointing to the src directory instead of the dist directory, and so the issue wasn't caught during testing.

@katalystkat
Copy link

hiya new to pinecone, am also having the same errors.

To recreate-- I cloned the repo from : https://github.com/mayooear/gpt4-pdf-chatbot-langchain && inputted my own API keys for OpenAI and PineCone. I've confirmed that my API keys work for both because when I removed them individually, I receive the expected corresponding errors of needing respective keys.

@rschwabco I am running Node 19.7, and I've tried updating my pinecone to 0.0.10 and 0.0.12 and both are returning below:

PineconeClient: Error getting project name: TypeError: fetch failed
[Error: PineconeClient: Project name not set. Call init() first.]

@rschwabco
Copy link
Contributor

@katalystkat - I cloned the repo and was able to make it work with the same Node version you mentioned. I suspect you might be pointing to the wrong environment, or that the key you're using has been rotated. Can you share which environment you're using and confirm you are using the correct API key? (This is different than not having the key at all, which will result in a different error message)

@rohitdhamija
Copy link

I am facing the same issue
When I try to run the app, I get following error

PineconeClient: Error getting project name: TypeError: fetch failed

error - [Error: PineconeClient: Project name not set. Call init() first.] { page: ‘/api/chat’ }

My node version is node -v v18.15.0 Pinecone version is “@pinecone-database/pinecone”: “^0.0.10”,

It seems it is due to issue of fetch() which is an experimental feature. How to disable fetch() and use node-fetch()

@felipeotarola
Copy link

I am facing the same issue When I try to run the app, I get following error

PineconeClient: Error getting project name: TypeError: fetch failed

error - [Error: PineconeClient: Project name not set. Call init() first.] { page: ‘/api/chat’ }

My node version is node -v v18.15.0 Pinecone version is “@pinecone-database/pinecone”: “^0.0.10”,

It seems it is due to issue of fetch() which is an experimental feature. How to disable fetch() and use node-fetch()

Had same problem. using node Node.js below 17 ,
Got further when adding
pinecone.projectName = "Pinecone Demo" in the initPinecone() function in pinecone-client.ts
But this mess the url that is created later in the library.
the the url looks like this
https://testy-PineconeDemo.svc.testy-54978f2.svc.us-east1-gcp.pinecone.io

with latest node 19 something, I do not get the init problem. But if I don't specify the pinecone.projectName the url in the library is looking like this

https://testy-undefined.svc.testy-54978f2.svc.us-east1-gcp.pinecone.io

Been hustling for 2 days with this.

@PMLS3
Copy link

PMLS3 commented Mar 29, 2023

Also getting the error: PineconeClient: Project name not set. Call init() first. at PineconeClient.Index (/usr/src/app/.output/server/node_modules/@pinecone-database/pinecone/dist/index.js

Upgraded my Docker version to Node.js 18.5 - error remains. "@pinecone-database/pinecone": "^0.0.11",

import { PineconeClient } from "@pinecone-database/pinecone";

const pinecone = new PineconeClient();

const setupPinecone = async () => {
console.log("Setting up Pinecone");
await pinecone.init({
environment: "XXXXXX",
apiKey: "XXXXXXXXXXXXXXXXXXXXXXX",
});
return 'done'
};

setupPinecone();

export { pinecone }

@rohitdhamija
Copy link

I did "@pinecone-database/pinecone": "^0.0.12", in package.json and did install again. it seems to be working fine

@felipeotarola
Copy link

what langchain version do you have? I get conflict with langchain 0.0.41

@PMLS3
Copy link

PMLS3 commented Mar 29, 2023

I did "@pinecone-database/pinecone": "^0.0.12", in package.json and did install again. it seems to be working fine

Upgraded but sitting with same issue

@rohitdhamija
Copy link

I did "@pinecone-database/pinecone": "^0.0.12", in package.json and did install again. it seems to be working fine

Upgraded but sitting with same issue

What is your node version?? Mine is 18.5

@PMLS3
Copy link

PMLS3 commented Mar 29, 2023

I did "@pinecone-database/pinecone": "^0.0.12", in package.json and did install again. it seems to be working fine

Upgraded but sitting with same issue

What is your node version?? Mine is 18.5

Correct yes
Nuxi 3.3.2
ℹ Node.js version: 18.15.0
"@pinecone-database/pinecone": "^0.0.12"
"langchain": "^0.0.33"

@rohitdhamija
Copy link

Are you behind some proxy?

@rohitdhamija
Copy link

I think you should pull the code again, there has been changes last night in the code.
B/w "langchain": "0.0.41", is that i am using

@felipeotarola
Copy link

I updated to 0.0.12 but got a new error.
now it complains about

error [ErrorWithoutStackTrace: PineconeClient: Error getting project name: TypeError: fetch failed]

even when I set the variable in the client.

@PMLS3
Copy link

PMLS3 commented Mar 29, 2023

I think you should pull the code again, there has been changes last night in the code. B/w "langchain": "0.0.41", is that i am using

Still getting the error:

Error: PineconeClient: Project name not set. Call init() first. at PineconeClient.Index (/usr/src/app/.output/server/node_modules/@pinecone-database/pinecone/dist/index.js:251:19) at upsertVectors (file:///usr/src/app/.output/server/chunks/index3.mjs:58:28) at file:///usr/src/app/.output/server/chunks/create.post2.mjs:11:24 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.handler (file:///usr/src/app/.output/server/node_modules/h3/dist/index.mjs:1247:19) at async Server.toNodeHandle (file:///usr/src/app/.output/server/node_modules/h3/dist/index.mjs:1322:7)

Deleted package-lock.json and node-modules

@pinecone-database/pinecone": "^0.0.12"
"langchain": "^0.0.41"

Deployed on Google cloud

@felipeotarola
Copy link

@PMLS3
Yes, Im also deploying to google clouds, the problem here is that when you deploy a new installation of node_modules happens.

Want to co op in discord?
my username is WhiteRhino#7935

@PMLS3
Copy link

PMLS3 commented Mar 29, 2023

Got it working on myside, have to call init everytime I call a function...

@rschwabco
Copy link
Contributor

@PMLS3 that definitely shouldn't be the case. You should only have to call init once. If you share a repro I could hopefully help resolve this.

@katalystkat
Copy link

@rschwabco

I currently have the pinecone environment set to 'us-central1-gcp' because that is what is shown on my pinecone dashboard.

I've rotated and tried a new API key as well but am still receiving the same error on my local machine. I tested my API key & environment via Pinecone API Reference (https://docs.pinecone.io/reference/list_collections) and I was able to get a 200 response there.

@bschleter
Copy link

bschleter commented Mar 30, 2023

Hate to add an extra comment but I too am getting this error. I have checked api key, index name, even added project name in there with the https://github.com/mayooear/gpt4-pdf-chatbot-langchain repo.

I am running node 18.15, pinecone 0.0.1.0 . Langchain 0.0.4.0 One odd thing is that after loading my vectors which I got called as successful, I was still unable to view them with fetch or upsert on pinecone dashboard. I uploaded 1000 or so vectors.

Shame because I finally got it…locally ok until I make a call.

Edit: got mine fixed day or two ago. Re did npm install, no apostrophes on api, project #, and reuploaded vectors.

@mariobm
Copy link

mariobm commented Mar 31, 2023

Why is this one closed? I'm getting the same error and I'm using this langchain example here: https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/pinecone#index-docs

@rschwabco
Copy link
Contributor

rschwabco commented Mar 31, 2023

@mariobm Langchain seems to be using an outed version of the client (0.0.10 instead of 0.0.12).

@mberman84
Copy link

I'm still getting this error as well. I cloned the repo everyone is talking about, then I upgraded the pinecone version to 0.0.1.2, and am using node ~18. I'm getting this error:

error [ErrorWithoutStackTrace: PineconeClient: Error getting project name: SyntaxError: Unexpected token A in JSON at position 0]
/Users/matthewberman/Desktop/gpt4-pdf-chatbot-langchain/utils/pinecone-client.ts:19
throw new Error('Failed to initialize Pinecone Client');

@bschleter
Copy link

I'm still getting this error as well. I cloned the repo everyone is talking about, then I upgraded the pinecone version to 0.0.1.2, and am using node ~18. I'm getting this error:

error [ErrorWithoutStackTrace: PineconeClient: Error getting project name: SyntaxError: Unexpected token A in JSON at position 0]

/Users/matthewberman/Desktop/gpt4-pdf-chatbot-langchain/utils/pinecone-client.ts:19

throw new Error('Failed to initialize Pinecone Client');

Did you try adding the project # in the pinecone.ts? Project number a weird hash like '13h5ja' before the -gcp-1-east or whatever. Not near a computer so don't have a snapshot of my example. The one used has it after the quotations after pinecone_index_name and ID. Sorry can't be much more help right now.

@mberman84
Copy link

mberman84 commented Apr 2, 2023

I'm still getting this error as well. I cloned the repo everyone is talking about, then I upgraded the pinecone version to 0.0.1.2, and am using node ~18. I'm getting this error:
error [ErrorWithoutStackTrace: PineconeClient: Error getting project name: SyntaxError: Unexpected token A in JSON at position 0]
/Users/matthewberman/Desktop/gpt4-pdf-chatbot-langchain/utils/pinecone-client.ts:19

throw new Error('Failed to initialize Pinecone Client');

Did you try adding the project # in the pinecone.ts? Project number a weird hash like '13h5ja' before the -gcp-1-east or whatever. Not near a computer so don't have a snapshot of my example. The one used has it after the quotations after pinecone_index_name and ID. Sorry can't be much more help right now.

Not sure I understand. Here's what I have:

if (!process.env.PINECONE_INDEX_NAME) {
  throw new Error('Missing Pinecone index name in .env file');
}

const PINECONE_INDEX_NAME = process.env.PINECONE_INDEX_NAME ?? '';

const PINECONE_NAME_SPACE = 'pdfchat-abf53ba'; //namespace is optional for your vectors

export { PINECONE_INDEX_NAME, PINECONE_NAME_SPACE };

still getting the unexpected token issue.

@dyeoman2
Copy link

dyeoman2 commented Apr 3, 2023

I was able to solve this problem by setting the project name after the init. Here is the code that worked for me.

I'm using Node v19.8.1, "langchain": "^0.0.45", and "@pinecone-database/pinecone": "^0.0.10".

import { PineconeClient } from '@pinecone-database/pinecone';

if (!process.env.PINECONE_ENVIRONMENT || !process.env.PINECONE_API_KEY) {
  throw new Error('Pinecone environment or api key vars missing');
}

async function initPinecone() {
  try {
    const pinecone = new PineconeClient();

    await pinecone.init({
      environment: process.env.PINECONE_ENVIRONMENT ?? '', //this is in the dashboard
      apiKey: process.env.PINECONE_API_KEY ?? '',
    });
    pinecone.projectName = 'default';

    return pinecone;
  } catch (error) {
    console.log('error', error);
    throw new Error('Failed to initialize Pinecone Client');
  }
}

export const pinecone = await initPinecone();

@felipeotarola
Copy link

I also did the project name workaround at first, but after some digging I understood that my environments were written wrong.
here is a template.

image
PINECONE_ENVIRONMENT="eu-west1-gcp"
PINECONE_INDEX_NAME="indexname"
PINECONE_API_KEY = "0000000-0000-42a9-901b-123456788"

@alangunning
Copy link

alangunning commented Apr 3, 2023

I also did the project name workaround at first, but after some digging I understood that my environments were written wrong. here is a template.

image PINECONE_ENVIRONMENT="eu-west1-gcp" PINECONE_INDEX_NAME="indexname" PINECONE_API_KEY = "0000000-0000-42a9-901b-123456788"

I was trying to setup repo 'https://github.com/mayooear/gpt4-pdf-chatbot-langchain'
and I was getting the same error that a lot of people are mentioning here.

The suggestion by @felipeotarola solved the error without doing anything else. I was simply setting the PINECONE_ENVIRONMENT incorrectly.

@kaleyroy
Copy link

kaleyroy commented Apr 4, 2023

My node version: v18.12.1
and downgrade to version @pinecone-database/pinecone": "^0.0.10
Fixed the problem

@ijot-nl
Copy link

ijot-nl commented Apr 10, 2023

I experienced this error, when the 'environment' was incorrectly set in the call to init().
I had 'us-east-gcp'. Should have been: 'us-east1-gcp'...
Strange that the init() call did not fail, but that the error was generated from the subsequent call.

@felipe1120gomez
Copy link

Update to version 0.0.12 and move to another wi-fi network to avoid problems with a proxy worked for me

@premgadwal
Copy link

hiya new to pinecone, am also having the same errors.

To recreate-- I cloned the repo from : https://github.com/mayooear/gpt4-pdf-chatbot-langchain && inputted my own API keys for OpenAI and PineCone. I've confirmed that my API keys work for both because when I removed them individually, I receive the expected corresponding errors of needing respective keys.

@rschwabco I am running Node 19.7, and I've tried updating my pinecone to 0.0.10 and 0.0.12 and both are returning below:

PineconeClient: Error getting project name: TypeError: fetch failed [Error: PineconeClient: Project name not set. Call init() first.]

is it solved?

@mjrussell91
Copy link

I also did the project name workaround at first, but after some digging I understood that my environments were written wrong. here is a template.

image PINECONE_ENVIRONMENT="eu-west1-gcp" PINECONE_INDEX_NAME="indexname" PINECONE_API_KEY = "0000000-0000-42a9-901b-123456788"

This is correct and fixed the issue for me. Perhaps the .env.example in this repo (https://github.com/mayooear/gpt4-pdf-chatbot-langchain) should be updated to reflect this.

mjrussell91 added a commit to mjrussell91/gpt4-pdf-chatbot-langchain that referenced this issue Apr 26, 2023
I was setting incorrect environment variables when using this project, and it seems like a few others have as well: pinecone-io/pinecone-ts-client#12

I propose outlining an example of correct environment variables in this example to reduce confusion.
@DigitalSolomon
Copy link

I also did the project name workaround at first, but after some digging I understood that my environments were written wrong. here is a template.

image PINECONE_ENVIRONMENT="eu-west1-gcp" PINECONE_INDEX_NAME="indexname" PINECONE_API_KEY = "0000000-0000-42a9-901b-123456788"

What was written wrong previously re: the environment? Is the correct approach just to copy the exact string displayed in the Pinecone UI in the Environment column? Because that's what I'm doing and I still get the error. Curious if there were any more subtleties hiding there.

@mjrussell91
Copy link

I also did the project name workaround at first, but after some digging I understood that my environments were written wrong. here is a template.
image PINECONE_ENVIRONMENT="eu-west1-gcp" PINECONE_INDEX_NAME="indexname" PINECONE_API_KEY = "0000000-0000-42a9-901b-123456788"

What was written wrong previously re: the environment? Is the correct approach just to copy the exact string displayed in the Pinecone UI in the Environment column? Because that's what I'm doing and I still get the error. Curious if there were any more subtleties hiding there.

Correct: PINECONE_INDEX_NAME="indexname"
Incorrect: PINECONE_INDEX_NAME="indexname-f15gc52.svc.eu-west1-gcp.pinecone.io"

Just try setting it as the first part of the Index Name column, not the whole string. Environment should be fine to be copied as is.

@liugod
Copy link

liugod commented Jun 10, 2023

I found that every index have a diffrent apikey,so if you have two or more index and you only set one apikey,you will get the "bug"

@richard523
Copy link

I was able to solve this problem by setting the project name after the init. Here is the code that worked for me.

I'm using Node v19.8.1, "langchain": "^0.0.45", and "@pinecone-database/pinecone": "^0.0.10".

import { PineconeClient } from '@pinecone-database/pinecone';

if (!process.env.PINECONE_ENVIRONMENT || !process.env.PINECONE_API_KEY) {
  throw new Error('Pinecone environment or api key vars missing');
}

async function initPinecone() {
  try {
    const pinecone = new PineconeClient();

    await pinecone.init({
      environment: process.env.PINECONE_ENVIRONMENT ?? '', //this is in the dashboard
      apiKey: process.env.PINECONE_API_KEY ?? '',
    });
    pinecone.projectName = 'default';

    return pinecone;
  } catch (error) {
    console.log('error', error);
    throw new Error('Failed to initialize Pinecone Client');
  }
}

export const pinecone = await initPinecone();

Current working solution for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests