pinecone-ts-client: [Bug] Pinecone client doesn't initialize on Cloudfare workers or Vercel

Is this a new bug?

  • I believe this is a new bug
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

When I try to initialise the client it throws errors

const pinecone = new Pinecone({
                apiKey: env.PINECONE_API_KEY,
                environment: env.PINECONE_ENVIRONMENT,
});

Cloudfare Error:

Error compiling schema, function code: const schema2 = scope.schema[2];const schema1 = scope.schema[1];return function validate1(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(!(((typeof data == "number") && (!(data % 1) && !isNaN(data))) && (isFinite(data)))){const err0 = {instancePath,schemaPath:"#/definitions/nonNegativeInteger/type",keyword:"type",params:{type: "integer"},message:"must be integer"};if(vErrors === null){vErrors = [err0];}else {vErrors.push(err0);}errors++;}if((typeof data == "number") && (isFinite(data))){if(data < 0 || isNaN(data)){const err1 = {instancePath,schemaPath:"#/definitions/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison: ">=", limit: 0},message:"must be >= 0"};if(vErrors === null){vErrors = [err1];}else {vErrors.push(err1);}errors++;}}validate1.errors = vErrors;return errors === 0;}
EvalError: Code generation from strings disallowed for this context
    at new Function (<anonymous>)
    at Ajv.compileSchema (file:///private/var/folders/c8/yj5plb7n12j4_dx2t602mjgw0000gn/T/tmp-36161-E863LF5hXPTq/index.js:10324:30)
    at Ajv.inlineOrCompile (file:///private/var/folders/c8/yj5plb7n12j4_dx2t602mjgw0000gn/T/tmp-36161-E863LF5hXPTq/index.js:10380:49)
    at Ajv.resolveRef (file:///private/var/folders/c8/yj5plb7n12j4_dx2t602mjgw0000gn/T/tmp-36161-E863LF5hXPTq/index.js:10374:47)
    at Object.code (file:///private/var/folders/c8/yj5plb7n12j4_dx2t602mjgw0000gn/T/tmp-36161-E863LF5hXPTq/index.js:12188:47)
    at keywordCode (file:///private/var/folders/c8/yj5plb7n12j4_dx2t602mjgw0000gn/T/tmp-36161-E863LF5hXPTq/index.js:10148:13)
    at file:///private/var/folders/c8/yj5plb7n12j4_dx2t602mjgw0000gn/T/tmp-36161-E863LF5hXPTq/index.js:9874:25
    at CodeGen.code (file:///private/var/folders/c8/yj5plb7n12j4_dx2t602mjgw0000gn/T/tmp-36161-E863LF5hXPTq/index.js:8139:11)
    at CodeGen.block (file:///private/var/folders/c8/yj5plb7n12j4_dx2t602mjgw0000gn/T/tmp-36161-E863LF5hXPTq/index.js:8266:16)
    at schemaKeywords (file:///private/var/folders/c8/yj5plb7n12j4_dx2t602mjgw0000gn/T/tmp-36161-E863LF5hXPTq/index.js:9874:13) {
  stack: EvalError: Code generation from strings disallowed…0000gn/T/tmp-36161-E863LF5hXPTq/index.js:9874:13),
  message: Code generation from strings disallowed for this context
}

Vercel Serverless/Edge functions:

ReferenceError: global not defined

Expected Behavior

I want to be able to run the pinecone client close to my LLM.

Steps To Reproduce

  1. Install the latest client
  2. Create a js file that initialises the client.

Relevant log output

No response

Environment

- **OS**:
- **Language version**:
- **Pinecone client version**:1.1.2

Additional Context

No response

About this issue

  • Original URL
  • State: open
  • Created 8 months ago
  • Reactions: 4
  • Comments: 16

Most upvoted comments

Hi everyone,

I wanted to update you on my progress with deploying on Next.js while using Langchain and Pinecone. I’ve found a temporary workaround that seems to be effective for now:

  1. Pinecone Version Update: I upgraded Pinecone from version 1.1.0 to 1.1.2. While I’m not entirely sure if this was a decisive factor, it’s part of the changes I made.

  2. Typo Correction in Configuration: I identified and corrected a typo in the configuration path. The original path ./node_modules/@pinecone-database/pinecone/** was changed to /node_modules/@pinecone-database/pinecone/**. This adjustment appears to have had a significant impact.

  3. Working Configuration: For those trying to deploy on Next.js and encountering similar issues, here’s the configuration that I used:

    export const config = {
      runtime: 'edge',
      unstable_allowDynamic: ['/node_modules/@pinecone-database/pinecone/**'],
    };
    

I want to emphasize that this is a temporary workaround, and I’m not entirely sure whether the version update, the typo fix, or both together led to the success. However, after these changes, my application is now able to call the API in production without throwing errors.

I hope this workaround might be useful for others in a similar situation. If you’re deploying on Next.js and using Langchain, you might want to give this configuration a try.

Would love to hear if this helps anyone else or if there are more permanent solutions being explored.

@RickRyan26 Mine works with ^1.1.2 as well, the exported class is just marked as @deprecated and you need to use the deprecated methods. Here is an excerpt from my codebase:

import { PineconeClient } from '@pinecone-database/pinecone';
const pinecone = new PineconeClient()
await pinecone.init({
  apiKey: env.PINECONE_API_KEY,
  environment: env.PINECONE_ENVIRONMENT,
})
const index = pinecone.Index(env.PINECONE_INDEX_NAME)
const upsertResponse = await index.upsert({ upsertRequest: { vectors, } })