{"id":18732322,"url":"https://github.com/ksylvest/voyageai","last_synced_at":"2025-10-13T20:39:19.826Z","repository":{"id":259094531,"uuid":"876370143","full_name":"ksylvest/voyageai","owner":"ksylvest","description":"A ruby client for VoyageAI","archived":false,"fork":false,"pushed_at":"2025-09-29T17:56:58.000Z","size":44,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T00:57:32.928Z","etag":null,"topics":["ruby","voyageai"],"latest_commit_sha":null,"homepage":"https://voyageai.ksylvest.com","language":"Ruby","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/ksylvest.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-10-21T21:15:23.000Z","updated_at":"2025-10-08T17:15:55.000Z","dependencies_parsed_at":"2024-12-03T14:31:00.131Z","dependency_job_id":"42219961-2660-4463-bd8e-dd8e508ff562","html_url":"https://github.com/ksylvest/voyageai","commit_stats":null,"previous_names":["ksylvest/voyageai"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/ksylvest/voyageai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksylvest%2Fvoyageai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksylvest%2Fvoyageai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksylvest%2Fvoyageai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksylvest%2Fvoyageai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ksylvest","download_url":"https://codeload.github.com/ksylvest/voyageai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksylvest%2Fvoyageai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007613,"owners_count":26084336,"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-10-11T02:00:06.511Z","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":["ruby","voyageai"],"created_at":"2024-11-07T15:05:17.483Z","updated_at":"2025-10-13T20:39:19.809Z","avatar_url":"https://github.com/ksylvest.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# VoyageAI\n\n[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ksylvest/voyageai/blob/main/LICENSE)\n[![RubyGems](https://img.shields.io/gem/v/voyageai)](https://rubygems.org/gems/voyageai)\n[![GitHub](https://img.shields.io/badge/github-repo-blue.svg)](https://github.com/ksylvest/voyageai)\n[![Yard](https://img.shields.io/badge/docs-site-blue.svg)](https://voyageai.ksylvest.com)\n[![CircleCI](https://img.shields.io/circleci/build/github/ksylvest/voyageai)](https://circleci.com/gh/ksylvest/voyageai)\n\n`voyageai` is a ruby client for [VoyageAI](https://www.voyageai.com)\n\n## Installation\n\n```bash\ngem install voyageai\n```\n\n## Usage\n\n### Embedding\n\n#### Generating Single Embedding\n\n```ruby\nrequire 'voyageai'\n\ninput = 'A quick brown fox jumps over the lazy dog.'\n\nvoyageai = VoyageAI::Client.new(api_key: 'pa-...') # or configure ENV['VOYAGEAI_API_KEY']\n\nembed = voyageai.embed(input)\nembed.model # \"...\"\nembed.usage # \"#\u003cVoyageAI::Usage total_tokens=...\u003e\"\nembed.embedding # [0.0, ...]\n```\n\n#### Generating Multiple Embeddings\n\n```ruby\nrequire 'voyageai'\n\ninput = [\n  'John is a musician.',\n  'Paul is a plumber.',\n  'George is a teacher.',\n  'Ringo is a doctor.',\n]\n\nvoyageai = VoyageAI::Client.new(api_key: 'pa-...') # or configure ENV['VOYAGEAI_API_KEY']\n\nembed = voyageai.embed(input)\nembed.model # \"...\"\nembed.usage # \"#\u003cVoyageAI::Usage total_tokens=...\u003e\"\nembed.embeddings # [[0.0, ...], ...]\n```\n\n### Reranking\n\n```ruby\nrequire 'voyageai'\n\nquery = 'Who is the best person to call for a toilet?'\n\ndocuments = [\n  'John is a musician.',\n  'Paul is a plumber.',\n  'George is a teacher.',\n  'Ringo is a doctor.',\n]\n\nvoyageai = VoyageAI::Client.new(api_key: 'pa-...') # or configure ENV['VOYAGEAI_API_KEY']\n\nrerank = voyageai.rerank(query:, documents:, top_k: 3)\nrerank.model # \"...\"\nrerank.usage # \"#\u003cVoyageAI::Usage total_tokens=...\u003e\"\nrerank.results # [#\u003cVoyageAI::Reranking index=0 relevance_score=0.5\u003e]\n```\n\n## Configuration\n\n```ruby\nrequire 'voyageai'\n\nVoyageAI.configure do |config|\n  config.api_key = 'pa-...' # defaults to ENV['VOYAGEAI_API_KEY']\n  config.host = 'https://api.voyageai.com'\n  config.version = 'v1'\n  config.timeout = 15 # seconds\n  config.logger = Logger.new(STDOUT)\nend\n```\n\n## Examples\n\n```ruby\nrequire \"voyageai\"\n\nEntry = Data.define(:document, :embedding)\n\nVOYAGEAI = VoyageAI::Client.new\n\nDOCUMENTS = [\n  \"John is a musician.\",\n  \"Paul is a plumber.\",\n  \"George is a teacher.\",\n  \"Ringo is a doctor.\",\n  \"Lisa is a lawyer.\",\n  \"Stuart is a painter.\",\n  \"Brian is a writer.\",\n  \"Jane is a chef.\",\n  \"Bill is a nurse.\",\n  \"Susan is a carpenter.\",\n].freeze\n\nembeddings = VOYAGEAI.embed(DOCUMENTS, input_type: \"document\").embeddings\n\nENTRIES = DOCUMENTS.zip(embeddings).map do |document, embedding|\n  Entry.new(document:, embedding:)\nend\n\n# @param src [Array\u003cFloat\u003e]\n# @param dst [Array\u003cFloat\u003e]\n#\n# @return [Float]\ndef euclidean_distance(src, dst)\n  Math.sqrt(src.zip(dst).map { |a, b| (a - b)**2 }.reduce(:+))\nend\n\n# @param query [String]\n# @param limit [Integer]\n#\n# @return [Array\u003cString\u003e]\ndef nearest_documents(query:, limit: 4)\n  embedding = VOYAGEAI.embed(query, input_type: \"query\").embedding\n\n  ENTRIES\n    .sort_by { |entry| euclidean_distance(entry.embedding, embedding) }\n    .first(limit)\n    .map(\u0026:document)\nend\n\n# @param query [String]\ndef search(query:)\n  documents = nearest_documents(query:)\n\n  results = VOYAGEAI.rerank(query:, documents:, top_k: 2).results\n\n  puts \"query=#{query.inspect}\"\n  results.each do |reranking|\n    document = documents[reranking.index]\n    puts(\"document=#{document.inspect} relevance_score=#{reranking.relevance_score}\")\n  end\nend\n\nsearch(query: \"What do George and Ringo do?\")\nsearch(query: \"Who works in the medical field?\")\n```\n\n```\nquery=\"What do George and Ringo do?\"\ndocument=\"Ringo is a doctor.\" relevance_score=0.67968755\ndocument=\"George is a teacher.\" relevance_score=0.58593755\n```\n\n```\nquery=\"Who works in the medical field?\"\ndocument=\"Bill is a nurse.\" relevance_score=0.55078125\ndocument=\"Ringo is a doctor.\" relevance_score=0.50390625\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksylvest%2Fvoyageai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fksylvest%2Fvoyageai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksylvest%2Fvoyageai/lists"}