Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CLI Usage

The csm binary provides command-line access to the memory system.

Installation

cargo install chaotic_semantic_memory --features cli

Commands

inject

Inject a new concept:

# Random vector
csm inject my-concept --database csm_memory.db

# Vector from file
csm inject my-concept --from-file vector.bin --database memory.db

# Vector from stdin
echo "vector data" | csm inject my-concept --vector-source stdin --database memory.db

# With metadata
csm inject my-concept --metadata '{"key":"value"}' --database memory.db

probe

Find similar concepts:

# By concept ID
csm probe my-concept -k 10 --database csm_memory.db

# Output as JSON
csm probe my-concept -k 10 --output-format json --database memory.db

query

Text-based similarity search (encodes text and finds similar concepts):

# Hybrid search (keyword + semantic)
csm query "machine learning neural networks" -k 10 --database csm_memory.db

# Semantic-only HDC search
csm query "machine learning" --semantic-only -k 5 --database memory.db

# Keyword-only BM25 search
csm query "exact term match" --keyword-only -k 5 --database memory.db

# With minimum score threshold
csm query "AI concepts" -k 10 --min-score 0.5 --database memory.db

# Compact output (trim long text)
csm query "long document content" --compact -k 5 --database memory.db

# Code-aware encoding for source code
csm query "fn process_data" --code-aware -k 5 --database memory.db

index-dir

Index Markdown files from a directory into memory:

# Index all markdown files in a directory
csm index-dir -g "docs/**/*.md" --database csm_memory.db

# Index with multiple glob patterns
csm index-dir -g "src/**/*.md" -g "book/**/*.md" --database memory.db

# Index code files with code-aware encoding
csm index-dir -g "src/**/*.rs" --code-aware --database memory.db

# Control heading chunking level (default: 2 for ## sections)
csm index-dir -g "docs/**/*.md" --heading-level 3 --database memory.db

Important: index-dir requires --glob <PATTERN> (not a direct path). Concept IDs follow format: md:<path>:<heading_level>:<chunk_index>

index-jsonl

Index JSONL file content into memory:

# Index from JSONL file
csm index-jsonl --file data.jsonl --database csm_memory.db

# Each line must be valid JSON with 'id' and optional 'text'/'metadata' fields

associate

Create associations:

csm associate source target --strength 0.8 --database csm_memory.db

export

Export memory state:

# JSON format
csm export --output backup.json --database csm_memory.db

# Binary format (smaller)
csm export --output backup.bin --format binary --database csm_memory.db

import

Import memory state:

# Replace existing
csm import backup.json --database csm_memory.db

# Merge with existing
csm import backup.json --merge --database memory.db

completions

Generate shell completions:

# Bash
csm completions bash > ~/.local/share/bash-completion/completions/csm

# Zsh
csm completions zsh > ~/.zsh/completions/_csm

# Fish
csm completions fish > ~/.config/fish/completions/csm.fish

# PowerShell
csm completions powershell > $HOME\.config\powershell\completions\csm.ps1

MCP Server

The MCP server defaults to stdio for desktop clients. Streamable HTTP supports the current stateless 2026-07-28 protocol and keeps negotiated legacy sessions only for older clients:

# Desktop/client stdio
csm mcp serve

# Local Streamable HTTP
csm --database memory.db mcp serve \
  --transport streamable-http \
  --bind 127.0.0.1:8765

Non-loopback binds fail unless CSM_MCP_BEARER_TOKEN is set. Configure the HTTP Host allowlist with repeatable --allowed-host values. Present browser Origin headers are rejected unless explicitly allowed with --allowed-origin. The token is read only from the environment, never a command-line argument, and is redacted from McpConfig debug output.

The server speaks plain HTTP; direct network binds require a trusted TLS terminating proxy. Keep the process behind that proxy, restrict its network reachability, and require authentication at the proxy as well. Browser requests need an explicit origin allowlist.

export CSM_MCP_BEARER_TOKEN="$(openssl rand -hex 32)"
csm --database memory.db mcp serve \
  --transport streamable-http \
  --bind 192.0.2.10:8765 \
  --allowed-host memory.example \
  --allowed-origin https://app.example

Output Formats

FormatFlagDescription
Table--output-format tableHuman-readable table (default)
JSON--output-format jsonMachine-parseable JSON
Quiet--output-format quietIDs/results only, suitable for scripts

The query command also accepts --compact to trim long result text; it is a query flag, not an output-format value.

Exit Codes

CodeMeaning
0Success
1Configuration error
2Database error
3Input error
4Output error
5Validation error
6Memory error
7I/O error
255Unknown error