{"id":13671968,"url":"https://github.com/ritchie46/lsh-rs","last_synced_at":"2025-07-28T06:06:37.625Z","repository":{"id":48804470,"uuid":"245437706","full_name":"ritchie46/lsh-rs","owner":"ritchie46","description":"Locality Sensitive Hashing in Rust with Python bindings","archived":false,"fork":false,"pushed_at":"2023-06-20T06:19:59.000Z","size":523,"stargazers_count":116,"open_issues_count":8,"forks_count":22,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-20T15:10:53.937Z","etag":null,"topics":["cosine-similarity","l2-distance","lsh","lsh-algorithm","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ritchie46.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-06T14:16:40.000Z","updated_at":"2025-05-21T05:25:17.000Z","dependencies_parsed_at":"2024-06-11T17:11:59.261Z","dependency_job_id":"f2805da5-c600-481f-9af3-2bf7ae3d0f8b","html_url":"https://github.com/ritchie46/lsh-rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ritchie46/lsh-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritchie46%2Flsh-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritchie46%2Flsh-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritchie46%2Flsh-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritchie46%2Flsh-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ritchie46","download_url":"https://codeload.github.com/ritchie46/lsh-rs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritchie46%2Flsh-rs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265266136,"owners_count":23737174,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cosine-similarity","l2-distance","lsh","lsh-algorithm","rust"],"created_at":"2024-08-02T09:01:23.209Z","updated_at":"2025-07-14T09:08:58.754Z","avatar_url":"https://github.com/ritchie46.png","language":"Rust","funding_links":[],"categories":["Rust","Vector Search"],"sub_categories":[],"readme":" # lsh-rs (Locality Sensitive Hashing)\n[![rust docs](https://docs.rs/lsh-rs/badge.svg)](https://docs.rs/lsh-rs/latest/lsh_rs/)\n[![Build Status](https://travis-ci.org/ritchie46/lsh-rs.svg?branch=master)](https://travis-ci.org/ritchie46/lsh-rs)\n\nLocality sensitive hashing can help retrieving Approximate Nearest Neighbors in sub-linear time.\n\nFor more information on the subject see:\n* [Introduction on LSH](http://people.csail.mit.edu/gregory/annbook/introduction.pdf)\n* [Section 2. describes the hash families used in this crate](https://arxiv.org/pdf/1411.3787.pdf)\n* [LSH and neural networks](https://www.ritchievink.com/blog/2020/04/07/sparse-neural-networks-and-hash-tables-with-locality-sensitive-hashing/)\n\n## Implementations\n\n* **Base LSH**\n    - Signed Random Projections *(Cosine similarity)*\n    - L2 distance\n    - MIPS *(Dot products/ Maximum Inner Product Search)*\n    - MinHash *(Jaccard Similarity)*\n* **Multi Probe LSH**\n    - **Step wise probing**\n        - SRP (only bit shifts)\n    - **Query directed probing**\n        - L2\n        - MIPS\n* Generic numeric types\n\n## Getting started\n\n```rust\nuse lsh_rs::LshMem;\n// 2 rows w/ dimension 3.\nlet p = \u0026[vec![1., 1.5, 2.],\n        vec![2., 1.1, -0.3]];\n\n// Do one time expensive preprocessing.\nlet n_projections = 9;\nlet n_hash_tables = 30;\nlet dim = 10;\nlet dim = 3;\nlet mut lsh = LshMem::new(n_projections, n_hash_tables, dim)\n    .srp()\n    .unwrap();\nlsh.store_vecs(p);\n\n// Query in sublinear time.\nlet query = \u0026[1.1, 1.2, 1.2];\nlsh.query_bucket(query);\n```\n\n## Documentation\n* [Read the Rust docs](https://docs.rs/lsh-rs/latest/lsh_rs/).\n* [Read the Python docs](https://lsh-rs.readthedocs.io/en/latest/) for the Python bindings.\n\n## Python\nAt the moment, the Python bindings are only compiled for Linux x86_64 systems.\n\n`$ pip install floky`\n\n```python\nfrom floky import SRP\nimport numpy as np\n\nN = 10000\nn = 100\ndim = 10\n\n# Generate some random data points\ndata_points = np.random.randn(N, dim)\n\n# Do a one time (expensive) fit.\nlsh = SRP(n_projections=19, n_hash_tables=10)\nlsh.fit(data_points)\n\n# Query approximated nearest neigbors in sub-linear time\nquery = np.random.randn(n, dim)\nresults = lsh.predict(query)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritchie46%2Flsh-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fritchie46%2Flsh-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritchie46%2Flsh-rs/lists"}