Skip to main content

High-performance NLP primitives for the Kelvin Agentic OS — SIMD string ops, multi-pattern matching, FST dictionaries, sentence segmentation, BM25 retrieval, fuzzy hashing

Project description

kaos-nlp-core

Part of Kelvin Agentic OS (KAOS) — open agentic infrastructure for legal work, built by 273 Ventures. See the full KAOS package map for the rest of the stack.

PyPI - Version Python License CI

kaos-nlp-core is a high-performance NLP primitives library for KAOS — a pure-Rust core with Python bindings via PyO3/Maturin. It provides the text-processing building blocks the rest of the stack relies on: SIMD-accelerated string operations, multi-pattern matching, finite-state transducers, sentence segmentation, BM25 retrieval, fuzzy hashing, and typed Python wrappers throughout.

It is dependency-light: the BASE install pulls only kaos-nlp-core itself plus the bundled Punkt sentence-segmenter model (~12 MB). Optional extras layer in the rest of the KAOS ecosystem.

Install

uv add kaos-nlp-core
# or
pip install kaos-nlp-core

kaos-nlp-core requires Python 3.13 or newer. The published wheels are cp313-abi3 — one wheel per OS/architecture covers every CPython 3.13+ minor (3.13, 3.14, 3.15, …). No re-release needed when 3.15 ships.

Platform coverage: Linux x86_64 (manylinux + musllinux), Linux aarch64 (manylinux + musllinux), macOS arm64, Windows x86_64, Windows arm64.

Quick start

from kaos_nlp_core import tokenizer, algorithms

# SIMD-accelerated tokenization
tokens = tokenizer.tokenize_words("kaos-nlp-core ships fast NLP primitives.")
print([t.text for t in tokens])

# String similarity
result = algorithms.levenshtein("kitten", "sitting")
print(result.distance)  # 3

# Multi-byte safe (CJK, emoji, etc.)
spans = tokenizer.tokenize_spans("東京 emoji 😀 test")
for span in spans:
    print(f"{span.start}-{span.end}: {span.text!r}")

Concepts

The package is organized around a small set of typed primitives.

Concept What it is
Algorithms kaos_nlp_core.algorithms — Levenshtein, Hamming, Jaro-Winkler, longest common substring, edit-distance variants. SIMD fast paths via stringzilla; ASCII fast paths before Unicode fallbacks.
Tokenizer kaos_nlp_core.tokenizer — Unicode-aware word/sentence tokenization with byte→char offset translation via build_byte_to_char_table(). Multi-byte safe (Latin diacritics, CJK, emoji).
Segmentation kaos_nlp_core.segmentation — Punkt sentence segmenter (bundled model models/default.npkt.gz, ~12 MB Apache-2.0 NLTK port).
Matching kaos_nlp_core.matching — Aho-Corasick multi-pattern matching, FST-backed fuzzy lookup via Levenshtein automata, regex.
Search kaos_nlp_core.search — BM25 retrieval, Searcher, sentence/paragraph search; pickle-safe with KNC magic header for index files.
Structures kaos_nlp_core.structuresVocabulary, InvertedIndex, SparseTermMatrix, SimilarityMatrix. Compact, pickle-safe, bincode-2.0 backed.
Hashing kaos_nlp_core.hashing — CTPH (context-triggered piecewise hashing) via blake3, MinHash, LSH index, near-duplicate grouping.
Lexicon kaos_nlp_core.lexicon — query expansion, semantic graph traversal, gazetteer lookups.
Documents kaos_nlp_core.documentsDocument, DocumentCollection with JSONL / HuggingFace loaders.
Quality kaos_nlp_core.quality — text-quality heuristics (token ratios, Unicode block distribution).

CLI

kaos-nlp-core ships a kaos-nlp administrative CLI plus an optional kaos-nlp-serve MCP server (loopback-only by default; --http requires KAOS_NLP_HTTP_TOKEN as an operator acknowledgement that a reverse proxy is fronting authentication):

kaos-nlp tokenize doc.txt --lowercase --json          # word tokenization with spans
kaos-nlp segment doc.txt --mode sentences             # sentence segmentation (Punkt)
kaos-nlp compare "Robert" "Rupert" --algorithm jaro-winkler
kaos-nlp find "pattern" doc.txt --case-insensitive    # SIMD substring search
kaos-nlp index build corpus.txt --output idx.kncidx   # native persisted index
kaos-nlp search --index idx.kncidx "query terms"      # ranked search (BM25 default)
kaos-nlp hash doc.txt --algorithm ctph                # fuzzy hash
kaos-nlp duplicates ./corpus/ --threshold 0.5         # near-duplicate detection
kaos-nlp encode "Robert" --algorithm soundex          # phonetic encoding
kaos-nlp vocab build doc.txt --type frequency         # build vocabulary
kaos-nlp analyze doc.txt --json                       # text statistics report

