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 +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +2 -10
- data/lib/rails_ai_kit/label_record.rb +1 -1
- data/lib/rails_ai_kit/version.rb +1 -1
- data/lib/rails_ai_kit.rb +14 -10
- metadata +10 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e2037f291c26e83110faa8bf175c1d41e22c504019185b49cedad10a709f61db
|
|
4
|
+
data.tar.gz: 39a510a0b7788da34a530e24a89ad832c1402fb29b101813a76f30fd290aa05a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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:
|
|
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
|
data/lib/rails_ai_kit/version.rb
CHANGED
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
|
-
|
|
14
|
-
|
|
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.
|
|
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:
|
|
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/
|
|
95
|
+
homepage: https://github.com/imrrohitt/rails_ai_kit
|
|
95
96
|
licenses: []
|
|
96
97
|
metadata:
|
|
97
|
-
homepage_uri: https://github.com/
|
|
98
|
-
source_code_uri: https://github.com/
|
|
99
|
-
changelog_uri: https://github.com/
|
|
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:
|
|
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: []
|