training-and-compression
This skill teaches a Researcher to train, compose, inspect, and troubleshoot Faiss compressed and binary indexes while preserving codec, dimension, and backend constraints.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- training-and-compression
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- This skill teaches a Researcher to train, compose, inspect, and troubleshoot Faiss compressed and binary indexes while preserving codec, dimension, and backend constraints.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md9.4 KB
- 参考文档references/troubleshooting.md8.2 KB
- 参考文档references/workflows.md9.5 KB
- 脚本scripts/smoke_codecs.py10.9 KB
03 SKILL.md 正文
Training and compression
Use this branch when the request involves training or adding compressed
codes, PQ/SQ/IVF-PQ, residual or additive quantization, RaBitQ, OPQ and
other transforms, PQ fast scan, standalone codecs, reconstruction, code size,
or binary/Hamming indexes. The CPU baseline is the verified Faiss 1.15.0
package (Python >=3.10, NumPy float32 arrays, OPTIMIZE DD AVX2). Treat every
CUDA, cuVS, ROCm, Metal, or SVS claim as conditional until the runtime probe
in the accelerated sibling succeeds.
Route first
- For generic exact-versus-approximate index choice, metrics,
nprobe, and search behavior, read index-selection-and-search. - For
IndexPreTransform, ID ownership, selectors, andIndexRefine*composition, read composition-and-filtering. - For persistence, ground truth, recall measurement, and benchmark/evaluation design, read persistence-and-evaluation.
- For GPU-resident codecs or CPU/GPU transfer, read accelerated-and-interoperable.
This branch owns the codec lifecycle and the compressed representation. It does not choose a general index family, own custom IDs/selectors, or certify optional accelerators.
Operating procedure
-
Normalize the input as a contiguous
float32matrix of shape(n, d)for float indexes, or a contiguousuint8matrix of shape(n, d // 8)for binary indexes. Binary dimension must be a multiple of eight; do not pass unpacked boolean/float bits to anIndexBinary. -
Select a factory or explicit class only after checking the constraints and code-size formulas in api-reference.md. Keep metric and transform dimensions consistent through the whole chain.
-
Keep a representative, finite training sample separate from the database. Call
train(training_vectors)beforeadd(database_vectors)wheneveris_trainedis false. Training data needs enough examples for the coarse centroids and every codec; a small smoke may warn, but production training should not ignore those warnings. -
Add only vectors with the input dimension expected by the outer index. For an IVF codec, Faiss trains the coarse quantizer and encoder as part of the outer lifecycle; do not manually add to an untrained IVF-PQ/SQ index.
-
Search with a deliberately chosen
nprobe(IVF) andk; then measure against an exact baseline before trading bits, subquantizers, or probes. Compression changes recall and reconstructed values even when the API succeeds. -
If a caller needs bytes, use
sa_encode/sa_decodewithuint8arrays of exactlysa_code_size()columns.reconstructand decoded values are approximations for lossy PQ/SQ/RQ/AQ/RaBitQ codecs; they are not the original vectors. RaBitQ'ssa_decodeis suitable for its IP-oriented codec representation but is explicitly not a reliable L2 reconstruction oracle; use its search path for L2. -
For a recall/latency compromise, first improve the candidate set (for example IVF
nprobe), then add a refinement stage owned by the composition sibling. Refinement requires a compatible reconstructable/exact storage choice and must not be used to hide an untrained or dimension-invalid base index. -
Run the bundled no-network check when validating a small configuration:
python /path/to/training-and-compression/scripts/smoke_codecs.py --help python /path/to/training-and-compression/scripts/smoke_codecs.pyIt uses deterministic tiny data and returns nonzero for invalid factory, dimension, metric, or binary input. It is a smoke, not a benchmark.
Fast scan and optional features
PQ/AQ fast scan is a storage/layout specialization, not a replacement for training or recall evaluation. The verified family is 4-bit PQ/AQ with a block size divisible by 32 (default 32); it repacks codes into blocks and may pad the final block. SIMD dispatch can select a different implementation or a scalar fallback. Do not infer that a fast-scan factory is available merely because the host has a GPU or because an unrelated SIMD level is present.
Residual, additive, product-residual, LSQ, and RaBitQ families expose more parameters than the compact examples here. Use the API and workflow tables, then run a tiny CPU trial before adopting one. GPU codec behavior belongs to the accelerated sibling and is unverified by this CPU branch.
Recovery routing
For invalid IVF.../PQ strings, wrong d % M, too few training points,
unsupported fast-scan blocks, bad byte shapes, or reconstruction surprises,
start with troubleshooting.md. Preserve the
original failing configuration and error; repair one constraint at a time.
For a high-level factory replacement route to the index-selection sibling,
for staged refinement route to composition, and for recall/memory evidence
route to persistence-and-evaluation.
Bundled references
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).