Class: Llmemory::VectorStore::OpenAIEmbeddings
- Defined in:
- lib/llmemory/vector_store/openai_embeddings.rb
Constant Summary collapse
- DEFAULT_MODEL =
"text-embedding-3-small"- DEFAULT_DIMS =
1536
Instance Method Summary collapse
- #embed(text) ⇒ Object
-
#initialize(api_key: nil, model: nil) ⇒ OpenAIEmbeddings
constructor
A new instance of OpenAIEmbeddings.
Constructor Details
#initialize(api_key: nil, model: nil) ⇒ OpenAIEmbeddings
Returns a new instance of OpenAIEmbeddings.
14 15 16 17 18 19 |
# File 'lib/llmemory/vector_store/openai_embeddings.rb', line 14 def initialize(api_key: nil, model: nil) @api_key = api_key || Llmemory.configuration.llm_api_key @model = model || DEFAULT_MODEL @cache = {} @cache_order = [] end |
Instance Method Details
#embed(text) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/llmemory/vector_store/openai_embeddings.rb', line 21 def (text) return Array.new(DEFAULT_DIMS, 0.0) if text.to_s.strip.empty? if Llmemory.configuration. key = cache_key(text) return @cache[key].dup if @cache.key?(key) end result = (text) if Llmemory.configuration. evict_if_needed @cache[cache_key(text)] = result.dup @cache_order << cache_key(text) end result end |