Module: Zvec::ActiveRecord::Vectorize

Extended by:
ActiveSupport::Concern
Defined in:
lib/zvec/active_record.rb

Overview

Rails concern that adds vector search capabilities to ActiveRecord models.

When included in a model, call vectorize to configure which text field to embed, the vector dimension, and the embedding function.

Examples:

Basic usage

class Article < ApplicationRecord
  include Zvec::ActiveRecord::Vectorize

  vectorize :content,
    dimensions: 1536,
    prefix: "articles",
    embed_with: ->(text) { OpenAI.embed(text) }
end

Searching

Article.vector_search("Ruby programming", top_k: 5)
Article.vector_search([0.1, 0.2, ...], top_k: 5, embed: false)

Instance methods

article.zvec_update_embedding!   # re-embed and store
article.zvec_remove_embedding!   # remove from vector store
article.zvec_embedding           # fetch stored embedding doc

Defined Under Namespace

Modules: InstanceMethods, SearchMethods