{"id":18376929,"url":"https://github.com/bbc/ruby-lsh","last_synced_at":"2025-07-13T03:42:41.450Z","repository":{"id":5947886,"uuid":"7168687","full_name":"bbc/ruby-lsh","owner":"bbc","description":"Locality Sensitive Hashing in Ruby","archived":false,"fork":false,"pushed_at":"2013-10-18T10:52:29.000Z","size":361,"stargazers_count":33,"open_issues_count":0,"forks_count":9,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-04-02T10:39:42.031Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bbc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-12-14T16:53:02.000Z","updated_at":"2024-05-21T02:18:20.000Z","dependencies_parsed_at":"2022-08-20T23:10:43.274Z","dependency_job_id":null,"html_url":"https://github.com/bbc/ruby-lsh","commit_stats":null,"previous_names":["bbcrd/ruby-lsh"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fruby-lsh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fruby-lsh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fruby-lsh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fruby-lsh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbc","download_url":"https://codeload.github.com/bbc/ruby-lsh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247547694,"owners_count":20956599,"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":[],"created_at":"2024-11-06T00:25:28.926Z","updated_at":"2025-04-06T20:31:50.935Z","avatar_url":"https://github.com/bbc.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"ruby-lsh\n========\n\nAn implementation of Locality-Sensitive Hashing in Ruby. \n\nLocality-Sensitive Hashing is an efficient technique for finding nearest neighbors in high-dimensional spaces.\n\nUses JBlas on JRuby and GSL on any other Ruby. Supports two backends (in-memory and Redis-backed) and includes a small HTTP API.\n\n\n\nUsage\n-----\n\nSee examples/evaluation.rb\n\n    require 'lsh'\n    index = LSH::Index.new({\n      :dim =\u003e 100, \n      :number_of_random_vectors =\u003e 8, \n      :window =\u003e Float::INFINITY, \n      :number_of_independent_projections =\u003e 150\n    }) # Creates an in-memory binary LSH index for 100-dim vectors, 8 bits, 150 independent projections\n    v1 = index.random_vector(100)\n    v2 = index.random_vector(100)\n    v3 = index.random_vector(100) # Creating three random vectors\n    index.add v1\n    index.add v2\n    index.add v3 # Adding the three vectors to the index\n    index.query(v1) # Query the index for vectors that fall in the same LSH bucket as v1\n    index.query(v2, 1) # Query the index for vectors that fall in the same LSH bucket as v2, and in buckets at hamming distance 1 of that bucket\n\n\nUsing the Redis backend\n-----------------------\n\nBy default, the LSH index will be stored in memory. A Redis-backed storage is also available, and can\nbe constructed as follows:\n\n    storage = LSH::Storage::RedisBackend.new\n    index = LSH::Index.new({\n      :dim =\u003e 100,\n      :number_of_random_vectors =\u003e 8,\n      :window =\u003e Float::Infinity,\n      :number_of_independent_projections =\u003e 150\n    }, storage)\n\nOnce created, the index can then be reused:\n\n    storage = LSH::Storage::RedisBackend.new\n    index = LSH::Index.new(storage.parameters, storage) if storage.has_index?\n\nThis will connect to a Redis backend on localhost and store binary dumps of the vectors (including the projections) in a 'data' directory, caching vectors in RAM to speed up comparison.\nThis can be overridden as follows:\n\n    storage = LSH::Storage::RedisBackend.new(:redis =\u003e { :host =\u003e '127.0.0.1', :port =\u003e 6379 },\n                                             :data_dir =\u003e 'data',\n                                             :cache_vectors =\u003e TRUE)\n\nThe Redis-backed LSH index is faster using the MRI than JRuby, due to the time it takes to load vectors from their\nbinary representations on disk. GSL is much faster than JBLAS on that point.\n\n\nUsing the Web frontend\n----------------------\n\nThis gem includes a minimal Web API, built using Sinatra. See examples/config.ru for an example setup.\n\n    $ cd examples\n    $ rackup\n    $ curl --data-urlencode data@vector.json http://localhost:9292/index # Adds a vector to the index\n    $ curl --data-urlencode data@vector.json http://localhost:9292/query # Query the index\n\nOr you can associate your vectors with ids and query using them.\n\n    $ cd examples\n    $ rackup\n    $ curl --data-urlencode data@vector.json -d'id=foo' http://localhost:9292/index # Adds a vector with id 'foo' to the index\n    $ curl -d'id=foo' http://localhost:9292/query-ids # Query the index\n\nGSL notes\n---------\n\nIf you get a compilation error when installing GSL, try this version:\n\n  https://github.com/romanbsd/rb-gsl\n\nAs you will need a version of GSL that includes this patch:\n\n  https://gist.github.com/1217974\n\n\nLicensing terms and authorship\n------------------------------\n\nSee 'COPYING' and 'AUTHORS' files.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbc%2Fruby-lsh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbc%2Fruby-lsh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbc%2Fruby-lsh/lists"}