Skip to main content

A high-performance C++ accelerated vector score fusion engine.

Project description

CosineFusion 🚀

Build Status License: MIT Python Version C++17

Overvieww

CosineFusion is a hardware-accelerated, high-performance cosine similarity engine that seamlessly bridges C++17 and Python using pybind11. By executing intense linear algebra routines directly on compiled binaries, CosineFusion bypasses the Python interpreter's performance bottlenecks, delivering bare-metal speed for matrix matching, AI embeddings, and content recommendation pipelines.


🔥 Key Features

  • Bare-Metal Performance: High-speed C++ back-end optimized for vector and matrix calculations.
  • Universal2 Multi-Chip Support: Natively compiled to support both Intel (x86_64) and Apple Silicon M-Series (arm64) Mac architectures out of the box with zero manual configuration.
  • Seamless Python Binding: Exposes highly optimized native bindings directly to Python workflows using pybind11.
  • Production-Grade Architecture: Restructured using the standard Python src-layout to ensure strict dependency separation, clean imports, and absolute deployment stability.

🎯 Use Cases & Applications

  • Enterprise Recommender Systems: Instantaneous user-to-item feature matrix matching for e-commerce or media content streaming.
  • Personalization Engines: Real-time scoring based on multi-dimensional user preference vectors.
  • Fast Similarity Search: Sub-millisecond similarity scoring for AI/ML feature embedding matching.

💻 Installation

Option 1: Direct from PyPI (Recommended Production Method)

Install the pre-compiled, optimized universal wheels directly from the global package registry:

pip install cosinefusion

Option 2: Local Development Setup

If working from source, clone the repository and build the native extensions locally:

git clone [https://github.com/RoughneckCoder/CosineFusion.git](https://github.com/RoughneckCoder/CosineFusion.git)
cd CosineFusion
pip install pybind11
pip install .

⚡ Usage Example

import numpy as np
import core_init

# Example item features
items = np.array([
    [0, 1, 0, 0, 1], # Tea
    [0, 1, 0, 0, 1], # Coffee
    [1, 0, 1, 1, 0], # Jaffa Cake
    [1, 0, 1, 0, 0], # Biscuit
    [1, 0, 1, 1, 1], # Chocolate Bar
    [0, 1, 0, 0, 1], # Espresso
])

item_names = ["Tea", "Coffee", "Jaffa Cake", "Biscuit", "Chocolate Bar", "Espresso"]

# User likes sweetness and chocolate
user = np.array([[0, 0, 0, 1, 0]]) 

# Executes natively on the underlying hardware (Intel or Apple Silicon)
res = core_init.cosine_similarity(user, items)
sim = res["similarity_matrix"]

top_indices = np.argsort(sim[0])[::-1]
print("Top recommendations for user:")
for i in top_indices:
    print(f"{item_names[i]}: {sim[0][i]:.2f}")

Sample Output:

Top recommendations for user:
Chocolate Bar: 0.89
Jaffa Cake: 0.75     <- Accurately indicates structural sweet-matrix alignment
Biscuit: 0.65
Tea: 0.45
Coffee: 0.45
Espresso: 0.43

🏗️ Hardware Architecture & Multi-Chip Targeting

To maximize cross-platform utility, the build pipeline leverages fat multi-architecture binary compilation. When deploying the package via pip install, the distribution system automatically delivers a native Universal2 binary.

This ensures that the underlying C++ extension automatically executes instructions matched perfectly to the host machine's physical CPU:

  • Apple Silicon (M1/M2/M3/M4 chips): Executes native ARM64 instructions.
  • Intel Processors: Executes native x86_64 instructions.

🧪 Testing

The repository includes an automated verification suite to guarantee mathematical accuracy and cross-platform compatibility. Run tests using pytest:

python -m pytest -v

📁 Project Structure

CosineFusion/
 ├── src/
 │    ├── cpp/
 │    │    └── core_init.cpp     # High-performance C++ core engine
 │    └── python/
 │         └── core_demo.py     # Functional verification demo
 ├── tests/
 │    └── test_bridge.py        # Automated PyTest matrix suite
 ├── setup.py                   # Pybind11 / Universal2 compilation configuration
 ├── pyproject.toml             # Standard modern build-system requirements
 ├── README.md                  # Project documentation
 ├── LICENSE                    # MIT License open-source file
 └── requirements.txt           # Environment dependencies

📄 License

This project is licensed under the MIT License — see the LICENSE file for details.


Author: Sam Chaudry

GitHub: RoughneckCoder

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cosinefusion-0.1.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cosinefusion-0.1.1-cp311-cp311-macosx_10_9_universal2.whl (146.3 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file cosinefusion-0.1.1.tar.gz.

File metadata

  • Download URL: cosinefusion-0.1.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for cosinefusion-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8bcc60a2e98060983327df5cb5d630dc0182a0553148d84e42ce0932c4a117ce
MD5 5191a0e82ce318b4676d1956d01be73b
BLAKE2b-256 840d63506626dc037f915e1bfc8fb8e1cb205ff30053395c2a5b01a63bd5c5c0

See more details on using hashes here.

File details

Details for the file cosinefusion-0.1.1-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for cosinefusion-0.1.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4c55fdddd76ac7c7d44e1a3bf9945c3104760493298407b0f8c8ca46deeb46bb
MD5 5009c97a9e8bd1e9414b9fa7d3553708
BLAKE2b-256 2a275e1573631de9313c727fbdcda57a35f95dd26aca0857a139bd4ed350884e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page