kaos-nlp-serve            # MCP server, stdio transport
kaos-nlp-serve --http     # MCP server, streamable HTTP (operator-token gated)

Every command supports --json for machine-readable output. CLI search reads both the native persisted index format (KNC) and legacy .json bundles.

Note: 11 MCP tools are registered by register_nlp_tools() and become available with pip install kaos-nlp-core[mcp] once the kaos-mcp companion package publishes (planned for 0.1.0a2). Until then, kaos-nlp-serve exits with an actionable install hint if kaos-core or kaos-mcp are missing.

Compatibility & status

Aspect
Python 3.13, 3.14 (informational matrix entries for 3.14t free-threaded and 3.15-dev). One cp313-abi3 wheel per OS/arch covers all 3.13+ minors.
OS Linux (manylinux + musllinux, x86_64 + aarch64), macOS arm64, Windows x86_64, Windows arm64. macOS x86_64 deliberately skipped (Apple ended Intel sales in 2023).
Maturity Alpha. The public API is documented in kaos_nlp_core.__all__.
Stability policy Pre-1.0: minor bumps may change behaviour. Every change is documented in CHANGELOG.md.
Test coverage 298 Rust unit tests + Python pytest suite. Round-trip offset tests cover ASCII, multi-byte Latin, CJK, and emoji.
Type checker Validated with ty, Astral's Python type checker.

Companion packages

kaos-nlp-core is one of the packages in the Kelvin Agentic OS. The broader stack:

Package Layer What it does
kaos-core Core Foundational runtime, MCP-native types, registries, execution engine, VFS
kaos-content Core Typed document AST: Block/Inline, provenance, views
kaos-mcp Bridge FastMCP server, kaos management CLI, MCP resource templates
kaos-pdf Extraction PDF → AST with provenance
kaos-web Extraction Web extraction, browser automation, search, domain intelligence
kaos-office Extraction DOCX / PPTX / XLSX readers + writers to AST
kaos-tabular Extraction DuckDB-powered SQL analytics
kaos-source Data Government + financial data connectors (Federal Register, eCFR, EDGAR, GovInfo, PACER, GLEIF)
kaos-llm-client LLM Multi-provider LLM transport
kaos-llm-core LLM Typed LLM programming (Signatures, Programs, Optimizers)
kaos-nlp-core Primitives (Rust) High-performance NLP primitives
kaos-nlp-transformers ML Dense embeddings + retrieval
kaos-graph Primitives (Rust) Graph algorithms + RDF/SPARQL
kaos-ml-core Primitives (Rust) Classical ML on the document AST
kaos-citations Legal Legal citation extraction, resolution, verification
kaos-agents Agentic Agent runtime, memory, recipes
kaos-reference Sample Reference module for module authors

Packages depend on kaos-core; everything else is opt-in. Mix and match the ones you need.

Development

git clone https://github.com/273v/kaos-nlp-core
cd kaos-nlp-core
uv sync --group dev
uv run maturin develop --release

Install pre-commit hooks (recommended — they run the same checks as CI on every commit, scoped to staged files):

uvx pre-commit install
uvx pre-commit run --all-files     # one-time full sweep

Manual QA commands (the same set CI runs):

cargo fmt --check
cargo clippy --no-default-features --all-targets -- -D warnings
cargo test --no-default-features --lib
uv run ruff format --check python/kaos_nlp_core tests
uv run ruff check python/kaos_nlp_core tests
uv run ty check python/kaos_nlp_core tests
uv run pytest tests/

Build from source

