
Deploy Mem0 Gemini
Gemini models and embeddings behind your Mem0 server
mem0-api
Just deployed
/app/history
Just deployed
/var/lib/postgresql/data
mem0-dashboard
Just deployed
Just deployed
Deploy and Host self hosted Mem0 Gemini (Open-Source AI Memory Layer on Google Gemini) on Railway
This template deploys Mem0 v2.2.1, its dashboard, Caddy, and Postgres with pgvector on Railway. It shows how to point memory extraction and embeddings at Gemini, for developers who want their memory layer off OpenAI.
About Hosting Mem0 Gemini open-source software on Railway (self hosted Mem0 with Google Gemini template)
Your memories stay in your own Postgres with pgvector, not someone else's database. Railway covers the public domain, TLS, private networking between services, and Postgres provisioning.
That means one origin for the API and dashboard, no CORS wiring, and per-app keys (m0sk_...) you create in the UI.
Why Deploy Mem0 Gemini, the Zep alternative on Railway (Railway Free Trial)
Zep Cloud bills per month for memory you cannot inspect, and Graphiti means running the graph stack yourself. The $5 Railway trial covers a real test against your own conversations.
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying Mem0 Gemini on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Railway vs Other Hosting Providers and VPS for Mem0 Gemini self hosting
Railway ships the four-service Mem0 stack as one unit; the others hand you a server to assemble.
| Provider | What You Get with Railway | What You Get with the Other Provider |
|---|---|---|
| DigitalOcean | Caddy, the FastAPI server, the dashboard, and Postgres 18 with pgvector routed to one domain. | A Droplet where you install Docker, pgvector Postgres, and a proxy, then patch and back up yourself. |
| AWS | Managed Postgres, generated secrets, and one public Caddy service routing /memories and /docs. | RDS plus ECS or EC2, IAM roles, security groups, and an ALB before the first memory call. |
| Hetzner | Push-to-deploy, health checks on /healthz, and per-service logs in one dashboard. | Cheap CX compute, but you own Compose, TLS certs, and the pgvector extension install. |
Your Gemini key stays in the dashboard Configuration page either way.
Common Use Cases for hosted Mem0 Gemini
- A Gemini chat assistant that remembers users: Mem0 pulls durable facts from each conversation and returns the right ones per user_id on the next turn, so it stops asking twice.
- One Google bill for the whole layer: extraction, updates, and embeddings all use Gemini, so you manage a single GOOGLE_API_KEY instead of juggling OpenAI for memory.
- Cheaper flash-class models for extraction: short structured extraction runs fine on a flash-class model at low temperature.
- Smaller 768-dim vectors to save Postgres space: truncate gemini-embedding-001 from its native 3072 dims to 768, and keep cosine search fast as the table grows.
- Multilingual memories: gemini-embedding-001 handles cross-lingual text, so a Spanish preference surfaces for an English query.
Dependencies for Mem0 Gemini Docker hosted on Railway
Four services. mem0 is caddy:2.11.7-alpine on port 8080 and routes /memories, /search, /auth, /api-keys and /docs to mem0-api. mem0-api (ghcr.io/onepush-dev/mem0-api:v2.2.1) is private on 8000 with volume /app/history and health /docs. mem0-dashboard (ghcr.io/onepush-dev/mem0-dashboard:v2.2.1) is private on 3000.
Deployment Dependencies for Managed Mem0 Gemini Service (AI Memory)
Generated secrets are JWT_SECRET, ADMIN_API_KEY and POSTGRES_PASSWORD. Fixed env covers MEM0_TELEMETRY=false, AUTH_DISABLED=false and POSTGRES_COLLECTION_NAME=memories. The GOOGLE_API_KEY from Google AI Studio powers both calls.
Implementation Details for Mem0 Gemini (Using Mem0 official docker image)
On boot mem0-api waits for Postgres, enables the vector extension, creates mem0_app, runs alembic migrations and listens on IPv6. Run one replica.
How does Mem0 Gemini compare against other memory layers for Gemini apps
Mem0 vs Zep (Zep Alternative)
- Memory model: Mem0 extracts facts with a Gemini LLM and stores them as embeddings. Zep builds a temporal knowledge graph that tracks how facts change.
- Where Mem0 wins: Apache-2.0, four small Railway services, and all extraction and embedding on your Google bill.
- Where Zep wins: validity windows and entity relationships, which graph memory handles better than snippet recall.
Mem0 vs Letta (Letta Alternative)
- Different shape: Mem0 is a memory service you call over HTTP. Letta is a stateful agent runtime, formerly MemGPT, with memory blocks inside it.
- Where Mem0 wins: you keep your own Gemini agent loop and just POST to /memories and /search.
- Where Letta wins: memory and runtime managed together, if you want the runtime deciding what stays in context.
Mem0 vs LangMem (LangMem Alternative)
- Scope: LangMem is a Python library called inside your process. Mem0 is a server with Postgres, pgvector and an API, so memory survives restarts.
- Where Mem0 wins: any language or service can hit the same store, plus a dashboard and per-app keys.
- Where LangMem wins: no extra infrastructure or network hop if you only build one LangGraph app.
Mem0 vs Vertex AI Memory Bank (Vertex Alternative)
- Where Mem0 wins: it runs on Railway beside your stack, works with any Gemini model, and vectors stay in your Postgres.
- Where Vertex wins: fully managed by Google, so no container, no migration and no collection name to pick.
- Honest note: both send memory text to Google for extraction and embedding, so check Google's data terms for your tier.
How to use Mem0 Gemini (the OSS AI memory layer)?
- Create a key in Google AI Studio, where GOOGLE_API_KEY comes from.
- Open your Railway domain; the first visitor to /setup becomes admin.
- On the Configuration page, set LLM provider gemini, a current model, and that key.
- Set embedder gemini, model models/gemini-embedding-001, dims 1536.
- Changed dims? Set a new POSTGRES_COLLECTION_NAME; old vectors aren't comparable.
- Save, then create an API key (m0sk_ prefix).
- Add and search with curl:
curl $URL/memories -H "X-API-Key: $KEY" -H "Content-Type: application/json" -d '{"messages":[{"role":"user","content":"I live in Berlin"}],"user_id":"u1"}'
curl $URL/search -H "X-API-Key: $KEY" -H "Content-Type: application/json" -d '{"query":"where do I live","user_id":"u1"}'
Search returns the Berlin memory.
How to self host Mem0 Gemini on other VPS Services (Mem0 self hosting guide)
You can run the same Mem0 server and dashboard on a plain VPS. You need Postgres with pgvector and about 2 GB RAM.
Clone the Repository
Pull the upstream repo, which ships the REST server and dashboard.
git clone https://github.com/mem0ai/mem0.git
cd mem0/server
Install Dependencies
Install Docker with the Compose plugin, plus Postgres 18 and the pgvector extension.
Configure Environment Variables
Get a key from Google AI Studio, then set provider gemini for both the LLM and the embedder.
llm: gemini, a current stable flash-class model
embedder: gemini, models/gemini-embedding-001, dims 768
Keep the vector store dims equal to the embedder output. If either changes, use a new collection name and re-add memories.
Start the Mem0 Gemini Application
docker compose up -d
Open your domain right away, since the first visitor to /setup becomes admin, then set the providers on the Configuration page and create an API key. Railway handles Postgres, TLS, and routing for you.
Official Pricing of Mem0 Gemini (Mem0 pricing)
Self-hosting Mem0 is free, Apache-2.0. You pay Railway and Google. Gemini API usage is billed by Google at Google's rates, not by Mem0. Enterprise is custom.
Mem0 Gemini cloud vs self hosted comparison (Pricing, features, costs, and more)
The hosted platform bills by request volume. Self hosting keeps the same Apache-2.0 code on your own Railway project, and you pay Railway plus Google for Gemini calls.
Monthly cost of self hosting Mem0 Gemini on Railway
Expect about $10-20 per month for the four small services and Postgres at light use, on top of Gemini API usage for extraction and embeddings. The Railway $5 trial covers the first stretch.
System Requirements for Hosting Mem0 Gemini on a VPS
Two vCPUs and 2 GB RAM handle the Caddy proxy, FastAPI server, dashboard and Postgres; give the volume room for pgvector. You also need Docker Compose, a TLS terminator, and enough disk for 3072-dim vectors.
Frequently Asked Questions (FAQs)
Which Gemini model should I set for the LLM?
Use a current stable model; older Gemini models are being retired. The docs examples use gemini-2.0-flash-001, and flash-class models are cheap for extraction.
What embedding dimension should I pick?
gemini-embedding-001 outputs 3072 natively and truncates to 1536 or 768. Pick 768 for smaller pgvector rows and keep embedding_dims matching output_dimensionality.
Why does search return nothing after I switched embedders?
New vectors live in a different space than the old ones, so results look empty. Changing model or dimension needs a new collection name, then re-adding memories.
Can I mix OpenAI and Gemini?
Yes, the LLM and embedder are set separately, so a Gemini LLM with OpenAI embeddings works. Changing the embedder later still means a fresh collection.
Where is the Gemini key stored?
Dashboard settings live in Postgres and override env vars, so the key sits in your Railway database. You can also set GOOGLE_API_KEY on mem0-api.
Does Gemini see my memories?
Yes, extracted facts and the conversation text behind them go to Google's Gemini API. Check Google's data terms for the tier you use.
Template Content

