Skip to content

Use honest NumPy-first vector backends - #39

Merged
CoreyLeath-code merged 13 commits into
mainfrom
agent/honest-vector-backends
Aug 15, 2026
Merged

Use honest NumPy-first vector backends#39
CoreyLeath-code merged 13 commits into
mainfrom
agent/honest-vector-backends

Conversation

@CoreyLeath-code

@CoreyLeath-code CoreyLeath-code commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • Make NumPy/BLAS the default cosine-similarity backend.
  • Keep the C++ ctypes path opt-in for safe FFI/interop demonstration only.
  • Retain pure Python as the NumPy-unavailable degradation path.
  • Add a reproducible three-way benchmark that writes measurements at execution time without checked-in result values.
  • Replace unsupported C++ speed/acceleration language with evidence-bound documentation and placeholders.

Safety and compatibility

  • Preserves cosine_sim(left, right) as the compatibility facade.
  • C++ inputs are coerced to contiguous float64 buffers before pointer passing; unequal dimensions raise ValueError, and uncoercible inputs raise TypeError.
  • No performance result is asserted or hardcoded.

Validation

  • Known-case tests cover NumPy, C++, and Python implementations.
  • Deterministic cross-backend agreement, C++ coercion, dispatch, and vector-benchmark contract tests are included.
  • Green: Lint & Test Engine, HelixAgent Enterprise CI, and HelixAgent Security & Supply Chain.

Summary by CodeRabbit

  • New Features

    • Added NumPy-based vector operations as the default, with optional C++ interoperability and a pure-Python fallback.
    • Added explicit vector backend selection through configuration or function arguments.
    • Added reproducible vector-operation benchmarks with timing metrics and JSON output.
  • Documentation

    • Updated architecture, capability, and performance documentation to reflect backend behavior and evidence-based claims.
  • Bug Fixes

    • Improved vector validation, input handling, and error reporting for unavailable native acceleration.
  • Tests

    • Added coverage for backend agreement, validation, fallback behavior, and benchmark reporting.

@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 95bfaa3c-a97c-4e37-86e7-21a9c86b9f1a

📥 Commits

Reviewing files that changed from the base of the PR and between a98b4ce and 683b609.

📒 Files selected for processing (11)
  • README.md
  • agent/agent_core.py
  • benchmarks/vector_ops.py
  • docs/CLAIMS_MATRIX.md
  • docs/architecture.md
  • docs/metrics.md
  • requirements.txt
  • streamlit_app.py
  • tests/test_benchmark.py
  • tests/test_runtime_invariants.py
  • tests/test_vector_backends.py

📝 Walkthrough

Walkthrough

The runtime now supports NumPy, optional C++ ctypes, and pure-Python cosine-similarity backends. Backend selection is explicit or environment-driven. A deterministic benchmark and evidence-bound architecture documentation were added.

Changes

Vector backend system

Layer / File(s) Summary
Backend contracts, implementations, and validation
agent/agent_core.py, requirements.txt, tests/test_vector_backends.py, tests/test_runtime_invariants.py, streamlit_app.py
The runtime adds NumPy, C++, and pure-Python cosine implementations. The compatibility facade selects NumPy by default, C++ only when requested, and Python when NumPy is unavailable. Tests cover validation, ctypes buffers, backend selection, and numerical invariants.
Deterministic vector benchmark
benchmarks/vector_ops.py, tests/test_benchmark.py
The benchmark measures available backends with deterministic vectors, warmups, repetitions, percentile timings, metadata, Markdown output, and JSON output.
Architecture and evidence documentation
README.md, docs/CLAIMS_MATRIX.md, docs/architecture.md, docs/metrics.md
Documentation describes the Python runtime, NumPy-default vector operations, optional C++ ctypes interop, pure-Python fallback, and reproducible local benchmark scope.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant cosine_sim
  participant NumPyBackend
  participant CppBackend
  participant PythonBackend
  Caller->>cosine_sim: request cosine similarity with backend
  alt NumPy selected or available by default
    cosine_sim->>NumPyBackend: validate and calculate
  else C++ explicitly selected
    cosine_sim->>CppBackend: coerce buffers and calculate through ctypes
  else NumPy unavailable
    cosine_sim->>PythonBackend: validate and calculate
  end
Loading

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/honest-vector-backends

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CoreyLeath-code
CoreyLeath-code marked this pull request as ready for review August 15, 2026 19:19
@CoreyLeath-code
CoreyLeath-code merged commit cc4fa98 into main Aug 15, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant