mentat-sr 0.1.0__tar.gz
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.
- mentat_sr-0.1.0/.claude/settings.local.json +30 -0
- mentat_sr-0.1.0/.env.example +54 -0
- mentat_sr-0.1.0/.gitignore +33 -0
- mentat_sr-0.1.0/.python-version +1 -0
- mentat_sr-0.1.0/CLAUDE.md +116 -0
- mentat_sr-0.1.0/LICENSE +190 -0
- mentat_sr-0.1.0/PKG-INFO +601 -0
- mentat_sr-0.1.0/README.md +542 -0
- mentat_sr-0.1.0/TODO.md +97 -0
- mentat_sr-0.1.0/benchmarks/1706.03762v7.pdf +0 -0
- mentat_sr-0.1.0/benchmarks/CONCLUSION.md +103 -0
- mentat_sr-0.1.0/benchmarks/benchmark.py +1142 -0
- mentat_sr-0.1.0/benchmarks/results.json +471 -0
- mentat_sr-0.1.0/examples/auto_routing.py +84 -0
- mentat_sr-0.1.0/examples/basic_usage.py +70 -0
- mentat_sr-0.1.0/examples/batch_indexing.py +84 -0
- mentat_sr-0.1.0/examples/collections.py +70 -0
- mentat_sr-0.1.0/examples/content_indexing.py +71 -0
- mentat_sr-0.1.0/examples/file_watcher.py +67 -0
- mentat_sr-0.1.0/examples/hybrid_search.py +98 -0
- mentat_sr-0.1.0/examples/session_lifecycle.py +87 -0
- mentat_sr-0.1.0/examples/two_step_retrieval.py +84 -0
- mentat_sr-0.1.0/mentat/__init__.py +570 -0
- mentat_sr-0.1.0/mentat/cli.py +664 -0
- mentat_sr-0.1.0/mentat/core/access_tracker.py +212 -0
- mentat_sr-0.1.0/mentat/core/embeddings.py +133 -0
- mentat_sr-0.1.0/mentat/core/hub.py +247 -0
- mentat_sr-0.1.0/mentat/core/indexer.py +564 -0
- mentat_sr-0.1.0/mentat/core/models.py +258 -0
- mentat_sr-0.1.0/mentat/core/queue.py +521 -0
- mentat_sr-0.1.0/mentat/core/reader.py +578 -0
- mentat_sr-0.1.0/mentat/core/searcher.py +382 -0
- mentat_sr-0.1.0/mentat/core/section_heat.py +325 -0
- mentat_sr-0.1.0/mentat/core/telemetry.py +104 -0
- mentat_sr-0.1.0/mentat/core/watcher.py +237 -0
- mentat_sr-0.1.0/mentat/librarian/__init__.py +0 -0
- mentat_sr-0.1.0/mentat/librarian/engine.py +365 -0
- mentat_sr-0.1.0/mentat/librarian/instruction_templates.py +380 -0
- mentat_sr-0.1.0/mentat/probes/__init__.py +77 -0
- mentat_sr-0.1.0/mentat/probes/_utils.py +430 -0
- mentat_sr-0.1.0/mentat/probes/archive_probe.py +202 -0
- mentat_sr-0.1.0/mentat/probes/base.py +99 -0
- mentat_sr-0.1.0/mentat/probes/calendar_probe.py +186 -0
- mentat_sr-0.1.0/mentat/probes/code_probe.py +498 -0
- mentat_sr-0.1.0/mentat/probes/config_probe.py +257 -0
- mentat_sr-0.1.0/mentat/probes/csv_probe.py +221 -0
- mentat_sr-0.1.0/mentat/probes/docx_probe.py +240 -0
- mentat_sr-0.1.0/mentat/probes/image_probe.py +160 -0
- mentat_sr-0.1.0/mentat/probes/json_probe.py +260 -0
- mentat_sr-0.1.0/mentat/probes/log_probe.py +267 -0
- mentat_sr-0.1.0/mentat/probes/markdown_probe.py +283 -0
- mentat_sr-0.1.0/mentat/probes/pdf_probe.py +307 -0
- mentat_sr-0.1.0/mentat/probes/pptx_probe.py +188 -0
- mentat_sr-0.1.0/mentat/probes/web_probe.py +327 -0
- mentat_sr-0.1.0/mentat/server.py +462 -0
- mentat_sr-0.1.0/mentat/service.py +161 -0
- mentat_sr-0.1.0/mentat/skill.py +334 -0
- mentat_sr-0.1.0/mentat/storage/base.py +129 -0
- mentat_sr-0.1.0/mentat/storage/cache.py +165 -0
- mentat_sr-0.1.0/mentat/storage/collections.py +244 -0
- mentat_sr-0.1.0/mentat/storage/file_store.py +68 -0
- mentat_sr-0.1.0/mentat/storage/filters.py +115 -0
- mentat_sr-0.1.0/mentat/storage/vector_db.py +354 -0
- mentat_sr-0.1.0/pyproject.toml +86 -0
- mentat_sr-0.1.0/tests/__init__.py +0 -0
- mentat_sr-0.1.0/tests/conftest.py +123 -0
- mentat_sr-0.1.0/tests/test_access_tracker.py +136 -0
- mentat_sr-0.1.0/tests/test_async_summary.py +221 -0
- mentat_sr-0.1.0/tests/test_async_workflow.py +393 -0
- mentat_sr-0.1.0/tests/test_cache.py +125 -0
- mentat_sr-0.1.0/tests/test_collection_search.py +186 -0
- mentat_sr-0.1.0/tests/test_collections.py +307 -0
- mentat_sr-0.1.0/tests/test_config.py +71 -0
- mentat_sr-0.1.0/tests/test_doc_meta.py +98 -0
- mentat_sr-0.1.0/tests/test_embeddings.py +65 -0
- mentat_sr-0.1.0/tests/test_file_store.py +63 -0
- mentat_sr-0.1.0/tests/test_instruction_templates.py +89 -0
- mentat_sr-0.1.0/tests/test_librarian.py +291 -0
- mentat_sr-0.1.0/tests/test_models.py +45 -0
- mentat_sr-0.1.0/tests/test_path_dedup.py +202 -0
- mentat_sr-0.1.0/tests/test_performance.py +298 -0
- mentat_sr-0.1.0/tests/test_probe_utils.py +71 -0
- mentat_sr-0.1.0/tests/test_queue.py +571 -0
- mentat_sr-0.1.0/tests/test_queue_perf.py +152 -0
- mentat_sr-0.1.0/tests/test_search_grouped.py +150 -0
- mentat_sr-0.1.0/tests/test_section_heat.py +400 -0
- mentat_sr-0.1.0/tests/test_server.py +252 -0
- mentat_sr-0.1.0/tests/test_server_collections.py +242 -0
- mentat_sr-0.1.0/tests/test_skill.py +116 -0
- mentat_sr-0.1.0/tests/test_smoke.py +196 -0
- mentat_sr-0.1.0/tests/test_source_metadata.py +220 -0
- mentat_sr-0.1.0/tests/test_telemetry.py +58 -0
- mentat_sr-0.1.0/tests/test_vector_db.py +214 -0
- mentat_sr-0.1.0/tests/test_watcher.py +272 -0
- mentat_sr-0.1.0/tests/test_watcher_integration.py +391 -0
- mentat_sr-0.1.0/uv.lock +3514 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(wc:*)",
|
|
5
|
+
"Bash(uv run python:*)",
|
|
6
|
+
"Bash(echo:*)",
|
|
7
|
+
"Bash(uv add:*)",
|
|
8
|
+
"Bash(uv run pytest:*)",
|
|
9
|
+
"Bash(uv run mentat probe:*)",
|
|
10
|
+
"Bash(uv run:*)",
|
|
11
|
+
"Bash(uv sync:*)",
|
|
12
|
+
"Bash(git commit:*)",
|
|
13
|
+
"Bash(chmod:*)",
|
|
14
|
+
"Bash(git -C /opt/nvme/home/shelven/Documents/mentat diff /opt/nvme/home/shelven/Documents/mentat/mentat/probes/json_probe.py)",
|
|
15
|
+
"Bash(/tmp/test_large_json.json:*)",
|
|
16
|
+
"Bash(ls:*)",
|
|
17
|
+
"Bash(python -c:*)",
|
|
18
|
+
"Bash(python3 -c \":*)",
|
|
19
|
+
"Bash(git checkout mentat/core/hub.py mentat/storage/vector_db.py)",
|
|
20
|
+
"Bash(git add mentat/probes/_utils.py mentat/probes/docx_probe.py mentat/probes/json_probe.py mentat/probes/markdown_probe.py mentat/probes/web_probe.py mentat/probes/instruction_templates.py mentat/probes/test_instruction_templates.py mentat/core/hub.py)",
|
|
21
|
+
"Bash(git add mentat/core/queue.py mentat/core/embeddings.py mentat/librarian/engine.py mentat/core/hub.py mentat/storage/vector_db.py tests/test_async_workflow.py tests/test_performance.py)",
|
|
22
|
+
"Bash(git add mentat/server.py mentat/core/access_tracker.py mentat/cli.py mentat/__init__.py pyproject.toml uv.lock mentat/storage/cache.py mentat/core/hub.py)",
|
|
23
|
+
"Bash(git status -u)",
|
|
24
|
+
"Bash(git add mentat/probes/pdf_probe.py benchmarks/benchmark.py benchmarks/CONCLUSION.md benchmarks/results.json benchmarks/1706.03762v7.pdf)",
|
|
25
|
+
"Bash(grep -n \"track_access\\\\|_on_access_promote\\\\|summarize_doc\\\\|hot.*promote\" /opt/nvme/home/shelven/Documents/mentat/tests/*.py)",
|
|
26
|
+
"Bash(git add CLAUDE.md TODO.md mentat/__init__.py mentat/cli.py mentat/core/access_tracker.py mentat/core/hub.py mentat/server.py mentat/skill.py tests/test_access_tracker.py tests/test_smoke.py tests/test_skill.py)",
|
|
27
|
+
"Bash(git add:*)"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# Mentat Configuration
|
|
3
|
+
# Copy this file to .env and fill in the values.
|
|
4
|
+
# =============================================================================
|
|
5
|
+
|
|
6
|
+
# --- Summary Model (Phase 1 — chunk summarisation) ---
|
|
7
|
+
# Fast/cheap model for bulk chunk summarisation.
|
|
8
|
+
# Accepts any litellm model string: openai/gpt-4o-mini, gemini/gemini-2.0-flash, ollama/llama3, etc.
|
|
9
|
+
# See: https://docs.litellm.ai/docs/providers
|
|
10
|
+
MENTAT_SUMMARY_MODEL=openai/gpt-4o-mini
|
|
11
|
+
# MENTAT_SUMMARY_API_KEY= # Optional — overrides the provider's global key
|
|
12
|
+
# MENTAT_SUMMARY_API_BASE= # Optional — custom endpoint (e.g. Azure, vLLM, local proxy)
|
|
13
|
+
|
|
14
|
+
# --- Embedding Model ---
|
|
15
|
+
# Accepts any litellm embedding model string.
|
|
16
|
+
# Vector dimension is auto-detected from the first embedding call.
|
|
17
|
+
MENTAT_EMBEDDING_MODEL=openai/text-embedding-3-small
|
|
18
|
+
# MENTAT_EMBEDDING_API_KEY= # Optional — overrides the provider's global key
|
|
19
|
+
# MENTAT_EMBEDDING_API_BASE= # Optional — custom endpoint
|
|
20
|
+
|
|
21
|
+
# --- Global Provider API Keys ---
|
|
22
|
+
# litellm reads these natively. Set the one(s) you need.
|
|
23
|
+
# The per-model keys above (MENTAT_SUMMARY_API_KEY, MENTAT_EMBEDDING_API_KEY) take
|
|
24
|
+
# priority when set; otherwise litellm falls back to these.
|
|
25
|
+
OPENAI_API_KEY=sk-...
|
|
26
|
+
# OPENAI_API_BASE= # Optional — for OpenAI-compatible endpoints
|
|
27
|
+
# ANTHROPIC_API_KEY=sk-ant-...
|
|
28
|
+
# GEMINI_API_KEY=...
|
|
29
|
+
# AZURE_API_KEY=...
|
|
30
|
+
# AZURE_API_BASE=https://your-resource.openai.azure.com
|
|
31
|
+
# AZURE_API_VERSION=2024-02-01
|
|
32
|
+
# OLLAMA_API_BASE=http://localhost:11434
|
|
33
|
+
|
|
34
|
+
# --- Storage ---
|
|
35
|
+
MENTAT_DB_PATH=./mentat_db
|
|
36
|
+
MENTAT_STORAGE_DIR=./mentat_files
|
|
37
|
+
|
|
38
|
+
# --- Background Processing ---
|
|
39
|
+
# Maximum number of documents to process concurrently in the background queue.
|
|
40
|
+
# Higher values = faster batch processing but more memory/API usage.
|
|
41
|
+
# Default: 5
|
|
42
|
+
MENTAT_MAX_CONCURRENT_TASKS=5
|
|
43
|
+
|
|
44
|
+
# --- Section Heat Tracking ---
|
|
45
|
+
# Exponential decay half-life for section importance scores (seconds).
|
|
46
|
+
# Default: 86400 (24 hours)
|
|
47
|
+
# MENTAT_SECTION_HEAT_HALF_LIFE=86400
|
|
48
|
+
# Score threshold for a section to be considered "hot".
|
|
49
|
+
# Default: 5.0
|
|
50
|
+
# MENTAT_SECTION_HEAT_THRESHOLD=5.0
|
|
51
|
+
# Maximum number of tracked section entries (coldest evicted first).
|
|
52
|
+
# Default: 1000
|
|
53
|
+
# MENTAT_SECTION_HEAT_MAX_ENTRIES=1000
|
|
54
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.pyc
|
|
4
|
+
*.pyo
|
|
5
|
+
*.pyd
|
|
6
|
+
.Python
|
|
7
|
+
env/
|
|
8
|
+
venv/
|
|
9
|
+
.env
|
|
10
|
+
.venv/
|
|
11
|
+
|
|
12
|
+
# uv
|
|
13
|
+
.uv/
|
|
14
|
+
|
|
15
|
+
# Mentat Storage
|
|
16
|
+
*mentat_db/
|
|
17
|
+
*mentat_files/
|
|
18
|
+
|
|
19
|
+
# IDEs
|
|
20
|
+
.vscode/
|
|
21
|
+
.idea/
|
|
22
|
+
|
|
23
|
+
# Testing
|
|
24
|
+
.pytest_cache/
|
|
25
|
+
.coverage
|
|
26
|
+
htmlcov/
|
|
27
|
+
|
|
28
|
+
# Mac
|
|
29
|
+
.DS_Store
|
|
30
|
+
|
|
31
|
+
design-docs/
|
|
32
|
+
samples/
|
|
33
|
+
references/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.10
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
Mentat is a next-generation Agentic RAG system (Python 3.10+) that transforms "Content Retrieval" into "Strategy Retrieval." Instead of feeding raw documents to an LLM, Mentat uses statistical probes to extract **semantic fingerprints** (hierarchy + metadata + anchors + snippets), then generates template-based actionable reading guides. Small files (< 1000 tokens) bypass skeleton extraction and return full content directly.
|
|
8
|
+
|
|
9
|
+
## Development Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Package manager: uv
|
|
13
|
+
uv sync # Install all dependencies
|
|
14
|
+
|
|
15
|
+
# Configuration
|
|
16
|
+
cp .env.example .env # Then edit .env with API keys / model names
|
|
17
|
+
|
|
18
|
+
# CLI (preferred way to run)
|
|
19
|
+
uv run python -m mentat.cli [COMMAND]
|
|
20
|
+
mentat --debug [COMMAND] # After install
|
|
21
|
+
|
|
22
|
+
# FastAPI server (port 7832)
|
|
23
|
+
mentat serve
|
|
24
|
+
|
|
25
|
+
# Tests (all mocked, no API keys needed; pytest-asyncio with asyncio_mode=auto)
|
|
26
|
+
uv run pytest tests/ -v # Full suite
|
|
27
|
+
uv run pytest tests/test_smoke.py -v # End-to-end smoke test
|
|
28
|
+
uv run pytest tests/test_queue.py -v # Single test file
|
|
29
|
+
uv run pytest tests/test_smoke.py::test_probe_markdown -v # Single test
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Architecture
|
|
33
|
+
|
|
34
|
+
Three-layer unidirectional pipeline: **Probes → Librarian → Storage**
|
|
35
|
+
|
|
36
|
+
### Layer 1 — Probes (`mentat/probes/`)
|
|
37
|
+
Semantic fingerprinting — no LLM, pure extraction. Each probe implements `BaseProbe` ABC (`can_handle()` + `run()` → `ProbeResult`). Registry in `__init__.py` — 13 probes tried in order, first match wins. Optional-dep probes (Image, DOCX, PPTX, Calendar) degrade gracefully via try/except import.
|
|
38
|
+
|
|
39
|
+
Key utilities in `_utils.py`: `estimate_tokens` (1 token ≈ 3 chars), `normalize_chunk_sizes` (merges adjacent small chunks <300 tokens, respects H1/H2 boundaries, max merged 1200 tokens), `should_bypass` (<1000 token files return full content).
|
|
40
|
+
|
|
41
|
+
### Layer 2 — Librarian (`mentat/librarian/`)
|
|
42
|
+
- `engine.py` — Uses `litellm` for all LLM calls. Takes only `ProbeResult` as input — never reads raw files.
|
|
43
|
+
- **Phase 1 — Chunk Summarisation** (optional): LLM generates 1-3 sentence summaries per chunk (batched, concurrent). Small files bypass this.
|
|
44
|
+
- **Phase 2 — Instruction Generation** (template-based, no LLM): produces `brief_intro` + `instructions` from ToC + statistics.
|
|
45
|
+
- `instruction_templates.py` — Format-specific reading guide templates used by all probes.
|
|
46
|
+
|
|
47
|
+
### Layer 3 — Storage (`mentat/storage/`)
|
|
48
|
+
- `BaseVectorStorage` (`base.py`) — ABC interface for vector storage backends. Enables swapping LanceDB for other backends.
|
|
49
|
+
- `LanceDBStorage` (`vector_db.py`) — implements `BaseVectorStorage`. Separate tables for document stubs and chunks. Lazy vector table creation (dimension auto-detected from first embedding). BTREE scalar index on `doc_id` for collection filtering. Chunks include metadata columns (`source`, `indexed_at`, `file_type`, `metadata_json`) for pre-filtering.
|
|
50
|
+
- `MetadataFilter` / `MetadataFilterSet` (`filters.py`) — Backend-agnostic filter representation with SQL builder for LanceDB WHERE clauses. Supports eq, neq, gt, gte, lt, lte, in, like, between operators.
|
|
51
|
+
- `LocalFileStore` (`file_store.py`) — raw file copies for downstream access.
|
|
52
|
+
- `ContentHashCache` (`cache.py`) — SHA-256 deduplication (JSON-backed). Shares `_JsonMap` base class with `PathIndex`.
|
|
53
|
+
- `PathIndex` (`cache.py`) — path→doc_id mapping for file identity tracking. When the same path is re-indexed with changed content, the old document (stubs + chunks) is deleted before creating the new one. Synthetic keys (`__content__:{filename}`) support `add_content()` dedup. Inherits `_JsonMap` base.
|
|
54
|
+
- `CollectionStore` (`collections.py`) — named doc groups as JSON references (no vector duplication).
|
|
55
|
+
|
|
56
|
+
### Orchestrator (`mentat/core/hub.py`)
|
|
57
|
+
`Mentat` class — singleton via `get_instance()`, reset with `reset()`. Delegates operations to focused modules:
|
|
58
|
+
- `core/indexer.py` — `Indexer`: `add()`, `add_batch()`, `add_content()`, processing status, wait.
|
|
59
|
+
- `core/searcher.py` — `Searcher`: `search()`, `search_grouped()`, `_raw_search()`, result assembly.
|
|
60
|
+
- `core/reader.py` — `Reader`: `inspect()`, `read_segment()`, `read_structured()`, `get_doc_meta()`, `summarize_doc()`.
|
|
61
|
+
|
|
62
|
+
`MentatConfig` dataclass in `core/models.py` (loads `.env` via python-dotenv, `MENTAT_*` env vars, precedence: explicit arg > env var > default).
|
|
63
|
+
|
|
64
|
+
**Async processing pipeline** (default): `add()` returns in ~1-3s after probe + stub storage, then queues background embeddings/summarization. Legacy sync: `add(wait=True)` blocks until complete.
|
|
65
|
+
|
|
66
|
+
### Data Models (`mentat/core/models.py`)
|
|
67
|
+
All Pydantic models and base interfaces in one place: `MentatResult`, `MentatDocResult`, `ChunkResult`, `MentatConfig`, `Collection`, `BaseAdaptor`.
|
|
68
|
+
|
|
69
|
+
### Background Queue (`mentat/core/queue.py`)
|
|
70
|
+
`ProcessingQueue` + `BackgroundProcessor` — in-memory priority queue (transient, lost on restart). Priority boosting: documents queried before processing completes get +10 priority. Concurrency: `max_concurrent_tasks` (default 5, via `MENTAT_MAX_CONCURRENT_TASKS`).
|
|
71
|
+
|
|
72
|
+
### Service Layer (`mentat/service.py`)
|
|
73
|
+
Shared stateless functions used by CLI, server, and future SDK: `index_file()`, `search_docs()`, `resolve_doc_id()`, `list_docs()`, etc. CLI formats for terminal; server returns as JSON.
|
|
74
|
+
|
|
75
|
+
### Other Core Modules
|
|
76
|
+
- `core/embeddings.py` — `BaseEmbedding` ABC + `LiteLLMEmbedding` provider with batching. `EmbeddingRegistry` for pluggable providers. Oversized chunks split with 500-char overlap.
|
|
77
|
+
- `core/access_tracker.py` — two-layer FIFO: recent (LRU) → hot (≥2 accesses). Promotion callback triggers on-demand summarization. Persistent heat map via `heat_map.json` (debounced writes, loaded on init).
|
|
78
|
+
- `core/section_heat.py` — `SectionHeatTracker`: section-level importance tracking with weighted scoring (read_segment=3.0, inspect=2.0, search=1.0), exponential time decay (24h half-life), hot threshold, LRU eviction, and JSON persistence (`section_heat_map.json`). Parent→child propagation via ToC hierarchy.
|
|
79
|
+
- `core/telemetry.py` — context-manager timing for probe/summarize/librarian phases, token savings tracking.
|
|
80
|
+
- `server.py` — FastAPI HTTP server. Delegates to `service.py` for shared operations.
|
|
81
|
+
- `skill.py` — Skill Integration Layer: OpenAI function calling tool schemas + system prompt fragment for agent two-step retrieval protocol. `export_skill()` returns combined payload.
|
|
82
|
+
|
|
83
|
+
### Public API (`mentat/__init__.py`)
|
|
84
|
+
Thin convenience wrappers delegating to `Mentat` singleton. Module-level async functions: `add()`, `add_batch()`, `add_content()`, `search()`, `search_grouped()`, `inspect()`, `get_doc_meta()`, `read_structured()`, `read_segment()`, `track_access()`, `start_processor()`, `shutdown()`, `wait_for()`. Sync functions: `probe()`, `stats()`, `get_section_heat()`, `collection()`, `collections()`, `get_status()`, `configure()`. Re-exports: `Mentat`, `MentatConfig`, `MentatResult`, `MentatDocResult`, `ChunkResult`, `Collection`, `BaseAdaptor`, `ProbeResult`.
|
|
85
|
+
|
|
86
|
+
## CLI Commands
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
mentat probe <file_paths> [--format rich|json] # Run probes (no LLM, no storage)
|
|
90
|
+
mentat index <path> [--force] [-c <collection>] [--summarize] [--llm-instructions] [--wait] [-j N]
|
|
91
|
+
mentat status <doc_id> # Check processing status
|
|
92
|
+
mentat search <query> [--top-k 5] [--hybrid] [-c <collection>] [--toc-only]
|
|
93
|
+
mentat segment <doc_id> <section> # Read specific section (two-step protocol step 2)
|
|
94
|
+
mentat inspect <doc_id> # Show probe results + instructions
|
|
95
|
+
mentat stats # System statistics
|
|
96
|
+
mentat collection list|show|delete|remove # Collection management
|
|
97
|
+
mentat skill [--format json|prompt] # Export agent tool schemas + system prompt
|
|
98
|
+
mentat serve # Start FastAPI server (port 7832)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Two-Step Retrieval Protocol (Agent Integration)
|
|
102
|
+
|
|
103
|
+
Mentat implements a Probe→Fetch protocol for token-efficient agent memory access:
|
|
104
|
+
|
|
105
|
+
1. **Step 1 — Discover**: `search(query, toc_only=True)` returns document summaries + ToC entries (no chunk content). Agent sees ~100-200 tokens per doc.
|
|
106
|
+
2. **Step 2 — Read**: `read_segment(doc_id, section_path)` fetches specific section content by doc_id + section name from step 1.
|
|
107
|
+
|
|
108
|
+
The `skill.py` module exports OpenAI function calling tool schemas and a system prompt fragment that teaches agents this protocol. Use `mentat skill` CLI or `GET /skill` endpoint.
|
|
109
|
+
|
|
110
|
+
## Key Patterns
|
|
111
|
+
|
|
112
|
+
- **Pydantic v2** for all data models (`ProbeResult`, `TopicInfo`, `StructureInfo`, `Chunk`, `TocEntry`) in `mentat/probes/base.py`, result/config models (`MentatResult`, `MentatDocResult`, `ChunkResult`, `MentatConfig`, `BaseAdaptor`) in `mentat/core/models.py`
|
|
113
|
+
- **Plugin registry** for probes — add new format by implementing `BaseProbe` and registering in `mentat/probes/__init__.py`
|
|
114
|
+
- **Two-stage storage** — stubs stored immediately (with ToC); chunks stored after background embedding/summarization
|
|
115
|
+
- **Collections** — named doc groups for scoped search; shared storage with doc_id references; LanceDB `WHERE doc_id IN (...)` pre-filtering
|
|
116
|
+
- **Config precedence** — explicit arg > `MENTAT_*` env var > default. Separate `api_key`/`api_base` for summary model (`MENTAT_SUMMARY_*`) and embedding model (`MENTAT_EMBEDDING_*`). Global provider keys (`OPENAI_API_KEY`, etc.) read by `litellm` as fallback.
|
mentat_sr-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025 Shelven Zhou
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|