[feat add]FastEmbed embedding for local embeddings (#3552)

This commit is contained in:
Tarun Jain
2025-10-16 22:52:22 +05:30
committed by GitHub
parent 394203d1b5
commit 1090784302
5 changed files with 78 additions and 0 deletions
+1
View File
@@ -24,6 +24,7 @@ class EmbedderConfig(BaseModel):
"lmstudio",
"langchain",
"aws_bedrock",
"fastembed",
]:
return v
else:
+29
View File
@@ -0,0 +1,29 @@
from typing import Optional, Literal
from mem0.embeddings.base import EmbeddingBase
from mem0.configs.embeddings.base import BaseEmbedderConfig
try:
from fastembed import TextEmbedding
except ImportError:
raise ImportError("FastEmbed is not installed. Please install it using `pip install fastembed`")
class FastEmbedEmbedding(EmbeddingBase):
def __init__(self, config: Optional[BaseEmbedderConfig] = None):
super().__init__(config)
self.config.model = self.config.model or "thenlper/gte-large"
self.dense_model = TextEmbedding(model_name = self.config.model)
def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
"""
Convert the text to embeddings using FastEmbed running in the Onnx runtime
Args:
text (str): The text to embed.
memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None.
Returns:
list: The embedding vector.
"""
text = text.replace("\n", " ")
embeddings = list(self.dense_model.embed(text))
return embeddings[0]
+1
View File
@@ -145,6 +145,7 @@ class EmbedderFactory:
"lmstudio": "mem0.embeddings.lmstudio.LMStudioEmbedding",
"langchain": "mem0.embeddings.langchain.LangchainEmbedding",
"aws_bedrock": "mem0.embeddings.aws_bedrock.AWSBedrockEmbedding",
"fastembed": "mem0.embeddings.fastembed.FastEmbedEmbedding",
}
@classmethod