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.4.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.4-cp312-cp312-manylinux_2_34_x86_64.whl (269.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

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

File metadata

  • Download URL: cos_rag_son_humg-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 a4e0556893ed1712dc815ecb8279baa8986082e2779f8a1d8563a76e4704f6cc
MD5 ed7767f8e6683c25890fb8e5aba38625
BLAKE2b-256 31f5ce1f60b18485e5af54e3e42f91b035cda01160ac7c2dbf28daa6edf3f0c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cos_rag_son_humg-0.1.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 785485cf8fe8a3aff8e2cc08ac04b787b5e44595d6391c463598d5be69b82871
MD5 7c35e1c3cf48cccd07aa703f1ec753a9
BLAKE2b-256 df1af07191a23cb7318b3304ea4288ed709c30971903923504567dec719406fa

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