{"id":16108683,"url":"https://github.com/aliosm/chromable","last_synced_at":"2025-09-09T03:32:17.427Z","repository":{"id":211336497,"uuid":"728706732","full_name":"AliOsm/chromable","owner":"AliOsm","description":"Ruby on Rails integration for ChromaDB","archived":false,"fork":false,"pushed_at":"2025-02-06T11:04:03.000Z","size":54,"stargazers_count":13,"open_issues_count":7,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-31T06:48:36.726Z","etag":null,"topics":["chromadb","llms","rails-gem","ruby-on-rails","semantic-search","vectorstore"],"latest_commit_sha":null,"homepage":"https://github.com/AliOsm/chromable","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/AliOsm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-07T14:16:09.000Z","updated_at":"2025-03-08T13:36:22.000Z","dependencies_parsed_at":"2024-01-11T10:27:23.104Z","dependency_job_id":null,"html_url":"https://github.com/AliOsm/chromable","commit_stats":null,"previous_names":["aliosm/chromable"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/AliOsm/chromable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliOsm%2Fchromable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliOsm%2Fchromable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliOsm%2Fchromable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliOsm%2Fchromable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AliOsm","download_url":"https://codeload.github.com/AliOsm/chromable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliOsm%2Fchromable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274238704,"owners_count":25247110,"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-09-09T02:00:10.223Z","response_time":80,"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":["chromadb","llms","rails-gem","ruby-on-rails","semantic-search","vectorstore"],"created_at":"2024-10-09T19:27:51.378Z","updated_at":"2025-09-09T03:32:17.150Z","avatar_url":"https://github.com/AliOsm.png","language":"Ruby","readme":"# Chromable\n\nRuby on Rails integration for ChromaDB based on `chroma-db` gem.\n\n`chromable` were tested with Ruby 3.2.2 and Rails 7.1.2.\n\n## Installation\n\nInstall `chromable` and add it to the application's Gemfile by executing:\n\n    $ bundle add chromable\n\nOr, if bundler is not being used to manage dependencies, install `chromable` by executing:\n\n    $ gem install chromable\n\n## Usage\n\n`chromable` is depending on `chroma-db`, so you will need to initialize it in `config/initializers/chroma.rb`:\n\n```ruby\nrequire 'chroma-db'\n\nChroma.connect_host = ENV.fetch('CHROMA_DB_URL', 'http://localhost:8000')\nChroma.logger = Logger.new($stdout)\nChroma.log_level = Chroma::LEVEL_ERROR\n```\n\nThen, include `Chromable` module in your model and initialize it:\n\n```ruby\nclass Post \u003c ApplicationRecord\n  include Chromable\n\n  chromable document: :content, metadata: %i[author category], embedder: :embed, keep_document: false\n\n  def self.embed(text, **options)\n    options[:is_query] ||= false\n\n    if options[:is_query]\n      # Call OpenAI API to embed `text` as a search query.\n    else\n      # Call OpenAI API to embed `text` as a post content.\n    end\n  end\nend\n```\n\nWhere:\n- `document:` is a callable represents the text content you want to embed and store in ChromaDB (e.g. Could be a model attribute).\n- `metadata:` is a list of callables to be evaluated and passed to ChromaDB as metadata to be used to filter (e.g. Could be an instance method).\n- `embedder:` is a callable defined at the model level that returns the embedding representation for the given `text` based on some `options`.\n- `keep_document:` tells chromable to pass the `document:` to ChromaDB and save it or not. It is useful if you just want to have the embeddings in ChromaDB and the rest of the data in your Rails application database to reduce memory footprint. `keep_document:` is `true` by default.\n\nOptionaly you can pass `collection_name:`. If not passed, the plural form of the model name will be used.\n\nThe only required option for `chromable` is `document:`.\n\nAt this point, `chromable` will create, update, and destroy the ChromaDB embeddings for your objects based on Rails `after_save` and `after_destroy` callbacks.\n\nTo interact with the ChromaDB collection, `chromable` provides:\n- `Model.query` to query the collection using similar API used in `chroma-db` gem, except for accepting `text:` instead of `query_embeddings:`. Extra arguments will be passed to the `embedder:` as `options`. Behind the scenes, `Model.query` will embed the given `text:`, then query the collection, and return the closest `results:` records.\n- `Model.collection` to access the collection directly.\n- `Model.delete_collection` to delete the entire collection.\n\n```ruby\nputs Post.collection.count # Gets the number of documents inside the collection. Should always match Post.count.\n\nPost.query(\n  text: params[:query],\n  results: 20,\n  where: chroma_search_filters,\n  is_query: true # `is_query` here will be passed to `Post.embed` as an option.\n)\n\nPost.first.neighbors(results: 20) # =\u003e [#\u003cPost:0x0000ffff9e0b5f10 id: \"0beb0f98...\", ...\u003e, ...]\n```\n\nAlso, `chromable` provides the following methods for each model instance:\n\n- `embedding`: Retrieves the instance's ChromaDB embedding object.\n- `upsert_embedding`: Creates or updates the instance's ChromaDB embedding object.\n- `destroy_embedding`: Destroys the instance's ChromaDB embedding object.\n- `neighbors`: Gets the closest `results:` records to the current record.\n\nAll these methods (including `Model.query`, `Model.collection`, and `Model.delete_collection`) are available with `chroma_` prefix, if you have similar methods defined in your model.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle install`. To release a new version, update the version number in `version.rb`, and then create a git tag for the version, push git commits and the created tag. The `Publish Gem` Github Action will push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/AliOsm/chromable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/AliOsm/chromable/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Chromable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/AliOsm/chromable/blob/main/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faliosm%2Fchromable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faliosm%2Fchromable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faliosm%2Fchromable/lists"}