🚀 CosRAG Son HUMG - High Performance Vector Engine
Engine tính toán Cosine Similarity hiệu năng cao được viết bằng Rust, tối ưu hóa sâu cho các hệ thống RAG (Retrieval-Augmented Generation).
🛠 Kỹ thuật tối ưu hóa (Technical Stack)
1. AVX2 SIMD Kernel
Sử dụng tập lệnh xử lý song song dữ liệu (Single Instruction, Multiple Data). Thay vì tính toán từng phần tử, engine xử lý đồng thời 8 số thực f32 trong một chu kỳ xung nhịp, giúp tăng tốc độ lên gấp nhiều lần so với code Python/C++ truyền thống.
2. Tail Processing Logic
Giải quyết vấn đề nan giải của SIMD khi số chiều không chia hết cho 8 (ví dụ: 771 dims). Engine tự động tách phần dư để xử lý bằng Scalar logic, đảm bảo độ chính xác tuyệt đối mà không cần padding dữ liệu.
3. Zero-copy Memory Access
Thông qua PyO3, Rust truy cập trực tiếp vào vùng nhớ (buffer) của NumPy mảng. Điều này giúp loại bỏ hoàn toàn việc sao chép dữ liệu (copy overhead), cực kỳ quan trọng khi làm việc với Big Data (hàng chục triệu vector) để tối ưu RAM.
⚡ Hiệu năng thực tế (Benchmarks)
Thử nghiệm trên môi trường Google Colab (CPU Intel Xeon):
- Tốc độ quét: ~3.500.000 vector/giây (với chiều 768).
- Khả năng mở rộng: Xử lý mượt mà 10 triệu vector (~15GB RAM) mà không gây tràn bộ nhớ nhờ cơ chế quản lý bộ nhớ của Rust.
- Độ trễ: Cực thấp, phù hợp cho các ứng dụng chatbot yêu cầu phản hồi thời gian thực.
🚀 Hướng dẫn sử dụng
Cài đặt
pip install cos_rag_son_humg
Cách dùng cơ bản
import numpy as np
import cos_rag_son_humg as sl
dim = 768
db = np.random.rand(1000000, dim).astype(np.float32)
query = np.random.rand(dim).astype(np.float32)
# Lưu ý: Cần .ravel() mảng database để tối ưu hóa SIMD
scores = sl.vecto(query, db.ravel(), dim)
idx, best_score = sl.cos_vecto(scores)
print(f"Kết quả: Index {idx}, Score {best_score}")
🌟 Ưu điểm
- Chính xác: Giữ nguyên định dạng
f32, không gây mất mát thông tin như Quantization. - Nhẹ: Thư viện nhỏ gọn, không phụ thuộc vào các framework nặng nề.
- Nhanh: Tận dụng tối đa sức mạnh phần cứng CPU hiện đại.
Phát triển bởi Son HUMG - Đam mê tốc độ và sự chính xác! 🦀
Metadata
Release files for cos-rag-son-humg 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cos_rag_son_humg-0.1.5.tar.gz | 5.0 kB | Without provenance | Details for cos_rag_son_humg-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cos_rag_son_humg-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.34+ x86-64 | Details for cos_rag_son_humg-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl |
Total release size: 274.1 kB
Release files / cos_rag_son_humg-0.1.5.tar.gz
| Download URL | cos_rag_son_humg-0.1.5.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
740691eb6f59c53fedc069db8a479ff4216320d6e992b3d2ad7828b0a412a488
|
|
BLAKE2b-256 checksum How to use checksums |
72387ccb6963e56fdb5c0de73601b470c1b5f7706356dd7581beba1480ce9339
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / cos_rag_son_humg-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | cos_rag_son_humg-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 269.1 kB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
0644a421d3fa2e9d0220330026318930ed747dbba7c5d77e8980e8383be1bdcc
|
|
BLAKE2b-256 checksum How to use checksums |
9b82389cff6fdadea289d1cde5fc1f658951d8992671c32b151cff04d21e31a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for cos-rag-son-humg 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.