mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-02-16 16:34:45 +00:00
Previous to this change we relied on explicit loading for a files in Discourse AI. This had a few downsides: - Busywork whenever you add a file (an extra require relative) - We were not keeping to conventions internally ... some places were OpenAI others are OpenAi - Autoloader did not work which lead to lots of full application broken reloads when developing. This moves all of DiscourseAI into a Zeitwerk compatible structure. It also leaves some minimal amount of manual loading (automation - which is loading into an existing namespace that may or may not be there) To avoid needing /lib/discourse_ai/... we mount a namespace thus we are able to keep /lib pointed at ::DiscourseAi Various files were renamed to get around zeitwerk rules and minimize usage of custom inflections Though we can get custom inflections to work it is not worth it, will require a Discourse core patch which means we create a hard dependency.
47 lines
801 B
Ruby
47 lines
801 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Embeddings
|
|
module VectorRepresentations
|
|
class TextEmbeddingAda002 < Base
|
|
def id
|
|
2
|
|
end
|
|
|
|
def version
|
|
1
|
|
end
|
|
|
|
def name
|
|
"text-embedding-ada-002"
|
|
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)
|
|
response = DiscourseAi::Inference::OpenAiEmbeddings.perform!(text)
|
|
response[:data].first[:embedding]
|
|
end
|
|
|
|
def tokenizer
|
|
DiscourseAi::Tokenizer::OpenAiTokenizer
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|