Skip to content

GottZ/ctx

Repository files navigation

ctx — The memory your LLM pretends to have.

Knowledge store with weighted 4-way RRF retrieval, multi-tenant scope isolation, temporal awareness, and autonomous cross-referencing. Built for AI workflows that need to remember.

Release Go License PostgreSQL

What it does

ctx gives your LLM a persistent, searchable memory. Store knowledge blocks, query them with hybrid retrieval (semantic + fulltext + trigram + temporal gravity), and get synthesized answers with source citations.

Dream Mode runs in the background — autonomously discovering relationships between blocks, marking outdated information, and promoting high-quality content. Your knowledge base grows, self-organizes, and stays current.

Quick Install

# Binary (Linux/macOS/Windows)
curl -fsSL https://github.com/GottZ/ctx/releases/latest/download/ctx-$(uname -s | tr A-Z a-z)-$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/') -o /usr/local/bin/ctx && chmod +x /usr/local/bin/ctx

# Or with Go
go install github.com/GottZ/ctx/cmd/ctx@latest

Setup

1. Configure endpoint

# Linux/macOS
mkdir -p ~/.config/ctx
cat > ~/.config/ctx/config << 'EOF'
CTX_BASE_URL=https://your-ctx-host.example
CTX_KEY=your-api-key-here
EOF
Windows (PowerShell)
New-Item -ItemType Directory -Force "$env:APPDATA\ctx"
@"
CTX_BASE_URL=https://your-ctx-host.example
CTX_KEY=your-api-key-here
"@ | Set-Content "$env:APPDATA\ctx\config"

2. Verify

ctx health    # DB + Ollama connectivity
ctx stats     # Block count, categories, storage

3. Claude Code integration (optional)

Statusline — live block count, health, and rate limits:

{ "statusLine": { "type": "command", "command": "ctx statusline" } }

Slash commands — add to ~/.claude/settings.json:

{
  "customSlashCommands": [
    { "name": "ctx",        "command": "ctx query \"$PROMPT\"" },
    { "name": "ctx-save",   "command": "ctx save $PROMPT" },
    { "name": "ctx-browse", "command": "ctx search $PROMPT" },
    { "name": "ctx-stats",  "command": "ctx stats" }
  ]
}

Agent hooks — automatic project briefing for subagents:

{
  "hooks": {
    "SubagentStart": [{ "type": "command", "command": "ctx brief --hook" }],
    "SubagentStop":  [{ "type": "command", "command": "ctx persist --hook" }]
  }
}

CLI

Command Description
ctx query "question" Hybrid search + LLM synthesis
ctx save <cat> <title> - <content> Upsert knowledge block
ctx save --tag tag1,tag2 <cat> <title> Upsert with tags
ctx search [category] [query:text] Compact search (no LLM)
ctx get <id> Fetch full block
ctx delete <id> Soft-delete (archive)
ctx categories List all categories
ctx stats Database statistics
ctx health Healthcheck
ctx guard [list|stats|resolve] Write Guard management
ctx dream [stats|review] Dream Mode stats + link review
ctx brief Project briefing from store
ctx persist Persist [PERSIST:cat:title] markers
ctx ingest <path> Ingest Obsidian vault
ctx digest Rebuild topic map
ctx statusline Claude Code status bar
ctx version Print version

Architecture

Query ──► Embed ──► 4-Way RRF ──► Temporal Gravity ──► filterSuperseded ──► LLM Synthesis
                    ├─ Semantic (0.45)
                    ├─ EN-FTS   (0.25)    ┌─────────────────────────┐
                    ├─ DE-FTS   (0.20)    │  Dream Mode (async)     │
                    └─ Trigram  (0.10)    │  Pick → Keywords → RRF  │
                                          │  → LLM Eval → Links     │
Store ──► Hash NOOP ──► Embed ──►         │  → ApplySupersedes      │
          Guard (async, 60s) ◄────────────│  → PromoteToCanonical   │
          ├─ ≥0.98: auto-archive          └─────────────────────────┘
          ├─ 0.92-0.98: flag
          └─ <0.92: clean

Stack: Go 1.25, PostgreSQL 18 + pgvector 0.8.2, Ollama (qwen3-embedding:8b + qwen3.5:9b)

Key features:

  • GottZ 4-Way RRF — reciprocal rank fusion across semantic, bilingual fulltext, and trigram channels
  • GottZ Scope Model — multi-tenant isolation (private/work/shared) via API key scoping
  • GottZ Guard — async deduplication via PG LISTEN/NOTIFY + HNSW similarity
  • GottZ Temporal Dimension Table — EAV temporal indexing with deterministic parser (59/60 cases in 0ms)
  • Dream Mode — autonomous cross-referencing with adaptive cooldown and supersedes detection
  • Supersedes Filtering — temporal-gated removal of outdated blocks from query results

API

All endpoints under /api/*. Auth via X-Context-Key header.

Endpoint Description
POST /api/query 4-Way RRF + LLM synthesis
POST /api/store Upsert + auto-embedding
POST /api/search Lightweight search (no LLM)
POST /api/manage CRUD, Guard API, stats
POST /api/digest Topic map generation
POST /api/ingest Obsidian vault ingestion
POST /api/blob/* Binary storage (store/fetch/search/manage)
GET /health DB + Ollama connectivity

Building

go build -o ctx ./cmd/ctx/           # CLI
go build -o ctxd ./cmd/ctxd/         # Daemon
go test ./... -short                  # Unit tests

License

MPL-2.0 — By GottZ

About

The memory your LLM pretends to have.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors