{"id":13878672,"url":"https://github.com/pgvector/pgvector-ruby","last_synced_at":"2025-06-20T10:40:18.245Z","repository":{"id":56887933,"uuid":"456424986","full_name":"pgvector/pgvector-ruby","owner":"pgvector","description":"pgvector support for Ruby","archived":false,"fork":false,"pushed_at":"2025-05-22T01:17:32.000Z","size":93,"stargazers_count":147,"open_issues_count":1,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-22T02:25:53.957Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pgvector.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":"2022-02-07T08:50:39.000Z","updated_at":"2025-05-22T01:17:36.000Z","dependencies_parsed_at":"2024-05-18T17:31:31.849Z","dependency_job_id":"8cc21e80-e4fe-4ffc-8e99-8ff3e4a21cd6","html_url":"https://github.com/pgvector/pgvector-ruby","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"b29006a0893f667f2dcfb6b31b92e3f9e317d59b"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/pgvector/pgvector-ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgvector%2Fpgvector-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgvector%2Fpgvector-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgvector%2Fpgvector-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgvector%2Fpgvector-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgvector","download_url":"https://codeload.github.com/pgvector/pgvector-ruby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgvector%2Fpgvector-ruby/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260927981,"owners_count":23084131,"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-08-06T08:01:56.384Z","updated_at":"2025-06-20T10:40:13.231Z","avatar_url":"https://github.com/pgvector.png","language":"Ruby","funding_links":[],"categories":["Ruby","Sdks \u0026 Libraries"],"sub_categories":[],"readme":"# pgvector-ruby\n\n[pgvector](https://github.com/pgvector/pgvector) support for Ruby\n\nSupports [pg](https://github.com/ged/ruby-pg) and [Sequel](https://github.com/jeremyevans/sequel)\n\nFor Rails, check out [Neighbor](https://github.com/ankane/neighbor)\n\n[![Build Status](https://github.com/pgvector/pgvector-ruby/actions/workflows/build.yml/badge.svg)](https://github.com/pgvector/pgvector-ruby/actions)\n\n## Installation\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"pgvector\"\n```\n\nAnd follow the instructions for your database library:\n\n- [pg](#pg)\n- [Sequel](#sequel)\n\nOr check out some examples:\n\n- [Embeddings](examples/openai/example.rb) with OpenAI\n- [Binary embeddings](examples/cohere/example.rb) with Cohere\n- [Sentence embeddings](examples/informers/example.rb) with Informers\n- [Hybrid search](examples/hybrid/example.rb) with Informers (Reciprocal Rank Fusion)\n- [Sparse search](examples/sparse/example.rb) with Transformers.rb\n- [Morgan fingerprints](examples/rdkit/example.rb) with RDKit.rb\n- [Topic modeling](examples/tomoto/example.rb) with tomoto.rb\n- [User-based recommendations](examples/disco/user_recs.rb) with Disco\n- [Item-based recommendations](examples/disco/item_recs.rb) with Disco\n- [Horizontal scaling](examples/citus/example.rb) with Citus\n- [Bulk loading](examples/loading/example.rb) with `COPY`\n\n## pg\n\nEnable the extension\n\n```ruby\nconn.exec(\"CREATE EXTENSION IF NOT EXISTS vector\")\n```\n\nOptionally enable type casting for results\n\n```ruby\nregistry = PG::BasicTypeRegistry.new.define_default_types\nPgvector::PG.register_vector(registry)\nconn.type_map_for_results = PG::BasicTypeMapForResults.new(conn, registry: registry)\n```\n\nCreate a table\n\n```ruby\nconn.exec(\"CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))\")\n```\n\nInsert a vector\n\n```ruby\nembedding = [1, 2, 3]\nconn.exec_params(\"INSERT INTO items (embedding) VALUES ($1)\", [embedding])\n```\n\nGet the nearest neighbors to a vector\n\n```ruby\nconn.exec_params(\"SELECT * FROM items ORDER BY embedding \u003c-\u003e $1 LIMIT 5\", [embedding]).to_a\n```\n\nAdd an approximate index\n\n```ruby\nconn.exec(\"CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)\")\n# or\nconn.exec(\"CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)\")\n```\n\nUse `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance\n\n## Sequel\n\nEnable the extension\n\n```ruby\nDB.run(\"CREATE EXTENSION IF NOT EXISTS vector\")\n```\n\nCreate a table\n\n```ruby\nDB.create_table :items do\n  primary_key :id\n  column :embedding, \"vector(3)\"\nend\n```\n\nAdd the plugin to your model\n\n```ruby\nclass Item \u003c Sequel::Model\n  plugin :pgvector, :embedding\nend\n```\n\nInsert a vector\n\n```ruby\nItem.create(embedding: [1, 1, 1])\n```\n\nGet the nearest neighbors to a record\n\n```ruby\nitem.nearest_neighbors(:embedding, distance: \"euclidean\").limit(5)\n```\n\nAlso supports `inner_product`, `cosine`, `taxicab`, `hamming`, and `jaccard` distance\n\nGet the nearest neighbors to a vector\n\n```ruby\nItem.nearest_neighbors(:embedding, [1, 1, 1], distance: \"euclidean\").limit(5)\n```\n\nAdd an approximate index\n\n```ruby\nDB.add_index :items, :embedding, type: \"hnsw\", opclass: \"vector_l2_ops\"\n```\n\nUse `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance\n\n## History\n\nView the [changelog](https://github.com/pgvector/pgvector-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/pgvector/pgvector-ruby/issues)\n- Fix bugs and [submit pull requests](https://github.com/pgvector/pgvector-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/pgvector/pgvector-ruby.git\ncd pgvector-ruby\ncreatedb pgvector_ruby_test\nbundle install\nbundle exec rake test\n```\n\nTo run an example:\n\n```sh\ncd examples/loading\nbundle install\ncreatedb pgvector_example\nbundle exec ruby example.rb\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgvector%2Fpgvector-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgvector%2Fpgvector-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgvector%2Fpgvector-ruby/lists"}