datapizza-ai-embedders-google 0.0.2__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.
@@ -0,0 +1,3 @@
1
+ from .google import GoogleEmbedder
2
+
3
+ __all__ = ["GoogleEmbedder"]
@@ -0,0 +1,62 @@
1
+ from datapizza.core.embedder import BaseEmbedder
2
+
3
+ from google import genai
4
+ from google.genai import types
5
+
6
+
7
+ class GoogleEmbedder(BaseEmbedder):
8
+ def __init__(self, *, api_key: str, model_name: str | None = None, task_type: str = "RETRIEVAL_DOCUMENT"):
9
+ self.api_key = api_key
10
+ self.model_name = model_name
11
+ self.task_type = task_type
12
+
13
+ self.client = None
14
+ self.a_client = None
15
+
16
+ def _set_client(self):
17
+ if not self.client:
18
+ client = genai.Client(api_key=self.api_key)
19
+ self.client = client
20
+
21
+ def _set_a_client(self):
22
+ if not self.a_client:
23
+ client = genai.Client(api_key=self.api_key)
24
+ self.a_client = client
25
+
26
+ def embed(
27
+ self, text: str | list[str], model_name: str | None = None
28
+ ) -> list[float] | list[list[float]]:
29
+ model = model_name or self.model_name
30
+ if not model:
31
+ raise ValueError("Model name is required.")
32
+
33
+ texts = [text] if isinstance(text, str) else text
34
+
35
+ client = self._get_client()
36
+
37
+ result = client.models.embed_content(
38
+ model=model,
39
+ contents=texts,
40
+ config=types.EmbedContentConfig(task_type=self.task_type)
41
+ )
42
+
43
+ res = [embedding.values for embedding in result.embeddings]
44
+
45
+ return res[0] if isinstance(text, str) else res
46
+
47
+ async def a_embed(
48
+ self, text: str | list[str], model_name: str | None = None
49
+ ) -> list[float]:
50
+ model = model_name or self.model_name
51
+ if not model:
52
+ raise ValueError("Model name is required.")
53
+
54
+ texts = [text] if isinstance(text, str) else text
55
+
56
+ client = self._get_a_client()
57
+
58
+ result = await client.models.embed_content_async(model=model, contents=texts, config=types.EmbedContentConfig(task_type=self.task_type))
59
+
60
+ res = [embedding.values for embedding in result.embeddings]
61
+
62
+ return res[0] if isinstance(text, str) else res
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: datapizza-ai-embedders-google
3
+ Version: 0.0.2
4
+ Summary: Google embedder for the datapizza-ai framework
5
+ Author-email: Datapizza <datapizza@datapizza.tech>
6
+ License: MIT
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: <4,>=3.10.0
11
+ Requires-Dist: datapizza-ai-core>=0.0.1
12
+ Requires-Dist: google-genai<2.0.0,>=1.3.0
13
+ Description-Content-Type: text/markdown
14
+
15
+ # Google Embedder
16
+
17
+ Google Generative AI embedder implementation for datapizza-ai
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install datapizza-ai-embedders-google
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```python
28
+ from datapizza.embedders.google import GoogleEmbedder
29
+
30
+ embedder = GoogleEmbedder(api_key="your-google-api-key")
31
+ embeddings = embedder.embed("Hello world", model_name="models/text-embedding-004")
32
+ ```
@@ -0,0 +1,5 @@
1
+ datapizza/embedders/google/__init__.py,sha256=lFSxh2zQ5enR9g2rRKcVW3gRuUTdTVlavZkd878zx8M,65
2
+ datapizza/embedders/google/google.py,sha256=PddSrcn02d4-nD0a9CP4T9zAY60q1YdJ7PF68czGsls,1969
3
+ datapizza_ai_embedders_google-0.0.2.dist-info/METADATA,sha256=GLnJ1wBtyl6HW1JETrBn2wa0MphcvY6jXs8fANlUCKk,864
4
+ datapizza_ai_embedders_google-0.0.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ datapizza_ai_embedders_google-0.0.2.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any