@deeplake/hivemind 0.7.31 → 0.7.32

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.
@@ -4,7 +4,14 @@
4
4
  import { createServer } from "node:net";
5
5
  import { unlinkSync, writeFileSync, existsSync, mkdirSync, chmodSync } from "node:fs";
6
6
 
7
+ // dist/src/embeddings/nomic.js
8
+ import { createRequire } from "node:module";
9
+ import { homedir } from "node:os";
10
+ import { join } from "node:path";
11
+ import { pathToFileURL } from "node:url";
12
+
7
13
  // dist/src/embeddings/protocol.js
14
+ var PROTOCOL_VERSION = 1;
8
15
  var DEFAULT_SOCKET_DIR = "/tmp";
9
16
  var DEFAULT_MODEL_REPO = "nomic-ai/nomic-embed-text-v1.5";
10
17
  var DEFAULT_DTYPE = "q8";
@@ -20,6 +27,39 @@ function pidPathFor(uid, dir = DEFAULT_SOCKET_DIR) {
20
27
  }
21
28
 
22
29
  // dist/src/embeddings/nomic.js
30
+ async function _importFromCanonicalSharedDeps(sharedDir = join(homedir(), ".hivemind", "embed-deps")) {
31
+ const base = pathToFileURL(`${sharedDir}/`).href;
32
+ const absMain = createRequire(base).resolve("@huggingface/transformers");
33
+ const mod = await import(pathToFileURL(absMain).href);
34
+ return _normalizeTransformersModule(mod);
35
+ }
36
+ async function _importFromBareSpecifier() {
37
+ const mod = await import("@huggingface/transformers");
38
+ return _normalizeTransformersModule(mod);
39
+ }
40
+ function _normalizeTransformersModule(mod) {
41
+ const m = mod;
42
+ if (m.default && typeof m.default === "object" && "pipeline" in m.default) {
43
+ return m.default;
44
+ }
45
+ return m;
46
+ }
47
+ async function defaultImportTransformers(canonical = _importFromCanonicalSharedDeps, bare = _importFromBareSpecifier) {
48
+ let canonicalErr;
49
+ try {
50
+ return await canonical();
51
+ } catch (err) {
52
+ canonicalErr = err;
53
+ }
54
+ try {
55
+ return await bare();
56
+ } catch (bareErr) {
57
+ const detail = bareErr instanceof Error ? bareErr.message : String(bareErr);
58
+ const canonicalDetail = canonicalErr instanceof Error ? canonicalErr.message : String(canonicalErr);
59
+ throw new Error(`@huggingface/transformers is not installed anywhere reachable. Run \`hivemind embeddings install\` to install it. (canonical: ${canonicalDetail}; bare: ${detail})`);
60
+ }
61
+ }
62
+ var _importTransformers = defaultImportTransformers;
23
63
  var NomicEmbedder = class {
24
64
  pipeline = null;
25
65
  loading = null;
@@ -37,7 +77,7 @@ var NomicEmbedder = class {
37
77
  if (this.loading)
38
78
  return this.loading;
39
79
  this.loading = (async () => {
40
- const mod = await import("@huggingface/transformers");
80
+ const mod = await _importTransformers();
41
81
  mod.env.allowLocalModels = false;
42
82
  mod.env.useFSCache = true;
43
83
  this.pipeline = await mod.pipeline("feature-extraction", this.repo, { dtype: this.dtype });
@@ -94,9 +134,9 @@ var NomicEmbedder = class {
94
134
 
95
135
  // dist/src/utils/debug.js
96
136
  import { appendFileSync } from "node:fs";
97
- import { join } from "node:path";
98
- import { homedir } from "node:os";
99
- var LOG = join(homedir(), ".deeplake", "hook-debug.log");
137
+ import { join as join2 } from "node:path";
138
+ import { homedir as homedir2 } from "node:os";
139
+ var LOG = join2(homedir2(), ".deeplake", "hook-debug.log");
100
140
  function isDebug() {
101
141
  return process.env.HIVEMIND_DEBUG === "1";
102
142
  }
@@ -120,6 +160,7 @@ var EmbedDaemon = class {
120
160
  pidPath;
121
161
  idleTimeoutMs;
122
162
  idleTimer = null;
163
+ daemonPath;
123
164
  constructor(opts = {}) {
124
165
  const uid = getUid();
125
166
  const dir = opts.socketDir ?? "/tmp";
@@ -127,6 +168,7 @@ var EmbedDaemon = class {
127
168
  this.pidPath = pidPathFor(uid, dir);
128
169
  this.idleTimeoutMs = opts.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS;
129
170
  this.embedder = new NomicEmbedder({ repo: opts.repo, dtype: opts.dtype, dims: opts.dims });
171
+ this.daemonPath = opts.daemonPath ?? process.argv[1] ?? "";
130
172
  }
131
173
  async start() {
132
174
  mkdirSync(this.socketPath.replace(/\/[^/]+$/, ""), { recursive: true });
@@ -218,6 +260,15 @@ var EmbedDaemon = class {
218
260
  }
219
261
  }
220
262
  async dispatch(req) {
263
+ if (req.op === "hello") {
264
+ const h = req;
265
+ return {
266
+ id: h.id,
267
+ daemonPath: this.daemonPath,
268
+ pid: process.pid,
269
+ protocolVersion: PROTOCOL_VERSION
270
+ };
271
+ }
221
272
  if (req.op === "ping") {
222
273
  const p = req;
223
274
  return { id: p.id, ready: true, model: this.embedder.repo, dims: this.embedder.dims };