Vertex AI - Mem0

Vertex AI

Google Cloud’s Vertex AI serves text embedding models such as gemini-embedding-001. Mem0 uses them through the provider’s own SDK, which you install alongside Mem0.

Installation

The Vertex AI client is an optional dependency, so install it yourself.

Python

pip install vertexai

TypeScript

npm install @google-cloud/aiplatform

Authentication

Both SDKs authenticate with Application Default Credentials. Pick whichever fits your environment:

The TypeScript SDK reads the project ID from googleProjectId, then the GCP_PROJECT_ID, GOOGLE_CLOUD_PROJECT, and GCLOUD_PROJECT environment variables, and finally from your credentials. Set it explicitly when your credentials cover more than one project.

Usage

Python

import os
from mem0 import Memory

# Set the path to your Google Cloud credentials JSON file
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/your/credentials.json"
os.environ["OPENAI_API_KEY"] = "your_api_key" # For LLM

config = {
    "embedder": {
        "provider": "vertexai",
        "config": {
            "model": "gemini-embedding-001",
            "memory_add_embedding_type": "RETRIEVAL_DOCUMENT",
            "memory_update_embedding_type": "RETRIEVAL_DOCUMENT",
            "memory_search_embedding_type": "RETRIEVAL_QUERY"
        }
    }
}

m = Memory.from_config(config)
messages = [\
    {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},\
    {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."},\
    {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."},\
    {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}\
]
m.add(messages, user_id="john")

TypeScript

import { Memory } from "mem0ai/oss";

const config = {
  embedder: {
    provider: "vertexai",
    config: {
      model: "gemini-embedding-001",
      // Optional. Falls back to GCP_PROJECT_ID / GOOGLE_CLOUD_PROJECT /
      // GCLOUD_PROJECT, then to the project on your credentials.
      googleProjectId: process.env.GCP_PROJECT_ID,
      location: "us-central1",
      // Optional. Path to a service account key file, or pass the JSON inline
      // via googleServiceAccountJson.
      vertexCredentialsJson: "/path/to/your/credentials.json",
      embeddingDims: 256,
      memoryAddEmbeddingType: "RETRIEVAL_DOCUMENT",
      memoryUpdateEmbeddingType: "RETRIEVAL_DOCUMENT",
      memorySearchEmbeddingType: "RETRIEVAL_QUERY",
    },
  },
};

const memory = new Memory(config);
await memory.add("I love sci-fi movies but not thrillers", { userId: "john" });

Embedding types

Vertex AI embeds the same text differently depending on the task you declare. The embedding types can be one of the following:

Check out the Vertex AI documentation for more information.

These embedding types map to the add, update, and search memory actions in both the Python and TypeScript SDKs. Stored memories use the add or update type, and searches use the search type.

Choosing a model

gemini-embedding-001 accepts one input text per request. When Mem0 embeds several texts at once, such as the memories extracted from a single conversation turn, it issues one request per text. The older text-embedding-005 and text-multilingual-embedding-002 models accept up to 250 texts per request, so they are faster and cheaper for large batches. See Get text embeddings.

Config

Here are the parameters available for configuring the Vertex AI embedder:

Parameter Description Default Value
model The name of the Vertex AI embedding model to use gemini-embedding-001
vertex_credentials_json Path to the Google Cloud credentials JSON file None
embedding_dims Dimensions of the embedding model 256
memory_add_embedding_type The embedding type to use for the add memory action RETRIEVAL_DOCUMENT
memory_update_embedding_type The embedding type to use for the update memory action RETRIEVAL_DOCUMENT
memory_search_embedding_type The embedding type to use for the search memory action RETRIEVAL_QUERY
Parameter Description Default Value
model The name of the Vertex AI embedding model to use gemini-embedding-001
googleProjectId Google Cloud project ID (falls back to GCP_PROJECT_ID env var, then to your credentials) Resolved from credentials
location Google Cloud region (falls back to GCP_LOCATION env var) us-central1
vertexCredentialsJson Path to the Google Cloud credentials JSON file None
googleServiceAccountJson Service account credentials as a JSON string or object None
embeddingDims Dimensions of the embedding model 256
memoryAddEmbeddingType The embedding type to use for the add memory action RETRIEVAL_DOCUMENT
memoryUpdateEmbeddingType The embedding type to use for the update memory action RETRIEVAL_DOCUMENT
memorySearchEmbeddingType The embedding type to use for the search memory action RETRIEVAL_QUERY