---
title: "Deploy Cognee Graph Memory API + pgvector"
description: "Cognee graph memory API for agents, pgvector Postgres and auth gateway"
category: "AI/ML"
url: https://railway.com/deploy/cognee-graph-memory-api-pgvector
---

# Deploy Cognee Graph Memory API + pgvector

Cognee graph memory API for agents, pgvector Postgres and auth gateway

**[Deploy Cognee Graph Memory API + pgvector on Railway](https://railway.com/template/cognee-graph-memory-api-pgvector)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/cognee-graph-memory-api-pgvector/manifest.json

- **Creator:** Protemplate
- **Category:** AI/ML
- **Total deploys:** 4

## Template content

### Postgres https://avatars.githubusercontent.com/u/177543?v=4

- **Image:** pgvector/pgvector:pg17
- **Start command:** `docker-entrypoint.sh postgres -c "listen_addresses=*"`

### Cognee https://avatars.githubusercontent.com/u/125468716?v=4

- **Image:** cognee/cognee:1.6.2
- **Start command:** `bash -c 'for i in $(seq 1 90); do (exec 3<>/dev/tcp/$DB_HOST/$DB_PORT) 2>/dev/null && break; echo "waiting for Postgres at $DB_HOST:$DB_PORT"; sleep 2; done; exec /app/entrypoint.sh'`
- **Health check:** /health

### Cognee Gateway https://avatars.githubusercontent.com/u/12955528?v=4

- **Image:** caddy:2.11-alpine
- **Start command:** `sh -c 'echo IyEvYmluL3NoCiMgQ29nbmVlIEdhdGV3YXkgc3RhcnQgc2NyaXB0IChjYWRkeToyLjExLWFscGluZSkuCiMgUHVibGljIGVudHJ5cG9pbnQgaW4gZnJvbnQgb2YgdGhlIHByaXZhdGUgQ29nbmVlIEFQSS4gRXZlcnl0aGluZyBpcyBwcm94aWVkCiMgZXhjZXB0IG9wZW4gc2VsZiByZWdpc3RyYXRpb24gKFBPU1QgL2FwaS92MS9hdXRoL3JlZ2lzdGVyKSwgd2hpY2ggQ29nbmVlCiMgY2Fubm90IHN3aXRjaCBvZmYgaXRzZWxmLiBTZXQgQUxMT1dfU0lHTlVQPXRydWUgdG8gcGFzcyBpdCB0aHJvdWdoLgojIHNlcmlhbGl6ZWQ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FJFQU19IHsKCQkJZmx1c2hfaW50ZXJ2YWwgLTEKCQl9Cgl9Cn0KRU9GCgplY2hvICJjb2duZWUtZ2F0ZXdheTogbGlzdGVuaW5nIG9uIDoke1BPUlR9LCB1cHN0cmVhbSAke1VQU1RSRUFNfSwgQUxMT1dfU0lHTlVQPSR7QUxMT1dfU0lHTlVQOi1mYWxzZX0iCmV4ZWMgY2FkZHkgcnVuIC0tY29uZmlnIC9ldGMvY2FkZHkvQ2FkZHlmaWxlIC0tYWRhcHRlciBjYWRkeWZpbGUK | base64 -d > /tmp/start.sh && exec sh /tmp/start.sh'`
- **Health check:** /gateway-health
- **Public domain:** Yes

## Documentation

# Deploy and Host Cognee on Railway

Cognee is an open source memory engine for AI agents. It turns documents, chats and application data into a knowledge graph plus vector embeddings, then lets agents remember, recall and forget through a REST API, the Python SDK or an MCP client. This template deploys the official Cognee API with PostgreSQL and pgvector, protected by a small gateway so the instance cannot be claimed by strangers.

## About Hosting Cognee

Hosting Cognee means running the FastAPI server next to three kinds of storage: a relational database for users, API keys and datasets, a vector store for embeddings, and a graph store for entities and relationships. This template follows the production layout from the Cognee deployment docs: PostgreSQL holds the relational tables and pgvector embeddings (one database per dataset), while the embedded Ladybug (Kuzu) graph and your original documents live on a persistent volume attached to the Cognee service. Multi user mode is on, so every endpoint needs a login token or an API key and each user's datasets stay isolated. Cognee cannot switch off its open signup endpoint, so the API has no public domain: a Caddy gateway is the public entrypoint and answers signup requests with 403.

## Common Use Cases

- **Long term agent memory**: store conversations, notes and documents, then recall them by meaning and by relationship
- **Knowledge graph RAG**: `cognify` extracts entities and relations; `GRAPH_COMPLETION` search answers from the graph
- **Shared team memory**: one Cognee backend used by several agents, apps and MCP clients through API keys
- **Coding assistants**: point Claude Code or Cursor at this instance through a locally run cognee MCP server
- **Per user isolation**: every user gets separate datasets and databases

## Dependencies for Cognee Hosting

- **PostgreSQL with pgvector** (included, `pgvector/pgvector:pg17`)
- **OpenAI API key** (required; used for extraction, answers and `text-embedding-3-large` embeddings)
- **Caddy gateway** (included, `caddy:2.11-alpine`)
- **Other LLM providers** (optional; Anthropic, Gemini, OpenRouter or Ollama for the LLM while embeddings stay on OpenAI)

### Deployment Dependencies

- [Deploy Cognee as a REST API server](https://docs.cognee.ai/guides/deploy-rest-api-server)
- [Cognee deployment options](https://docs.cognee.ai/how-to-guides/cognee-sdk/deployment/deployment-options)
- [Cognee security settings](https://docs.cognee.ai/setup-configuration/security)
- [Cognee GitHub repository](https://github.com/topoteretes/cognee)

### Implementation Details

The Cognee service runs the pinned `cognee/cognee:1.6.2` image. Its start command waits for Postgres, then runs the image entrypoint, which applies migrations and starts gunicorn on a dual stack socket so the gateway can reach it over private networking. The admin account is created on first boot from generated credentials, token secrets are generated, API keys are stored hashed, server side file paths and raw Cypher queries are disabled, following upstream's recommended production settings.

```env
OPENAI_API_KEY=
LLM_API_KEY=${{OPENAI_API_KEY}}
EMBEDDING_API_KEY=${{OPENAI_API_KEY}}
DEFAULT_USER_EMAIL=default_user@example.com
DEFAULT_USER_PASSWORD=${{secret(32)}}
FASTAPI_USERS_JWT_SECRET=${{secret(64)}}
DB_PROVIDER=postgres
VECTOR_DB_PROVIDER=pgvector
ENABLE_BACKEND_ACCESS_CONTROL=true
ALLOW_SIGNUP=false
```

After deploy, copy `DEFAULT_USER_PASSWORD` from the Cognee service variables and log in at `POST /api/v1/auth/login` on the gateway URL (username `default_user@example.com`). Create an API key with `POST /api/v1/auth/api-keys` and send it as the `X-Api-Key` header. Add data with `POST /api/v1/add`, build the graph with `POST /api/v1/cognify` and query it with `POST /api/v1/search`. Interactive API docs are at `/docs` on the gateway URL. To let teammates create accounts, set `ALLOW_SIGNUP=true` on the gateway for a moment, then set it back.

## 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 the memory API, pgvector database and authenticated gateway wired together with generated secrets, health checks, persistent volumes, managed SSL and private networking to the rest of your project.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [stella](https://railway.com/deploy/stella) — Self-host stella with web, API, Postgres, Redis, and object storage.
- [Hermes Agent | OpenClaw Alternative with Dashboard](https://railway.com/deploy/hermes-agent-or-openclaw-alternative-wit) — Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

Open this page in a browser: https://railway.com/deploy/cognee-graph-memory-api-pgvector
