rails_ai_kit 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d497000abdc4e0a8f02f6167570d5d00888979e31ed5e484fc707647ebdface5
4
- data.tar.gz: b721aeaeddabe1c8dce81f6aca4ff94188623c6cdb8fd5b22dd5199a7d1fb3bf
3
+ metadata.gz: e2037f291c26e83110faa8bf175c1d41e22c504019185b49cedad10a709f61db
4
+ data.tar.gz: 39a510a0b7788da34a530e24a89ad832c1402fb29b101813a76f30fd290aa05a
5
5
  SHA512:
6
- metadata.gz: 0f6a1a9ec8f3f9a4d0404f2ef5b7b8dc61ad41bee7a7557d3701a7e958786114430ca4b5c3db4e1581b98bda4b280856eca1a1cd7152987c6d5db54ebc4b1b63
7
- data.tar.gz: 43316a2c58575ae72429deb036cd3499b42bd19ec5c7fadf15404b46a864fdcffa3b41a33b24815fef16dd426ace74bac38fe8460e6e722c9639785ee5c4d7ef
6
+ metadata.gz: ede0b9f2d61943ee974e9b89c5b40d492e2e81ed3b31a5a04031c7fb32906cc746cf6720b930d404eb293a8814caa72ecfc794b5beb8dc2b72567beadf36d8f1
7
+ data.tar.gz: 95db7112cee6a9922fc93b5fe83b053588a4b46ea7d4d3fb9166e0192873653ef8a20b134b195bb05dd20ca07942e351a9170b1581dcbf45b08af138b568ebc5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.1.2] - 2026-03-07
6
+
7
+ ### Fixed
8
+
9
+ - Compatibility with Neighbor 0.6: load label_record, classifier, and vector_classify in `ActiveSupport.on_load(:active_record)` so `has_neighbors` is available
10
+ - Use integer for `dimensions` in LabelRecord (Neighbor 0.6 does not support proc)
11
+
12
+ ## [0.1.1] - 2026-03-07
13
+
14
+ ### Fixed
15
+
16
+ - Define `RailsAiKit::Error` before loading embedding providers to fix `uninitialized constant RailsAiKit::Error` when running generators or migrations
17
+
5
18
  ## [0.1.0] - 2025-03-07
6
19
 
