firebase / genkit

An open source framework for building AI-powered apps with familiar code-centric patterns. Genkit makes it easy to integrate, test, and deploy sophisticated AI features to Firebase or Google Cloud.
Apache License 2.0
607 stars 74 forks source link

[JS] Adding vertexAI Plugin increases memory consumption on Firebase Cloud Function Trigger #743

Open dario-digregorio opened 1 month ago

dario-digregorio commented 1 month ago

Describe the bug When I add the vertexAI plugin to genkit I am unable to deploy my cloud function triggers (Firestore document trigger). I get the error Memory limit of 256 MiB exceeded with 280 MiB used. Only increasing the memory or removing the vertexAI plugin fixes the problem. So I am wondering way the memory increases so high.

To Reproduce add this configuration:

configureGenkit({
  plugins: [
    firebase(),
    vertexAI(),
    googleAI(),
    dotprompt(),
  ],
  traceStore: "firebase",
  logLevel: "debug",
  defaultModel: gemini15Pro,
  enableTracingAndMetrics: true,
});

add this cloud function trigger:

export const generateChatAnswer = onDocumentCreated({
  document: "rooms/{roomId}/events/{eventId}",
  memory: "512MiB",
},
async (e) => {
  logger.info("Event triggered");
});

run a deploy:

firebase deploy --only functions

Expected behavior I should be able deploy the functions because I just use a different model API

Screenshots If applicable, add screenshots to help explain your problem.

Runtime (please complete the following information):

** Node version

marcelpinto commented 2 weeks ago

I was struggling with the same issue today. Not only this, but it affects all the other functions, they all started to fail because of memory limit.

For now, the solution was to configureGenKit inside the trigger function and increase that function memory.

pavelgj commented 2 weeks ago

Vertexai plugin has grown in size recently, so it's not too surprising that it's memory hungry. That said, I have some ideas how to improve this -- we can break up the vertexAI plugin into multiple plugins. Specifically the features with non-core deps (like anthropic and llama3.1 model support).

cabljac commented 3 days ago

I guess this needs some planning on what exactly we need to do, before i start? @pavelgj