# Repository Briefing: zellige-ai/basinkv
> Source: https://repoforai.com/repo/zellige-ai/basinkv (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/zellige-ai/basinkv
- **Official Docs / Website**: https://zellige.ai
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Python
- **License**: See repository
- **Engineering Health**: B+ (71/100 · Maintenance 35/35 · Adoption 10/25 · Releases 20/20 · License 6/20)
- **Latest Release**: v0.1.1 (2026-12-03) — https://github.com/zellige-ai/basinkv/releases
- **Review Snapshot**: 2026-12-03 (Note: v0.1.1 on 2026-12-03 shipped after this review; verify latest release notes)
- **Deployment / Stack Signals**: Self-Hosted, GPU, CLI
- **Momentum**: 177 ★ total (+45 24h / +45 7d) · 13 forks
- **When to Use**: Best for: Self-hosted NVIDIA GPU long-context serving where dense KV exhausts VRAM, or vLLM V1 deployments that explicitly need RAM/NVMe prefix reuse without patching the engine. Skip if: The model uses MLA, your workload requires exact full-history attention or stock KV already meets the target, or you need sparse decode but cannot maintain engine patches.

## Overview
```text
### Architecture & Core Mechanics
BasinKV extends existing inference engines rather than replacing the serving stack. Its sparse decode path keeps a fixed GPU working set per full-attention head: attention-sink blocks, retrieved blocks, and a ring of recent tokens share static pages managed by `src/oasiskv/pool.py`. Full KV history is offloaded to pinned host RAM or NVMe. The selector scores evicted blocks on the GPU and prefetches selected blocks over PCIe while earlier layers compute. Static buffer shapes let the engine retain its stock FlashAttention or FlashInfer decode kernels and CUDA graphs on supported paths.

The implementation separates block selection (`selector.py`), the CUDA SphereIndex (`sphere_index_cuda.py`), host KV encoding (`wht_int4_kv.py`), and persistent prefix reuse (`prefix_cache.py`). Integration depth differs by engine: llama.cpp and SGLang use pinned wiring patches, whereas vLLM V1 loads an out-of-tree `KVConnectorBase_V1` plugin for Mode 1 prefix caching. Mode 2 sparse decode is a separate path requiring three upstream hooks. The distribution is named `basinkv`, while v0.1 retains the `oasiskv` namespace in code and launch flags.

### Key Capabilities & Differentiators
The model matrix covers dense GQA/MHA and selected recurrent or sliding-window attention hybrids. Verified paths include Qwen models and Gemma 4 E4B on llama.cpp and SGLang, and Granite 4.0 H Micro state caching on vLLM 0.34.0. vLLM Mode 1 can persist hybrid state alongside attention KV, preserving the recurrent state losslessly at exact token boundaries. Compatibility is engine-specific: Inkling 2 Mini is live-verified on llama.cpp, wired and kernel-tested on SGLang with caching off, and planned for vLLM. MLA models are rejected at initialization across all three engines.

The sparse path supports Quest selection, SphereIndex, and one-hop successor co-fetch for cues spanning block boundaries. In a BF16 Qwen3.8-27B partial-RoPE ablation, setting `alpha` to 0.25 raised per-step top-8 recall from 29.9% with unweighted Quest to 95.5% and recovered 5/5 128K RULER cases from 0/5. On an A100-80GB PCIe, llama.cpp decoded Qwen3.6-35B-A3B Q4_K_M at 256K at 141.12 tok/s versus 95.01 tok/s stock, with 22.4 GiB versus 31.5 GiB measured VRAM. These are results for specific model, engine, and hardware combinations, not general throughput or quality guarantees.

### Trade-offs & Limitations
Stock dense attention avoids block selection and host transfers. Prefer it when KV already fits at the target concurrency and predictable latency or full-history attention matters more than VRAM savings. Native FP8 KV is an intermediate baseline where available: it reduces GPU residency without introducing sparse retrieval. BasinKV trades resident KV for GPU index memory, host capacity, and PCIe traffic. Prefetch can overlap with compute, but weights, index memory, and prefill allocations remain outside the fixed KV-page budget. In llama.cpp, hot slabs and indexes also scale with `-np`.

Start with Quest and INT8 host KV when retrieval quality matters most. Move to SphereIndex with WHT-INT4 when host RAM, NVMe capacity, or GPU index memory is the binding constraint, and retest quality on your workload. Dense models such as Qwen3-8B and Llama 3 can warrant 4,096 resident tokens instead of 2,048. Evaluate retrieval and task accuracy together with time to first token and tail latency under concurrency: passkeys and decode throughput alone do not establish production parity. The patched paths also carry an upgrade burden that the vLLM Mode 1 connector avoids, at the cost of not offering sparse decode.

### Hardware & Deployment Guide
This is a self-hosted stack targeting Linux with Python 3.10 or later and CUDA-capable NVIDIA GPUs for the sparse serving paths. For llama.cpp, pin commit `ca123ba76311290ec6ab041dd2058fed8d9f03d2`, run `integrations/llamacpp/apply_llamacpp_wiring.py`, and build the CUDA targets with CMake. SGLang uses editable installs and `integrations/sglang/apply_wiring.py` against pinned commit `a3f0bff5babfe18d3862e134449cd8fd11fcb84a`; the sparse launch selects `--attention-backend oasiskv` and disables RadixCache. The supplied SWA hybrid preset also leaves prefix caching off and does not use MTP.

For unmodified vLLM V1, install `basinkv` or use an editable checkout, disable native prefix caching in the supplied setup, and pass `OasisKVConnector` through `--kv-transfer-config`. Start with explicit RAM and NVMe budgets and choose the KV encoding deliberately: the sample mixed-tier preset uses INT8, while the connector defaults to WHT-INT4. The package manifest identifies version 0.1.0 as Beta, and no GitHub release is listed. Treat the pinned checkouts and verified vLLM configurations as the starting point for upgrade testing rather than assuming compatibility with newer engine versions.
```

