kgmodule-utils 0.4.5__tar.gz → 0.4.6__tar.gz

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.
Files changed (27) hide show
  1. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/PKG-INFO +1 -1
  2. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/pyproject.toml +1 -1
  3. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/__init__.py +1 -1
  4. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/embedder.py +23 -5
  5. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/LICENSE +0 -0
  6. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/README.md +0 -0
  7. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/embed.py +0 -0
  8. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/extractor.py +0 -0
  9. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/module.py +0 -0
  10. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/pipeline.py +0 -0
  11. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/py.typed +0 -0
  12. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/retrieval/__init__.py +0 -0
  13. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/retrieval/hits.py +0 -0
  14. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/semantic.py +0 -0
  15. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/snapshots/__init__.py +0 -0
  16. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/snapshots/manager.py +0 -0
  17. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/snapshots/models.py +0 -0
  18. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/specs.py +0 -0
  19. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/store.py +0 -0
  20. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/synthesis/__init__.py +0 -0
  21. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/synthesis/_config.py +0 -0
  22. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/synthesis/_image.py +0 -0
  23. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/synthesis/_text.py +0 -0
  24. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/synthesis/factory.py +0 -0
  25. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/worker/__init__.py +0 -0
  26. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/worker/client.py +0 -0
  27. {kgmodule_utils-0.4.5 → kgmodule_utils-0.4.6}/src/kg_utils/worker/ops.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kgmodule-utils
3
- Version: 0.4.5
3
+ Version: 0.4.6
4
4
  Summary: Shared types, graph store, semantic index, and pipeline base for the KGModule SDK
5
5
  License: Elastic-2.0
6
6
  License-File: LICENSE
@@ -10,7 +10,7 @@ build-backend = "poetry.core.masonry.api"
10
10
 
11
11
  [project]
12
12
  name = "kgmodule-utils"
13
- version = "0.4.5"
13
+ version = "0.4.6"
14
14
  description = "Shared types, graph store, semantic index, and pipeline base for the KGModule SDK"
15
15
  readme = "README.md"
16
16
  license = { text = "Elastic-2.0" }
@@ -24,4 +24,4 @@ Optional extras
24
24
  pip install 'kgmodule-utils[synthesis-mflux]' # + mflux (Apple Silicon local gen)
25
25
  """
26
26
 
27
- __version__ = "0.4.5"
27
+ __version__ = "0.4.6"
@@ -40,6 +40,14 @@ from typing import Any
40
40
 
41
41
  from kg_utils.embed import DEFAULT_MODEL, KNOWN_MODELS, resolve_model_path
42
42
 
43
+ #: Default per-call encode batch fed to ``model.encode(batch_size=...)``.
44
+ #: Transformer attention memory scales with ``batch x seq^2``, so a large batch
45
+ #: on long (near-max-sequence) chunks can allocate many GB per call and OOM /
46
+ #: stall MPS. Throughput is flat above ~128 on both CPU and MPS for the models
47
+ #: in use, so 128 is the safe default; raise it only for a large-VRAM CUDA GPU
48
+ #: with short sequences.
49
+ DEFAULT_ENCODE_BATCH: int = 128
50
+
43
51
  # ---------------------------------------------------------------------------
44
52
  # Abstract base
45
53
  # ---------------------------------------------------------------------------
@@ -53,10 +61,14 @@ class Embedder:
53
61
 
54
62
  dim: int
55
63
 
56
- def embed_texts(self, texts: list[str]) -> list[list[float]]:
64
+ def embed_texts(
65
+ self, texts: list[str], encode_batch_size: int = DEFAULT_ENCODE_BATCH
66
+ ) -> list[list[float]]:
57
67
  """Embed a list of strings into float32 vectors.
58
68
 
59
69
  :param texts: Input strings.
70
+ :param encode_batch_size: Per-call ``model.encode`` batch (default
71
+ :data:`DEFAULT_ENCODE_BATCH`); memory scales with ``batch x seq^2``.
60
72
  :return: One float32 vector per input.
61
73
  """
62
74
  raise NotImplementedError
@@ -200,11 +212,15 @@ class SentenceTransformerEmbedder(Embedder):
200
212
  )
201
213
  self.dim: int = (_dim_fn() if _dim_fn is not None else None) or 384
202
214
 
203
- def embed_texts(self, texts: list[str], encode_batch_size: int = 512) -> list[list[float]]:
215
+ def embed_texts(
216
+ self, texts: list[str], encode_batch_size: int = DEFAULT_ENCODE_BATCH
217
+ ) -> list[list[float]]:
204
218
  """Embed a list of strings into float32 vectors.
205
219
 
206
220
  :param texts: Input strings.
207
- :param encode_batch_size: Passed to ``model.encode()`` tune down if OOM on MPS.
221
+ :param encode_batch_size: Per-call ``model.encode`` batch (default
222
+ :data:`DEFAULT_ENCODE_BATCH`). Memory scales with ``batch x seq^2``;
223
+ tune down further if OOM on MPS, up only for large-VRAM CUDA.
208
224
  """
209
225
  np = importlib.import_module("numpy")
210
226
 
@@ -263,10 +279,12 @@ def wrap_embedder(st_model: Any, model_name: str = DEFAULT_MODEL) -> Embedder:
263
279
  model_name: str = resolved
264
280
  dim: int = _dim
265
281
 
266
- def embed_texts(self, texts: list[str]) -> list[list[float]]:
282
+ def embed_texts(
283
+ self, texts: list[str], encode_batch_size: int = DEFAULT_ENCODE_BATCH
284
+ ) -> list[list[float]]:
267
285
  vecs = st_model.encode(
268
286
  texts,
269
- batch_size=512,
287
+ batch_size=encode_batch_size,
270
288
  normalize_embeddings=True,
271
289
  show_progress_bar=False,
272
290
  )
File without changes
File without changes