repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | from typing import Optional, Literal |
| #2 | |
| #3 | from mem0.embeddings.base import EmbeddingBase |
| #4 | from mem0.configs.embeddings.base import BaseEmbedderConfig |
| #5 | |
| #6 | try: |
| #7 | from fastembed import TextEmbedding |
| #8 | except ImportError: |
| #9 | raise ImportError("FastEmbed is not installed. Please install it using `pip install fastembed`") |
| #10 | |
| #11 | class FastEmbedEmbedding(EmbeddingBase): |
| #12 | def __init__(self, config: Optional[BaseEmbedderConfig] = None): |
| #13 | super().__init__(config) |
| #14 | |
| #15 | self.config.model = self.config.model or "thenlper/gte-large" |
| #16 | self.dense_model = TextEmbedding(model_name = self.config.model) |
| #17 | |
| #18 | def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None): |
| #19 | """ |
| #20 | Convert the text to embeddings using FastEmbed running in the Onnx runtime |
| #21 | Args: |
| #22 | text (str): The text to embed. |
| #23 | memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None. |
| #24 | Returns: |
| #25 | list: The embedding vector. |
| #26 | """ |
| #27 | text = text.replace("\n", " ") |
| #28 | embeddings = list(self.dense_model.embed(text)) |
| #29 | return embeddings[0] |
| #30 |