Open Blaizzy opened 7 months ago
Is there any workaround for this? Langchainjs requires 1.1.0 now, so I can't upgrade that without breaking in our cloudflare workers - hoping there is some alternative
@PlasticLizard AFAIU, the current workaround is to use the old deprecated PineconeClient
in the meantime.
@kenju Do you have a working version number? I can't find one. Thanks!
I'm using 0.0.12
It sucks because that version conflicts with all LangChain versions prior to 0.0.159, so we're locked into the relatively distant past, but it seems the best that can be done at the moment to run on CloudFlare.
Oh nice, Thanks for the tip! No clue how elaborately you're using LangChain so this info might be worthless but if you're just using it for extending OpenAi, their new GPTs Assistants Beta API is making LangChain seem pretty obsolete to me.
@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, } })
"@pinecone-database/pinecone": "^1.1.2",
"langchain": "^0.0.211",
I managed to make it work on Cloudflare Workers with the following workaround:
globals.d.ts
declare global {
var EdgeRuntime: string;
}
index.ts
globalThis.EdgeRuntime = "cloudflare" // the content doesn't really matter as long as it is a string
whatever-your-file-is.ts
const pinecone = new Pinecone({
apiKey: env.PINECONE_API_KEY,
environment: env.PINECONE_ENVIRONMENT
});
const pineconeIndex = pinecone.Index(env.PINECONE_INDEX_NAME);
// Langchain Vector Store vectorStore = await PineconeStore.fromExistingIndex( embeddings, { pineconeIndex } );
4. `wrangler.toml`
```toml
node_compat = true
pinecone-ts-client
depends on some Node.js globals like global
and process
. That's why turning node_compat = true
was necessary. @edge-runtime
?Facing same issue when deploying to Vercel Edge api.
Issue Details:
Failed to compile.
The error log points to ./node_modules/@pinecone-database/pinecone/node_modules/ajv/dist/compile/index.js
.eval
, new Function
, WebAssembly.compile
), which is not permitted in the Edge Runtime (reference: Next.js documentation).Attempted Solutions and Further Issues:
VectorOperationsApi
, which is not supported by Langchain
. Langchain
expects Index<RecordMetadata>
from PineconeStore.fromExistingIndex
.Current Stance:
@rpatel15-hue have you tried setting EdgeRuntime
global variable?
Refs:
Hi @marpontes,
Thank you for your suggestion. I've attempted both the EdgeRuntime global variable approach and the unstable_allowDynamic configuration for Next.js, but I'm still encountering a compilation error.
Summary of my attempts:
1. EdgeRuntime global variable:
globals.d.ts
and set EdgeRuntime
in index.ts
as you described.I'm facing a TypeScript error when trying to set the EdgeRuntime
global variable in my index.ts
file:
Error: "Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.ts(7017)"
Steps Taken:
Created globals.d.ts
.
Attempted to set EdgeRuntime
in index.ts
:
globalThis.EdgeRuntime = "vercel"; // Using "vercel" for Next.js Edge Runtime
EdgeRuntime
global variable in TypeScript without triggering this error?2. unstable_allowDynamic configuration:
Added the following configuration to my edge API route file:
export const config = {
runtime: 'edge',
unstable_allowDynamic: [
'./node_modules/@pinecone-database/pinecone/**'
],
}
Additional Questions (clarifications and additions):
Equivalent to node_compat = true for Next.js: Is there a mechanism in Next.js that provides Node.js compatibility features for the Edge Runtime, similar to Cloudflare's node_compat = true
?
Alternative workarounds: Besides the EdgeRuntime
variable, are there other known workarounds or compatibility approaches for using Pinecone with Langchain in Next.js Edge Runtime?
Specific guidance for Next.js: The referenced commit (3671748) doesn't provide Next.js-specific instructions. Is there any further guidance or examples tailored for Next.js?
For more information on Edge Dynamic Code Evaluation in Next.js, you can refer to the official Next.js documentation.
I would appreciate any further insights or suggestions you might have, especially those relevant to the Next.js environment.
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:
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.
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.
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.
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:
Pinecone Version Update: I upgraded Pinecone from version
1.1.0
to1.1.2
. While I'm not entirely sure if this was a decisive factor, it's part of the changes I made.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.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.
Excited to try this thank you, sounds like a brilliant fix.
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:
- Pinecone Version Update: I upgraded Pinecone from version
1.1.0
to1.1.2
. While I'm not entirely sure if this was a decisive factor, it's part of the changes I made.- 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.- 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.
Excited to try this thank you, sounds like a brilliant fix.
Hi @RickRyan26, did it work for you?
My team and I ended up going in a different direction so I'm not sure but I bet it will. Surprised pinecone hasn't fixed this yet
@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:
Hey I have this issue
https://github.com/langchain-ai/langchainjs/discussions/4423
I just fixed it by installing old version of packages from here package.json
"@pinecone-database/pinecone": "^0.1.6",
"langchain": "^0.0.92",
I don't think node-fetch should imported if you are passing in a fetch function. This causes issues when using the pine cone library in plugins for rivet (v8 browser). Additionally, this would be an issue in cloudflare workers.
With node 18 LTS and after, not sure why we need an external library node-fetch
as a default. node-fetch
should be imported dynamically based on an option.
I think this would be the best way to make this package friendly across different runtimes. cc @jhamon
the user could easily just pass in any fetch function if a native fetch doesn't exist. This would easily solve a lot of issues in edge runtime.
if (!this.config.fetch && typeof fetch === 'undefined') {
throw new Error(
'The Fetch API is not supported in this environment. Please provide an alternative, for example, node-fetch.'
);
}
Man this is disappointing... it's sort of rare these days to find client libraries that don't work on Cloudflare, or edge workers.
Is this a new bug?
Current Behavior
When I try to initialise the client it throws errors
Cloudfare Error:
Vercel Serverless/Edge functions:
Expected Behavior
I want to be able to run the pinecone client close to my LLM.
Steps To Reproduce
Relevant log output
No response
Environment
Additional Context
No response