Skip to main content

High Performance Vector Engine for RAG using AVX2 SIMD and Zero-copy

Project description

🚀 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! 🦀

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

cos_rag_son_humg-0.1.5.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

cos_rag_son_humg-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl (269.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file cos_rag_son_humg-0.1.5.tar.gz.

File metadata

  • Download URL: cos_rag_son_humg-0.1.5.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for cos_rag_son_humg-0.1.5.tar.gz
Algorithm Hash digest
SHA256 740691eb6f59c53fedc069db8a479ff4216320d6e992b3d2ad7828b0a412a488
MD5 0c27355d130dc1526ffe706d7bfdca87
BLAKE2b-256 72387ccb6963e56fdb5c0de73601b470c1b5f7706356dd7581beba1480ce9339

See more details on using hashes here.

File details

Details for the file cos_rag_son_humg-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for cos_rag_son_humg-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0644a421d3fa2e9d0220330026318930ed747dbba7c5d77e8980e8383be1bdcc
MD5 fcde51bb5594fd6318d268d69386728a
BLAKE2b-256 9b82389cff6fdadea289d1cde5fc1f658951d8992671c32b151cff04d21e31a7

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