polyvoice 0.6.9

Speaker diarization for Rust — who spoke when. ONNX-powered: Silero VAD, WeSpeaker embeddings, Pyannote segmentation, K-means/AHC clustering, overlap detection.
Documentation
---
schema_version: 1
kind: module_contract
module: src/kmeans
level: subsystem
layer: algorithm
purpose: >
  Owns k-means++ initialization and iterative clustering. Used by spectral
  clustering and other modules. Does NOT own the Clusterer trait.
status: stable
owners:
  - polyvoice-core
workcell:
  type: leaf
  parent: ""
  children: []
  owns_paths:
    - src/kmeans/
  context_budget:
    max_files: 12
    max_source_lines: 1500
    max_contract_lines: 180
    max_readme_lines: 120
    max_todo_lines: 80
authority:
  write_policy: single_active_write_lease
  orchestrator: polyvoice-core
  read_agents: many_allowed
  migration_lease_required:
    - cross-workcell write
    - public surface migration
surface:
  - name: kmeans_pp
    kind: function
    visibility: public
    contract: >
      K-means++ clustering: smart initialization + iterative Lloyd refinement.
      Returns cluster labels.
    proof:
      kind: unit-test
      target: src/kmeans::mod::tests
      command: cargo test --lib kmeans
dependencies:
  internal: []
  external: []

consumers:
  - path: src/spectral/mod.rs
    uses:
      - kmeans_pp
invariants:
  - id: labels-contiguous
    rule: Output labels are in 0..k.
    proof:
      kind: unit-test
      target: src/kmeans::mod::tests
      command: cargo test --lib kmeans
  - id: empty-input-empty-output
    rule: Empty embeddings input returns empty labels.
    proof:
      kind: unit-test
      target: src/kmeans::mod::tests::empty_input_returns_empty
      command: cargo test --lib kmeans
  - id: well-separated-clusters
    rule: Well-separated clusters are correctly grouped.
    proof:
      kind: unit-test
      target: src/kmeans::mod::tests::well_separated_clusters
      command: cargo test --lib kmeans
  - id: property-labels-range
    rule: For any valid embeddings and k, all labels are in 0..k.min(n).
    proof:
      kind: unit-test
      target: tests/property_kmeans_test.rs::labels_in_range
      command: cargo test --test property_kmeans_test
  - id: property-k-one
    rule: For k=1, all labels are 0.
    proof:
      kind: unit-test
      target: tests/property_kmeans_test.rs::k_one_all_zero
      command: cargo test --test property_kmeans_test
verification:
  pre_change:
    - cargo test --lib kmeans
  full:
    - cargo test --lib kmeans
    - cargo clippy --all-targets --all-features -- -D warnings
agent_policy:
  allowed_mutations:
    - Tuning convergence criteria.
    - Optimizing distance computations.
  forbidden_mutations:
    - Changing kmeans_pp signature without updating spectral.rs.
  escalation:
    - Changes to output semantics or signature.
---

# src/kmeans

K-means++ clustering algorithm.