### Build and Setup MCP-Sophon Benchmarks
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/benchmarks/README.md
Builds the Rust project and sets environment variables for running benchmarks. Ensure you have Rust and Cargo installed.
```bash
cargo build --release -p mcp-integration
export SOPHON_BIN=./sophon/target/release/sophon
export SOPHON_REPO_ROOT=$(pwd)
```
--------------------------------
### Recommended Sophon Runtime Setup
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Set environment variables for persistent memory, on-disk retriever store, and BM25+Hash hybrid retrieval. Then, start the Sophon server.
```bash
# Persistent memory + on-disk retriever store + BM25+Hash hybrid
export SOPHON_MEMORY_PATH=~/.sophon/memory.jsonl
export SOPHON_RETRIEVER_PATH=~/.sophon/retriever
export SOPHON_HYBRID=1
sophon serve
```
--------------------------------
### Install and verify mcp-sophon
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/npm/README.md
Install the package globally and verify the installation by running the help command.
```bash
npm install -g mcp-sophon
sophon --help
```
--------------------------------
### Install MCP-Sophon via npm
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Install the MCP-Sophon CLI globally using npm. Run 'sophon doctor' to verify the installation and check configuration.
```bash
npm install -g mcp-sophon
sophon doctor # verify install + show config
```
--------------------------------
### Install Sophon Python Package
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon-py/README.md
Install the Sophon Python package using pip.
```bash
pip install sophon
```
--------------------------------
### Sophon CLI Quick Commands
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Execute common Sophon CLI commands for running tests, compressing prompts, installing agents, and viewing statistics.
```bash
sophon exec -- cargo test # run + compress combined output
sophon compress-prompt --prompt ./system.txt --query "rust errors" --max-tokens 500
sophon hook install --agent claude --global # transparent Claude Code integration
sophon stats --period session # token savings rollup
```
--------------------------------
### Build Sophon from Source
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon-py/README.md
Build the Sophon Python package from source using maturin. This involves installing maturin, navigating to the directory, and running the development build command.
```bash
pip install maturin
cd sophon-py
maturin develop --release
pytest tests/
```
--------------------------------
### Install Sophon Hook for Claude Agent
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Installs Sophon transparently for the Claude agent globally. This is the primary method for integrating Sophon with code-focused LLM agents.
```bash
sophon hook install --agent claude --global
```
--------------------------------
### Build with All Features
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Build the mcp-integration binary with all available features, including tree-sitter and BGE embedder. This results in the largest binary size.
```bash
# All features (~42 MB):
cargo build --release -p mcp-integration --features "codebase-navigator/tree-sitter,bge"
```
--------------------------------
### Run LLMLingua Head-to-Head Benchmark
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/benchmarks/README.md
Compares LLMLingua performance. Requires creating a data directory and potentially copying a system prompt file.
```bash
mkdir -p benchmarks/data
cp sophon/tests/fixtures/claude_system_prompt.txt benchmarks/data/system_prompt_large.txt # or use your own
python3 benchmarks/llmlingua_compare.py
```
--------------------------------
### Benchmark Comparison Scripts
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/CONTRIBUTING.md
Set up environment variables and run various Python scripts to compare Sophon's performance against other tools.
```bash
cargo build --release -p mcp-integration
export SOPHON_BIN=./sophon/target/release/sophon
export SOPHON_REPO_ROOT=$(pwd)
python3 benchmarks/llmlingua_compare.py # § 7.8.d (Sophon vs LLMLingua-2)
python3 benchmarks/locomo_retrieval.py # § 3.7 (Sophon 4-condition LOCOMO)
python3 benchmarks/locomo_mem0lite.py # § 7.8.e (mem0-lite comparison)
python3 benchmarks/repos_scan.py # § 7.2 / § 7.8.b (real-repo scan)
python3 benchmarks/repos_recall.py # § 7.3 (recall@K)
```
--------------------------------
### Build MCP-Sophon from Source
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Clone the repository and build the mcp-integration binary from source. This requires Rust 1.75+.
```bash
git clone https://github.com/lacausecrypto/mcp-sophon
cd mcp-sophon/sophon
cargo build --release -p mcp-integration # ~5.2 MB binary
```
--------------------------------
### Build and Test Sophon
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/CONTRIBUTING.md
Build the release binary for the mcp-integration crate and run the entire test suite.
```bash
git clone https://github.com/lacausecrypto/mcp-sophon
cd mcp-sophon/sophon
cargo build --release -p mcp-integration
cargo test --workspace
```
--------------------------------
### Run Repository QA Benchmark
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/BENCHMARK.md
Executes the repository question-answering benchmark script. Ensure the Sophon binary is built and accessible.
```bash
python3 benchmarks/repo_qa.py
```
--------------------------------
### Run Session Token Economics Benchmark
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/BENCHMARK.md
Executes the session token economics benchmark script. Ensure the Sophon binary is built and accessible.
```bash
python3 benchmarks/session_token_economics.py
```
--------------------------------
### Build Sophon Integration Binary
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/BENCHMARK.md
Builds the mcp-integration package in release mode for benchmarking. This command produces a 34 MB binary.
```bash
cargo build --release -p mcp-integration
```
--------------------------------
### Run Prompt Compression Extended Benchmark
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/BENCHMARK.md
Executes the extended prompt compression benchmark script. Ensure the Sophon binary is built and accessible.
```bash
python3 benchmarks/prompt_compression_extended.py
```
--------------------------------
### Run LOCOMO Cross-Model Benchmark
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/BENCHMARK.md
Executes the LOCOMO cross-provider A/B benchmark. Requires the LOCOMO dataset to be downloaded and its path set in SOPHON_BENCH_LOCOMO.
```bash
export SOPHON_BENCH_LOCOMO=/path/to/locomo/dir # with all_items.jsonl
python3 benchmarks/locomo_cross_model.py # cross-provider A/B
```
--------------------------------
### Format Code
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/CONTRIBUTING.md
Format all code in the project according to the defined style.
```bash
cargo fmt --all
```
--------------------------------
### Run All Tests
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/CONTRIBUTING.md
Execute all unit and integration tests across the workspace.
```bash
cargo test --workspace --no-fail-fast
```
--------------------------------
### Build and Test Sophon Workspace
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Commands to build and test the Sophon Rust workspace, including options for enabling tree-sitter for AST extraction.
```bash
# default build — regex extractors, no C deps, ~17 MB binary
car go build --release -p mcp-integration
car go test --workspace
# opt into 11-language AST extraction, ~25 MB binary
car go build --release -p mcp-integration --features codebase-navigator/tree-sitter
car go test --features codebase-navigator/tree-sitter
```
--------------------------------
### Run Rust Test Suite
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Execute the full Rust test suite for the mcp-sophon project, excluding the prompt-compressor feature.
```bash
cd sophon && cargo test --workspace --lib --tests --exclude prompt-compressor # 405 tests
```
--------------------------------
### Run Cross-Model Benchmarks (Default)
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/benchmarks/README.md
Executes the cross-model benchmark script with default settings. This configuration uses Stack A with a Sonnet answerer/judge and Stack B with a Codex answerer, while the internal Sophon LLM remains on Haiku.
```bash
python3 benchmarks/locomo_cross_model.py
```
--------------------------------
### Build with Tree-sitter AST Extraction Feature
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Build the mcp-integration binary with the 11-language tree-sitter AST extraction feature enabled. This increases the binary size.
```bash
# 11-language tree-sitter AST extraction (~25 MB):
cargo build --release -p mcp-integration --features codebase-navigator/tree-sitter
```
--------------------------------
### Run LOCOMO Stratified Benchmark
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/BENCHMARK.md
Executes the LOCOMO benchmark with stratified sampling (N=30). Requires the LOCOMO dataset to be downloaded and its path set in SOPHON_BENCH_LOCOMO.
```bash
export SOPHON_BENCH_LOCOMO=/path/to/locomo/dir # with all_items.jsonl
python3 benchmarks/locomo_v032_ab.py # N=30 stratified
```
--------------------------------
### Run Sophon Benchmarks
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Commands to run benchmarks for specific Sophon crates using Criterion.
```bash
car go bench -p prompt-compressor
car go bench -p memory-manager
car go bench -p delta-streamer
```
--------------------------------
### Build with BGE Semantic Embedder Feature
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Build the mcp-integration binary with the BGE-small semantic embedder feature. Activate it at runtime using the SOPHON_EMBEDDER environment variable.
```bash
# BGE-small semantic embedder (~34 MB), activate with SOPHON_EMBEDDER=bge:
cargo build --release -p mcp-integration --features bge
```
--------------------------------
### Run LOCOMO Retrieval Benchmark
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/benchmarks/README.md
Executes the LOCOMO retrieval benchmark. This requires a 'locomo' data directory and the 'all_items.jsonl' dataset.
```bash
mkdir -p benchmarks/data/locomo
# ...place all_items.jsonl here...
python3 benchmarks/locomo_retrieval.py
```
--------------------------------
### Run Cross-Model Benchmarks (Focused)
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/benchmarks/README.md
Executes the cross-model benchmark script with a focus on adversarial items. This configuration limits the benchmark to 10 samples per type for the adversarial category.
```bash
CROSS_N=10 CROSS_TYPES=adversarial python3 benchmarks/locomo_cross_model.py
```
--------------------------------
### Run mem0-lite LOCOMO Benchmark
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/benchmarks/README.md
Executes the mem0-lite LOCOMO benchmark. This is a faster variant of the LOCOMO retrieval benchmark.
```bash
python3 benchmarks/locomo_mem0lite.py
```
--------------------------------
### Run Cross-Model Benchmarks (All-Claude)
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/benchmarks/README.md
Executes the cross-model benchmark script using only Claude models. Both Stack A and Stack B utilize Claude models, with Stack A using Sonnet and Stack B using Opus as answerers.
```bash
CROSS_ANSWERER_A="python3 benchmarks/llm_cli.py --provider claude --model sonnet" \
CROSS_ANSWERER_B="python3 benchmarks/llm_cli.py --provider claude --model opus" \
python3 benchmarks/locomo_cross_model.py
```
--------------------------------
### Project Directory Structure
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
This snippet displays the directory layout of the MCP-Sophon project. It shows the main files and subdirectories, including the location of crates for different functionalities.
```bash
.
├── README.md ← you are here
├── BENCHMARK.md ← full per-section benchmark detail
├── CHANGELOG.md ← version history + deprecated numbers
├── benchmarks/ ← reproducible scripts for every number above
├── npm/ ← npm wrapper package
└── sophon/crates/ ← 11-crate Rust workspace
├── prompt-compressor/ compress_prompt
├── memory-manager/ compress_history, update_memory, rolling summary
├── delta-streamer/ read/write_file_delta
├── fragment-cache/ encode/decode_fragments
├── semantic-retriever/ chunker + HashEmbedder + BM25 + entity graph
├── output-compressor/ 21 command-aware filters + JsonStructural
├── codebase-navigator/ tree-sitter / regex + PageRank
├── cli-hooks/ transparent agent installer
└── mcp-integration/ stdio server, async dispatch, cancellation
```
--------------------------------
### Run Python Test Suite
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Execute the Python test suite for the mcp-sophon project using pytest.
```bash
cd sophon-py && .venv/bin/pytest tests/ # 4 Python tests
```
--------------------------------
### Set Sophon Binary Path
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/BENCHMARK.md
Sets the SOPHON_BIN environment variable to point to the compiled Sophon executable. This is a prerequisite for running most benchmark scripts.
```bash
export SOPHON_BIN=./sophon/target/release/sophon
```
--------------------------------
### Run Rust AST Tests
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Execute Rust tests that include Abstract Syntax Tree (AST) functionality, specifically for the codebase-navigator feature.
```bash
cd sophon && cargo test --features codebase-navigator/tree-sitter # +AST tests
```
--------------------------------
### Configure mcp-sophon as an MCP server
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/npm/README.md
Use this JSON configuration to set up Sophon as an MCP server within your project.
```json
{
"mcpServers": {
"sophon": {
"command": "sophon",
"args": ["serve"]
}
}
}
```
--------------------------------
### Sophon Workspace Layout
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Overview of the directory structure for the Sophon Rust workspace, detailing the purpose of each crate.
```text
sophon/
├── Cargo.toml
├── sophon.toml runtime defaults
├── crates/
│ ├── sophon-core/ shared types, cl100k_base counting, hashing
│ ├── prompt-compressor/ compress_prompt
│ ├── memory-manager/ compress_history, update_memory, persistence
│ ├── delta-streamer/ read_file_delta, write_file_delta
│ ├── fragment-cache/ encode_fragments, decode_fragments
│ ├── semantic-retriever/ chunker + HashEmbedder + linear k-NN
│ ├── output-compressor/ command-aware stdout/stderr compression
│ ├── cli-hooks/ transparent command rewriter + installer
│ ├── codebase-navigator/ tree-sitter/regex extractors + PageRank + digest
│ └── mcp-integration/ MCP stdio server, CLI, tool schemas
└── tests/
└── fixtures/
```
--------------------------------
### Sophon Prompt Compression
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon-py/README.md
Use Sophon's prompt compression feature to select relevant sections of a prompt based on a query. This helps in reducing token usage for large prompts.
```python
from sophon import Sophon
s = Sophon()
# Prompt compression (query-driven section selection)
result = s.compress_prompt(
"use Result and ?fetch()",
"rust errors",
max_tokens=500,
)
print(result.compressed_prompt)
print(f"{result.token_count} tokens, ratio={result.compression_ratio:.2f}")
```
--------------------------------
### compress_prompt
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Compresses a prompt by trimming less relevant sections while preserving topic-matched content, especially under a tight token budget.
```APIDOC
## compress_prompt
### Description
Compresses a prompt by trimming less relevant sections while preserving topic-matched content, especially under a tight token budget.
### Method
POST
### Endpoint
/tools/compress_prompt
### Parameters
#### Request Body
- **prompt** (string) - Required - The input prompt.
- **query** (string) - Required - The query used for topic matching.
- **max_tokens** (integer) - Optional - The maximum number of tokens allowed for the compressed prompt.
```
--------------------------------
### Run Latency Reliability Benchmark
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/BENCHMARK.md
Executes the latency and reliability benchmark script. Sets environment variables LAT_N and LAT_N_HEAVY to control sample sizes.
```bash
LAT_N=30 LAT_N_HEAVY=10 python3 benchmarks/latency_reliability.py
```
--------------------------------
### Agent Session Token Economics Breakdown
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/BENCHMARK.md
This table breaks down token usage and savings per operation within a simulated 25-turn coding session. It shows the raw tokens, sent tokens, and percentage saved for each operation, illustrating Sophon's efficiency.
```text
Operation | Count | Raw tokens | Sent tokens | Saved |
|---|---|---|---|---|
| `compress_output` | 5 | 11 480 | 2 320 | **79.8 %** |
| `write_file_delta` | 3 | 4 644 | 258 | **94.4 %** |
| `file_read_baseline` | 3 | 4 599 | 4 599 | 0.0 % |
| `read_file_delta` (re-reads) | 3 | 4 599 | 90 | **98.0 %** |
| `compress_history` | 9 | 3 615 | 2 483 | 31.3 % |
| `compress_prompt` | 2 | 1 900 | 88 | **95.4 %** |
| **TOTAL** | **25** | **30 837** | **9 838** | **68.1 %** |
```
--------------------------------
### LOCOMO Benchmark Confidence Intervals
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/BENCHMARK.md
Displays the 95% Wilson Confidence Intervals for LOCOMO benchmark results across different system versions. Overlapping CIs indicate results are not statistically robust.
```text
V030 33.3 % [19.2 — 51.2]
V032_FULL 40.0 % [24.6 — 57.7]
FULL 73.3 % [55.6 — 85.8]
```
--------------------------------
### Programmatic JSON-RPC Call to Sophon
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/README.md
Send a one-shot JSON-RPC request to the Sophon server to perform an action, such as compressing a prompt with specific arguments.
```bash
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"compress_prompt","arguments":{"prompt":"?: operatorfetch()","query":"rust errors","max_tokens":500}}}' \
| sophon serve
```
--------------------------------
### Sophon Output Compression
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon-py/README.md
Utilize Sophon's output compression to filter long command outputs. This is useful for commands that produce verbose results, like test suites.
```python
# Output compression (command-aware filtering)
out = s.compress_output("cargo test", long_test_output)
print(out.compressed)
print(f"ratio={out.ratio:.2f}, filter={out.filter_name}")
```
--------------------------------
### Compress History Configuration Flags
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/BENCHMARK.md
These environment variables are used to activate the v0.4.0 flag stack for compress_history, significantly impacting its performance and reliability.
```shell
SOPHON_HYDE=1 SOPHON_FACT_CARDS=1 SOPHON_ADAPTIVE=1
SOPHON_LLM_RERANK=1 SOPHON_TAIL_SUMMARY=1
SOPHON_ENTITY_GRAPH=1 SOPHON_CHUNK_TARGET=500
```
--------------------------------
### get_token_stats
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Retrieves cumulative per-module token statistics, including compression ratios.
```APIDOC
## get_token_stats
### Description
Retrieves cumulative per-module token statistics, including compression ratios.
### Method
GET
### Endpoint
/tools/get_token_stats
### Response
#### Success Response (200)
- **stats** (object) - An object containing per-module statistics.
- **compression_ratio** (number) - The compression ratio (compressed / original), clamped to [0, 1].
```
--------------------------------
### update_memory
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Manages stateful session memory by appending new information and creating snapshots without resending the full history. Can persist to disk.
```APIDOC
## update_memory
### Description
Manages stateful session memory by appending new information and creating snapshots without resending the full history. Can persist to disk.
### Method
POST
### Endpoint
/tools/update_memory
### Parameters
#### Request Body
- **state** (object) - Required - The current memory state.
- **append** (object) - Required - New information to append to the memory.
### Notes
Set `SOPHON_MEMORY_PATH=~/.sophon/memory/session.jsonl` to persist appends to disk across server restarts.
```
--------------------------------
### Sophon Token Counting
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon-py/README.md
Count the number of tokens in a given string using the cl100k_base encoding with Sophon's static method.
```python
# Token counting (cl100k_base)
tokens = Sophon.count_tokens("hello world")
```
--------------------------------
### compress_history
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Compresses conversation history. Short histories that already fit within the budget are passed through unchanged.
```APIDOC
## compress_history
### Description
Compresses conversation history. Short histories that already fit within the budget are passed through unchanged.
### Method
POST
### Endpoint
/tools/compress_history
### Parameters
#### Request Body
- **messages** (array) - Required - An array of message objects representing the conversation history.
- **max_tokens** (integer) - Optional - The maximum number of tokens allowed for the compressed history.
- **recent_window** (integer) - Optional - The number of recent messages to prioritize.
- **include_index** (boolean) - Optional - Whether to include an index in the compressed history (default: false).
```
--------------------------------
### write_file_delta
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Performs an atomic staged write of file content or delta.
```APIDOC
## write_file_delta
### Description
Performs an atomic staged write of file content or delta.
### Method
POST
### Endpoint
/tools/write_file_delta
### Parameters
#### Request Body
- **path** (string) - Required - The path to the file.
- **content** (string) - Required - The file content or delta to write.
```
--------------------------------
### count_tokens
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Calculates the ground-truth token count for a given string using the cl100k_base encoding.
```APIDOC
## count_tokens
### Description
Calculates the ground-truth token count for a given string using the cl100k_base encoding.
### Method
POST
### Endpoint
/tools/count_tokens
### Parameters
#### Request Body
- **text** (string) - Required - The input text to count tokens for.
```
--------------------------------
### read_file_delta
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Reads a file delta, returning the status of the file content relative to a known version or hash.
```APIDOC
## read_file_delta
### Description
Reads a file delta, returning the status of the file content relative to a known version or hash.
### Method
POST
### Endpoint
/tools/read_file_delta
### Parameters
#### Request Body
- **path** (string) - Required - The path to the file.
- **known_version** (string) - Optional - The known version of the file.
- **known_hash** (string) - Optional - The known hash of the file.
### Response
#### Success Response (200)
- **status** (string) - 'Unchanged', 'Delta', or 'Full' - Indicates the file status.
- **content** (string) - The file content or delta (if applicable).
```
--------------------------------
### decode_fragments
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Reconstructs a document from encoded fragments, replacing fragment identifiers with their original content.
```APIDOC
## decode_fragments
### Description
Reconstructs a document from encoded fragments, replacing fragment identifiers with their original content.
### Method
POST
### Endpoint
/tools/decode_fragments
### Parameters
#### Request Body
- **encoded_document** (string) - Required - The document with encoded fragments.
- **fragments** (object) - Required - A mapping of fragment identifiers to their original content.
```
--------------------------------
### encode_fragments
Source: https://github.com/lacausecrypto/mcp-sophon/blob/main/sophon/README.md
Deduplicates repeated multi-paragraph blocks within a document by encoding them into fragments.
```APIDOC
## encode_fragments
### Description
Deduplicates repeated multi-paragraph blocks within a document by encoding them into fragments.
### Method
POST
### Endpoint
/tools/encode_fragments
### Parameters
#### Request Body
- **document** (string) - Required - The input document.
- **max_window** (integer) - Optional - The maximum window size for detector (defaults to 64 paragraphs, or paragraphs/2).
### Notes
The detector window is adaptive and can be overridden with `SOPHON_FRAGMENT_MAX_WINDOW`.
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.