Fix Cascading Bugs in Huggingface and Ollama Embedder #1574
7
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Note
This pull request builds upon the previous PR #1548 , which addressed Bug 1. During further testing, additional bugs were discovered and have been documented and resolved in this PR.
Summary
This pull request addresses a series of bugs in the embeddings especially while using 'huggingface' as embedder. Each fix revealed the next issue, which has been documented and resolved in sequence. I already made PR for Bug1 beforehand itself but discovered series of bugs later on as mentioned below.
Details
Bug 1: ModuleNotFoundError: No module named 'embedding'
mem0/embeddings/huggingface.py
andmem0/embeddings/ollama.py
EmbeddingBase
from non-existing directory.EmbeddingBase
class with correct parent directory.Bug 2: Value error, Unsupported embedding provider: huggingface
mem0/embeddings/configs.py
EmbedderConfig
.huggingface
to the provider checklist inEmbedderConfig
.Bug 3: TypeError: Can't instantiate abstract class HuggingFaceEmbedding with abstract method embed
mem0/embeddings/huggingface.py
HuggingFaceEmbedding
was not being instantiated. The abstract methodembed
was missing.HuggingFaceEmbedding
Bug 4: AttributeError: 'HuggingFaceEmbedding' object has no attribute 'dims'
mem0/embeddings/huggingface.py
HuggingFaceEmbedding
was not being instantiated. The attributedims
was missing.dims
attribute toHuggingFaceEmbedding
usingget_sentence_embedding_dimension
method ofSentenceTransformer
Impact
These fixes, by addressing multiple cascading issues, improve the reliability and performance of mem0 while using the custom embedder config (like huggingface, ollama), preventing crashes and unexpected results.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Please delete options that are not relevant.
Test Script
This code initializes the Memory class with the specified configuration, ensuring that the embedding provider 'huggingface' and the model 'multi-qa-MiniLM-L6-cos-v1' are correctly set up and functional.
Steps to Reproduce
Checklist:
Maintainer Checklist