Class: Leann::Embedding::FastEmbed
- Defined in:
- lib/leann/embedding/fastembed.rb
Overview
FastEmbed provider for local embeddings
Uses ONNX Runtime for fast, local embedding generation without requiring an API key or external service.
Constant Summary collapse
- MAX_BATCH_SIZE =
64- MODELS =
Supported models with their dimensions
{ "BAAI/bge-small-en-v1.5" => 384, "BAAI/bge-base-en-v1.5" => 768, "intfloat/multilingual-e5-small" => 384, "nomic-ai/nomic-embed-text-v1.5" => 768 }.freeze
- DEFAULT_MODEL =
"BAAI/bge-small-en-v1.5"
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#compute(texts) ⇒ Array<Array<Float>>
Compute embeddings for texts.
-
#dimensions ⇒ Integer
Get dimensions for the configured model.
-
#initialize(model: nil, cache_dir: nil, threads: nil) ⇒ FastEmbed
constructor
A new instance of FastEmbed.
Methods inherited from Base
Constructor Details
#initialize(model: nil, cache_dir: nil, threads: nil) ⇒ FastEmbed
Returns a new instance of FastEmbed.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/leann/embedding/fastembed.rb', line 32 def initialize(model: nil, cache_dir: nil, threads: nil) model ||= DEFAULT_MODEL super(model: model) @cache_dir = cache_dir || ENV["FASTEMBED_CACHE_PATH"] @threads = threads @client = nil check_gem! end |
Instance Method Details
#compute(texts) ⇒ Array<Array<Float>>
Compute embeddings for texts
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/leann/embedding/fastembed.rb', line 47 def compute(texts) return [] if texts.empty? = [] in_batches(texts, MAX_BATCH_SIZE) do |batch| = compute_batch(batch) .concat() print "." # Progress indicator end puts " Done! (#{.size} embeddings)" unless texts.size < MAX_BATCH_SIZE # FastEmbed returns normalized vectors by default end |
#dimensions ⇒ Integer
Get dimensions for the configured model
66 67 68 |
# File 'lib/leann/embedding/fastembed.rb', line 66 def dimensions @dimensions ||= MODELS[model] || detect_dimensions end |