composition-and-filtering
This skill teaches a Researcher to compose Faiss indexes, preserve external IDs and child lifetimes, apply selectors and per-search parameters, and choose safe shard, replica, refinement, and IVF inspection workflows.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- composition-and-filtering
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- This skill teaches a Researcher to compose Faiss indexes, preserve external IDs and child lifetimes, apply selectors and per-search parameters, and choose safe shard, replica, refinement, and IVF inspection workflows.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md9.4 KB
- 参考文档references/troubleshooting.md6.9 KB
- 参考文档references/workflows.md7.7 KB
- 脚本scripts/smoke_composition.py7.1 KB
03 SKILL.md 正文
Composition and filtering
Use this branch when a working Faiss index must be wrapped, filtered, refined, sharded, replicated, assigned external IDs, deleted by ID, or inspected through IVF metadata. It owns composition order, label translation, selector routing, child ownership, direct-map prerequisites, and per-query parameter overrides. It does not choose the base index family, codec, persistence format, or optional accelerator.
Route first
- For metric, dimension, exact/approximate family, factory strings, ordinary
nprobe, and baseline search behavior, read index-selection-and-search. - For training, transforms used as codecs, PQ/SQ/RQ/AQ, code sizes, fast scan, and lossy reconstruction, read training-and-compression.
- For serialization, merge/persistence constraints, ground truth, recall, or evaluation, read persistence-and-evaluation.
- For RPC/network, C/C++ interop, CUDA, cuVS, ROCm, Metal, SVS, or GPU transfer, read accelerated-and-interoperable.
Operating procedure
-
Draw the data-flow before constructing anything. The outermost wrapper sees caller vectors and queries; each
IndexPreTransformapplies its transform chain in order;IndexIDMap/IndexIDMap2translates inner positions to caller IDs; IVF performs coarse assignment then list scanning;IndexRefineasks its base index for candidates and its refine index for final distances. Search parameters must be wrapped to match that same nesting order. -
Make the ID policy explicit. Use
add_with_ids(x, ids)for stable external labels; do not calladd()on anIndexIDMap*.IndexIDMap2adds an external-ID reverse map and supports external-IDreconstructwhen the wrapped index can reconstruct. A selector passed at the outer ID map is translated to inner positions. Verify that IDs are unique in a logical corpus; shards withsuccessive_ids=Falsedo not prevent cross-shard ID collisions. -
Keep child objects alive. Python wrappers retain constructor children and children added through
add_shard/addIndexinreferenced_objectsfor the supported classes. Still retain references yourself when assigning raw pointer fields, replacing quantizers, or using custom extensions. Never delete or mutate a quantizer, transform, selector backing array, or refine child while a search can use it.own_fieldsis a C++ ownership flag, not a substitute for understanding Python SWIG references. -
Choose composition order deliberately. Put a transform outside the index whose stored/search space it should change. Put an ID map outside the storage whose results need external labels. Put refinement outside the candidate index and add the same vectors to base and refine storage through the refinement wrapper. For a transformed refinement search, use
SearchParametersPreTransform(index_params=...)when the inner parameter object must cross the transform; useIndexRefineSearchParametersfork_factorandbase_index_params. -
For IVF filtering, create an
IDSelectorin the same ID namespace as the parameter recipient. UseIDSelectorRangefor a contiguous interval,IDSelectorBatchfor a set,IDSelectorBitmapfor a dense bounded mask, andIDSelectorAnd/Or/XOr/Notfor boolean composition. Put the selector inSearchParametersIVF(sel=selector)(or the appropriate base parameter class), not in a global mutable setting. Check support for the concrete index: selector behavior is not a promise that every backend or wrapper accepts every selector type. -
Override IVF search per call with
SearchParametersIVF:nprobecontrols lists,max_codesbounds work,max_lists_numlimits fast-scan list visits,ensure_topk_fullsoftens small post-selector budgets, andmax_empty_result_bucketstrades range-search recall for early stopping.quantizer_paramsroutes parameters to a parameterized coarse quantizer. Compare against an unfiltered/unbounded baseline before interpreting a recall change. -
Use direct maps only for a declared need.
IndexIVF.reconstruct(id)andupdate_vectorsrequire a maintained direct map; callmake_direct_map()orset_direct_map_type(...)before those operations. Direct maps add memory and impose ID/merge constraints;search_and_reconstructcan avoid a direct map for supported IVF paths. An ID map does not make an arbitrary lossy or non-reconstructable child reconstructable. -
Select shards versus replicas by semantics: shards partition stored vectors and merge candidates; replicas hold the same logical corpus and distribute query work. Keep dimensions, metrics, training state, and ID policy aligned. For implicit shard IDs, use
successive_ids=True; for explicit IDs usesuccessive_ids=Falseand prove global uniqueness. Do not use replicas to deduplicate conflicting IDs or to merge independently trained incompatible indexes. -
For advanced IVF tooling, prefer read-only inspection of
nlist, list sizes, quantizer state,direct_map.type, andntotal. Preassigned add/search and quantizer replacement are expert-only operations: validate dimensions, list assignments, ownership, and trained state first. Do not expose raw inverted-list mutation, network/RPC, or destructive merge operations in a default smoke. -
Run the bundled deterministic check from any directory:
python /path/to/composition-and-filtering/scripts/smoke_composition.py --help python /path/to/composition-and-filtering/scripts/smoke_composition.pyIt validates external-ID translation/deletion, a transformed refinement chain, a selector route, and safe IVF metadata inspection. It is a CPU smoke, not a performance or backend certification.
Recovery routing
Start with troubleshooting.md for stale or translated labels, deleted-child crashes, incorrect parameter nesting, empty filtered results, failed reconstruction, shard collisions, or refinement mismatches. Route a wrong base family or metric to the index-selection sibling, codec/training errors to training-and-compression, persistence/merge/evaluation to persistence-and-evaluation, and backend/network behavior to accelerated-and-interoperable.
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).