Skip to content

Commit 744f4c9

Browse files
napetrovmihaic
andauthored
docs: enhance AGENTS with project context and performance guardrails (#277)
## Summary Follow-up to #276 — adds Intel-specific technical detail and performance guardrails based on code review. ## Changes **Root AGENTS.md** - Add project description, tech stack (C++20, MKL, OpenMP, pybind11) - Add core principle: _performance over simplicity_ in hot paths - Add quick start commands (build/test/Python) - Add directory map for navigation **`.github/copilot-instructions.md`** - Add concrete authoring rules (e.g. don't refactor full files for 2-line changes) - Add contribution expectations: backward compat, pre-commit, regression tests - Expand source-of-truth: explicitly list `mkl.cmake`, `multi-arch.cmake`, `numa.cmake`, `pyproject.toml` - Add negative constraint: no `std::iostream` in perf-critical headers **`include/svs/AGENTS.md`** - Add perf constraints: memory alignment, SIMD dispatch rules, hot path rules - Add failure modes: template instantiation impact, ABI compat **`bindings/python/AGENTS.md`** - Add pybind11 rules: GIL release, dtype/shape validation, memory ownership - Add common failure modes: wrapper sync on C++ signature changes, edge cases, lifetime management **`cmake/AGENTS.md`** - Document Intel-specific modules: `mkl.cmake` (threading), `multi-arch.cmake` (ISA dispatch), `numa.cmake`, `openmp.cmake` - Add guardrail: no removal of optimization flags without benchmark validation **`benchmark/AGENTS.md`** - Add constraints: warmup/iteration stability, dataset provenance, baseline comparisons - Add reporting requirements: median/min/max/stddev **`include/svs/quantization/AGENTS.md`** (new) - Quantization guardrails: type safety, precision bounds, SIMD alignment, codec compat - Common failure modes: float arithmetic in hot paths, misaligned access, codebook sync ## Notes - No mutable details (versions, flags) hardcoded in instruction files - All changes are additive — no policy removed from original PR --------- Co-authored-by: Mihai Capotă <mihai@mihaic.ro>
1 parent 1c02cf4 commit 744f4c9

File tree

7 files changed

+92
-19
lines changed

7 files changed

+92
-19
lines changed

.github/copilot-instructions.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@
33
This file is the canonical instruction set for Copilot behavior in this repository
44
(required flow, precedence, and fallback rules).
55

6-
`AGENTS.md` is reserved for AGENTS-aware tooling context and should not duplicate
7-
Copilot policy text.
6+
`AGENTS.md` provides project context and tech stack overview.
87

98
## Mandatory
10-
1. Read root `AGENTS.md` first.
9+
1. Read root `AGENTS.md` for project context.
1110
2. Read the nearest directory `AGENTS.md` for edited files.
1211
3. If multiple apply, use the most specific.
1312

1413
## Authoring rules
15-
- Keep suggestions minimal and scoped.
14+
- Keep suggestions minimal and scoped (do not refactor entire files for 2-line changes).
1615
- Use source-of-truth files for mutable details.
1716
- Do not invent or hardcode versions/flags/matrices.
17+
- Avoid `std::iostream` in performance-critical headers.
18+
19+
## Contribution expectations
20+
- Preserve backward compatibility for public API (`include/svs/`)
21+
- Prefer additive API evolution (avoid duplication of existing functionality)
22+
- Pair public API changes with tests and documentation
23+
- For bug fixes: add regression tests
24+
- Run `pre-commit run --all-files` before proposing changes
1825

1926
## Source-of-truth files
20-
- `CMakeLists.txt`, `cmake/*.cmake`
21-
- `.github/workflows/`
22-
- `.clang-format`, `.pre-commit-config.yaml`
23-
- `include/svs/`, `bindings/python/`
27+
- Build: `CMakeLists.txt`, `cmake/*.cmake` (incl. `cmake/mkl.cmake`, `cmake/multi-arch.cmake`, `cmake/numa.cmake`)
28+
- Dependencies: `bindings/python/pyproject.toml`, `bindings/python/setup.py`
29+
- CI: `.github/workflows/`
30+
- Style: `.clang-format`, `.pre-commit-config.yaml`
31+
- API: `include/svs/`, `bindings/python/`

AGENTS.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1-
# AGENTS.md
1+
# AGENTS.md — ScalableVectorSearch
22

3-
This file is for AGENTS-aware tools.
3+
## What this project is
4+
High-performance C++ library for vector similarity search at billion scale. Uses Intel MKL, AVX-512/multi-arch SIMD dispatch, quantization, NUMA-aware memory, OpenMP threading. Python bindings via pybind11. Archetype: **C++** (with Python bindings).
45

5-
Scope:
6-
- Tool-specific guidance for AGENTS-aware agents.
7-
- Repository context that is not Copilot-specific.
6+
Tech stack: C++20, Intel MKL, OpenMP, pybind11, CMake.
7+
Core principle: **Performance over simplicity** in hot paths.
88

9-
For Copilot policy (required flow, source-of-truth, fallback rules), see:
10-
- `.github/copilot-instructions.md` (canonical for Copilot behavior)
9+
## How to work
10+
- Backward compatibility is default for public API (`include/svs/`)
11+
- Performance-critical: avoid allocations in hot loops, respect memory alignment
12+
- For SIMD dispatch changes: consult `cmake/multi-arch.cmake` and `include/svs/multi-arch/`
13+
- Python bindings: update `bindings/python/` and ensure GIL release for blocking MKL calls
1114

12-
Do not duplicate Copilot policy here.
15+
## Quick start
16+
Build: `cmake -B build && cmake --build build`
17+
Test: `ctest --test-dir build`
18+
Python: `pip install -e bindings/python/`
19+
20+
## Directory AGENTS files
21+
- `.github/AGENTS.md` — CI/CD
22+
- `benchmark/AGENTS.md` — performance benchmarks
23+
- `bindings/AGENTS.md` — C++/Python bindings (router)
24+
- `cmake/AGENTS.md` — build system
25+
- `include/svs/AGENTS.md` — public C++ API
26+
- `tests/AGENTS.md` — test suite
27+
28+
For Copilot/agent behavior policy: `.github/copilot-instructions.md`

benchmark/AGENTS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ Benchmark harness and performance-eval code.
55
- Keep runs reproducible (inputs/config in repo).
66
- Separate harness changes from algorithm changes when possible.
77
- If shared with tests, validate impacted test targets.
8+
9+
## Performance benchmarking constraints
10+
- **Warmup and iterations:** Do not change warmup rounds or iteration counts without justification. These values are tuned for CI stability.
11+
- **Input datasets:** Use fixed seeds and document dataset provenance. Do not commit large binary datasets without approval.
12+
- **Baseline comparisons:** When adding new benchmarks, provide baseline comparisons against existing algorithms.
13+
- **Reporting:** Report median, min, max, stddev — not just mean. Flag outliers and variance sources (e.g., NUMA effects, Turbo Boost).

bindings/python/AGENTS.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
Python package, extension bindings, and Python-facing behavior.
44

5-
- Source of truth: files under `bindings/python/` (+ cross-check with `CMakeLists.txt`).
5+
- Source of truth: `bindings/python/pyproject.toml`, `setup.py`, `CMakeLists.txt`.
66
- Keep API compatibility by default.
77
- Preserve clear dtype/shape validation and error messages.
88
- Add tests for every user-visible behavior change.
9+
10+
## pybind11 integration
11+
- **GIL release:** For blocking MKL calls or long-running C++ operations, release GIL with `py::call_guard<py::gil_scoped_release>()`.
12+
- **Type validation:** Explicitly validate NumPy dtypes (float32, float64, uint8 for quantized) and shapes before passing to C++.
13+
- **Memory ownership:** Document lifetime expectations for array views vs copies in docstrings.
14+
15+
## Common failure modes
16+
- Forgetting to update pybind11 wrappers when C++ signatures change in `include/svs/`.
17+
- Not testing edge cases: empty arrays, mismatched dtypes, out-of-bounds indices.
18+
- Returning raw pointers without proper lifetime management — use `py::return_value_policy`.

cmake/AGENTS.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,14 @@ Build modules, dependency wiring, and feature toggles.
55
- `CMakeLists.txt` + `cmake/*.cmake` are authoritative.
66
- Keep option names/defaults stable unless task requires change.
77
- Prefer additive options over rewrites.
8-
- Validate option/target changes against CI workflows.
8+
- Validate option/target changes against CI workflows (`.github/workflows/`).
9+
10+
## Intel-specific modules
11+
- **`cmake/mkl.cmake`:** MKL linkage (static vs dynamic threading). Do not hardcode MKL versions. When changing linkage mode, validate threading behavior in tests.
12+
- **`cmake/multi-arch.cmake`:** AVX-512 / SIMD ISA dispatch. Do not hardcode `-march` or ISA flags outside this file. Changes must align with `include/svs/multi-arch/` runtime dispatch code.
13+
- **`cmake/numa.cmake`:** NUMA-aware memory allocation. Respect NUMA topology assumptions in performance-critical code.
14+
- **`cmake/openmp.cmake`:** Threading model. Do not assume specific OpenMP version or runtime without checking source-of-truth.
15+
16+
## Guardrails
17+
- Do not remove optimization flags without justification and benchmark validation.
18+
- Keep CMake minimum version conservative unless a new feature is required across all CI targets.

include/svs/AGENTS.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
Public C++ headers and API contracts.
44

55
- Backward compatibility is default.
6-
- Prefer additive API evolution.
6+
- Prefer additive API evolution (avoid duplicating existing functionality).
77
- Keep headers self-contained and aligned with CMake C++ standard.
88
- Pair public API changes with tests and docs.
9+
10+
## Performance-critical constraints
11+
- **Memory alignment:** Respect alignment requirements for SIMD operations (use SVS-specific allocators).
12+
- **SIMD dispatch:** Changes to `include/svs/multi-arch/` must align with `cmake/multi-arch.cmake` ISA dispatch logic.
13+
- **Hot paths:** Avoid heap allocations, virtual calls, and `std::iostream` in performance-critical code.
14+
- **MKL integration:** Do not hardcode MKL versions or assume threading model; check `cmake/mkl.cmake`.
15+
16+
## Failure modes to avoid
17+
- Adding template instantiations without checking compile-time impact.
18+
- Changing header-only code without validating ABI compatibility.

include/svs/quantization/AGENTS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# AGENTS.md — include/svs/quantization/
2+
3+
Quantization algorithms and data types (scalar quantization).
4+
5+
- **Type safety:** Explicitly validate quantized dtype (uint8, int8, uint16) before operations.
6+
- **Precision:** Changes to quantization schemes must preserve reconstruction error bounds. Document expected accuracy impact.
7+
- **SIMD alignment:** Quantized data structures must respect SIMD lane widths (16/32/64 bytes for AVX-512).
8+
- **Codec compatibility:** Do not break serialization format without versioning and migration path.
9+
10+
## Common failure modes
11+
- Using `float` arithmetic in quantization hot paths (use integer SIMD intrinsics).
12+
- Misaligned memory access in quantized vector loads/stores.
13+
- Forgetting to update codebook when changing quantization levels.

0 commit comments

Comments
 (0)