kgmodule-utils 0.4.4__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.
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/PKG-INFO +2 -2
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/README.md +1 -1
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/pyproject.toml +1 -1
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/__init__.py +1 -1
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/embedder.py +23 -5
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/synthesis/_text.py +25 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/LICENSE +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/embed.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/extractor.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/module.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/pipeline.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/py.typed +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/retrieval/__init__.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/retrieval/hits.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/semantic.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/snapshots/__init__.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/snapshots/manager.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/snapshots/models.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/specs.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/store.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/synthesis/__init__.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/synthesis/_config.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/synthesis/_image.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/synthesis/factory.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/worker/__init__.py +0 -0
- {kgmodule_utils-0.4.4 → kgmodule_utils-0.4.6}/src/kg_utils/worker/client.py +0 -0
- {kgmodule_utils-0.4.4 → 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.
|
|
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
|
|
@@ -35,7 +35,7 @@ Description-Content-Type: text/markdown
|
|
|
35
35
|
|
|
36
36
|
[](https://www.python.org/)
|
|
37
37
|
[](https://www.elastic.co/licensing/elastic-license)
|
|
38
|
-
[](https://github.com/Flux-Frontiers/KG_utils/releases)
|
|
39
39
|
[](https://github.com/Flux-Frontiers/KG_utils/actions/workflows/ci.yml)
|
|
40
40
|
[](https://python-poetry.org/)
|
|
41
41
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
[](https://www.python.org/)
|
|
3
3
|
[](https://www.elastic.co/licensing/elastic-license)
|
|
4
|
-
[](https://github.com/Flux-Frontiers/KG_utils/releases)
|
|
5
5
|
[](https://github.com/Flux-Frontiers/KG_utils/actions/workflows/ci.yml)
|
|
6
6
|
[](https://python-poetry.org/)
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
10
10
|
|
|
11
11
|
[project]
|
|
12
12
|
name = "kgmodule-utils"
|
|
13
|
-
version = "0.4.
|
|
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" }
|
|
@@ -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(
|
|
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(
|
|
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:
|
|
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(
|
|
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=
|
|
287
|
+
batch_size=encode_batch_size,
|
|
270
288
|
normalize_embeddings=True,
|
|
271
289
|
show_progress_bar=False,
|
|
272
290
|
)
|
|
@@ -98,6 +98,31 @@ class TextSynthesizer:
|
|
|
98
98
|
# Public API
|
|
99
99
|
# ------------------------------------------------------------------
|
|
100
100
|
|
|
101
|
+
def complete(
|
|
102
|
+
self,
|
|
103
|
+
messages: list[dict],
|
|
104
|
+
*,
|
|
105
|
+
model: str | None = None,
|
|
106
|
+
max_tokens: int | None = None,
|
|
107
|
+
temperature: float = 0.7,
|
|
108
|
+
) -> str | None:
|
|
109
|
+
"""Run a raw chat completion against the configured backend.
|
|
110
|
+
|
|
111
|
+
General-purpose entry point for callers that build their own message
|
|
112
|
+
list — summarization, classification, arbitrary prompting — rather than
|
|
113
|
+
using :meth:`synthesize_rag` or :meth:`rewrite_for_image`. Applies the
|
|
114
|
+
same oMLX thinking suppression and ``<think>`` stripping as the other
|
|
115
|
+
public methods.
|
|
116
|
+
|
|
117
|
+
:param messages: OpenAI-style chat messages (``[{"role": ..., "content": ...}]``).
|
|
118
|
+
:param model: Override the configured model for this single call.
|
|
119
|
+
:param max_tokens: Override the configured ``max_tokens`` for this call.
|
|
120
|
+
:param temperature: Sampling temperature (lower = more deterministic).
|
|
121
|
+
:returns: The completion text with thinking stripped, or ``None`` on
|
|
122
|
+
failure or empty output.
|
|
123
|
+
"""
|
|
124
|
+
return self._complete(messages, model=model, max_tokens=max_tokens, temperature=temperature)
|
|
125
|
+
|
|
101
126
|
def list_models(self) -> list[str]:
|
|
102
127
|
"""Return the model IDs available at the configured endpoint.
|
|
103
128
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|