beltrewilton
Does anyone have experience tuning Bumblebee for better results with the roberta-based
nomic-ai/nomic-embed-text-v2-moe model? I’m seeing poor retrieval performance in Elixir, even though the same setup works well with all-MiniLM-L6-v2, and the Python version using nomic and all-MiniLM gives correct results.
# EmbeddingGenserver
@model_id "nomic-ai/nomic-embed-text-v2-moe"
...
@impl true
def handle_continue(:model_loader, _state) do
{:ok, model} =
Bumblebee.load_model({:hf, @model_id},
module: Bumblebee.Text.Roberta,
architecture: :base
)
{:ok, tokenizer} = Bumblebee.load_tokenizer({:hf, @model_id}, type: :roberta)
...
@impl true
def handle_call({:embed, input}, _from, state) do
serving =
Bumblebee.Text.text_embedding(state.model, state.tokenizer,
output_attribute: :hidden_state,
output_pool: :mean_pooling,
embedding_processor: :l2_norm
)
...
# Embedding
def ingest(input, task \\ "search_document") do
...
input_mask =
input |> Stream.map(fn i -> "#{task}: #{i}" end) |> Enum.to_list()
embedding = EmbeddingGenserver.embed(input_mask)
Stream.zip(Stream.map(input, & &1), Stream.map(embedding, & &1))
|> Stream.map(fn {text, embedding} ->
Repo.insert(%Document{text: text, embedding: embedding}, prefix: tenant)
end)
|> Stream.run()
end
...
def retrieve(text, task \\ "search_document", k \\ 3) do
...
[embedding] = EmbeddingGenserver.embed("#{task}: #{text}")
Repo.all(
from d in Document,
prefix: ^tenant,
select: {fragment("1 - (? <=> ?::vector)", d.embedding, ^embedding), d.text},
order_by: cosine_distance(d.embedding, ^embedding),
limit: ^k
)
end
....
**poor similarity**
iex> Embedding.retrieve("project")
[
{0.9799439930982597,
"Contact Timeframe: After submitting the form on ccdcare.com or via this chat, our recruiters typically reach out within 24 to 48 hours. Thank you for your patience."},
{0.9761637491887082,
"Applying for Non-Agent Positions: Thank you for your interest. Staff positions are posted on our LinkedIn account. If the position you’re seeking isn’t listed, stay updated via our social media channels."},
{0.976003851891173,
"Campaigns with High Pay: Hourly rates depend on the campaign you qualify for. Our salaries start at RD$ 260.00 p/h, with full compensation including base salary and hourly incentives. Complete the recruitment process for detailed information."}
]
tokenizer_embed = AutoTokenizer.from_pretrained('nomic-ai/nomic-embed-text-v2-moe')
model_embed = AutoModel.from_pretrained('nomic-ai/nomic-embed-text-v2-moe', trust_remote_code=True)
model_embed.eval()
def embedd(text: list):
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0]
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
encoded_input = tokenizer_embed(text, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
model_output = model_embed(**encoded_input)
embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
embeddings = F.normalize(embeddings, p=2, dim=1)
return np.array(embeddings)[0]
...
ef retrieve_similar_documents_pgvector(query_text, top_k=5):
query_embedding = embedd([f"search_document: {query_text}"]).squeeze().tolist()
try:
connection = psycopg2.connect(user="postgres",
password="postgres",
host="localhost",
port="5432",
database="...")
register_vector(connection)
cursor = connection.cursor()
cursor.execute("""
SELECT text, 1 - (embedding <=> %s::vector) AS cosine_similarity
FROM ceidy.documents_copy
ORDER BY cosine_similarity DESC
LIMIT %s
""", (query_embedding, top_k))
results = cursor.fetchall()
return results # [(text, cosine_similarity), ...]
except (Exception, psycopg2.Error) as error:
print("Error during retrieval:", error)
return []
finally:
if connection:
cursor.close()
connection.close()
...
results = retrieve_similar_documents_pgvector("project", top_k=3)
for text, score in results:
print(f"Score: {score:.4f} | Text: {text}")
**the similarity looks good**
output:
Score: 0.7170 | Text: Spanish Projects: We do not currently have Spanish-language projects available. Please follow our social media for updates.
Score: 0.6636 | Text: Part-Time Projects: We currently have part-time projects available. Please share your direct number, email, ID number, and full name so a recruitment representative can assist you. Don’t miss out—apply today!
Score: 0.5672 | Text: Overseas Remote Work: At this moment, we do not have an option for overseas remote work. Please stay updated through our social media for any changes.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
jonatanklosko
The problem is that
nomic-ai/nomic-embed-text-v2-moeusesNomicBertModel, which is not implemented in Bumblebee. The Python implementation is not in the huggingface/transformers library either, it lives on HuggingFace Hub. We usually only implement models in Bumblebee once they are added to huggingface/transformers, there is an issue upstream, which seems relevant Add Nomic Embed Code to Transformers · Issue #30995 · huggingface/transformers · GitHub. We usually wait for that because the implementations on HuggingFace hub are not always well structured (e.g. they change over time, or authors make multiple implementations for different checkpoints). That said, it looks like multiple Nomic Embed checkpoints use the same code (nomic-ai/nomic-bert-2048 at main), so it should be relatively solid and I think it’s ok to implement it in Bumblebee, if someone wants to send a PR.If you did
Bumblebee.load_model({:hf, @model_id}), you should get an error. Since you explicitly specify:moduleand:architecture, Bumblebee is going to try loading as if the model was Roberta, which in this case is not going to give meaningful results. I expect that when you load the model there is a number of log messages that certain parameters are not found, and as a result they are initialized to random values.beltrewilton
Thanks a lot for the detailed explanation and for the awesome work on Bumblebee
Really appreciate you taking the time to share the background on the
NomicBertModelsituation — that totally makes sense now.I ended up switching to
paraphrase-multilingual-MiniLM-L12-v2and it works perfectly for my use case, no changes needed in my code. Super smooth.