{"id":13619170,"url":"https://github.com/patterns-ai-core/weaviate-ruby","last_synced_at":"2025-05-01T14:33:54.235Z","repository":{"id":147738293,"uuid":"618703002","full_name":"patterns-ai-core/weaviate-ruby","owner":"patterns-ai-core","description":"Ruby wrapper for the Weaviate vector search database API","archived":false,"fork":false,"pushed_at":"2024-03-06T16:12:24.000Z","size":150,"stargazers_count":42,"open_issues_count":4,"forks_count":14,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-05-22T03:09:21.995Z","etag":null,"topics":["api-client","embedding-vectors","machine-learning","ml","ruby","rubyml","vector-search","vector-search-engine","weaviate"],"latest_commit_sha":null,"homepage":"https://rubydoc.info/gems/weaviate-ruby","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/patterns-ai-core.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}},"created_at":"2023-03-25T05:09:30.000Z","updated_at":"2024-04-12T17:20:12.000Z","dependencies_parsed_at":"2024-01-07T10:50:52.275Z","dependency_job_id":"0c437278-02c8-4486-8f0a-dbe308305016","html_url":"https://github.com/patterns-ai-core/weaviate-ruby","commit_stats":null,"previous_names":["patterns-ai-core/weaviate-ruby","andreibondarev/weaviate-ruby"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patterns-ai-core%2Fweaviate-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patterns-ai-core%2Fweaviate-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patterns-ai-core%2Fweaviate-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patterns-ai-core%2Fweaviate-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patterns-ai-core","download_url":"https://codeload.github.com/patterns-ai-core/weaviate-ruby/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224262972,"owners_count":17282454,"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":["api-client","embedding-vectors","machine-learning","ml","ruby","rubyml","vector-search","vector-search-engine","weaviate"],"created_at":"2024-08-01T21:00:35.759Z","updated_at":"2025-05-01T14:33:54.216Z","avatar_url":"https://github.com/patterns-ai-core.png","language":"Ruby","readme":"# Weaviate\n\n\u003cp\u003e\n    \u003cimg alt='Weaviate logo' src='https://weaviate.io/img/site/weaviate-logo-light.png' height='50' /\u003e\n    +\u0026nbsp;\u0026nbsp;\n    \u003cimg alt='Ruby logo' src='https://user-images.githubusercontent.com/541665/230231593-43861278-4550-421d-a543-fd3553aac4f6.png' height='40' /\u003e\n\u003c/p\u003e\n\nRuby wrapper for the Weaviate.io API.\n\nPart of the [Langchain.rb](https://github.com/andreibondarev/langchainrb) stack.\n\nAvailable for paid consulting engagements! [Email me](mailto:andrei@sourcelabs.io).\n\n![Tests status](https://github.com/andreibondarev/weaviate-ruby/actions/workflows/ci.yml/badge.svg)\n[![Gem Version](https://badge.fury.io/rb/weaviate-ruby.svg)](https://badge.fury.io/rb/weaviate-ruby)\n[![Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/gems/weaviate-ruby)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/andreibondarev/weaviate-ruby/blob/main/LICENSE.txt)\n[![](https://dcbadge.vercel.app/api/server/WDARp7J2n8?compact=true\u0026style=flat)](https://discord.gg/WDARp7J2n8)\n[![X](https://img.shields.io/twitter/url/https/twitter.com/cloudposse.svg?style=social\u0026label=Follow%20%40rushing_andrei)](https://twitter.com/rushing_andrei)\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n    $ bundle add weaviate-ruby\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n    $ gem install weaviate-ruby\n\n## Usage\n\n### Instantiating API client\n\n```ruby\nrequire 'weaviate'\n\nclient = Weaviate::Client.new(\n    url: 'https://some-endpoint.weaviate.network',  # Replace with your endpoint\n    api_key: '', # Weaviate API key\n    model_service: :openai, # Service that will be used to generate vectors. Possible values: :openai, :azure_openai, :cohere, :huggingface, :google_palm\n    model_service_api_key: 'xxxxxxx' # Either OpenAI, Azure OpenAI, Cohere, Hugging Face or Google PaLM api key\n)\n```\n\n### Using the Schema endpoints\n\n```ruby\n# Creating a new data object class in the schema\nclient.schema.create(\n    class_name: 'Question',\n    description: 'Information from a Jeopardy! question',\n    properties: [\n        {\n            \"dataType\": [\"text\"],\n            \"description\": \"The question\",\n            \"name\": \"question\"\n        }, { \n            \"dataType\": [\"text\"],\n            \"description\": \"The answer\",\n            \"name\": \"answer\"\n        }, {\n            \"dataType\": [\"text\"],\n            \"description\": \"The category\",\n            \"name\": \"category\"\n        }\n    ],\n    # Possible values: 'text2vec-cohere', 'text2vec-ollama', 'text2vec-openai', 'text2vec-huggingface', 'text2vec-transformers', 'text2vec-contextionary', 'img2vec-neural', 'multi2vec-clip', 'ref2vec-centroid'\n    vectorizer: \"text2vec-openai\"\n)\n\n# Get a single class from the schema\nclient.schema.get(class_name: 'Question')\n\n# Get the schema\nclient.schema.list()\n\n# Update settings of an existing schema class.\n# Does not support modifying existing properties.\nclient.schema.update(\n    class_name: 'Question',\n    description: 'Information from a Wheel of Fortune question'\n)\n\n# Adding a new property\nclient.schema.add_property(\n    class_name: 'Question',\n    property: {\n        \"dataType\": [\"boolean\"],\n        \"name\": \"homepage\"\n    }\n)\n\n# Inspect the shards of a class\nclient.schema.shards(class_name: 'Question')\n\n# Remove a class (and all data in the instances) from the schema.\nclient.schema.delete(class_name: 'Question')\n\n# Creating a new data object class in the schema while configuring the vectorizer on the schema and on individual properties (Ollama example)\nclient.schema.create(\n    class_name: 'Question',\n    description: 'Information from a Jeopardy! question',\n    properties: [\n        {\n            \"dataType\": [\"text\"],\n            \"description\": \"The question\",\n            \"name\": \"question\"\n            # By default all properties are included in the vector\n        }, { \n            \"dataType\": [\"text\"],\n            \"description\": \"The answer\",\n            \"name\": \"answer\",\n            \"moduleConfig\": {\n                \"text2vec-ollama\": {\n                    \"skip\": false,\n                    \"vectorizePropertyName\": true,\n                },\n            },\n        }, {\n            \"dataType\": [\"text\"],\n            \"description\": \"The category\",\n            \"name\": \"category\",\n            \"indexFilterable\": true,\n            \"indexSearchable\": false,\n            \"moduleConfig\": {\n                \"text2vec-ollama\": {\n                    \"skip\": true, # Don't include in the vector\n                },\n            },\n        }\n    ],\n    vectorizer: \"text2vec-ollama\",\n    module_config: {\n        \"text2vec-ollama\": {\n            apiEndpoint: \"http://localhost:11434\",\n            model: \"mxbai-embed-large\",\n        },\n    },\n)\n\n# Creating named schemas\n\nclient.schema.create(\n  class_name: 'ArticleNV',\n  description: 'Articles with named vectors',\n  properties: [\n    {\n      \"dataType\": [\"text\"],\n      \"name\": \"title\"\n    },\n    {\n      \"dataType\": [\"text\"],\n      \"name\": \"body\"\n    }\n  ],\n  # cannot use vectorizer and vector_config at the same time\n  # will need to specify for each property\n  vector_config: {\n    \"title\": {\n      \"vectorizer\": {\n        \"text2vec-openai\": {\n          \"properties\": [\"title\"]\n        }\n      },\n      \"vectorIndexType\": \"hnsw\",  # This is the default \n    },\n    \"body\": {\n      \"vectorizer\": {\n        \"text2vec-openai\": {\n          \"properties\": [\"body\"]\n        }\n      },\n      \"vectorIndexType\": \"hnsw\",  # This is the default\n\n    }\n  }\n)\n```\n\n### Using the Objects endpoint\n```ruby\n# Create a new data object. \noutput = client.objects.create(\n    class_name: 'Question',\n    properties: {\n        answer: '42',\n        question: 'What is the meaning of life?',\n        category: 'philosophy'\n    }\n)\nuuid = output[\"id\"]\n\n# Lists all data objects in reverse order of creation.\nclient.objects.list()\n\n# Get a single data object.\nclient.objects.get(\n    class_name: \"Question\",\n    id: uuid\n)\n\n# Check if a data object exists.\nclient.objects.exists?(\n    class_name: \"Question\",\n    id: uuid\n)\n\n# Perform a partial update on an object based on its uuid.\nclient.objects.update(\n    class_name: \"Question\",\n    id: uuid,\n    properties: {\n        category: \"simple-math\"\n    }\n)\n\n# Replace an object based on its uuid.\nclient.objects.replace(\n    class_name: \"Question\",\n    id: uuid,\n    properties: {\n        question: \"What does 6 times 7 equal to?\",\n        category: \"math\",\n        answer: \"42\"\n    }\n)\n\n# Delete a single data object from Weaviate.\nclient.objects.delete(\n    class_name: \"Question\",\n    id: uuid\n)\n\n# Batch create objects\noutput = client.objects.batch_create(objects: [\n    {\n        class: \"Question\",\n        properties: {\n            answer: \"42\",\n            question: \"What is the meaning of life?\",\n            category: \"philosophy\"\n        }\n    }, {\n        class: \"Question\",\n        properties: {\n            answer: \"42\",\n            question: \"What does 6 times 7 equal to?\",\n            category: \"math\"\n        }\n    }\n])\nuuids = output.pluck(\"id\")\n\n# Batch delete objects\nclient.objects.batch_delete(\n    class_name: \"Question\",\n    where: {\n        valueStringArray: uuids,\n        operator: \"ContainsAny\",\n        path: [\"id\"]\n    }\n)\n```\n\n### Querying\n\n#### Get{}\n```ruby\nnear_text = '{ concepts: [\"biology\"] }'\nnear_vector = '{ vector: [0.1, 0.2, ...] }'\nsort_obj = '{ path: [\"category\"], order: desc }'\nwhere_obj = '{ path: [\"id\"], operator: Equal, valueString: \"...\" }'\nwith_hybrid = '{ query: \"Sweets\", alpha: 0.5 }'\n\nclient.query.get(\n    class_name: 'Question',\n    fields: \"question answer category _additional { answer { result hasAnswer property startPosition endPosition } }\",\n    limit: \"1\",\n    offset: \"1\",\n    after: \"id\",\n    sort: sort_obj,\n    where: where_obj,\n\n    # To use this parameter you must have created your schema by setting the `vectorizer:` property to\n    # either 'text2vec-transformers', 'text2vec-contextionary', 'text2vec-openai', 'multi2vec-clip', 'text2vec-huggingface' or 'text2vec-cohere'\n    near_text: near_text,\n\n    # To use this parameter you must have created your schema by setting the `vectorizer:` property to 'multi2vec-clip' or 'img2vec-neural'\n    near_image: near_image,\n    \n    near_vector: near_vector,\n\n    with_hybrid: with_hybrid,\n\n    bm25: bm25,\n\n    near_object: near_object,\n\n    ask: '{ question: \"your-question?\" }'\n)\n\n# Example queries:\nclient.query.get class_name: 'Question', where: '{ operator: Like, valueText: \"SCIENCE\", path: [\"category\"] }', fields: 'answer question category', limit: \"2\"\n\nclient.query.get class_name: 'Question', fields: 'answer question category _additional { id }', after: \"3c5f7039-37f3-4244-b3e2-8f4a083e448d\", limit: \"1\"\n\n# Named vector query - uses targetVectors\nquery_title = client.query.get(\n  class_name: 'ArticleNV',\n  fields: 'title body _additional { id }',\n  near_text: '{\n    targetVectors: [\"title\"],\n    concepts: [\"quantum computers advances\"]\n  }',\n  limit: \"2\"\n)\n\n\n\n```\n\n#### Aggs{}\n```ruby\nclient.query.aggs(\n    class_name: \"Question\",\n    fields: 'meta { count }',\n    group_by: [\"category\"],\n    object_limit: \"10\",\n    near_text: \"{ concepts: [\\\"knowledge\\\"] }\"\n)\n```\n\n#### Explore{}\n```ruby\nclient.query.explore(\n    fields: 'className',\n    near_text: \"{ concepts: [\\\"science\\\"] }\",\n    limit: \"1\"\n)\n```\n\n### Classification\n```ruby\n# Start a classification\nclient.classifications.create(\n    type: \"zeroshot\",\n    class_name: \"Posts\",\n    classify_properties: [\"hasColor\"],\n    based_on_properties: [\"text\"]\n)\n\n# Get the status, results and metadata of a previously created classification\nclient.classifications.get(\n    id: \"\"\n)\n```\n\n### Backups\n```ruby\n# Create backup\nclient.backups.create(\n    backend: \"filesystem\",\n    id: \"my-first-backup\",\n    include: [\"Question\"]\n)\n\n# Get the backup\nclient.backups.get(\n    backend: \"filesystem\",\n    id: \"my-first-backup\"\n)\n\n# Restore backup\nclient.backups.restore(\n    backend: \"filesystem\",\n    id: \"my-first-backup\"\n)\n\n# Check the backup restore status\nclient.backups.restore_status(\n    backend: \"filesystem\",\n    id: \"my-first-backup\"\n)\n```\n\n### Nodes\n```ruby\nclient.nodes\n```\n\n### Health\n```ruby\n# Live determines whether the application is alive. It can be used for Kubernetes liveness probe.\nclient.live?\n```\n\n```ruby\n# Live determines whether the application is ready to receive traffic. It can be used for Kubernetes readiness probe.\nclient.ready?\n```\n\n### Tenants\n\nAny schema can be multi-tenant by passing in these options for to `schema.create()`.\n\n```ruby\nclient.schema.create(\n    # Other keys...\n    multi_tenant: true,\n    auto_tenant_creation: true,\n    auto_tenant_activation: true\n)\n```\n\nSee [Weaviate Multi-tenancy operations](https://weaviate.io/developers/weaviate/manage-data/multi-tenancy). Note that the mix of snake case(used by Ruby) and lower camel case(used by Weaviate) is intentional as that hash is passed directly to Weaviate.\n\nAll data methods in this library support an optional `tenant` argument which must be passed if multi-tenancy is enabled on the related collection\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` 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 exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and 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/andreibondarev/weaviate.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":["Open Source","Ruby"],"sub_categories":["API Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatterns-ai-core%2Fweaviate-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatterns-ai-core%2Fweaviate-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatterns-ai-core%2Fweaviate-ruby/lists"}