Skip to main content

Local Development Setup

This guide walks you through running the Memintel backend on your local machine — from installing dependencies through to verifying a working server.


Prerequisites

Install the following before continuing:

DependencyMinimum versionNotes
Python3.11+python.org/downloads
PostgreSQL15+Local install or Supabase / Neon free tier
Redis7+Local install or Upstash free tier
GitAny recentTo clone the repository

Optional — only needed if you use the LLM-assisted pipeline (/execute/full):

DependencyNotes
Anthropic API keyRequired when llm.provider: anthropic and USE_LLM_FIXTURES=false. Get from console.anthropic.com
OpenAI-compatible endpointRequired when llm.provider: openai_compatible. Set base_url in memintel_config.yaml. Covers Ollama, vLLM, LM Studio, Azure OpenAI, and on-premise model servers. No additional environment variable needed unless your endpoint requires authentication.

Step 1 — Clone the repository

git clone https://github.com/your-org/memintel.git
cd memintel/backend/memintel-backend

Step 2 — Install Python dependencies

python -m venv .venv

# macOS / Linux
source .venv/bin/activate

# Windows (PowerShell)
.\.venv\Scripts\Activate.ps1

pip install -r requirements.txt

Step 3 — Set environment variables

Copy the example startup script and fill in your values:

# Windows PowerShell
Copy-Item start_server.ps1.example start_server.ps1
# macOS / Linux — create an equivalent shell script
cp start_server.ps1.example start_server.sh

Open start_server.ps1 (or start_server.sh) and replace every placeholder with a real value. The complete variable reference is below.

warning

Never commit start_server.ps1 or start_server.sh — they contain real credentials. The .example file is safe to commit. Keep your local copy out of version control.

Environment variable reference

Core — required for all routes

VariablePurposeRequiredExample
MEMINTEL_CONFIG_PATHPath to memintel_config.yamlYesmemintel_config.yaml
DATABASE_URLPostgreSQL connection URL for the primary Memintel database (definitions, graphs, jobs, feedback)Yespostgresql://user:pass@localhost:5432/memintel
REDIS_URLRedis connection URL for the execution result cacheYesredis://localhost:6379

Security

VariablePurposeRequiredExample
MEMINTEL_ELEVATED_KEYSecret key for privileged endpoints — pass as X-Elevated-Key header. See Elevated Key below.Yesa-long-random-secret

LLM provider

VariablePurposeRequiredExample
ANTHROPIC_API_KEYAnthropic API key for the LLM-assisted pipelineOnly if llm.provider: anthropic and USE_LLM_FIXTURES=falsesk-ant-...
MEMINTEL_LLM_API_KEYAPI key for OpenAI-compatible endpoints that require authenticationOnly if endpoint requires auth when llm.provider: openai_compatibleyour-internal-key
USE_LLM_FIXTURESSet to false in production to use a real LLM provider. Defaults to true (fixture mode) — safe for local dev without an API keyNofalse

Data connector credentials

These variables correspond to connectors declared in memintel_config.yaml. Add only the variables for connectors you have configured.

VariableConnectorPurposeExample
ANALYTICS_DB_HOSTpostgres.analyticsHostname of the analytics PostgreSQL instanceanalytics-db.internal
ANALYTICS_DB_USERpostgres.analyticsDatabase useranalytics_reader
ANALYTICS_DB_PASSWORDpostgres.analyticsDatabase password••••••••
ACCOUNTS_DB_HOSTpostgres.accountsHostname of the accounts PostgreSQL instanceaccounts-db.internal
ACCOUNTS_DB_USERpostgres.accountsDatabase useraccounts_reader
ACCOUNTS_DB_PASSWORDpostgres.accountsDatabase password••••••••
BILLING_API_URLrest.billing_apiBase URL of the billing REST APIhttps://billing.example.com
BILLING_API_TOKENrest.billing_apiBearer token for billing API auth••••••••

Step 4 — Run database migrations

Memintel uses Alembic to manage the schema. Run migrations once after cloning and again after each update that includes new migration files:

alembic upgrade head

You should see output like:

INFO  [alembic.runtime.migration] Running upgrade  -> abc123, create conditions table
INFO [alembic.runtime.migration] Running upgrade abc123 -> def456, create execution_graphs table
...

If the database already contains the latest schema (e.g. on a re-run), Alembic prints nothing and exits cleanly — this is expected.


Step 5 — Start the server

Windows (PowerShell):

.\start_server.ps1

macOS / Linux:

# Set variables inline or export them from start_server.sh
export MEMINTEL_CONFIG_PATH=memintel_config.yaml
export DATABASE_URL=postgresql://user:pass@localhost:5432/memintel
export REDIS_URL=redis://localhost:6379
export MEMINTEL_ELEVATED_KEY=your-elevated-key
# ... add remaining variables ...

uvicorn app.main:app --host 0.0.0.0 --port 8000

The server starts on port 8000. You should see:

INFO:     Started server process [12345]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
Hot reload for development

Add --reload to the uvicorn command to automatically restart the server when source files change:

uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload

Step 6 — Verify the server is running

curl http://127.0.0.1:8000/openapi.json

A successful response returns the full OpenAPI specification as JSON. You can also open the interactive docs in a browser:

http://127.0.0.1:8000/docs
Use 127.0.0.1, not localhost

On some systems localhost resolves to ::1 (IPv6) but the server binds to 0.0.0.0 (IPv4). Using 127.0.0.1 directly avoids a ~2-second TCP timeout on every request.


The Elevated Key

Certain endpoints require the X-Elevated-Key header in addition to the standard X-API-Key. These are privileged operations that modify shared registry state:

EndpointOperation
POST /compileCompile a concept to an execution graph
POST /registry/definitionsRegister a primitive type schema
POST /guardrailsPost guardrails policy
POST /actionsRegister an action
POST /conditions/apply-calibrationApply a calibration recommendation

Set the header value to match MEMINTEL_ELEVATED_KEY:

curl -X POST http://127.0.0.1:8000/compile \
-H "X-Elevated-Key: your-elevated-key" \
-H "Content-Type: application/json" \
-d '{ "concept": { ... } }'

Use a long, randomly generated secret. Generate one with:

# macOS / Linux
openssl rand -hex 32

# Python (any platform)
python -c "import secrets; print(secrets.token_hex(32))"

Troubleshooting

connection refused on port 8000 The server is not running, or it started on a different port. Check the terminal where you ran uvicorn.

startup_failed — database connection error Verify DATABASE_URL is correct and the PostgreSQL instance is reachable. Test the connection:

psql "$DATABASE_URL" -c "SELECT 1;"

startup_failed — Redis connection error Verify REDIS_URL is correct and Redis is running:

redis-cli -u "$REDIS_URL" ping
# Expected output: PONG

alembic upgrade head fails with relation already exists The database was partially initialised. Reset it and re-run migrations:

# Drop and recreate the database (local dev only — destroys all data)
psql "$DATABASE_URL" -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
alembic upgrade head

HTTP 403 on compile or register endpoints These endpoints require the X-Elevated-Key header. See The Elevated Key above.