Skip to main content

Search Engine

Project description

MySearch

Giới thiệu

MySearch là một module tìm kiếm dựa trên FAISS (Facebook AI Similarity Search) để thực hiện tìm kiếm vector hiệu quả. Hệ thống hỗ trợ tìm kiếm theo khoảng cách cosine và L2, đồng thời quản lý dữ liệu thông qua các lớp hỗ trợ như IndexDB, FaissDB, InfoDB.

Tính năng chính

  • Thêm vector embedding vào FAISS.
  • Tìm kiếm các vector gần nhất dựa trên chỉ số khoảng cách.
  • Xóa vector khỏi cơ sở dữ liệu FAISS.
  • Cập nhật hoặc thay thế vector embedding.
  • Kiểm tra tính nhất quán của cơ sở dữ liệu.

Cấu trúc thư mục

.
├── logs/
│   ├── log_handler.py  # Xử lý ghi log
├── modules/
│   ├── utils/
│   │   ├── checker.py  # Kiểm tra tính hợp lệ của dữ liệu
│   │   ├── faiss_db.py  # Quản lý FAISS
│   │   ├── helper.py  # Hỗ trợ xử lý vector
│   │   ├── index_db.py  # Quản lý index của vector
│   │   ├── info_db.py  # Quản lý thông tin đối tượng
├── my_search.py  # Lớp chính MySearch
├── README.md  # Tài liệu này

Cài đặt

Yêu cầu Python 3.8 trở lên và các thư viện:

pip install faiss-cpu numpy

Hướng dẫn sử dụng

Khởi tạo MySearch

from my_search import MySearch

search_engine = MySearch(distance_type="cosin", element=512)

Tạo collection

list_field = ["id", "name", "vector"]
key_main = "id"
search_engine.create_collection(list_field, key_main)

Thêm dữ liệu vào FAISS

embedding = [[0.1, 0.2, 0.3, ..., 0.512]]  # Danh sách embedding có kích thước 512
list_field = [{"id": 1, "name": "Object1", "vector": embedding[0]}]

search_engine.add(embedding, list_field)

Tìm kiếm

query_vector = [0.1, 0.2, 0.3, ..., 0.512]
result = search_engine.search(query_vector, result_of_num=5)
print(result)

Xóa dữ liệu

search_engine.delete(key_mains=[1])

Cập nhật dữ liệu

new_vector = [0.2, 0.3, 0.4, ..., 0.512]
search_engine.replace(key_mains=[1], embeddings=[new_vector], indexs=[0])

Cấu trúc lớp

MySearch

  • add(embedding, list_field): Thêm một hoặc nhiều vector embedding vào FAISS.
  • search(embedding, result_of_num): Tìm kiếm vector gần nhất.
  • delete(key_mains): Xóa vector theo khóa chính.
  • replace(key_mains, embeddings, indexs, new_key_mains): Thay thế hoặc cập nhật vector.
  • create_collection(list_field, key_main): Tạo tập dữ liệu mới.

Cấu trúc dữ liệu

  • IndexDB: Lưu trữ ánh xạ giữa index FAISS và khóa chính (key_main).
  • FaissDB: Quản lý cơ sở dữ liệu FAISS và thực hiện truy vấn.
  • InfoDB: Quản lý thông tin đối tượng liên quan đến embedding.

Ghi log

Module sử dụng logger để ghi lại quá trình hoạt động. Log được lưu trong thư mục logs/.

Đóng góp

Mọi đóng góp vui lòng gửi pull request hoặc mở issue trên GitHub.

Giấy phép

Dự án này sử dụng giấy phép MIT.

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

tsearch-1.0.2.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

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

tsearch-1.0.2-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file tsearch-1.0.2.tar.gz.

File metadata

  • Download URL: tsearch-1.0.2.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for tsearch-1.0.2.tar.gz
Algorithm Hash digest
SHA256 145e6bc11e32854e03241f4dfa34213526a02113d6ed8412d028443710120fc9
MD5 997dca826b55ba79c05341202490f1ae
BLAKE2b-256 110e0bd462b4310f90c059824090b93a5bf5d709d240e763ac3d1e7f413d6e50

See more details on using hashes here.

File details

Details for the file tsearch-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: tsearch-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for tsearch-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c89ffd50148098e0224565f3aa1befb95d2d6b232d81eb481b49a00a8aa10ad
MD5 12a34072d8e30c1766042c2566c21761
BLAKE2b-256 2dcffbfa06ceb4d47ce8fd74751e4b76a6d9494365556bd32d5d00224e12c51b

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