uv build
uv pip install dist/*.whl

Contributing

Issues and pull requests are welcome. By contributing you certify the Developer Certificate of Origin v1.1 — sign every commit with git commit -s. Please open an issue before starting on a non-trivial change so we can align on scope.

Security

For security issues, please do not file a public issue. Report privately via GitHub Private Vulnerability Reporting or email security@273ventures.com. See SECURITY.md for the full disclosure policy.

License

Apache License 2.0 — see LICENSE and NOTICE.

Copyright 2026 273 Ventures LLC. Built for kelvin.legal.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kaos_nlp_core-0.1.0a1.tar.gz (58.8 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

kaos_nlp_core-0.1.0a1-cp313-abi3-win_arm64.whl (48.6 MB view details)

Uploaded CPython 3.13+Windows ARM64

kaos_nlp_core-0.1.0a1-cp313-abi3-win_amd64.whl (48.8 MB view details)

Uploaded CPython 3.13+Windows x86-64

kaos_nlp_core-0.1.0a1-cp313-abi3-musllinux_1_2_x86_64.whl (49.9 MB view details)

Uploaded CPython 3.13+musllinux: musl 1.2+ x86-64

kaos_nlp_core-0.1.0a1-cp313-abi3-musllinux_1_2_aarch64.whl (49.1 MB view details)

Uploaded CPython 3.13+musllinux: musl 1.2+ ARM64

kaos_nlp_core-0.1.0a1-cp313-abi3-manylinux_2_28_x86_64.whl (49.6 MB view details)

Uploaded CPython 3.13+manylinux: glibc 2.28+ x86-64

kaos_nlp_core-0.1.0a1-cp313-abi3-manylinux_2_28_aarch64.whl (48.9 MB view details)

Uploaded CPython 3.13+manylinux: glibc 2.28+ ARM64

kaos_nlp_core-0.1.0a1-cp313-abi3-macosx_11_0_arm64.whl (49.0 MB view details)

Uploaded CPython 3.13+macOS 11.0+ ARM64

File details

Details for the file kaos_nlp_core-0.1.0a1.tar.gz.

File metadata

  • Download URL: kaos_nlp_core-0.1.0a1.tar.gz
  • Upload date:
  • Size: 58.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kaos_nlp_core-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 58b3d12fb72ada18328195b17a3b61591376b0baa522f324b8d11bdda9a178f1
MD5 c27ac952c08a554b19feb737b088457b
BLAKE2b-256 f9eb4f0cc885da63f0a937a0a192378407c87620a280efd568f3492d149fa058

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaos_nlp_core-0.1.0a1.tar.gz:

Publisher: release.yml on 273v/kaos-nlp-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kaos_nlp_core-0.1.0a1-cp313-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for kaos_nlp_core-0.1.0a1-cp313-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 311e6b59c769c6d13d24eee00a6bda28b9c37ec8beebe5d3fdc119046a8cc218
MD5 b4d54aeafa1f8b3c73004796b7fd5d97
BLAKE2b-256 23d957c6f00bbcb7cc30eb550ee56cd221462ef36f4bfd76899fde274c6813d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaos_nlp_core-0.1.0a1-cp313-abi3-win_arm64.whl:

Publisher: release.yml on 273v/kaos-nlp-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kaos_nlp_core-0.1.0a1-cp313-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for kaos_nlp_core-0.1.0a1-cp313-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ead76f08082069de5aae1ff98d553a0df7ad7516cb80656d840eab763ed9cdb8
MD5 dcc64f3ecd58482e7e33ef25b5d0bc41
BLAKE2b-256 02a09fb5d43333a6f11aa2c7b0ebefa31fd25c61e8a285fec49b561b653fc20f

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaos_nlp_core-0.1.0a1-cp313-abi3-win_amd64.whl:

Publisher: release.yml on 273v/kaos-nlp-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kaos_nlp_core-0.1.0a1-cp313-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for kaos_nlp_core-0.1.0a1-cp313-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 964d7f22286a2910763e00c8753f844780af47ef5a17755db43317afad283567
MD5 915f1c1910569699983767e4ba30952c
BLAKE2b-256 a0542a8b8393f723ecc37f3015899efb14fa7c4485fee297d91b482f906a5173

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaos_nlp_core-0.1.0a1-cp313-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on 273v/kaos-nlp-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kaos_nlp_core-0.1.0a1-cp313-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for kaos_nlp_core-0.1.0a1-cp313-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 515bb0f91ef7ae13f987cbb2383f347233e8c261f56d0dab68935a73908c0a6b
MD5 44f84fa759e45bba50a28d57f1005d06
BLAKE2b-256 23944459176bb7a294069322bfc8928c3c25bcd23dab68309ff32e51ed874ecb

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaos_nlp_core-0.1.0a1-cp313-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on 273v/kaos-nlp-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kaos_nlp_core-0.1.0a1-cp313-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kaos_nlp_core-0.1.0a1-cp313-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f4c803a36b17262cb6ab8b486310efd55329d9c71f86b5769c4a43755d065231
MD5 c3d9f3f7926d5fb0886ac528ebad86ab
BLAKE2b-256 b5c9a7e27fa1bd055efee0ca655abfb8ccedece78abc71a597bd8d68213e624f

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaos_nlp_core-0.1.0a1-cp313-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on 273v/kaos-nlp-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kaos_nlp_core-0.1.0a1-cp313-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for kaos_nlp_core-0.1.0a1-cp313-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4732a04e4b9eaad9efaccd244e8597e8ce482cd8bd90574d4a999b34f4aae3c0
MD5 415444d068229312acdebe0f106a1e4d
BLAKE2b-256 d58a7da31699e43af26ef91cf66aafb2ed3cd1801bb31c8e686e282c744a5eb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaos_nlp_core-0.1.0a1-cp313-abi3-manylinux_2_28_aarch64.whl:

Publisher: release.yml on 273v/kaos-nlp-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kaos_nlp_core-0.1.0a1-cp313-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kaos_nlp_core-0.1.0a1-cp313-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 133be9540acc453f9348ad94a32f7cc34a579b869ee30af6a7f1203efa6b24de
MD5 7e04c22098b39e668e68f0ed23e0a5a1
BLAKE2b-256 99872d2662ddadfdf0a76fbec26eb01613acda405c843482ed66ac3eecba3b41

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaos_nlp_core-0.1.0a1-cp313-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on 273v/kaos-nlp-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page