2024-04-10 16:24:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscourseAi
|
|
|
|
module Embeddings
|
|
|
|
module VectorRepresentations
|
|
|
|
class BgeM3 < Base
|
|
|
|
class << self
|
|
|
|
def name
|
|
|
|
"bge-m3"
|
|
|
|
end
|
|
|
|
|
|
|
|
def correctly_configured?
|
|
|
|
DiscourseAi::Inference::HuggingFaceTextEmbeddings.configured?
|
|
|
|
end
|
|
|
|
|
|
|
|
def dependant_setting_names
|
|
|
|
%w[ai_hugging_face_tei_endpoint_srv ai_hugging_face_tei_endpoint]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def vector_from(text, asymetric: false)
|
|
|
|
truncated_text = tokenizer.truncate(text, max_sequence_length - 2)
|
2024-11-25 11:12:43 -05:00
|
|
|
inference_client.perform!(truncated_text)
|
2024-04-10 16:24:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def dimensions
|
|
|
|
1024
|
|
|
|
end
|
|
|
|
|
|
|
|
def max_sequence_length
|
|
|
|
8192
|
|
|
|
end
|
|
|
|
|
|
|
|
def id
|
|
|
|
8
|
|
|
|
end
|
|
|
|
|
|
|
|
def version
|
|
|
|
1
|
|
|
|
end
|
|
|
|
|
|
|
|
def pg_function
|
|
|
|
"<#>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def pg_index_type
|
2024-08-08 10:55:20 -04:00
|
|
|
"halfvec_ip_ops"
|
2024-04-10 16:24:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tokenizer
|
|
|
|
DiscourseAi::Tokenizer::BgeM3Tokenizer
|
|
|
|
end
|
2024-11-25 11:12:43 -05:00
|
|
|
|
|
|
|
def inference_client
|
|
|
|
DiscourseAi::Inference::HuggingFaceTextEmbeddings.instance
|
|
|
|
end
|
2024-04-10 16:24:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|