docs/components/embedders/models/vertexai.mdx
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.
The Vertex AI client is an optional dependency, so install it yourself.
<CodeGroup> ```bash Python pip install vertexai ```npm install @google-cloud/aiplatform
Both SDKs authenticate with Application Default Credentials. Pick whichever fits your environment:
gcloud auth application-default login.GOOGLE_APPLICATION_CREDENTIALS at the JSON file, or pass its path through the embedder config.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.
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 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" });
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.
<Note> 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. </Note>Here are the parameters available for configuring the Vertex AI embedder:
<Tabs> <Tab title="Python"> | 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` | </Tab> <Tab title="TypeScript"> | 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` | </Tab> </Tabs>