@cerefox/memory 0.4.3 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,271 @@
1
+ # Operations Scripts
2
+
3
+ Reference guide for the operational scripts in `scripts/`. Run these from the project root.
4
+
5
+ > Looking for `cerefox <subcommand>` reference (ingest, search, get-doc, etc.)? See [`docs/guides/cli.md`](cli.md). This guide covers the `scripts/` directory only.
6
+
7
+ ## Two languages, one directory
8
+
9
+ As of v0.3.0, Cerefox scripts come in two flavors:
10
+
11
+ | Script | Language | Run with |
12
+ |---|---|---|
13
+ | `db_status.ts` | TypeScript (v0.3.0+) | `bun scripts/db_status.ts` |
14
+ | `sync_docs.ts` | TypeScript (v0.3.0+) | `bun scripts/sync_docs.ts` |
15
+ | `db_deploy.py` | Python | `uv run python scripts/db_deploy.py` |
16
+ | `db_migrate.py` | Python | `uv run python scripts/db_migrate.py` |
17
+ | `backup_create.py` | Python | `uv run python scripts/backup_create.py` |
18
+ | `backup_restore.py` | Python | `uv run python scripts/backup_restore.py` |
19
+ | `reindex_all.py` | Python | `uv run python scripts/reindex_all.py` |
20
+
21
+ The TS scripts require [Bun](https://bun.sh) — install with `curl -fsSL https://bun.sh/install | bash`. They are functionally equivalent to their previous Python forms; **the legacy `db_status.py` and `sync_docs.py` are deprecation shims that exit non-zero with a pointer to the TS replacement**. The shims are kept indefinitely as a migration aid — there's no scheduled removal date, but the exit code stays non-zero, so update any cron jobs / CI / make targets that invoke them.
22
+
23
+ The remaining `.py` scripts stay Python until their scheduled port (v0.5 for `db_deploy` / `db_migrate`; v0.7 for `backup_*` / `reindex_all`) — per the §12f script-language policy in [`CONTRIBUTING.md`](../../CONTRIBUTING.md), Python scripts get ported when they're extended.
24
+
25
+ ### TS scripts and `.env` resolution
26
+
27
+ `bun scripts/<name>.ts` reads the same `.env` the Python CLI does. Precedence:
28
+
29
+ 1. `CEREFOX_CONFIG_DIR` env var (explicit override; supports `~`).
30
+ 2. `./.env` in the current working directory (dev mode).
31
+ 3. `~/.cerefox/.env` (user-state root).
32
+
33
+ See [`docs/specs/polish-and-distribution-design.md` §7b](../specs/polish-and-distribution-design.md) for the full rule.
34
+
35
+ ---
36
+
37
+ ## db_deploy.py — Schema deployment
38
+
39
+ Applies the full Cerefox schema (tables, indexes, RPC functions) to a Postgres database. Use this for **fresh installs** or to re-apply the schema after a Cerefox update.
40
+
41
+ ```bash
42
+ uv run python scripts/db_deploy.py [OPTIONS]
43
+ ```
44
+
45
+ | Option | Description |
46
+ |--------|-------------|
47
+ | `--dry-run` | Print the SQL that would be executed, without running it |
48
+ | `--reset` | Drop all `cerefox_*` tables before deploying (destructive) |
49
+
50
+ **Requires**: `CEREFOX_DATABASE_URL` — a direct Postgres connection URL (not the Supabase API URL).
51
+
52
+ After applying the schema, `db_deploy.py` automatically stamps any migration files in `src/cerefox/db/migrations/` into the `cerefox_migrations` table. This ensures `db_migrate.py` does not re-apply changes that are already incorporated in the base schema.
53
+
54
+ Example:
55
+ ```bash
56
+ # Deploy to local Docker Postgres
57
+ CEREFOX_DATABASE_URL=postgresql://cerefox:cerefox@localhost:5432/cerefox \
58
+ uv run python scripts/db_deploy.py
59
+ ```
60
+
61
+ ---
62
+
63
+ ## db_status.ts — Schema verification
64
+
65
+ **TypeScript (v0.3.0+).** Checks that the schema is correctly deployed and reports table statistics. Replaces the legacy `db_status.py`, which now prints a deprecation notice and exits non-zero.
66
+
67
+ ```bash
68
+ bun scripts/db_status.ts # human-readable report
69
+ bun scripts/db_status.ts --json # structured JSON output
70
+ ```
71
+
72
+ Reports:
73
+ - Tables: `cerefox_documents`, `cerefox_chunks`, `cerefox_document_versions`, `cerefox_projects`, `cerefox_document_projects`, `cerefox_audit_log`, `cerefox_migrations`
74
+ - RPC functions: hybrid_search, fts_search, semantic_search, reconstruct_doc, save_note, search_docs, context_expand, snapshot_version, get_document, list_document_versions, ingest_document, delete_document, create_audit_entry, list_audit_entries, list_metadata_keys, update_chunk_fts, **`cerefox_schema_version`** (new in v0.3.0), **`cerefox_pg_function_exists`** (new in v0.3.0)
75
+ - Row counts per table
76
+ - **Schema-version mismatch**: compares the `@version` marker in the bundled `schema.sql` against the deployed `cerefox_schema_version()` RPC. Non-zero exit if they differ (the same check powers the web UI's schema-mismatch banner).
77
+
78
+ Exit code 0 if everything is healthy; 1 if any check fails; 2 on configuration error.
79
+
80
+ **Function-existence detection** routes through the `cerefox_pg_function_exists()` introspection RPC for reliability. Legacy deployments missing that RPC fall back to a naive "call with no args" probe — the legacy fallback will misreport RPCs that take required parameters as missing, which is itself a signal that the deployment needs `db_deploy.py`.
81
+
82
+ ---
83
+
84
+ ## db_migrate.py — Schema migrations
85
+
86
+ Applies incremental migration files to an **existing** database with data. Use this when upgrading Cerefox on a database that already has documents — it applies only the changes that haven't been applied yet.
87
+
88
+ ```bash
89
+ uv run python scripts/db_migrate.py [OPTIONS]
90
+ ```
91
+
92
+ | Option | Description |
93
+ |--------|-------------|
94
+ | `--dry-run` | Show which migrations would run, without applying them |
95
+ | `--status` | List all migration files and whether each has been applied |
96
+
97
+ **When to use `db_deploy.py` vs `db_migrate.py`:**
98
+
99
+ | Situation | Use |
100
+ |-----------|-----|
101
+ | Fresh database, no data | `db_deploy.py` |
102
+ | Existing database, upgrading to a new version | `db_migrate.py` |
103
+
104
+ On a freshly deployed database, `db_migrate.py` is always a no-op — `db_deploy.py` has already stamped all existing migrations.
105
+
106
+ Migration files live in `src/cerefox/db/migrations/` and are applied in filename order (`0001_...`, `0002_...`). Each file is applied exactly once; applied filenames are recorded in the `cerefox_migrations` table.
107
+
108
+ Always run a backup before migrating:
109
+
110
+ ```bash
111
+ uv run python scripts/backup_create.py && uv run python scripts/db_migrate.py
112
+ ```
113
+
114
+ ---
115
+
116
+ ## backup_create.py — Create a backup
117
+
118
+ Exports all documents, chunks, and metadata to a JSON file in the backup directory.
119
+
120
+ ```bash
121
+ uv run python scripts/backup_create.py [OPTIONS]
122
+ ```
123
+
124
+ | Option | Description |
125
+ |--------|-------------|
126
+ | `--label LABEL` | Optional label appended to the filename (e.g. `pre-migration`) |
127
+ | `--dir DIR` | Directory to write backup to (default: `./backup-data`) |
128
+ | `--git-commit` | Stage and commit the backup file to git after writing |
129
+
130
+ Backup filename format: `cerefox-{YYYYMMDDTHHMMSSZ}[-{label}].json`
131
+
132
+ **Versioning note**: Backups capture only **current** chunks (those not yet archived). Archived version history (previous content snapshots) is intentionally excluded — backups represent the present state of your knowledge base, not its history. Archived versions remain in the database and continue to be accessible via the versioning API until they expire.
133
+
134
+ Example:
135
+ ```bash
136
+ uv run python scripts/backup_create.py --label before-v2-migration
137
+ ```
138
+
139
+ Output: `backup-data/cerefox-20260308T143022Z-before-v2-migration.json`
140
+
141
+ ---
142
+
143
+ ## backup_restore.py — Restore from a backup
144
+
145
+ Restores documents and chunks from a previously created backup file. Idempotent — documents with the same content hash are skipped.
146
+
147
+ ```bash
148
+ uv run python scripts/backup_restore.py BACKUP_FILE [OPTIONS]
149
+ ```
150
+
151
+ | Option | Description |
152
+ |--------|-------------|
153
+ | `--dry-run` | Show what would be restored without writing |
154
+
155
+ Example:
156
+ ```bash
157
+ # Preview what will be restored
158
+ uv run python scripts/backup_restore.py backup-data/cerefox-20260308T143022Z.json --dry-run
159
+
160
+ # Restore
161
+ uv run python scripts/backup_restore.py backup-data/cerefox-20260308T143022Z.json
162
+ ```
163
+
164
+ Restore output shows counts of restored / skipped / error documents.
165
+
166
+ ---
167
+
168
+ ## Backup format
169
+
170
+ Backups are JSON files with the following structure:
171
+
172
+ ```json
173
+ {
174
+ "version": 1,
175
+ "created_at": "2026-03-08T14:30:22.000Z",
176
+ "document_count": 42,
177
+ "chunk_count": 317,
178
+ "documents": [
179
+ {
180
+ "id": "uuid",
181
+ "title": "My Note",
182
+ "source": "file",
183
+ "content_hash": "sha256hex",
184
+ "metadata": {},
185
+ "chunks": [
186
+ {
187
+ "chunk_index": 0,
188
+ "heading_path": ["My Note", "Section"],
189
+ "heading_level": 2,
190
+ "title": "Section",
191
+ "content": "...",
192
+ "char_count": 120,
193
+ "embedder_primary": "text-embedding-3-small",
194
+ "embedding_primary": [0.012, -0.034, ...],
195
+ "embedding_upgrade": null
196
+ }
197
+ ]
198
+ }
199
+ ]
200
+ }
201
+ ```
202
+
203
+ **Embeddings are included** in backups. This means a restored database is immediately searchable — no `cerefox reindex` required after restore.
204
+
205
+ The backup directory (`./backup-data/` by default) is gitignored. Back up the backup files separately if you want off-site copies (e.g. copy to cloud storage).
206
+
207
+ ---
208
+
209
+ ## sync_docs.ts — Sync project documentation into Cerefox
210
+
211
+ **TypeScript (v0.3.0+).** Ingests `README.md`, `AGENT_GUIDE.md`, `AGENT_QUICK_REFERENCE.md`, and every Markdown file under `docs/` into your Cerefox knowledge base, updating existing documents in-place. Run this any time after editing documentation so AI agents always have access to the current state of the project.
212
+
213
+ Replaces the legacy `sync_docs.py`, which now prints a deprecation notice and exits non-zero.
214
+
215
+ ```bash
216
+ bun scripts/sync_docs.ts [OPTIONS]
217
+ ```
218
+
219
+ | Option | Description |
220
+ |--------|-------------|
221
+ | `--project NAME`, `-p NAME` | Project to assign documents to (default: `cerefox`) |
222
+ | `--dry-run`, `-n` | List files that would be synced without ingesting anything |
223
+
224
+ **Requires**: `CEREFOX_SUPABASE_URL` and `CEREFOX_SUPABASE_ANON_KEY` (the legacy anon JWT — `eyJ…` — used to invoke Edge Functions). Embedding happens server-side inside the `cerefox-ingest` Edge Function, so you don't need an OpenAI / Fireworks key in your local env for the TS script.
225
+
226
+ The target project must already exist (create it with `uv run cerefox create-project cerefox` if needed).
227
+
228
+ **What gets synced**: `README.md` + `AGENT_GUIDE.md` + `AGENT_QUICK_REFERENCE.md` + all `.md` files under `docs/` (including `docs/research/` and `docs/specs/`). Research notes are included because Cerefox is a shared memory layer for multiple agents — exploratory notes, experiments, and decision rationale are exactly the kind of context agents benefit from. Files are matched to existing documents by their relative path (`source_path`), so re-running the script updates content in-place rather than creating duplicates.
229
+
230
+ Example output:
231
+ ```
232
+ Syncing 22 file(s) → project "cerefox"
233
+ = README.md (Cerefox) [unchanged]
234
+ ↑ docs/plan.md (Cerefox Implementation Plan) [re-embedded]
235
+ = docs/guides/quickstart.md (Quickstart) [unchanged]
236
+ ...
237
+ Done. 0 new · 1 updated · 21 unchanged · 0 errors
238
+ ```
239
+
240
+ ---
241
+
242
+ ## Recommended backup schedule
243
+
244
+ For a personal knowledge base, a simple daily cron is sufficient:
245
+
246
+ ```cron
247
+ 0 3 * * * cd /path/to/cerefox && uv run python scripts/backup_create.py --label daily
248
+ ```
249
+
250
+ Backups include embeddings so they are larger than pure-text exports, but for a personal knowledge base they typically remain well under 100 MB.
251
+
252
+ ---
253
+
254
+ ## CLI commands
255
+
256
+ The `cerefox` CLI also provides data management commands:
257
+
258
+ | Command | Description |
259
+ |---------|-------------|
260
+ | `uv run cerefox ingest FILE` | Ingest a markdown file |
261
+ | `uv run cerefox ingest --paste --title TITLE` | Ingest text from stdin |
262
+ | `uv run cerefox search QUERY` | Search the knowledge base |
263
+ | `uv run cerefox list-docs` | List all documents |
264
+ | `uv run cerefox delete-doc ID` | Delete a document by ID |
265
+ | `uv run cerefox list-projects` | List all projects |
266
+ | `uv run cerefox list-versions ID` | List all archived versions of a document |
267
+ | `uv run cerefox get-doc ID` | Retrieve current content of a document |
268
+ | `uv run cerefox get-doc ID --version VERSION_ID` | Retrieve a specific archived version |
269
+ | `uv run cerefox web` | Start the web UI |
270
+
271
+ Run `uv run cerefox --help` or `uv run cerefox COMMAND --help` for details.
@@ -0,0 +1,165 @@
1
+ # Quickstart -- Zero to First Document in 15 Minutes
2
+
3
+ Get Cerefox running locally and ingest your first document.
4
+
5
+ > **Upgrading from a previous version?** See the [Upgrading Guide](upgrading.md) for migration steps instead.
6
+
7
+ ---
8
+
9
+ ## 1. Prerequisites (2 min)
10
+
11
+ - Python 3.11+ (`python3 --version`)
12
+ - Node.js 18+ and npm (`node --version`)
13
+ - `uv` package manager (`pip install uv`)
14
+ - A Supabase account -- [supabase.com](https://supabase.com) (free tier works)
15
+ - An OpenAI API key -- [platform.openai.com/api-keys](https://platform.openai.com/api-keys)
16
+
17
+ ---
18
+
19
+ ## 2. Install Cerefox (2 min)
20
+
21
+ ```bash
22
+ git clone https://github.com/fstamatelopoulos/cerefox.git
23
+ cd cerefox
24
+ uv sync
25
+ ```
26
+
27
+ > No heavy ML model downloads needed -- embeddings are handled by the OpenAI API.
28
+
29
+ ---
30
+
31
+ ## 3. Set up Supabase (5 min)
32
+
33
+ 1. Create a new Supabase project at [app.supabase.com](https://app.supabase.com).
34
+ 2. Go to **Project Settings → API → Project URL** and copy it. Also note your project ref (the slug in the URL, e.g. `abcd1234`).
35
+ 3. Go to **Project Settings → API Keys** and copy the **Secret key** (`sb_secret_…`). The legacy `service_role` JWT also works if you prefer; either goes into `CEREFOX_SUPABASE_KEY`. See [`setup-supabase.md` → Supabase API keys (2026)](setup-supabase.md#supabase-api-keys-2026) for the full key story (including why the anon key, if you ever need it, must currently stay as the legacy JWT — `sb_publishable_…` does not work for Edge Functions).
36
+ 4. Go to **Project Settings → Database → Connection pooling** and copy the **Session Pooler** URI (host ends `.pooler.supabase.com`, port `5432`). If you only see the Transaction Pooler in the dashboard, take that URI and change `:6543` → `:5432`. **Do not use port 6543** — Transaction Pooler does not support DDL. See [`setup-supabase.md` → Connection pooling (2026)](setup-supabase.md#connection-pooling-2026) for context.
37
+
38
+ Create a `.env` file:
39
+
40
+ ```env
41
+ CEREFOX_SUPABASE_URL=https://your-project-ref.supabase.co
42
+ CEREFOX_SUPABASE_KEY=sb_secret_...your-supabase-secret-key...
43
+ CEREFOX_DATABASE_URL=postgresql://postgres.your-project-ref:your-db-password@aws-N-region.pooler.supabase.com:5432/postgres?sslmode=require
44
+ OPENAI_API_KEY=sk-...your-openai-key...
45
+ ```
46
+
47
+ The username must include the `.<project-ref>` suffix (e.g. `postgres.abcd1234`) — without it, Supabase returns "Tenant or user not found".
48
+
49
+ ---
50
+
51
+ ## 4. Deploy the schema (1 min)
52
+
53
+ ```bash
54
+ uv run python scripts/db_deploy.py
55
+ ```
56
+
57
+ You should see all steps complete with a final `Done` message.
58
+
59
+ Verify:
60
+ ```bash
61
+ uv run python scripts/db_status.py
62
+ ```
63
+
64
+ This should show all checks passed.
65
+
66
+ ---
67
+
68
+ ## 5. Ingest your first document (2 min)
69
+
70
+ Have a markdown file? Ingest it:
71
+
72
+ ```bash
73
+ uv run cerefox ingest my-notes.md
74
+ ```
75
+
76
+ Or paste directly from the terminal:
77
+
78
+ ```bash
79
+ echo "# My First Note
80
+
81
+ This is the beginning of my personal knowledge base." | uv run cerefox ingest --paste --title "First Note"
82
+ ```
83
+
84
+ ---
85
+
86
+ ## 6. Build and start the web app (1 min)
87
+
88
+ Build the React frontend:
89
+
90
+ ```bash
91
+ cd frontend && npm install && npm run build && cd ..
92
+ ```
93
+
94
+ Start the web app:
95
+
96
+ ```bash
97
+ uv run cerefox web
98
+ ```
99
+
100
+ Open [http://localhost:8000/app/](http://localhost:8000/app/) -- your dashboard is live.
101
+
102
+ > The root URL (`http://localhost:8000/`) redirects to `/app/` automatically.
103
+
104
+ ---
105
+
106
+ ## 7. Search your knowledge (30 sec)
107
+
108
+ From the CLI:
109
+
110
+ ```bash
111
+ uv run cerefox search "my first note"
112
+ ```
113
+
114
+ Or use the web UI search page at [http://localhost:8000/app/search](http://localhost:8000/app/search).
115
+
116
+ ---
117
+
118
+ ## 8. Connect an AI agent (optional, 5 min)
119
+
120
+ Cerefox ships a built-in MCP server. Add it to Claude Desktop's config file
121
+ (`~/Library/Application Support/Claude/claude_desktop_config.json`):
122
+
123
+ ```json
124
+ {
125
+ "mcpServers": {
126
+ "cerefox": {
127
+ "command": "uv",
128
+ "args": ["--directory", "/path/to/cerefox", "run", "cerefox", "mcp"]
129
+ }
130
+ }
131
+ }
132
+ ```
133
+
134
+ Replace `/path/to/cerefox` with the absolute path to this checkout. Restart Claude Desktop.
135
+
136
+ > **Recommended: remote MCP** -- if you deployed the Edge Functions (see the main
137
+ > README), use the remote MCP path instead -- no Python install needed on the client machine.
138
+ > See `docs/guides/connect-agents.md` for Path A-Remote.
139
+ >
140
+ > **ChatGPT** does not support MCP -- use a Custom GPT with
141
+ > Edge Functions instead (see `docs/guides/connect-agents.md`, Path B).
142
+
143
+ For full setup details (remote MCP, Cursor, cloud clients, GPT Actions), see `docs/guides/connect-agents.md`.
144
+
145
+ ---
146
+
147
+ ## You're done!
148
+
149
+ **What's next:**
150
+ - Ingest a directory of notes: `cerefox ingest-dir ./notes/ --recursive`
151
+ - Re-embed existing content: `cerefox reindex`
152
+ - Create a backup: `python scripts/backup_create.py`
153
+ - Sync project docs into your knowledge base: `python scripts/sync_docs.py`
154
+ (this also ingests the agent reference guides -- `AGENT_GUIDE.md` and `AGENT_QUICK_REFERENCE.md` --
155
+ so your AI agents can search for "How AI Agents Use Cerefox" and learn how to use the tools)
156
+ - See all commands: `cerefox --help`
157
+
158
+ **More guides:**
159
+ - `AGENT_GUIDE.md` -- comprehensive reference for AI agents using Cerefox tools
160
+ - `AGENT_QUICK_REFERENCE.md` -- minimal quick reference card for AI agents
161
+ - `docs/guides/setup-supabase.md` -- detailed Supabase setup
162
+ - `docs/guides/configuration.md` -- all configuration options
163
+ - `docs/guides/connect-agents.md` -- connecting AI agents via MCP and Edge Functions
164
+ - `docs/guides/setup-local.md` -- local Docker setup (no Supabase account needed)
165
+ - `docs/guides/upgrading.md` -- upgrading from a previous version
@@ -0,0 +1,151 @@
1
+ # Cerefox Response Size Limits
2
+
3
+ Cerefox returns content from your knowledge base — documents can be large, and returning
4
+ too much in a single search response can overwhelm an AI agent's context window. This guide
5
+ explains how response size limits work and how to tune them.
6
+
7
+ ---
8
+
9
+ ## The key principle: opt-in limits, never truncate the web UI
10
+
11
+ The web UI and CLI never truncate results. They have no size limit — the browser or terminal
12
+ can handle arbitrarily large responses and there is no LLM context window to worry about.
13
+
14
+ Limits are **opt-in per call**, used only on the MCP and Edge Function paths where an AI
15
+ agent's context window matters. Callers always choose whether to apply a limit.
16
+
17
+ ---
18
+
19
+ ## How each access path handles response size
20
+
21
+ | Path | Limit behaviour |
22
+ |------|----------------|
23
+ | Web UI (`/search`) | **No limit** — all results returned |
24
+ | CLI (`cerefox search`) | **No limit** — all results returned |
25
+ | Local MCP server (`cerefox mcp`) | Defaults to `CEREFOX_MAX_RESPONSE_BYTES` (200 000); agent can request less |
26
+ | Edge Function (`cerefox-search`) | Defaults to 200 000 bytes; agent can request less via `max_bytes` body param |
27
+ | Remote MCP (`cerefox-mcp` Edge Function) | Defaults to 200 000 bytes; agent can request less via `max_bytes` tool param |
28
+
29
+ ---
30
+
31
+ ## How limits are applied
32
+
33
+ Truncation is always **whole-document**: results are dropped in full once adding the next
34
+ document would exceed the budget. Cerefox never cuts a document mid-content.
35
+
36
+ When truncation occurs:
37
+ - The local MCP server appends `[Results truncated at N bytes — ...]` to the response text.
38
+ - The Edge Function includes `"truncated": true` and `"response_bytes": N` in the JSON response.
39
+
40
+ ---
41
+
42
+ ## The server ceiling — agents can request less, never more
43
+
44
+ For both the local MCP server and the `cerefox-search` Edge Function, the server-side
45
+ maximum acts as a hard ceiling. An agent can pass a smaller `max_bytes` value; a larger
46
+ value is silently capped.
47
+
48
+ ```
49
+ effective_max = min(agent_requested_max, SERVER_MAX)
50
+ ```
51
+
52
+ The Edge Function's `SERVER_MAX` is `200 000` bytes (hardcoded TypeScript constant).
53
+ The local MCP server's ceiling is `CEREFOX_MAX_RESPONSE_BYTES` from `.env`.
54
+
55
+ ---
56
+
57
+ ## Configuring the local MCP server limit
58
+
59
+ Set `CEREFOX_MAX_RESPONSE_BYTES` in `.env`:
60
+
61
+ ```env
62
+ CEREFOX_MAX_RESPONSE_BYTES=200000
63
+ ```
64
+
65
+ This value is used as both the **default** and the **ceiling** for the local MCP server.
66
+ Agents can pass a smaller `max_bytes` in the tool call, but never larger.
67
+
68
+ When should you lower this?
69
+ - Your MCP client (Claude Desktop, Cursor) has a small context window
70
+ - You want tighter, more focused responses at the cost of potentially seeing fewer results
71
+
72
+ When should you raise it?
73
+ - You use high `match_count` values (e.g. 20) and want all results returned
74
+ - Your documents are large and you want full content even for large-document results
75
+
76
+ ---
77
+
78
+ ## Passing `max_bytes` as an agent
79
+
80
+ The `cerefox_search` MCP tool accepts an optional `max_bytes` parameter in both the local
81
+ and remote MCP paths. Pass it when you want the response to fit within a specific budget:
82
+
83
+ ```json
84
+ {
85
+ "query": "knowledge management",
86
+ "max_bytes": 50000
87
+ }
88
+ ```
89
+
90
+ Values above the server ceiling are silently capped. Omitting `max_bytes` uses the server
91
+ default (200 000).
92
+
93
+ The `cerefox-search` Edge Function (Path B / GPT Actions) also accepts `max_bytes` as a
94
+ JSON body field:
95
+
96
+ ```http
97
+ POST https://<project>.supabase.co/functions/v1/cerefox-search
98
+ Authorization: Bearer <legacy-anon-jwt> # see docs/guides/setup-supabase.md#supabase-api-keys-2026
99
+ Content-Type: application/json
100
+
101
+ {
102
+ "query": "knowledge management",
103
+ "max_bytes": 50000
104
+ }
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Why 200 000 bytes?
110
+
111
+ 200 KB is a safe ceiling that prevents pathologically large responses (e.g. very high
112
+ `match_count` combined with many large documents) while never cutting legitimate results
113
+ at the default `match_count=5`.
114
+
115
+ **Worst-case budget at default settings:**
116
+ 5 documents × 20 000 chars each (the small-to-big threshold) ≈ 100 KB — comfortably under
117
+ 200 KB. In practice, most documents are shorter and the limit is rarely reached.
118
+
119
+ The original 65 KB default was driven by the Supabase MCP protocol limit, which no longer
120
+ applies (Cerefox now uses its own `cerefox-mcp` Edge Function for remote MCP access).
121
+
122
+ ---
123
+
124
+ ## How small-to-big retrieval complements the limit
125
+
126
+ For large documents (over 20 000 chars by default), `cerefox_search_docs` returns only the
127
+ matched chunks plus their immediate neighbours, not the full document text. This means a
128
+ single large document contributes only a few kilobytes to the response rather than tens of
129
+ kilobytes.
130
+
131
+ This **small-to-big threshold** acts as a complementary guard that keeps individual document
132
+ contributions compact. The response size limit then governs the total across all returned
133
+ documents.
134
+
135
+ See `docs/guides/configuration.md` → "RPC-level retrieval parameters" to change the
136
+ threshold (it is a SQL DEFAULT in `rpcs.sql`, changed via `db_deploy.py`).
137
+
138
+ ---
139
+
140
+ ## Summary
141
+
142
+ | Question | Answer |
143
+ |----------|--------|
144
+ | Does the web UI truncate results? | No — unlimited |
145
+ | Does the CLI truncate results? | No — unlimited |
146
+ | What is the default MCP response limit? | 200 000 bytes |
147
+ | Can an agent request a smaller limit? | Yes — `max_bytes` tool parameter |
148
+ | Can an agent exceed the server ceiling? | No — always capped |
149
+ | Where is the ceiling configured? | `.env` for local MCP; TypeScript constant in Edge Functions |
150
+ | How are limits applied? | Whole-document drop; never mid-content truncation |
151
+ | Is truncation signalled? | Yes — `truncated: true` in responses |