Unable to setup pinecone with convex
Why am I getting this error, when trying to setup Pinecone under a lib folder in my convex.
Error:
This is how I am setting up my pinecone.
✖ Error: Unable to push deployment config to https://....
400 Bad Request: UnableToPush: Hit an error while pushing:
Loading the pushed modules encountered the following
error:
Failed to analyze lib/pinecone.js: Uncaught EvalError: Code generation from strings disallowed for this context
at new Function (<anonymous>)
✖ Error: Unable to push deployment config to https://....
400 Bad Request: UnableToPush: Hit an error while pushing:
Loading the pushed modules encountered the following
error:
Failed to analyze lib/pinecone.js: Uncaught EvalError: Code generation from strings disallowed for this context
at new Function (<anonymous>)
const pinecone = new Pinecone({
apiKey: process.env.PINECONE_API_KEY as string,
environment: process.env.PINECONE_ENVIRONMENT as string,
});
const pinecone = new Pinecone({
apiKey: process.env.PINECONE_API_KEY as string,
environment: process.env.PINECONE_ENVIRONMENT as string,
});
3 Replies
@Rayy this is something we may be able to support in the future, but for now I'd use the Node.js runtime by adding
"use node";
to the top of the file where you define this function https://docs.convex.dev/functions/runtimes#nodejs-runtimefor future reference here's the full error I see — looks like it's this ajv issue https://github.com/ajv-validator/ajv/issues/2318
✖ Error: Unable to push deployment config to https://small-goldfinch-247.convex.cloud
400 Bad Request: UnableToPush: Hit an error while pushing:
Loading the pushed modules encountered the following
error:
Failed to analyze messages.js: Uncaught EvalError: Code generation from strings disallowed fo
r this context
at new Function (<anonymous>)
at compileSchema (../node_modules/ajv/lib/compile/index.ts:171:42)
at inlineOrCompile (../node_modules/ajv/lib/compile/index.ts:228:0)
at resolveRef (../node_modules/ajv/lib/compile/index.ts:223:0)
at code [as code] (../node_modules/ajv/lib/vocabularies/core/ref.ts:18:21)
at keywordCode (../node_modules/ajv/lib/compile/validate/index.ts:531:26)
at <anonymous> (../node_modules/ajv/lib/compile/validate/index.ts:228:4)
at code [as code] (../node_modules/ajv/lib/compile/codegen/index.ts:524:33)
at block [as block] (../node_modules/ajv/lib/compile/codegen/index.ts:680:11)
at schemaKeywords (../node_modules/ajv/lib/compile/validate/index.ts:228:4)
✖ Error: Unable to push deployment config to https://small-goldfinch-247.convex.cloud
400 Bad Request: UnableToPush: Hit an error while pushing:
Loading the pushed modules encountered the following
error:
Failed to analyze messages.js: Uncaught EvalError: Code generation from strings disallowed fo
r this context
at new Function (<anonymous>)
at compileSchema (../node_modules/ajv/lib/compile/index.ts:171:42)
at inlineOrCompile (../node_modules/ajv/lib/compile/index.ts:228:0)
at resolveRef (../node_modules/ajv/lib/compile/index.ts:223:0)
at code [as code] (../node_modules/ajv/lib/vocabularies/core/ref.ts:18:21)
at keywordCode (../node_modules/ajv/lib/compile/validate/index.ts:531:26)
at <anonymous> (../node_modules/ajv/lib/compile/validate/index.ts:228:4)
at code [as code] (../node_modules/ajv/lib/compile/codegen/index.ts:524:33)
at block [as block] (../node_modules/ajv/lib/compile/codegen/index.ts:680:11)
at schemaKeywords (../node_modules/ajv/lib/compile/validate/index.ts:228:4)
GitHub
Allow it to work on edge (e.g. cloudflare workers) · Issue #2318 · ...
Currently AJV can't run on cloudflare workers, vercel-edge and other edge environments. When trying to run it, the worker throws an error: Code generation from strings disallowed for this conte...
Even after using
The full error stack
use node
, I am getting the error.
"use node";
import { Pinecone } from "@pinecone-database/pinecone";
import { Id, TableNames } from "../_generated/dataModel";
import { VectorOperationsApi } from "@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch";
export const MaxUpsertBatchLimit = 100;
const pinecone = new Pinecone({
apiKey: process.env.PINECONE_API_KEY as string,
environment: process.env.PINECONE_ENVIRONMENT as string,
});
export const pineconeIndex = async () => {
return pinecone.Index("student-corner");
};
export const upsertVectors = async <TableName extends TableNames>(
namespace: TableName,
vectors: { id: Id<TableName>; values: number[]; metadata: object }[],
index?: VectorOperationsApi | undefined
) => {
const start = Date.now();
if (!index) {
index = (await pineconeIndex()) as unknown as VectorOperationsApi;
}
const results = [];
// Insert all the vectors in batches of 100
// https://docs.pinecone.io/docs/insert-data#batching-upserts
for (let i = 0; i < vectors.length; i += MaxUpsertBatchLimit) {
results.push(
await index?.upsert({
upsertRequest: {
namespace,
vectors: vectors.slice(i, i + MaxUpsertBatchLimit),
},
})
);
}
console.log({
count: vectors.length,
pineconeUpsertMs: Date.now() - start,
});
return results;
};
"use node";
import { Pinecone } from "@pinecone-database/pinecone";
import { Id, TableNames } from "../_generated/dataModel";
import { VectorOperationsApi } from "@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch";
export const MaxUpsertBatchLimit = 100;
const pinecone = new Pinecone({
apiKey: process.env.PINECONE_API_KEY as string,
environment: process.env.PINECONE_ENVIRONMENT as string,
});
export const pineconeIndex = async () => {
return pinecone.Index("student-corner");
};
export const upsertVectors = async <TableName extends TableNames>(
namespace: TableName,
vectors: { id: Id<TableName>; values: number[]; metadata: object }[],
index?: VectorOperationsApi | undefined
) => {
const start = Date.now();
if (!index) {
index = (await pineconeIndex()) as unknown as VectorOperationsApi;
}
const results = [];
// Insert all the vectors in batches of 100
// https://docs.pinecone.io/docs/insert-data#batching-upserts
for (let i = 0; i < vectors.length; i += MaxUpsertBatchLimit) {
results.push(
await index?.upsert({
upsertRequest: {
namespace,
vectors: vectors.slice(i, i + MaxUpsertBatchLimit),
},
})
);
}
console.log({
count: vectors.length,
pineconeUpsertMs: Date.now() - start,
});
return results;
};
✖ Error: Unable to push deployment config to https://dutiful-meerkat-502.convex.cloud
400 Bad Request: UnableToPush: Hit an error while pushing:
Loading the pushed modules encountered the following
error:
Failed to analyze sources.js: Uncaught EvalError: Code generation from strings disallowed for this context
at new Function (<anonymous>)
at compileSchema (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/index.ts:171:42)
at inlineOrCompile (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/index.ts:228:0)
at resolveRef (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/index.ts:223:0)
at code [as code] (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/vocabularies/core/ref.ts:18:21)
at keywordCode (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/validate/index.ts:531:26)
at <anonymous> (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/validate/index.ts:228:4)
at code [as code] (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/codegen/index.ts:524:33)
at block [as block] (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/codegen/index.ts:680:11)
at schemaKeywords (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/validate/index.ts:228:4)
✖ Error: Unable to push deployment config to https://dutiful-meerkat-502.convex.cloud
400 Bad Request: UnableToPush: Hit an error while pushing:
Loading the pushed modules encountered the following
error:
Failed to analyze sources.js: Uncaught EvalError: Code generation from strings disallowed for this context
at new Function (<anonymous>)
at compileSchema (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/index.ts:171:42)
at inlineOrCompile (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/index.ts:228:0)
at resolveRef (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/index.ts:223:0)
at code [as code] (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/vocabularies/core/ref.ts:18:21)
at keywordCode (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/validate/index.ts:531:26)
at <anonymous> (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/validate/index.ts:228:4)
at code [as code] (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/codegen/index.ts:524:33)
at block [as block] (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/codegen/index.ts:680:11)
at schemaKeywords (../node_modules/@pinecone-database/pinecone/node_modules/ajv/lib/compile/validate/index.ts:228:4)