2024-01-29 11:24:30 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscourseAi
|
|
|
|
module Embeddings
|
|
|
|
module VectorRepresentations
|
|
|
|
class TextEmbedding3Small < Base
|
2024-02-01 11:05:38 -05:00
|
|
|
class << self
|
|
|
|
def name
|
|
|
|
"text-embedding-3-small"
|
|
|
|
end
|
|
|
|
|
|
|
|
def correctly_configured?
|
|
|
|
SiteSetting.ai_openai_api_key.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def dependant_setting_names
|
|
|
|
%w[ai_openai_api_key]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-01-29 11:24:30 -05:00
|
|
|
def id
|
|
|
|
6
|
|
|
|
end
|
|
|
|
|
|
|
|
def version
|
|
|
|
1
|
|
|
|
end
|
|
|
|
|
|
|
|
def dimensions
|
|
|
|
1536
|
|
|
|
end
|
|
|
|
|
|
|
|
def max_sequence_length
|
|
|
|
8191
|
|
|
|
end
|
|
|
|
|
|
|
|
def pg_function
|
|
|
|
"<=>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def pg_index_type
|
|
|
|
"vector_cosine_ops"
|
|
|
|
end
|
|
|
|
|
|
|
|
def vector_from(text)
|
2024-02-01 11:05:38 -05:00
|
|
|
response = DiscourseAi::Inference::OpenAiEmbeddings.perform!(text, model: self.class.name)
|
2024-01-29 11:24:30 -05:00
|
|
|
response[:data].first[:embedding]
|
|
|
|
end
|
|
|
|
|
|
|
|
def tokenizer
|
|
|
|
DiscourseAi::Tokenizer::OpenAiTokenizer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|