Deploy Cognee — Self-Hosted AI Memory with MCP
Self-host Cognee — persistent agent memory over MCP, knowledge graph
Just deployed
/var/lib/postgresql/data
cognee-api
Just deployed
cognee-mcp
Just deployed
Deploy and Host Cognee on Railway
Cognee is an open-source AI memory platform that gives your AI agents persistent, long-term memory across sessions — a self-hosted knowledge-graph engine that goes beyond vector search to map relationships between your data. It ingests documents, builds a knowledge graph plus embeddings, and serves memory to agents through an API and a Model Context Protocol (MCP) server, so tools like Claude Code, Cursor, and OpenCode remember context across conversations. This template deploys the Cognee API, the MCP server in SSE mode, and managed Postgres with pgvector — pre-wired — so your agents have durable memory in minutes.
What This Template Deploys
| Service | Purpose |
|---|---|
| cognee-api | The private memory backend — ingestion, Cognify processing, search (port 8000) |
| cognee-mcp | The public MCP server in SSE mode for AI-client integration (port 8001) |
| PostgreSQL + pgvector | Shared relational, graph, and vector storage |
All three connect over Railway's private network. The API backend processes and stores memory, the MCP server exposes it to AI assistants over the Model Context Protocol, and PostgreSQL with pgvector holds the relational data and vector embeddings — a single-user-ready memory stack.
About Hosting
Cognee is a multi-service memory platform, and a couple of configuration specifics make it store durably and connect to your agents — both handled here.
The MCP server is the standout — persistent memory for your AI tools. Cognee ships a dedicated MCP server (cognee/cognee-mcp) alongside the API, exposed here in SSE mode so AI coding assistants and agents — Claude Code, Cursor, OpenCode, and other MCP clients — connect and gain memory that persists across sessions. Point your client at the MCP endpoint and your agent can store, structure, and retrieve context without bespoke integration — the reason to run Cognee as a service rather than a library.
Set the storage providers to Postgres and pgvector — or it uses ephemeral defaults. This is the key configuration point: Cognee defaults to local SQLite and LanceDB/kuzu stores, which aren't durable on a PaaS. This template sets DB_PROVIDER=postgres and VECTOR_DB_PROVIDER=pgvector with the connection details, so relational data and vector embeddings persist in managed PostgreSQL instead of vanishing on redeploy. This is what makes the memory durable.
Knowledge graphs, not just vectors. Where a vector database stops at similarity search, Cognee's Cognify pipeline extracts entities and relationships into a knowledge graph, so agents reason across connected information — following relationships between data points, not just finding nearby chunks. This graph-plus-vector approach sets Cognee apart from a plain vector store, and pgvector backs both in one database.
Bring your own LLM and embedding keys. Cognee is model-agnostic — set LLM_API_KEY (OpenRouter, OpenAI, Anthropic, Gemini, or Ollama) for the LLM that powers extraction, and optionally a separate embedding key; by default the same provider handles both. The API backend stays private on the internal network while the MCP server is public for client access, so for production set REQUIRE_AUTHENTICATION=true for JWT auth and restrict CORS_ALLOWED_ORIGINS to your domains.
Typical cost: ~$10–20/month on Railway for the three services, plus your LLM provider usage for ingestion and processing. Cognee is open source and free to self-host.
How It Compares
| Cognee (self-hosted) | Plain vector DB | Cloud memory API | No memory | |
|---|---|---|---|---|
| Storage model | Graph + vectors | Vectors only | Varies | None |
| MCP integration | Built-in (SSE) | No | Some | No |
| Cross-session memory | Yes | Manual | Yes | No |
| Reasoning over relationships | Yes | No | Varies | No |
| Data ownership | Full — your infra | Full | Vendor | N/A |
| Self-hostable | Yes | Yes | No | N/A |
A plain vector database stores embeddings but can't map relationships or serve agents over MCP. Cloud memory APIs work but keep your agents' memory on a vendor's servers. Without a memory layer, agents forget everything between sessions. Cognee's edge is a knowledge-graph memory platform with native MCP — persistent, relationship-aware memory your AI tools connect to directly — self-hosted, on infrastructure you own.
Deploy in Under 5 Minutes
- Click Deploy on Railway — cognee-api, cognee-mcp, and PostgreSQL build and wire together (~4 minutes)
- Add your
LLM_API_KEY(and optionally an embedding key) on the services - Confirm
DB_PROVIDER=postgresandVECTOR_DB_PROVIDER=pgvectorare set - Point an MCP client (Claude Code, Cursor, OpenCode) at your public MCP SSE endpoint
- Ingest documents through the API, run Cognify, and your agent has persistent memory
For production, enable REQUIRE_AUTHENTICATION and restrict CORS_ALLOWED_ORIGINS.
Common Use Cases
- Agent long-term memory — give AI agents context that persists across sessions via MCP
- Coding-assistant memory — Claude Code, Cursor, or OpenCode remember your project over time
- Data-owned AI memory — keep your agents' memory on your own infrastructure
Configuration
| Variable | Required | Description |
|---|---|---|
LLM_API_KEY | Required | Key for your LLM provider (OpenRouter, OpenAI, Anthropic, Ollama) |
DB_PROVIDER | Pre-set | postgres — durable relational storage (not default SQLite) |
VECTOR_DB_PROVIDER | Pre-set | pgvector — durable vector storage (not default LanceDB) |
DB_HOST / DB_PORT / DB_USERNAME / DB_PASSWORD / DB_NAME | Auto-injected | Postgres connection |
REQUIRE_AUTHENTICATION | Recommended | true for JWT auth on the API in production |
Set Postgres and pgvector, or memory is ephemeral. Cognee defaults to local SQLite/LanceDB — this template sets
DB_PROVIDER=postgresandVECTOR_DB_PROVIDER=pgvectorso memory persists. Add yourLLM_API_KEYto power ingestion.
The MCP server is public; harden it. The API stays private and the MCP SSE server is public for clients — for production, enable
REQUIRE_AUTHENTICATIONand restrictCORS_ALLOWED_ORIGINS.
Dependencies for Cognee Hosting
- Railway account — ~$10–20/month for the three services, plus LLM provider usage
- PostgreSQL with pgvector (included and wired for relational, graph, and vector storage)
- An LLM provider key (OpenRouter, OpenAI, Anthropic, or Ollama) for extraction and embeddings
- An MCP client (Claude Code, Cursor, OpenCode) to connect to the memory server
Deployment Dependencies
Implementation Details
The template deploys three services over Railway's private network: cognee/cognee as the private API backend (port 8000 — ingestion, the Cognify pipeline, and search), cognee/cognee-mcp as the public MCP server in SSE mode (port 8001, for AI-client integration), and a PostgreSQL database with pgvector as the shared relational, graph, and vector store. The backend and MCP service are wired over internal networking into a single-user-ready memory stack.
A critical configuration detail is storage: Cognee defaults to SQLite for the relational store and LanceDB/kuzu for vectors and graphs, which are local and non-durable on a PaaS. The template sets DB_PROVIDER=postgres and VECTOR_DB_PROVIDER=pgvector with the connection details, so data and embeddings persist in managed Postgres. Cognee's Cognify pipeline extracts entities and relationships into a knowledge graph alongside the embeddings, enabling relationship-aware retrieval rather than similarity-only search.
Model access is via LLM_API_KEY (OpenRouter by default, or OpenAI, Anthropic, Gemini, Ollama), with an optional separate embedding key. For production, REQUIRE_AUTHENTICATION=true enables JWT auth and CORS_ALLOWED_ORIGINS should be restricted. PostgreSQL is the backup target. Cognee is actively developed, so pinning image versions is advisable.
Frequently Asked Questions
What is the MCP server for? It exposes Cognee's memory to AI assistants over the Model Context Protocol in SSE mode, so clients like Claude Code, Cursor, and OpenCode gain memory that persists across sessions — pointing your client at the endpoint is all it takes, no bespoke integration.
Why must I set Postgres and pgvector? Cognee defaults to local SQLite and LanceDB, which lose data on a PaaS redeploy. This template sets DB_PROVIDER=postgres and VECTOR_DB_PROVIDER=pgvector so your memory persists durably in the managed database.
Is it secured? The API stays private on the internal network; the MCP server is public for client access. For production, enable REQUIRE_AUTHENTICATION for JWT auth and restrict CORS_ALLOWED_ORIGINS to your domains.
Does my memory persist? Yes — with Postgres and pgvector configured (as this template does), all relational data, graph, and embeddings persist in the managed database across redeploys. Back up Postgres to preserve your agents' memory.
Why Deploy Cognee on Railway?
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 Cognee on Railway you get an AI memory platform with the hard parts solved — the API and MCP server wired together, Postgres and pgvector set for durable storage, and BYOK model access. Give your AI agents persistent, relationship-aware memory over MCP, self-hosted on infrastructure you own.
Template Content
cognee-api
RockinPaul/cognee_railway_templateLLM_API_KEY
Your OpenRouter API key. Cognee uses it for the OpenRouter LLM and, by default, for embeddings too.
EMBEDDING_API_KEY
Optional separate OpenRouter API key for embeddings. Leave empty to reuse LLM_API_KEY.
cognee-mcp
RockinPaul/cognee_railway_template