A high-performance C++ accelerated vector score fusion engine.
Project description
CosineFusion 🚀
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-layoutto 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bcc60a2e98060983327df5cb5d630dc0182a0553148d84e42ce0932c4a117ce
|
|
| MD5 |
5191a0e82ce318b4676d1956d01be73b
|
|
| BLAKE2b-256 |
840d63506626dc037f915e1bfc8fb8e1cb205ff30053395c2a5b01a63bd5c5c0
|
File details
Details for the file cosinefusion-0.1.1-cp311-cp311-macosx_10_9_universal2.whl.
File metadata
- Download URL: cosinefusion-0.1.1-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 146.3 kB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c55fdddd76ac7c7d44e1a3bf9945c3104760493298407b0f8c8ca46deeb46bb
|
|
| MD5 |
5009c97a9e8bd1e9414b9fa7d3553708
|
|
| BLAKE2b-256 |
2a275e1573631de9313c727fbdcda57a35f95dd26aca0857a139bd4ed350884e
|