Hindsight
Hindsight is the vector-memory system running on vanessa. It is assembled from
four cooperating pieces plus a Cloudflare Worker:
@luxus/hindsight-api— the Hindsight server (containerized via Podman), port8888.@luxus/postgres— PostgreSQL withpgvector, port5432, holding thehindsightdatabase.@luxus/hindsight-monitoring— Grafanaotel-lgtmobservability stack, Grafana on port3000, OTLP on4317/4318.@luxus/cloudflared— Cloudflare tunnel exposingh1.luxus.ai→http://localhost:8888.hindsight-mcp-oauth-worker— a Cloudflare Worker atmcp.luxus.aithat adds GitHub OAuth → JWT in front of the Hindsight MCP endpoint.
This is reference documentation for the running system; the code is the source of truth.
Architecture
Section titled “Architecture”flowchart LR client["MCP / API client"] worker["Cloudflare Worker<br/>mcp.luxus.ai<br/>GitHub OAuth → JWT"] cf["cloudflared tunnel<br/>h1.luxus.ai"] api["hindsight-api<br/>(Podman) :8888"] pg[("PostgreSQL :5432<br/>pgvector · db: hindsight")] deepseek["DeepSeek LLM API"] graf["Grafana otel-lgtm<br/>:3000 · OTLP :4318"]
client -->|"Bearer JWT"| worker worker -->|"injects API key, /mcp"| cf client -->|"Bearer API key"| cf cf --> api api -->|"DATABASE_URL"| pg api -->|"completions"| deepseek api -->|"OTLP traces :4318"| graf graf -->|"scrape /metrics :8888"| apiComponents
Section titled “Components”hindsight-api (services/hindsight-api/default.nix)
Section titled “hindsight-api (services/hindsight-api/default.nix)”- Runs the official image
ghcr.io/vectorize-io/hindsight:0.6.2@sha256:f0f9e9a…via Podman + podman-compose (Podman is preferred over Docker;dockerCompatprovides adockerCLI shim). - Listens on host port
8888(→ container8888) and also publishes9999. - Managed by the
hindsight-apisystemdoneshotservice (RemainAfterExit), orderedafter/requirespodman.service.ExecStartrunspodman-compose up -dagainst the Nix-pinned image (bump the digest in flake to upgrade). - Data persists under
/var/lib/hindsight-data(owned by uid/gid1000). - Firewall: opens
8888and9999whenopenFirewall = true.
Environment is assembled in the service preStart into
/run/hindsight-api/hindsight.env (consumed via compose env_file):
- LLM provider is DeepSeek (OpenAI-compatible):
HINDSIGHT_API_LLM_PROVIDER=openai,HINDSIGHT_API_LLM_BASE_URL=https://api.deepseek.com,HINDSIGHT_API_LLM_MODEL=deepseek-v4-flash. The key comes from/run/secrets/vars/deepseek-api-key/key. - Database URL points at the host PostgreSQL via
postgresql://postgres:<urlencoded-pw>@host.containers.internal:5432/hindsight. The password is read from thepostgres-passwordClan var and percent-encoded withjq … @uri. Without this, Hindsight falls back to its embeddedpg0, which is not wanted here. - OTel tracing (enabled via
enableOtelTracing = true): exports toHINDSIGHT_API_OTEL_EXPORTER_OTLP_ENDPOINT=http://host.containers.internal:4318with service namehindsight-api, environmenthomelab. - API-key auth for external access: the
hindsight-api-keyClan var is decoded (sops decrypt, falling back to plaincat) and set asHINDSIGHT_API_TENANT_API_KEY,HINDSIGHT_API_MCP_AUTH_TOKEN, andHINDSIGHT_CP_DATAPLANE_API_KEY, enabling theApiKeyTenantExtension. Without it, external access would be unprotected. - Cohere embeddings/reranker are intentionally disabled on cost grounds; Hindsight uses the embeddings bundled in the image.
PostgreSQL (services/postgres/default.nix)
Section titled “PostgreSQL (services/postgres/default.nix)”services.postgresqlon port5432,listen_addresses = "*"for LAN access.enablePgvector = true→ adds thepgvectorextension, setsshared_preload_libraries = "vector", and runsCREATE EXTENSION IF NOT EXISTS vectoron each database inpostStart.- Databases created on startup:
hindsight,app_data. - The superuser (
postgres) password is a Clan var (postgres-password) applied inpostStartvia a safe:'pw'substitution. - Authentication:
trustfor the local socket and127.0.0.1/::1;md5(password required) for all other IPv4/IPv6. Firewall opens5432on the LAN.
Hindsight reaches Postgres from inside its container via
host.containers.internal, which Podman maps back to the host.
hindsight-monitoring (services/hindsight-monitoring/default.nix)
Section titled “hindsight-monitoring (services/hindsight-monitoring/default.nix)”- Runs
grafana/otel-lgtm:0.9.3@sha256:325a40d…(Grafana + Prometheus/Mimir + Tempo + Loki) via Podman, as aoneshotsystemd service ordered afterpodman.serviceand (wants)hindsight-api.service. - Published ports: Grafana
3000, OTLP gRPC4317, OTLP HTTP4318. - Grafana runs with anonymous admin access and the login form disabled
(
GF_AUTH_ANONYMOUS_ENABLED=true,GF_AUTH_ANONYMOUS_ORG_ROLE=Admin,GF_AUTH_DISABLE_LOGIN_FORM=true). - Prometheus scrapes
host.containers.internal:8888/metricsevery 5s and accepts OTLP push; bundled dashboards (RED metrics, JVM, plus Hindsight Operations / LLM / API Service from./dashboards/) are provisioned read-only. - Local network only — firewall opens just the Grafana port; do not route it through the Cloudflare tunnel.
This is the receiving end of the API’s OTel traces (:4318) and also the metrics
scraper (:8888).
cloudflared (services/cloudflared/default.nix)
Section titled “cloudflared (services/cloudflared/default.nix)”-
Runs a custom
cloudflared-tunnelsystemd service (the NixOSservices.cloudflaredmodule is disabled in favor of an explicit unit). -
Tunnel ID + credentials JSON come from the
cloudflare-tunnel-credsClan var generator (tunnel-idnon-secret,credentials-jsonsecret). -
Ingress is generated from the
ingressattrset into a YAML config with a trailinghttp_status:404catch-all. For Hindsight the relevant mapping (set inflake.nix) is:Hostname Backend h1.luxus.aihttp://localhost:8888(Other ingress entries:
hb/bb/gy.luxus.ai,a1.luxus.ai→ SSH.)
So h1.luxus.ai exposes the raw Hindsight API; clients that can send
Authorization: Bearer <api-key> use it directly.
MCP OAuth Worker (services/hindsight-mcp-oauth-worker/)
Section titled “MCP OAuth Worker (services/hindsight-mcp-oauth-worker/)”A Cloudflare Worker (TypeScript, deployed with wrangler) that provides an OAuth
facade so browser-based MCP clients (ChatGPT, Perplexity, etc.) can authenticate
without ever seeing the internal Hindsight API key.
Routing (wrangler.jsonc / README.md):
- Route
mcp.luxus.ai/*,ISSUER = https://mcp.luxus.ai. - Upstream
HINDSIGHT_ORIGIN = https://h1.luxus.ai, MCP path/mcp.
OAuth + JWT flow (src/index.ts):
- Standard OAuth metadata is served at
/.well-known/oauth-authorization-serverand/.well-known/oauth-protected-resource. PKCE (S256) is required;token_endpoint_auth_methodisnone(public clients). - Dynamic client registration at
POST /register(stored in theOAUTH_KVnamespace). Redirect URIs must behttps:or localhost. GET /authorizestores the pending request in KV and redirects to GitHub (scope=read:user user:email read:org).GET /callbackexchanges the GitHub code, fetches the user, and enforces allow-lists:GITHUB_ALLOWED_USERS(luxus) andGITHUB_ALLOWED_ORGS(luxusAi). On success it mints a short-lived auth code in KV.POST /tokenverifies the PKCE challenge and issues an HS256 JWT signed withJWT_SECRET(1-houraccess_token,aud = <issuer>/mcp).- Requests to
/mcpare proxied byproxyMcp: it verifies the Bearer JWT, then forwards tohttps://h1.luxus.ai/mcpafter injectingAuthorization: Bearer <HINDSIGHT_API_KEY>and identity headers (x-bank-id,x-forwarded-user,x-forwarded-email). On invalid/missing JWT it returns401with aWWW-Authenticateresource-metadata pointer.
Bank mapping: DEFAULT_BANK_ID = global-luxus (all OAuth users share one
bank). Setting DEFAULT_BANK_ID=github-login maps each login to
github-<login> via the X-Bank-Id header.
Worker secrets (set with wrangler secret put, not in source):
HINDSIGHT_API_KEY (matches the Hindsight tenant API key), GITHUB_CLIENT_ID,
GITHUB_CLIENT_SECRET, JWT_SECRET. State lives in the OAUTH_KV namespace.
| Port | Component | Exposure |
|---|---|---|
8888 |
hindsight-api | LAN (firewall) + h1.luxus.ai via tunnel |
9999 |
hindsight-api (secondary) | LAN |
5432 |
PostgreSQL (pgvector) | LAN only |
3000 |
Grafana (otel-lgtm) | LAN only |
4317 / 4318 |
OTLP gRPC / HTTP ingest | host/container-local |
Data & request flow
Section titled “Data & request flow”- A client either talks to
h1.luxus.aidirectly with the Hindsight API key, or tomcp.luxus.ai/mcpwith a GitHub-OAuth-issued JWT. - The Worker validates the JWT, swaps in the internal API key, and proxies to
h1.luxus.ai/mcp; the cloudflared tunnel delivers it tolocalhost:8888. hindsight-apiauthenticates via its tenant API key, stores/queries vectors in thehindsightdatabase on PostgreSQL (pgvector), and calls DeepSeek for LLM completions.- The API exports traces over OTLP to the otel-lgtm container (
:4318), which also scrapes its/metrics(:8888); Grafana on:3000visualizes both.
Secrets summary
Section titled “Secrets summary”| Secret | Source | Consumed by |
|---|---|---|
postgres-password |
Clan var | hindsight-api DATABASE_URL, Postgres superuser |
deepseek-api-key |
Clan var (/run/secrets/vars/...) |
hindsight-api LLM key |
hindsight-api-key |
Clan var (sops) | hindsight-api tenant/MCP/dataplane auth |
cloudflare-tunnel-creds |
Clan var (id + credentials JSON) | cloudflared tunnel |
HINDSIGHT_API_KEY |
Worker secret (wrangler) | Worker → upstream injection |
GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET |
Worker secret | GitHub OAuth |
JWT_SECRET |
Worker secret | HS256 JWT signing/verification |
Source of truth
Section titled “Source of truth”| Concern | File |
|---|---|
| Service inventory & tunnel ingress | flake.nix |
| Hindsight API container & env | services/hindsight-api/default.nix |
| PostgreSQL + pgvector | services/postgres/default.nix |
| Observability stack | services/hindsight-monitoring/default.nix |
| Cloudflare tunnel | services/cloudflared/default.nix |
| MCP OAuth facade | services/hindsight-mcp-oauth-worker/ |