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 | import os |
| #2 | from typing import Literal, Optional |
| #3 | |
| #4 | from google import genai |
| #5 | from google.genai import types |
| #6 | |
| #7 | from mem0.configs.embeddings.base import BaseEmbedderConfig |
| #8 | from mem0.embeddings.base import EmbeddingBase |
| #9 | |
| #10 | |
| #11 | class GoogleGenAIEmbedding(EmbeddingBase): |
| #12 | def __init__(self, config: Optional[BaseEmbedderConfig] = None): |
| #13 | super().__init__(config) |
| #14 | |
| #15 | self.config.model = self.config.model or "models/text-embedding-004" |
| #16 | self.config.embedding_dims = self.config.embedding_dims or self.config.output_dimensionality or 768 |
| #17 | |
| #18 | api_key = self.config.api_key or os.getenv("GOOGLE_API_KEY") |
| #19 | |
| #20 | self.client = genai.Client(api_key=api_key) |
| #21 | |
| #22 | def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None): |
| #23 | """ |
| #24 | Get the embedding for the given text using Google Generative AI. |
| #25 | Args: |
| #26 | text (str): The text to embed. |
| #27 | memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None. |
| #28 | Returns: |
| #29 | list: The embedding vector. |
| #30 | """ |
| #31 | text = text.replace("\n", " ") |
| #32 | |
| #33 | # Create config for embedding parameters |
| #34 | config = types.EmbedContentConfig(output_dimensionality=self.config.embedding_dims) |
| #35 | |
| #36 | # Call the embed_content method with the correct parameters |
| #37 | response = self.client.models.embed_content(model=self.config.model, contents=text, config=config) |
| #38 | |
| #39 | return response.embeddings[0].values |
| #40 |