leviathan README

The project's README from github.com/elstongun/leviathan. As one markdown file: README.md.

Leviathan

Deep memory for agents over large datasets.
Index any table, export or log once; your agent gets the few records that answer the question.

CI License: Apache-2.0 Rust 1.88+ MCP optional

Leviathan is a single binary that turns records (JSONL, JSON, CSV/TSV, SQLite, or any database CLI's output) into a ranked full-text index. Agents ask in plain words and get short, cited result cards: ~450 tokens per answer at any dataset size, instead of grepping and reading raw history.

Median tokens per question at 1M records: Leviathan 436, grep entity + question words 107K, grep entity history 209K, read all 203M

Median tokens per question vs dataset size Answer rate vs dataset size

Tokens per question vs entity history size Latency vs dataset size

At 1M records (678 MB) Leviathan best grep strategy
Median tokens per question 436 107,122 (245×)
Relevant record returned 99.0% top 5 · 98.5% rank 1 96.0% within a 30K-char output
Worst case (1,200 questions) 602 tokens 9.7M tokens
Median latency 33 ms 92 ms

Measured on a synthetic maintenance log (one example dataset; nothing in Leviathan is specific to it). Methodology, all six scales and caveats: docs/BENCHMARKS.md.

Quickstart

cargo install leviathan-index       # or: cargo install --git https://github.com/elstongun/leviathan
cd examples/tickets && leviathan index
leviathan search -g acme "sso login loop after password reset"
leviathan search · customer C-ACME "Acme Corp" (7 tickets) · query "sso login loop after password reset" · shown 3 of 3 · 24 tickets indexed
[1] T-1001 · 2024-01-08 09:12 · rel 16.9
  Login loops back to sign-in page after password reset
  status: closed · priority: high
  resolution: Cleared stale session cookies on password reset; shipped in 4.2.1. Workaround: clear site data.
  match: Users who reset their password get redirected to the sign-in page again in an endless loop.
...

Prebuilt binaries are on Releases. No runtime dependencies; the index is one SQLite file.

Map your data

Fields are paths (a.b, items[].name); only id is required.

Field Enables
id get, upsert, delete, citations
title / text Card headline (weighted 2×) / searched text (default: all strings)
group / group_name -g scoped search, name resolution, labeled fallback
date --since, --until, recent
filters / display --where facets / fields shown on cards
empty_values / rank.boost Placeholders treated as missing / favor complete records
leviathan init ./export                       # infer a commented leviathan.toml
leviathan index tickets.csv --id "Ticket ID" --group customer_id --date created_at   # or flags
leviathan index -c tickets.toml               # or a config your agent wrote from the schema
leviathan describe                            # fields, groups, filter values, example calls

Any database works through its own CLI; Leviathan never holds credentials:

psql "$DATABASE_URL" -At -c "SELECT row_to_json(t) FROM tickets t" | leviathan index - -c tickets.toml
leviathan index app.db --sql "SELECT * FROM tickets" -c tickets.toml
duckdb -json -c "SELECT * FROM 'events/*.parquet'" | leviathan index - -c events.toml

Builds are atomic and skipped when nothing changed; upsert and delete keep an index fresh. Full reference: docs/CONFIG.md.

Plug it into your agent

CLI + skill (recommended): any agent with a shell can call it. Copy skills/leviathan into ~/.claude/skills/ or paste it into AGENTS.md / .cursor/rules. Costs 0 tokens until used.

MCP (optional): leviathan mcp serves four read-only stdio tools (search, resolve_group, get, describe) whose descriptions include a summary of your dataset (~640 tokens per session). leviathan wrap <claude|cursor|codex|vscode|gemini|windsurf|generic> prints the config.

Commands

Command Does
init / index / upsert / delete Propose a mapping / build / update / remove records
search [-g G] [words] Ranked records (--scope, --where, --since, --until, -n, --offset)
recent [-g G] · resolve <g> · get <id…> · describe Newest · group candidates · full records · index summary
mcp · wrap <agent> MCP server · agent config

Global: --index PATH, --json, --max-chars N. Exit codes: 0 ok (zero hits included), 1 error, 2 bad request, 3 group unknown/ambiguous.

How it works

Records stream into one SQLite file with an FTS5 index. A search resolves the group (exact → name → contains → fuzzy), runs one FTS5 match where group and filter values are indexed tokens (no post-filtering), ranks by BM25 × boosts, and decodes only the top N into capped cards. A record's own group name is excluded from scoped matching, placeholders count as missing, and every answer reports shown N of M so agents can tell "no match" from "no data".

Reproduce the benchmark

python3 -m venv bench/.venv && bench/.venv/bin/pip install -r bench/requirements.txt
bench/.venv/bin/python bench/run_bench.py && bench/.venv/bin/python bench/report.py   # ~30 min, ~4 GB

Index build time and size

Contributing, security, license

See CONTRIBUTING.md (ranking changes need before/after benchmark numbers) and SECURITY.md (read-only, offline, unsafe-free; report privately). Licensed under Apache-2.0; dependencies in THIRD_PARTY.md.

leviathan (elstongun/leviathan)

Searching Database…

这是什么?Leviathan 把你的记录(JSONL、JSON、CSV/TSV、SQLite,或任何数据库 CLI 能导出的东西)变成一个单文件的、带排序的全文搜索索引,让 AI 代理直接拿到能回答问题的少数几条记录,而不用在原始历史记录里 grep。
这是一个数据库,还是构建在我已有数据之上的东西?它本身不是数据库——它会根据你导出的数据构建一个带 FTS5 索引的 SQLite 文件,任何源数据库都可以,只要它自己的 CLI 能导出记录;Leviathan 绝不接触或存储原始数据库的凭据。
怎么把它跑起来?从 GitHub Releases 获取预编译二进制文件,用 init 映射你的字段(只有 id 是必填的),构建索引,然后用 search 查询。
我需要在它旁边运行服务器或其他服务吗?不需要——它没有运行时依赖,整个索引都在一个 SQLite 文件里,Leviathan 只是读取你自己的数据库 CLI 导出的内容。
如果我搜索一个未知或有歧义的分组会怎样?Leviathan 从不瞎猜:未知或有歧义的 -g 值会列出匹配的候选并以退出码 3 退出,而不是默默选一个。
我的数据或源数据库凭据会离开我的机器吗?Leviathan 的设计是只读且离线的,只在它自己构建的本地 SQLite 索引上工作,而且它从不保存其导出来源数据库的凭据。
和 grep 相比,它的速度和 token 效率如何?在一个 100 万条记录的合成基准上,Leviathan 回答问题的中位 token 数为 436、延迟 33ms,而最好的 grep 策略大约需要 107,000 个 token 和 92ms;同时它有 99% 的情况能把相关记录排进前 5 条结果。
搜索结果长什么样?搜索返回简短、带引用的结果卡片(无论数据集多大,每个答案约 450 个 token),按带字段权重的 BM25 排序,每张卡片都会报告“共 M 条中显示 N 条”,让代理能区分“没有匹配”和“没有数据”。
能不从头重建就更新索引吗?可以。upsert 和 delete 会就地更新记录,完整构建是原子性的,而且如果自上次运行以来没有任何变化就会完全跳过。
MCP 模式是做什么用的?运行 leviathan mcp 会为兼容 MCP 的代理暴露四个只读 stdio 工具(search、resolvegroup、get、describe),每个会话只需一次性消耗约 640 个 token 来描述数据集。
Creator
elstongun
Size
1.8 MB
Stars
831
Age
13d
Commits · 90 Days