@littlebigbrain/client 0.13.0 → 0.13.2

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.
@@ -1,6 +1,7 @@
1
1
  import { attributeFilter, firstPatternVariable, parseSparqlResults, } from "./types.js";
2
- // SPARQL is the only query surface. The search, embedding, decode,
3
- // groundability, and analytics operations were removed with their routes.
2
+ // SPARQL is the query language. Search by meaning is `embeddings.search`
3
+ // (`POST /v1/search`); the older search, embedding, decode, groundability,
4
+ // and analytics operations were removed with their routes.
4
5
  /** A5: fold read-consistency options into a request body's `consistency` /
5
6
  * `min_indexed_seq` fields; a per-call value wins over the client default. */
6
7
  function withReadConsistency(client, body, opts) {
@@ -23,6 +24,8 @@ export class GraphNamespace {
23
24
  query;
24
25
  schema;
25
26
  search;
27
+ evals;
28
+ embeddings;
26
29
  constructor(client) {
27
30
  this.client = client;
28
31
  this.facts = new FactsNamespace(client);
@@ -31,6 +34,8 @@ export class GraphNamespace {
31
34
  this.query = client.query;
32
35
  this.schema = client.schema;
33
36
  this.search = client.search;
37
+ this.evals = client.evals;
38
+ this.embeddings = client.embeddings;
34
39
  }
35
40
  branch(name) {
36
41
  return new GraphNamespace(this.client.withScope({ branch: name }));
@@ -135,7 +140,7 @@ export class FactsNamespace {
135
140
  }
136
141
  /**
137
142
  * Relevance-label storage. The query surfaces this namespace once fronted were
138
- * removed with their routes; SPARQL is the only query path now.
143
+ * removed with their routes; search by meaning is `embeddings.search`.
139
144
  */
140
145
  export class SearchNamespace {
141
146
  client;
@@ -199,6 +204,173 @@ export class EntityNamespace {
199
204
  });
200
205
  }
201
206
  }
207
+ /**
208
+ * Search: embeddings declared on classes of the graph. The platform keeps the
209
+ * vectors in step with the published graph; a search checks every hit against
210
+ * one graph snapshot.
211
+ */
212
+ export class EmbeddingsNamespace {
213
+ client;
214
+ constructor(client) {
215
+ this.client = client;
216
+ }
217
+ /** Every embedding of the branch with its status. */
218
+ list(opts = {}) {
219
+ return this.client.request("GET", "/v1/embeddings", opts);
220
+ }
221
+ /** One embedding: serving and building version, backfill, lag, recall. */
222
+ get(name, opts = {}) {
223
+ return this.client.request("GET", "/v1/embeddings", {
224
+ ...opts,
225
+ query: { name },
226
+ });
227
+ }
228
+ /**
229
+ * Declare or change the embedding of a class. Without `from` the server
230
+ * picks the fields (the label, frequent text, the names of linked
231
+ * entities). A new recipe builds as a new version while the old one serves.
232
+ */
233
+ declare(body, opts = {}) {
234
+ return this.client.request("PUT", "/v1/embeddings", { ...opts, body });
235
+ }
236
+ /**
237
+ * What a declaration would embed: the fields, every candidate fact of the
238
+ * class with its coverage and examples, and sample texts. Calls no model.
239
+ */
240
+ preview(body, opts = {}) {
241
+ return this.client.request("POST", "/v1/embeddings/preview", {
242
+ ...opts,
243
+ body,
244
+ });
245
+ }
246
+ /**
247
+ * Move every embedding of the graph to another model (one model per
248
+ * graph). Each builds a new version; the graph switches at once when
249
+ * every embedding has it ready, so a search never mixes two models.
250
+ */
251
+ setModel(body, opts = {}) {
252
+ return this.client.request("PUT", "/v1/embeddings/model", {
253
+ ...opts,
254
+ body,
255
+ });
256
+ }
257
+ /** Run one bounded step of the embed job now. */
258
+ refresh(name, opts = {}) {
259
+ return this.client.request("POST", "/v1/embeddings/refresh", {
260
+ ...opts,
261
+ query: { name },
262
+ });
263
+ }
264
+ /** Remove an embedding. */
265
+ delete(name, opts = {}) {
266
+ return this.client.request("DELETE", "/v1/embeddings", {
267
+ ...opts,
268
+ query: { name, confirm: name },
269
+ });
270
+ }
271
+ /**
272
+ * Search by meaning over every searchable class of the graph (or one
273
+ * `embedding`). `filter` lists the conditions every hit must meet:
274
+ * `{ class: iri }` (or a list; subclasses too) and
275
+ * `{ via: "calls", to: "payment-service", direction?: "in" }` (`to` an IRI
276
+ * or a name). Every hit carries its class and is checked against one
277
+ * graph snapshot; `include: ["text"]` returns the embedded text of each
278
+ * hit; `explain: true` plans without running.
279
+ */
280
+ search(body, opts = {}) {
281
+ return this.client.request("POST", "/v1/search", {
282
+ ...opts,
283
+ retry: opts.retry ?? true,
284
+ body,
285
+ });
286
+ }
287
+ }
288
+ /** Managed evals: traces, labels (thumbs up or down), goldens, and runs. */
289
+ export class EvalsNamespace {
290
+ client;
291
+ constructor(client) {
292
+ this.client = client;
293
+ }
294
+ /** Settings, golden counts, unlabeled traces, the latest run, and the score by commit. */
295
+ summary(opts = {}) {
296
+ return this.client.request("GET", "/v1/evals", opts);
297
+ }
298
+ /** Recent traces, newest first. */
299
+ traces(options = {}) {
300
+ const { limit, unlabeled, ...opts } = options;
301
+ return this.client.request("GET", "/v1/evals/traces", {
302
+ ...opts,
303
+ query: { limit, unlabeled: unlabeled ? "true" : undefined },
304
+ });
305
+ }
306
+ /** One trace: the request, its query, its results (one item per hit or
307
+ * row), and their labels. */
308
+ trace(id, opts = {}) {
309
+ return this.client.request("GET", "/v1/evals/trace", {
310
+ ...opts,
311
+ query: { id },
312
+ });
313
+ }
314
+ /** Thumbs up or down on results of a trace: one result as `item` +
315
+ * `valid`, or several in `items`. The labels become the golden's ground
316
+ * truth. */
317
+ label(traceId, body, opts = {}) {
318
+ return this.client.request("POST", "/v1/evals/label", {
319
+ ...opts,
320
+ query: { trace: traceId },
321
+ body,
322
+ });
323
+ }
324
+ /** Let the managed judge label the results of one trace, or of a batch of
325
+ * traces with unlabeled results. */
326
+ judge(options = {}) {
327
+ const { traceId, limit, ...opts } = options;
328
+ return this.client.request("POST", "/v1/evals/judge", {
329
+ ...opts,
330
+ query: { trace: traceId, limit },
331
+ });
332
+ }
333
+ goldens(opts = {}) {
334
+ return this.client.request("GET", "/v1/evals/goldens", opts);
335
+ }
336
+ /** Freeze a query: every result it returns now is relevant. */
337
+ createGolden(body, opts = {}) {
338
+ return this.client.request("POST", "/v1/evals/goldens", { ...opts, body });
339
+ }
340
+ /** Accept the results a golden returns now as its reference. */
341
+ acceptGolden(id, opts = {}) {
342
+ return this.client.request("POST", "/v1/evals/goldens/accept", {
343
+ ...opts,
344
+ query: { id, consistency: opts.consistency },
345
+ });
346
+ }
347
+ deleteGolden(id, opts = {}) {
348
+ return this.client.request("DELETE", "/v1/evals/goldens", {
349
+ ...opts,
350
+ query: { id },
351
+ });
352
+ }
353
+ /** Replay every golden at the current commit. */
354
+ run(opts = {}) {
355
+ return this.client.request("POST", "/v1/evals/run", {
356
+ ...opts,
357
+ query: { consistency: opts.consistency },
358
+ });
359
+ }
360
+ results(options = {}) {
361
+ const { limit, ...opts } = options;
362
+ return this.client.request("GET", "/v1/evals/results", {
363
+ ...opts,
364
+ query: { limit },
365
+ });
366
+ }
367
+ settings(opts = {}) {
368
+ return this.client.request("GET", "/v1/evals/settings", opts);
369
+ }
370
+ setSettings(body, opts = {}) {
371
+ return this.client.request("PUT", "/v1/evals/settings", { ...opts, body });
372
+ }
373
+ }
202
374
  /** Active ontology/SHACL bundle metadata and atomic publication. */
203
375
  export class SchemaNamespace {
204
376
  client;
@@ -213,6 +385,7 @@ export class SchemaNamespace {
213
385
  publish(body, opts = {}) {
214
386
  return this.client.request("POST", "/v1/schema/publish", {
215
387
  ...opts,
388
+ query: { dry_run: opts.dryRun },
216
389
  idempotencyKey: opts.idempotencyKey ?? this.client.idempotencyKey("schema-publish"),
217
390
  body,
218
391
  });
@@ -266,6 +439,7 @@ export class OntologyNamespace {
266
439
  evolve(body, opts = {}) {
267
440
  return this.client.request("POST", "/v1/ontology/evolve", {
268
441
  ...opts,
442
+ query: { dry_run: opts.dryRun },
269
443
  body,
270
444
  });
271
445
  }