agentrun-mem0ai 0.0.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentrun_mem0/__init__.py +6 -0
- agentrun_mem0/client/__init__.py +0 -0
- agentrun_mem0/client/main.py +1747 -0
- agentrun_mem0/client/project.py +931 -0
- agentrun_mem0/client/utils.py +115 -0
- agentrun_mem0/configs/__init__.py +0 -0
- agentrun_mem0/configs/base.py +90 -0
- agentrun_mem0/configs/embeddings/__init__.py +0 -0
- agentrun_mem0/configs/embeddings/base.py +110 -0
- agentrun_mem0/configs/enums.py +7 -0
- agentrun_mem0/configs/llms/__init__.py +0 -0
- agentrun_mem0/configs/llms/anthropic.py +56 -0
- agentrun_mem0/configs/llms/aws_bedrock.py +192 -0
- agentrun_mem0/configs/llms/azure.py +57 -0
- agentrun_mem0/configs/llms/base.py +62 -0
- agentrun_mem0/configs/llms/deepseek.py +56 -0
- agentrun_mem0/configs/llms/lmstudio.py +59 -0
- agentrun_mem0/configs/llms/ollama.py +56 -0
- agentrun_mem0/configs/llms/openai.py +79 -0
- agentrun_mem0/configs/llms/vllm.py +56 -0
- agentrun_mem0/configs/prompts.py +459 -0
- agentrun_mem0/configs/rerankers/__init__.py +0 -0
- agentrun_mem0/configs/rerankers/base.py +17 -0
- agentrun_mem0/configs/rerankers/cohere.py +15 -0
- agentrun_mem0/configs/rerankers/config.py +12 -0
- agentrun_mem0/configs/rerankers/huggingface.py +17 -0
- agentrun_mem0/configs/rerankers/llm.py +48 -0
- agentrun_mem0/configs/rerankers/sentence_transformer.py +16 -0
- agentrun_mem0/configs/rerankers/zero_entropy.py +28 -0
- agentrun_mem0/configs/vector_stores/__init__.py +0 -0
- agentrun_mem0/configs/vector_stores/alibabacloud_mysql.py +64 -0
- agentrun_mem0/configs/vector_stores/aliyun_tablestore.py +32 -0
- agentrun_mem0/configs/vector_stores/azure_ai_search.py +57 -0
- agentrun_mem0/configs/vector_stores/azure_mysql.py +84 -0
- agentrun_mem0/configs/vector_stores/baidu.py +27 -0
- agentrun_mem0/configs/vector_stores/chroma.py +58 -0
- agentrun_mem0/configs/vector_stores/databricks.py +61 -0
- agentrun_mem0/configs/vector_stores/elasticsearch.py +65 -0
- agentrun_mem0/configs/vector_stores/faiss.py +37 -0
- agentrun_mem0/configs/vector_stores/langchain.py +30 -0
- agentrun_mem0/configs/vector_stores/milvus.py +42 -0
- agentrun_mem0/configs/vector_stores/mongodb.py +25 -0
- agentrun_mem0/configs/vector_stores/neptune.py +27 -0
- agentrun_mem0/configs/vector_stores/opensearch.py +41 -0
- agentrun_mem0/configs/vector_stores/pgvector.py +52 -0
- agentrun_mem0/configs/vector_stores/pinecone.py +55 -0
- agentrun_mem0/configs/vector_stores/qdrant.py +47 -0
- agentrun_mem0/configs/vector_stores/redis.py +24 -0
- agentrun_mem0/configs/vector_stores/s3_vectors.py +28 -0
- agentrun_mem0/configs/vector_stores/supabase.py +44 -0
- agentrun_mem0/configs/vector_stores/upstash_vector.py +34 -0
- agentrun_mem0/configs/vector_stores/valkey.py +15 -0
- agentrun_mem0/configs/vector_stores/vertex_ai_vector_search.py +28 -0
- agentrun_mem0/configs/vector_stores/weaviate.py +41 -0
- agentrun_mem0/embeddings/__init__.py +0 -0
- agentrun_mem0/embeddings/aws_bedrock.py +100 -0
- agentrun_mem0/embeddings/azure_openai.py +55 -0
- agentrun_mem0/embeddings/base.py +31 -0
- agentrun_mem0/embeddings/configs.py +30 -0
- agentrun_mem0/embeddings/gemini.py +39 -0
- agentrun_mem0/embeddings/huggingface.py +44 -0
- agentrun_mem0/embeddings/langchain.py +35 -0
- agentrun_mem0/embeddings/lmstudio.py +29 -0
- agentrun_mem0/embeddings/mock.py +11 -0
- agentrun_mem0/embeddings/ollama.py +53 -0
- agentrun_mem0/embeddings/openai.py +49 -0
- agentrun_mem0/embeddings/together.py +31 -0
- agentrun_mem0/embeddings/vertexai.py +64 -0
- agentrun_mem0/exceptions.py +503 -0
- agentrun_mem0/graphs/__init__.py +0 -0
- agentrun_mem0/graphs/configs.py +105 -0
- agentrun_mem0/graphs/neptune/__init__.py +0 -0
- agentrun_mem0/graphs/neptune/base.py +497 -0
- agentrun_mem0/graphs/neptune/neptunedb.py +511 -0
- agentrun_mem0/graphs/neptune/neptunegraph.py +474 -0
- agentrun_mem0/graphs/tools.py +371 -0
- agentrun_mem0/graphs/utils.py +97 -0
- agentrun_mem0/llms/__init__.py +0 -0
- agentrun_mem0/llms/anthropic.py +87 -0
- agentrun_mem0/llms/aws_bedrock.py +665 -0
- agentrun_mem0/llms/azure_openai.py +141 -0
- agentrun_mem0/llms/azure_openai_structured.py +91 -0
- agentrun_mem0/llms/base.py +131 -0
- agentrun_mem0/llms/configs.py +34 -0
- agentrun_mem0/llms/deepseek.py +107 -0
- agentrun_mem0/llms/gemini.py +201 -0
- agentrun_mem0/llms/groq.py +88 -0
- agentrun_mem0/llms/langchain.py +94 -0
- agentrun_mem0/llms/litellm.py +87 -0
- agentrun_mem0/llms/lmstudio.py +114 -0
- agentrun_mem0/llms/ollama.py +117 -0
- agentrun_mem0/llms/openai.py +147 -0
- agentrun_mem0/llms/openai_structured.py +52 -0
- agentrun_mem0/llms/sarvam.py +89 -0
- agentrun_mem0/llms/together.py +88 -0
- agentrun_mem0/llms/vllm.py +107 -0
- agentrun_mem0/llms/xai.py +52 -0
- agentrun_mem0/memory/__init__.py +0 -0
- agentrun_mem0/memory/base.py +63 -0
- agentrun_mem0/memory/graph_memory.py +698 -0
- agentrun_mem0/memory/kuzu_memory.py +713 -0
- agentrun_mem0/memory/main.py +2229 -0
- agentrun_mem0/memory/memgraph_memory.py +689 -0
- agentrun_mem0/memory/setup.py +56 -0
- agentrun_mem0/memory/storage.py +218 -0
- agentrun_mem0/memory/telemetry.py +90 -0
- agentrun_mem0/memory/utils.py +208 -0
- agentrun_mem0/proxy/__init__.py +0 -0
- agentrun_mem0/proxy/main.py +189 -0
- agentrun_mem0/reranker/__init__.py +9 -0
- agentrun_mem0/reranker/base.py +20 -0
- agentrun_mem0/reranker/cohere_reranker.py +85 -0
- agentrun_mem0/reranker/huggingface_reranker.py +147 -0
- agentrun_mem0/reranker/llm_reranker.py +142 -0
- agentrun_mem0/reranker/sentence_transformer_reranker.py +107 -0
- agentrun_mem0/reranker/zero_entropy_reranker.py +96 -0
- agentrun_mem0/utils/factory.py +283 -0
- agentrun_mem0/utils/gcp_auth.py +167 -0
- agentrun_mem0/vector_stores/__init__.py +0 -0
- agentrun_mem0/vector_stores/alibabacloud_mysql.py +547 -0
- agentrun_mem0/vector_stores/aliyun_tablestore.py +252 -0
- agentrun_mem0/vector_stores/azure_ai_search.py +396 -0
- agentrun_mem0/vector_stores/azure_mysql.py +463 -0
- agentrun_mem0/vector_stores/baidu.py +368 -0
- agentrun_mem0/vector_stores/base.py +58 -0
- agentrun_mem0/vector_stores/chroma.py +332 -0
- agentrun_mem0/vector_stores/configs.py +67 -0
- agentrun_mem0/vector_stores/databricks.py +761 -0
- agentrun_mem0/vector_stores/elasticsearch.py +237 -0
- agentrun_mem0/vector_stores/faiss.py +479 -0
- agentrun_mem0/vector_stores/langchain.py +180 -0
- agentrun_mem0/vector_stores/milvus.py +250 -0
- agentrun_mem0/vector_stores/mongodb.py +310 -0
- agentrun_mem0/vector_stores/neptune_analytics.py +467 -0
- agentrun_mem0/vector_stores/opensearch.py +292 -0
- agentrun_mem0/vector_stores/pgvector.py +404 -0
- agentrun_mem0/vector_stores/pinecone.py +382 -0
- agentrun_mem0/vector_stores/qdrant.py +270 -0
- agentrun_mem0/vector_stores/redis.py +295 -0
- agentrun_mem0/vector_stores/s3_vectors.py +176 -0
- agentrun_mem0/vector_stores/supabase.py +237 -0
- agentrun_mem0/vector_stores/upstash_vector.py +293 -0
- agentrun_mem0/vector_stores/valkey.py +824 -0
- agentrun_mem0/vector_stores/vertex_ai_vector_search.py +635 -0
- agentrun_mem0/vector_stores/weaviate.py +343 -0
- agentrun_mem0ai-0.0.11.data/data/README.md +205 -0
- agentrun_mem0ai-0.0.11.dist-info/METADATA +277 -0
- agentrun_mem0ai-0.0.11.dist-info/RECORD +150 -0
- agentrun_mem0ai-0.0.11.dist-info/WHEEL +4 -0
- agentrun_mem0ai-0.0.11.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Literal, Optional
|
|
3
|
+
|
|
4
|
+
from google import genai
|
|
5
|
+
from google.genai import types
|
|
6
|
+
|
|
7
|
+
from agentrun_mem0.configs.embeddings.base import BaseEmbedderConfig
|
|
8
|
+
from agentrun_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
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Literal, Optional
|
|
3
|
+
|
|
4
|
+
from openai import OpenAI
|
|
5
|
+
from sentence_transformers import SentenceTransformer
|
|
6
|
+
|
|
7
|
+
from agentrun_mem0.configs.embeddings.base import BaseEmbedderConfig
|
|
8
|
+
from agentrun_mem0.embeddings.base import EmbeddingBase
|
|
9
|
+
|
|
10
|
+
logging.getLogger("transformers").setLevel(logging.WARNING)
|
|
11
|
+
logging.getLogger("sentence_transformers").setLevel(logging.WARNING)
|
|
12
|
+
logging.getLogger("huggingface_hub").setLevel(logging.WARNING)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class HuggingFaceEmbedding(EmbeddingBase):
|
|
16
|
+
def __init__(self, config: Optional[BaseEmbedderConfig] = None):
|
|
17
|
+
super().__init__(config)
|
|
18
|
+
|
|
19
|
+
if config.huggingface_base_url:
|
|
20
|
+
self.client = OpenAI(base_url=config.huggingface_base_url)
|
|
21
|
+
self.config.model = self.config.model or "tei"
|
|
22
|
+
else:
|
|
23
|
+
self.config.model = self.config.model or "multi-qa-MiniLM-L6-cos-v1"
|
|
24
|
+
|
|
25
|
+
self.model = SentenceTransformer(self.config.model, **self.config.model_kwargs)
|
|
26
|
+
|
|
27
|
+
self.config.embedding_dims = self.config.embedding_dims or self.model.get_sentence_embedding_dimension()
|
|
28
|
+
|
|
29
|
+
def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
|
|
30
|
+
"""
|
|
31
|
+
Get the embedding for the given text using Hugging Face.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
text (str): The text to embed.
|
|
35
|
+
memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None.
|
|
36
|
+
Returns:
|
|
37
|
+
list: The embedding vector.
|
|
38
|
+
"""
|
|
39
|
+
if self.config.huggingface_base_url:
|
|
40
|
+
return self.client.embeddings.create(
|
|
41
|
+
input=text, model=self.config.model, **self.config.model_kwargs
|
|
42
|
+
).data[0].embedding
|
|
43
|
+
else:
|
|
44
|
+
return self.model.encode(text, convert_to_numpy=True).tolist()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from typing import Literal, Optional
|
|
2
|
+
|
|
3
|
+
from agentrun_mem0.configs.embeddings.base import BaseEmbedderConfig
|
|
4
|
+
from agentrun_mem0.embeddings.base import EmbeddingBase
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from langchain.embeddings.base import Embeddings
|
|
8
|
+
except ImportError:
|
|
9
|
+
raise ImportError("langchain is not installed. Please install it using `pip install langchain`")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class LangchainEmbedding(EmbeddingBase):
|
|
13
|
+
def __init__(self, config: Optional[BaseEmbedderConfig] = None):
|
|
14
|
+
super().__init__(config)
|
|
15
|
+
|
|
16
|
+
if self.config.model is None:
|
|
17
|
+
raise ValueError("`model` parameter is required")
|
|
18
|
+
|
|
19
|
+
if not isinstance(self.config.model, Embeddings):
|
|
20
|
+
raise ValueError("`model` must be an instance of Embeddings")
|
|
21
|
+
|
|
22
|
+
self.langchain_model = self.config.model
|
|
23
|
+
|
|
24
|
+
def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
|
|
25
|
+
"""
|
|
26
|
+
Get the embedding for the given text using Langchain.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
text (str): The text to embed.
|
|
30
|
+
memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None.
|
|
31
|
+
Returns:
|
|
32
|
+
list: The embedding vector.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
return self.langchain_model.embed_query(text)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from typing import Literal, Optional
|
|
2
|
+
|
|
3
|
+
from openai import OpenAI
|
|
4
|
+
|
|
5
|
+
from agentrun_mem0.configs.embeddings.base import BaseEmbedderConfig
|
|
6
|
+
from agentrun_mem0.embeddings.base import EmbeddingBase
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class LMStudioEmbedding(EmbeddingBase):
|
|
10
|
+
def __init__(self, config: Optional[BaseEmbedderConfig] = None):
|
|
11
|
+
super().__init__(config)
|
|
12
|
+
|
|
13
|
+
self.config.model = self.config.model or "nomic-ai/nomic-embed-text-v1.5-GGUF/nomic-embed-text-v1.5.f16.gguf"
|
|
14
|
+
self.config.embedding_dims = self.config.embedding_dims or 1536
|
|
15
|
+
self.config.api_key = self.config.api_key or "lm-studio"
|
|
16
|
+
|
|
17
|
+
self.client = OpenAI(base_url=self.config.lmstudio_base_url, api_key=self.config.api_key)
|
|
18
|
+
|
|
19
|
+
def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
|
|
20
|
+
"""
|
|
21
|
+
Get the embedding for the given text using LM Studio.
|
|
22
|
+
Args:
|
|
23
|
+
text (str): The text to embed.
|
|
24
|
+
memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None.
|
|
25
|
+
Returns:
|
|
26
|
+
list: The embedding vector.
|
|
27
|
+
"""
|
|
28
|
+
text = text.replace("\n", " ")
|
|
29
|
+
return self.client.embeddings.create(input=[text], model=self.config.model).data[0].embedding
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from typing import Literal, Optional
|
|
2
|
+
|
|
3
|
+
from agentrun_mem0.embeddings.base import EmbeddingBase
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MockEmbeddings(EmbeddingBase):
|
|
7
|
+
def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
|
|
8
|
+
"""
|
|
9
|
+
Generate a mock embedding with dimension of 10.
|
|
10
|
+
"""
|
|
11
|
+
return [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import sys
|
|
3
|
+
from typing import Literal, Optional
|
|
4
|
+
|
|
5
|
+
from agentrun_mem0.configs.embeddings.base import BaseEmbedderConfig
|
|
6
|
+
from agentrun_mem0.embeddings.base import EmbeddingBase
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
from ollama import Client
|
|
10
|
+
except ImportError:
|
|
11
|
+
user_input = input("The 'ollama' library is required. Install it now? [y/N]: ")
|
|
12
|
+
if user_input.lower() == "y":
|
|
13
|
+
try:
|
|
14
|
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "ollama"])
|
|
15
|
+
from ollama import Client
|
|
16
|
+
except subprocess.CalledProcessError:
|
|
17
|
+
print("Failed to install 'ollama'. Please install it manually using 'pip install ollama'.")
|
|
18
|
+
sys.exit(1)
|
|
19
|
+
else:
|
|
20
|
+
print("The required 'ollama' library is not installed.")
|
|
21
|
+
sys.exit(1)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class OllamaEmbedding(EmbeddingBase):
|
|
25
|
+
def __init__(self, config: Optional[BaseEmbedderConfig] = None):
|
|
26
|
+
super().__init__(config)
|
|
27
|
+
|
|
28
|
+
self.config.model = self.config.model or "nomic-embed-text"
|
|
29
|
+
self.config.embedding_dims = self.config.embedding_dims or 512
|
|
30
|
+
|
|
31
|
+
self.client = Client(host=self.config.ollama_base_url)
|
|
32
|
+
self._ensure_model_exists()
|
|
33
|
+
|
|
34
|
+
def _ensure_model_exists(self):
|
|
35
|
+
"""
|
|
36
|
+
Ensure the specified model exists locally. If not, pull it from Ollama.
|
|
37
|
+
"""
|
|
38
|
+
local_models = self.client.list()["models"]
|
|
39
|
+
if not any(model.get("name") == self.config.model or model.get("model") == self.config.model for model in local_models):
|
|
40
|
+
self.client.pull(self.config.model)
|
|
41
|
+
|
|
42
|
+
def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
|
|
43
|
+
"""
|
|
44
|
+
Get the embedding for the given text using Ollama.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
text (str): The text to embed.
|
|
48
|
+
memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None.
|
|
49
|
+
Returns:
|
|
50
|
+
list: The embedding vector.
|
|
51
|
+
"""
|
|
52
|
+
response = self.client.embeddings(model=self.config.model, prompt=text)
|
|
53
|
+
return response["embedding"]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import warnings
|
|
3
|
+
from typing import Literal, Optional
|
|
4
|
+
|
|
5
|
+
from openai import OpenAI
|
|
6
|
+
|
|
7
|
+
from agentrun_mem0.configs.embeddings.base import BaseEmbedderConfig
|
|
8
|
+
from agentrun_mem0.embeddings.base import EmbeddingBase
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class OpenAIEmbedding(EmbeddingBase):
|
|
12
|
+
def __init__(self, config: Optional[BaseEmbedderConfig] = None):
|
|
13
|
+
super().__init__(config)
|
|
14
|
+
|
|
15
|
+
self.config.model = self.config.model or "text-embedding-3-small"
|
|
16
|
+
self.config.embedding_dims = self.config.embedding_dims or 1536
|
|
17
|
+
|
|
18
|
+
api_key = self.config.api_key or os.getenv("OPENAI_API_KEY")
|
|
19
|
+
base_url = (
|
|
20
|
+
self.config.openai_base_url
|
|
21
|
+
or os.getenv("OPENAI_API_BASE")
|
|
22
|
+
or os.getenv("OPENAI_BASE_URL")
|
|
23
|
+
or "https://api.openai.com/v1"
|
|
24
|
+
)
|
|
25
|
+
if os.environ.get("OPENAI_API_BASE"):
|
|
26
|
+
warnings.warn(
|
|
27
|
+
"The environment variable 'OPENAI_API_BASE' is deprecated and will be removed in the 0.1.80. "
|
|
28
|
+
"Please use 'OPENAI_BASE_URL' instead.",
|
|
29
|
+
DeprecationWarning,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
self.client = OpenAI(api_key=api_key, base_url=base_url)
|
|
33
|
+
|
|
34
|
+
def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
|
|
35
|
+
"""
|
|
36
|
+
Get the embedding for the given text using OpenAI.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
text (str): The text to embed.
|
|
40
|
+
memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None.
|
|
41
|
+
Returns:
|
|
42
|
+
list: The embedding vector.
|
|
43
|
+
"""
|
|
44
|
+
text = text.replace("\n", " ")
|
|
45
|
+
return (
|
|
46
|
+
self.client.embeddings.create(input=[text], model=self.config.model, dimensions=self.config.embedding_dims)
|
|
47
|
+
.data[0]
|
|
48
|
+
.embedding
|
|
49
|
+
)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Literal, Optional
|
|
3
|
+
|
|
4
|
+
from together import Together
|
|
5
|
+
|
|
6
|
+
from agentrun_mem0.configs.embeddings.base import BaseEmbedderConfig
|
|
7
|
+
from agentrun_mem0.embeddings.base import EmbeddingBase
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TogetherEmbedding(EmbeddingBase):
|
|
11
|
+
def __init__(self, config: Optional[BaseEmbedderConfig] = None):
|
|
12
|
+
super().__init__(config)
|
|
13
|
+
|
|
14
|
+
self.config.model = self.config.model or "togethercomputer/m2-bert-80M-8k-retrieval"
|
|
15
|
+
api_key = self.config.api_key or os.getenv("TOGETHER_API_KEY")
|
|
16
|
+
# TODO: check if this is correct
|
|
17
|
+
self.config.embedding_dims = self.config.embedding_dims or 768
|
|
18
|
+
self.client = Together(api_key=api_key)
|
|
19
|
+
|
|
20
|
+
def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
|
|
21
|
+
"""
|
|
22
|
+
Get the embedding for the given text using OpenAI.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
text (str): The text to embed.
|
|
26
|
+
memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None.
|
|
27
|
+
Returns:
|
|
28
|
+
list: The embedding vector.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
return self.client.embeddings.create(model=self.config.model, input=text).data[0].embedding
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Literal, Optional
|
|
3
|
+
|
|
4
|
+
from vertexai.language_models import TextEmbeddingInput, TextEmbeddingModel
|
|
5
|
+
|
|
6
|
+
from agentrun_mem0.configs.embeddings.base import BaseEmbedderConfig
|
|
7
|
+
from agentrun_mem0.embeddings.base import EmbeddingBase
|
|
8
|
+
from agentrun_mem0.utils.gcp_auth import GCPAuthenticator
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class VertexAIEmbedding(EmbeddingBase):
|
|
12
|
+
def __init__(self, config: Optional[BaseEmbedderConfig] = None):
|
|
13
|
+
super().__init__(config)
|
|
14
|
+
|
|
15
|
+
self.config.model = self.config.model or "text-embedding-004"
|
|
16
|
+
self.config.embedding_dims = self.config.embedding_dims or 256
|
|
17
|
+
|
|
18
|
+
self.embedding_types = {
|
|
19
|
+
"add": self.config.memory_add_embedding_type or "RETRIEVAL_DOCUMENT",
|
|
20
|
+
"update": self.config.memory_update_embedding_type or "RETRIEVAL_DOCUMENT",
|
|
21
|
+
"search": self.config.memory_search_embedding_type or "RETRIEVAL_QUERY",
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# Set up authentication using centralized GCP authenticator
|
|
25
|
+
# This supports multiple authentication methods while preserving environment variable support
|
|
26
|
+
try:
|
|
27
|
+
GCPAuthenticator.setup_vertex_ai(
|
|
28
|
+
service_account_json=getattr(self.config, 'google_service_account_json', None),
|
|
29
|
+
credentials_path=self.config.vertex_credentials_json,
|
|
30
|
+
project_id=getattr(self.config, 'google_project_id', None)
|
|
31
|
+
)
|
|
32
|
+
except Exception:
|
|
33
|
+
# Fall back to original behavior for backward compatibility
|
|
34
|
+
credentials_path = self.config.vertex_credentials_json
|
|
35
|
+
if credentials_path:
|
|
36
|
+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = credentials_path
|
|
37
|
+
elif not os.getenv("GOOGLE_APPLICATION_CREDENTIALS"):
|
|
38
|
+
raise ValueError(
|
|
39
|
+
"Google application credentials JSON is not provided. Please provide a valid JSON path or set the 'GOOGLE_APPLICATION_CREDENTIALS' environment variable."
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
self.model = TextEmbeddingModel.from_pretrained(self.config.model)
|
|
43
|
+
|
|
44
|
+
def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
|
|
45
|
+
"""
|
|
46
|
+
Get the embedding for the given text using Vertex AI.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
text (str): The text to embed.
|
|
50
|
+
memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None.
|
|
51
|
+
Returns:
|
|
52
|
+
list: The embedding vector.
|
|
53
|
+
"""
|
|
54
|
+
embedding_type = "SEMANTIC_SIMILARITY"
|
|
55
|
+
if memory_action is not None:
|
|
56
|
+
if memory_action not in self.embedding_types:
|
|
57
|
+
raise ValueError(f"Invalid memory action: {memory_action}")
|
|
58
|
+
|
|
59
|
+
embedding_type = self.embedding_types[memory_action]
|
|
60
|
+
|
|
61
|
+
text_input = TextEmbeddingInput(text=text, task_type=embedding_type)
|
|
62
|
+
embeddings = self.model.get_embeddings(texts=[text_input], output_dimensionality=self.config.embedding_dims)
|
|
63
|
+
|
|
64
|
+
return embeddings[0].values
|