7
20
  ### Added
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A Rails gem that adds a **classification layer on top of [pgvector](https://github.com/pgvector/pgvector)**. Instead of building custom ML or calling LLMs every time, use vector similarity to classify data: support tickets, content moderation, ecommerce categories, document routing, and more.
4
4
 
5
+ **Source:** [github.com/imrrohitt/rails_ai_kit](https://github.com/imrrohitt/rails_ai_kit)
6
+
5
7
  - **No ML training** – train labels with example texts and compare embeddings
6
8
  - **No LLM cost** – one-time embedding per piece of content; classification is nearest-neighbor in PostgreSQL
7
9
  - **Rails-friendly** – `vector_classify`, `Classifier.train`, `Classifier.classify`, `Article.similar_to("query")`
@@ -247,15 +249,6 @@ MIT.
247
249
 
248
250
  ## How it’s built
249
251
 
250
- - **Configuration** (`lib/rails_ai_kit/configuration.rb`) – Embeding provider, dimensions, and API keys (e.g. `api_keys[:openai]`).
251
- - **Embedding providers** (`lib/rails_ai_kit/embedding_providers/`) – Base class plus OpenAI and Cohere. Each implements `embed(text)` and `embed_batch(texts)` using the provider API.
252
- - **EmbeddingService** – Wraps the configured provider and API key so `RailsAiKit.embedding.embed(text)` works without passing keys every time.
253
- - **LabelRecord** – ActiveRecord model for `rails_ai_kit_labels` (classifier_name, label_name, embedding). Uses Neighbor’s `has_neighbors :embedding` for similarity.
254
- - **Classifier** – Trains labels by averaging example embeddings and storing them; classifies by nearest-neighbor (cosine) against those label vectors. Supports `classify(text)`, `classify_by_embedding(vector)`, and `batch_classify(records)`.
255
- - **VectorClassify** – Concern that adds the `vector_classify` macro: `has_neighbors` on the embedding column, a before_save that embeds the source column and runs `classify_by_embedding`, and a `similar_to(query_text)` scope that embeds the query and runs nearest-neighbor search.
256
-
257
- ## How it’s built
258
-
259
252
  - **Configuration** (`lib/rails_ai_kit/configuration.rb`) – Embedding provider, dimensions, and API keys (e.g. `api_keys[:openai]`).
260
253
  - **Embedding providers** (`lib/rails_ai_kit/embedding_providers/`) – Base class plus OpenAI and Cohere. Each implements `embed(text)` and `embed_batch(texts)` using the provider API.
261
254
  - **EmbeddingService** – Wraps the configured provider and API key so `RailsAiKit.embedding.embed(text)` works without passing keys every time.
@@ -268,4 +261,3 @@ MIT.
268
261
 
269
262
  - [pgvector](https://github.com/pgvector/pgvector) – Open-source vector similarity search for Postgres
270
263
  - [Neighbor](https://github.com/ankane/neighbor) – Nearest neighbor search for Rails (used by this gem)
271
- test
@@ -7,7 +7,7 @@ module RailsAiKit
7
7
  class LabelRecord < ActiveRecord::Base
8
8
  self.table_name = "rails_ai_kit_labels"
9
9
 
10
- has_neighbors :embedding, dimensions: -> { RailsAiKit.configuration.embedding_dimensions }
10
+ has_neighbors :embedding, dimensions: RailsAiKit.configuration.embedding_dimensions
11
11
 
12
12
  validates :classifier_name, presence: true
13
13
  validates :label_name, presence: true
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAiKit
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/rails_ai_kit.rb CHANGED
@@ -2,24 +2,28 @@
2
2
 
3
3
  require_relative "rails_ai_kit/version"
4
4
  require_relative "rails_ai_kit/configuration"
5
+
6
+ module RailsAiKit
7
+ class Error < StandardError; end
8
+ end
9
+
5
10
  require_relative "rails_ai_kit/embedding_providers/base"
6
11
  require_relative "rails_ai_kit/embedding_providers/openai"
7
12
  require_relative "rails_ai_kit/embedding_providers/cohere"
8
13
  require_relative "rails_ai_kit/embedding_service"
9
- require_relative "rails_ai_kit/label_record"
10
- require_relative "rails_ai_kit/classifier"
11
- require_relative "rails_ai_kit/vector_classify"
12
14
 
13
- module RailsAiKit
14
- class Error < StandardError; end
15
+ # Load models and AR integration only after ActiveRecord (and Neighbor) are ready.
16
+ # Neighbor 0.6+ adds has_neighbors via ActiveSupport.on_load(:active_record).
17
+ ActiveSupport.on_load(:active_record) do
18
+ require_relative "rails_ai_kit/label_record"
19
+ require_relative "rails_ai_kit/classifier"
20
+ require_relative "rails_ai_kit/vector_classify"
21
+ ActiveRecord::Base.include RailsAiKit::VectorClassify
22
+ end
15
23
 
24
+ module RailsAiKit
16
25
  # Top-level classifier using default classifier name. For custom name use Classifier.new(classifier_name: "MyClassifier").
17
26
  def self.classifier(classifier_name = nil)
18
27
  Classifier.new(classifier_name: classifier_name)
19
28
  end
20
29
  end
21
-
22
- # Optional Rails integration: extend ActiveRecord so vector_classify is available.
23
- if defined?(ActiveRecord::Base)
24
- ActiveRecord::Base.include RailsAiKit::VectorClassify
25
- end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_ai_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rails AI Kit Contributors
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-03-07 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: activerecord
@@ -91,12 +92,13 @@ files:
91
92
  - lib/rails_ai_kit/label_record.rb
92
93
  - lib/rails_ai_kit/vector_classify.rb
93
94
  - lib/rails_ai_kit/version.rb
94
- homepage: https://github.com/your-org/rails_ai_kit
95
+ homepage: https://github.com/imrrohitt/rails_ai_kit
95
96
  licenses: []
96
97
  metadata:
97
- homepage_uri: https://github.com/your-org/rails_ai_kit
98
- source_code_uri: https://github.com/your-org/rails_ai_kit
99
- changelog_uri: https://github.com/your-org/rails_ai_kit/blob/main/CHANGELOG.md
98
+ homepage_uri: https://github.com/imrrohitt/rails_ai_kit
99
+ source_code_uri: https://github.com/imrrohitt/rails_ai_kit
100
+ changelog_uri: https://github.com/imrrohitt/rails_ai_kit/blob/main/CHANGELOG.md
101
+ post_install_message:
100
102
  rdoc_options: []
101
103
  require_paths:
102
104
  - lib
@@ -111,7 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
113
  - !ruby/object:Gem::Version
112
114
  version: '0'
113
115
  requirements: []
114
- rubygems_version: 4.0.7
116
+ rubygems_version: 3.0.3.1
117
+ signing_key:
115
118
  specification_version: 4
116
119
  summary: Vector-based classification layer on top of pgvector for Rails
117
120
  test_files: []