{"id":13878095,"url":"https://github.com/ankane/ngt-ruby","last_synced_at":"2025-11-17T14:17:30.518Z","repository":{"id":56885496,"uuid":"216916846","full_name":"ankane/ngt-ruby","owner":"ankane","description":"High-speed approximate nearest neighbors for Ruby","archived":false,"fork":false,"pushed_at":"2025-09-20T01:32:52.000Z","size":116,"stargazers_count":53,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-08T00:46:30.246Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2019-10-22T21:57:19.000Z","updated_at":"2025-09-20T01:32:55.000Z","dependencies_parsed_at":"2023-12-26T21:32:12.006Z","dependency_job_id":"4dbd6de1-2ef4-449f-be51-b9d547f4cb73","html_url":"https://github.com/ankane/ngt-ruby","commit_stats":{"total_commits":105,"total_committers":2,"mean_commits":52.5,"dds":0.4380952380952381,"last_synced_commit":"3ef314577f058e106d90cdb6c4bd9ac91b39dc0c"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/ankane/ngt-ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fngt-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fngt-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fngt-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fngt-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/ngt-ruby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fngt-ruby/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284894659,"owners_count":27080744,"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","status":"online","status_checked_at":"2025-11-17T02:00:06.431Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-08-06T08:01:39.686Z","updated_at":"2025-11-17T14:17:30.501Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","readme":"# NGT Ruby\n\n[NGT](https://github.com/yahoojapan/NGT) - high-speed approximate nearest neighbors - for Ruby\n\n[![Build Status](https://github.com/ankane/ngt-ruby/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/ngt-ruby/actions)\n\n## Installation\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"ngt\"\n```\n\nOn Mac, also install OpenMP:\n\n```sh\nbrew install libomp\n```\n\nNGT is not available for Windows\n\n## Getting Started\n\nPrep your data\n\n```ruby\nobjects = [\n  [1, 1, 2, 1],\n  [5, 4, 6, 5],\n  [1, 2, 1, 2]\n]\n```\n\nCreate an index\n\n```ruby\nindex = Ngt::Index.new(dimensions)\n```\n\nInsert objects\n\n```ruby\nindex.batch_insert(objects)\n```\n\nSearch the index\n\n```ruby\nindex.search(query, size: 3)\n```\n\nSave the index\n\n```ruby\nindex.save(path)\n```\n\nLoad an index\n\n```ruby\nindex = Ngt::Index.load(path)\n```\n\nGet an object by id\n\n```ruby\nindex.object(id)\n```\n\nInsert a single object\n\n```ruby\nindex.insert(object)\n```\n\nRemove an object by id\n\n```ruby\nindex.remove(id)\n```\n\nBuild the index\n\n```ruby\nindex.build_index\n```\n\nOptimize the index\n\n```ruby\noptimizer = Ngt::Optimizer.new(outgoing: 10, incoming: 120)\noptimizer.adjust_search_coefficients(index)\noptimizer.execute(index, new_path)\n```\n\n## Full Example\n\n```ruby\ndim = 10\nobjects = []\n100.times do |i|\n  objects \u003c\u003c dim.times.map { rand(100) }\nend\n\nindex = Ngt::Index.new(dim)\nindex.batch_insert(objects)\n\nquery = objects[0]\nresult = index.search(query, size: 3)\n\nresult.each do |res|\n  puts \"#{res[:id]}, #{res[:distance]}\"\n  p index.object(res[:id])\nend\n```\n\n## Index Options\n\nDefaults shown below\n\n```ruby\nNgt::Index.new(dimensions,\n  edge_size_for_creation: 10,\n  edge_size_for_search: 40,\n  object_type: :float, # :float, :integer\n  distance_type: :l2,  # :l1, :l2, :hamming, :angle, :cosine, :normalized_angle, :normalized_cosine, :jaccard\n  path: nil\n)\n```\n\n## Optimizer Options\n\nDefaults shown below\n\n```ruby\nNgt::Optimizer.new(\n  outgoing: 10,\n  incoming: 120,\n  queries: 100,\n  low_accuracy_from: 0.3,\n  low_accuracy_to: 0.5,\n  high_accuracy_from: 0.8,\n  high_accuracy_to: 0.9,\n  gt_epsilon: 0.1,\n  merge: 0.2\n)\n```\n\n## Data\n\nData can be an array of arrays\n\n```ruby\n[[1, 2, 3], [4, 5, 6]]\n```\n\nOr a Numo array\n\n```ruby\nNumo::NArray.cast([[1, 2, 3], [4, 5, 6]])\n```\n\n## Resources\n\n- [ANN Benchmarks](https://github.com/erikbern/ann-benchmarks)\n\n## Credits\n\nThis library is modeled after NGT’s [Python API](https://github.com/yahoojapan/NGT/blob/master/python/README-ngtpy.md).\n\n## History\n\nView the [changelog](https://github.com/ankane/ngt-ruby/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/ngt-ruby/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/ngt-ruby/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https://github.com/ankane/ngt-ruby.git\ncd ngt-ruby\nbundle install\nbundle exec rake vendor:all\nbundle exec rake test\n```\n","funding_links":[],"categories":["Ruby","Machine Learning Libraries"],"sub_categories":["Vector search"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fngt-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Fngt-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fngt-ruby/lists"}