## Key Capabilities
```text
- GPU residency: Static pages hold sink, retrieved, and recent KV; the default budget is 2,048 tokens per full-attention head.
- Block index: SphereIndex uses a WHT-rotated INT4 centroid and separate RoPE and non-RoPE radii; metadata occupies 136 bytes per block at head dimension 256.
- Host compression: WHT-INT4 stores each K or V vector in D/2 + 4 bytes, using 3.88× less space than BF16 at D = 256.
- Boundary retrieval: One-hop successor score propagation lets the next block compete for a top-k slot when a cue crosses a block boundary.
- Integration boundary: Sparse decode uses pinned patches for llama.cpp and SGLang; unmodified vLLM V1 exposes prefix caching through OasisKVConnector.
- Measured concurrency: SGLang on one H100-80GB reached 470.4 tok/s versus 358.0 tok/s with stock FP8 KV for Qwen3.8-27B-FP8 at 16 × 64K, recovering 16/16 passkeys.
```

## Quick Start / Clone
```bash
pip install basinkv   # or `pip install -e .` from a checkout; registers the vLLM plugin entry point

# Qwen3-8B, RAM + NVMe tiered prefix cache (verified on vLLM 0.19.1)
vllm serve Qwen/Qwen3-8B --no-enable-prefix-caching --kv-transfer-config '{
  "kv_connector": "OasisKVConnector",
  "kv_role": "kv_both",
  "kv_connector_extra_config": {
    "cache_mode": "mixed", "pcie_quant": "int8",
    "prefix_cache_dir": "/tmp/basinkv_cache",
    "prefix_cache_ram_gb": 4.0, "prefix_cache_nvme_gb": 32.0
  }
}'

# Gemma 4 / Gemma 3 multi-group SWA + full attention (SupportsHMA, verified on vLLM 0.34.0)
vllm serve google/gemma-4-26B-A4B-it --no-enable-prefix-caching --kv-transfer-config '{
  "kv_connector": "OasisKVConnector",
  "kv_role": "kv_both",
  "kv_connector_extra_config": {
    "cache_mode": "nvme", "pcie_quant": "wht_int4",
    "prefix_cache_dir": "/tmp/basinkv_cache_gemma4", "prefix_cache_
```
