Railway

Deploy Cognee — Self-Hosted AI Memory with MCP

Self-host Cognee — persistent agent memory over MCP, knowledge graph

Deploy Cognee — Self-Hosted AI Memory with MCP

/var/lib/postgresql/data

Just deployed

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

ServicePurpose
cognee-apiThe private memory backend — ingestion, Cognify processing, search (port 8000)
cognee-mcpThe public MCP server in SSE mode for AI-client integration (port 8001)
PostgreSQL + pgvectorShared 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 DBCloud memory APINo memory
Storage modelGraph + vectorsVectors onlyVariesNone
MCP integrationBuilt-in (SSE)NoSomeNo
Cross-session memoryYesManualYesNo
Reasoning over relationshipsYesNoVariesNo
Data ownershipFull — your infraFullVendorN/A
Self-hostableYesYesNoN/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

  1. Click Deploy on Railway — cognee-api, cognee-mcp, and PostgreSQL build and wire together (~4 minutes)
  2. Add your LLM_API_KEY (and optionally an embedding key) on the services
  3. Confirm DB_PROVIDER=postgres and VECTOR_DB_PROVIDER=pgvector are set
  4. Point an MCP client (Claude Code, Cursor, OpenCode) at your public MCP SSE endpoint
  5. 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

VariableRequiredDescription
LLM_API_KEYRequiredKey for your LLM provider (OpenRouter, OpenAI, Anthropic, Ollama)
DB_PROVIDERPre-setpostgres — durable relational storage (not default SQLite)
VECTOR_DB_PROVIDERPre-setpgvector — durable vector storage (not default LanceDB)
DB_HOST / DB_PORT / DB_USERNAME / DB_PASSWORD / DB_NAMEAuto-injectedPostgres connection
REQUIRE_AUTHENTICATIONRecommendedtrue 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=postgres and VECTOR_DB_PROVIDER=pgvector so memory persists. Add your LLM_API_KEY to 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_AUTHENTICATION and restrict CORS_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

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
116
View Template
stella
Self-host stella with web, API, Postgres, Redis, and object storage.

Jan Kubica
5
View Template
Hermes Agent | OpenClaw Alternative with Dashboard
Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

codestorm
64