@kortexya/reasoninglayer 1.17.0 → 1.18.0

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.
package/dist/index.cjs CHANGED
@@ -7,7 +7,7 @@ var __export = (target, all) => {
7
7
  };
8
8
 
9
9
  // src/config.ts
10
- var SDK_VERSION = "1.17.0";
10
+ var SDK_VERSION = "1.18.0";
11
11
  function resolveConfig(config) {
12
12
  if (!config.baseUrl) {
13
13
  throw new Error("ClientConfig.baseUrl is required");
@@ -6379,7 +6379,7 @@ var Query = class {
6379
6379
  this.http = http;
6380
6380
  }
6381
6381
  /**
6382
- * @description Returns all terms with the specified sort OR any of its subtypes. This implements proper OSF polymorphic query semantics where querying a parent sort returns all instances of that sort and its descendants.
6382
+ * @description Returns all terms with the specified sort OR any of its subtypes. This implements proper OSF polymorphic query semantics where querying a parent sort returns all instances of that sort and its descendants. ## Resolving `sort_name` A name can denote more than one id (see `sort_name_candidates`), and no cheap probe tells which of them the query can actually answer from: on the production adapter `get_sort` and `get_sort_ids_by_names` are bare reads of an in-memory cache with no persistence fallback, while the query's own `get_compatible_sorts` does fall back to Postgres. Confirming a candidate with `get_sort` would therefore 404 every tenant sort created before the last restart — a guard strictly stricter than the thing it guards. So the candidates are **tried** against the real query, in order, and the first that answers wins; only `SortNotFound` moves on to the next, every other failure is returned as-is. When the first candidate answers — the common case — the route runs exactly one term query, as it always did. A phantom id (minted into the tenant lattice by ingestion and never persisted, #138) cannot be returned: the query authority refuses it and the loop skips past it. When no candidate answers, the sort is not queryable and the honest reply is 404 naming the sort the CALLER asked for — never a 400 leaking an internal `SortId` the caller never supplied.
6383
6383
  *
6384
6384
  * @tags query
6385
6385
  * @name FindBySort
@@ -11864,6 +11864,32 @@ var OntologyExport = class {
11864
11864
  });
11865
11865
  };
11866
11866
 
11867
+ // src/api-spec/generated/Embeddings.ts
11868
+ var Embeddings = class {
11869
+ http;
11870
+ constructor(http) {
11871
+ this.http = http;
11872
+ }
11873
+ /**
11874
+ * @description POST /api/v1/embeddings/rank
11875
+ *
11876
+ * @tags embeddings
11877
+ * @name RankEmbeddings
11878
+ * @summary Score every candidate against the query by embedding cosine similarity.
11879
+ * @request POST:/api/v1/embeddings/rank
11880
+ * @secure
11881
+ */
11882
+ rankEmbeddings = (data, params = {}) => this.http.request({
11883
+ path: `/api/v1/embeddings/rank`,
11884
+ method: "POST",
11885
+ body: data,
11886
+ secure: true,
11887
+ type: "application/json" /* Json */,
11888
+ format: "json",
11889
+ ...params
11890
+ });
11891
+ };
11892
+
11867
11893
  // src/normalizers/sorts.ts
11868
11894
  function ConstraintDtoFromApiToFront(dto) {
11869
11895
  if (dto.type === "FuzzyPathSimilarity") {
@@ -20811,8 +20837,10 @@ function EvidenceAssessmentRequestFromFrontToApi(model) {
20811
20837
  };
20812
20838
  }
20813
20839
  function EvidenceItemDtoFromApiToFront(dto) {
20840
+ const wireDescription = dto.description;
20814
20841
  return {
20815
20842
  contribution: dto.contribution,
20843
+ description: wireDescription ?? null,
20816
20844
  qualityWeight: dto.quality_weight,
20817
20845
  supports: dto.supports,
20818
20846
  termId: dto.term_id
@@ -20967,6 +20995,13 @@ var ReasoningClient = class {
20967
20995
  /**
20968
20996
  * Assess the truthfulness/validity of a subject based on related evidence.
20969
20997
  *
20998
+ * @remarks
20999
+ * Each item in the supporting/contradicting breakdown carries a
21000
+ * `description` — the evidence term's own sentence,
21001
+ * e.g. `"Aspirin reduces_risk_of Cancer"` — so evidence can be rendered
21002
+ * without a second lookup by `termId`. It is `null` against a backend that
21003
+ * predates the field.
21004
+ *
20970
21005
  * @param request - Evidence assessment request.
20971
21006
  * @returns Assessment result with truthfulness score, label, and evidence breakdown.
20972
21007
  */
@@ -29302,7 +29337,8 @@ function IngestPaperRequestFromFrontToApi(model) {
29302
29337
  function VerifyClaimRequestFromFrontToApi(model) {
29303
29338
  return {
29304
29339
  claim_term_id: model.claimTermId,
29305
- evidence_sort_id: model.evidenceSortId
29340
+ evidence_sort_id: model.evidenceSortId,
29341
+ session_id: model.sessionId
29306
29342
  };
29307
29343
  }
29308
29344
 
@@ -36915,6 +36951,81 @@ var ConnectorsClient = class {
36915
36951
  }
36916
36952
  };
36917
36953
 
36954
+ // src/normalizers/embeddings.ts
36955
+ function EmbeddingRankRequestFromFrontToApi(model) {
36956
+ return {
36957
+ candidates: model.candidates ?? [],
36958
+ query: model.query
36959
+ };
36960
+ }
36961
+ function EmbeddingRankResponseFromApiToFront(dto) {
36962
+ return {
36963
+ scores: dto.scores ?? []
36964
+ };
36965
+ }
36966
+
36967
+ // src/resources/embeddings.ts
36968
+ var EmbeddingsClient = class {
36969
+ /** @internal */
36970
+ api;
36971
+ /** @internal */
36972
+ constructor(api) {
36973
+ this.api = api;
36974
+ }
36975
+ /**
36976
+ * Score every candidate against the query by embedding cosine similarity.
36977
+ *
36978
+ * @param request - The query and the candidate texts to score against it.
36979
+ * @returns `scores` — one cosine similarity in `[-1, 1]` per candidate,
36980
+ * **index-aligned with `request.candidates`** (index `i` scores
36981
+ * `candidates[i]`) and the same length, so the scores can be zipped straight
36982
+ * back onto whatever was retrieved. Higher is more similar; a candidate
36983
+ * whose text is blank scores `0`.
36984
+ * @throws {BadRequestError} `400` — the query is blank, the candidate list is
36985
+ * over the backend's 512-candidate cap, or the query / a candidate is over
36986
+ * 8192 characters.
36987
+ * @throws {ApiError} `503` when the deployment has **no embedding backend
36988
+ * configured** (or its embedder is unreachable / misconfigured). The SDK
36989
+ * surfaces every 5xx as an `InternalServerError`; read its `status` to tell
36990
+ * `503` (no embedder) from `500` (ranking failed).
36991
+ *
36992
+ * @remarks
36993
+ * Distinguish "no embedder" from "no similarity": a deployment without an
36994
+ * embedding backend answers `503` rather than a fabricated score, precisely so
36995
+ * a caller cannot mistake it for "everything scored 0" and silently rank by
36996
+ * noise. The documented fallback on a `503` is to keep the source order.
36997
+ *
36998
+ * An empty `candidates` list is valid, not an error: it answers `200` with an
36999
+ * empty `scores` array, so a caller that retrieved nothing still gets a
37000
+ * well-formed, index-aligned response.
37001
+ *
37002
+ * A `0` score is absence of signal, not evidence of dissimilarity — it is also
37003
+ * what an orthogonal candidate and a blank candidate both receive.
37004
+ *
37005
+ * @example
37006
+ * ```typescript
37007
+ * const retrieved = [
37008
+ * { id: 'doc-1', text: 'Chaperones assist protein folding in the cytosol.' },
37009
+ * { id: 'doc-2', text: 'Quarterly revenue rose 12% year over year.' },
37010
+ * ];
37011
+ *
37012
+ * const { scores } = await client.embeddings.rank({
37013
+ * query: 'how proteins fold',
37014
+ * candidates: retrieved.map((doc) => doc.text),
37015
+ * });
37016
+ *
37017
+ * // Scores are index-aligned — zip them back onto what was retrieved.
37018
+ * const ranked = retrieved
37019
+ * .map((doc, i) => ({ doc, score: scores[i] }))
37020
+ * .sort((a, b) => b.score - a.score);
37021
+ * ```
37022
+ */
37023
+ async rank(request) {
37024
+ const response = await this.api.rankEmbeddings(EmbeddingRankRequestFromFrontToApi(request));
37025
+ return EmbeddingRankResponseFromApiToFront(response.data);
37026
+ }
37027
+ };
37028
+
36918
37029
  // src/client.ts
36919
37030
  var ReasoningLayerClient = class {
36920
37031
  /** Sort (type hierarchy) operations. */
@@ -37101,6 +37212,8 @@ var ReasoningLayerClient = class {
37101
37212
  speech;
37102
37213
  /** External data connectors — register / list / remove / connect / disconnect + OAuth callback. */
37103
37214
  connectors;
37215
+ /** Embedding-space ranking — cosine score per candidate against a query, index-aligned. */
37216
+ embeddings;
37104
37217
  // ─── Group Caches ─────────────────────────────────────────────────
37105
37218
  _core;
37106
37219
  _ai;
@@ -37418,6 +37531,7 @@ var ReasoningLayerClient = class {
37418
37531
  this.speakers = new SpeakersClient(new Speakers(generatedHttp));
37419
37532
  this.speech = new SpeechClient(new Speech(generatedHttp));
37420
37533
  this.connectors = new ConnectorsClient(new Connectors(generatedHttp));
37534
+ this.embeddings = new EmbeddingsClient(new Embeddings(generatedHttp));
37421
37535
  }
37422
37536
  };
37423
37537
 
@@ -37701,6 +37815,9 @@ var speech_exports = {};
37701
37815
  // src/types/connectors.ts
37702
37816
  var connectors_exports = {};
37703
37817
 
37818
+ // src/types/embeddings.ts
37819
+ var embeddings_exports = {};
37820
+
37704
37821
  // src/builders/value.ts
37705
37822
  var Value = {
37706
37823
  /**
@@ -38740,6 +38857,7 @@ exports.Demo = demo_exports;
38740
38857
  exports.Discovery = discovery_exports;
38741
38858
  exports.DocumentCheck = document_check_exports;
38742
38859
  exports.Documents = documents_exports;
38860
+ exports.Embeddings = embeddings_exports;
38743
38861
  exports.Execution = execution_exports;
38744
38862
  exports.Extract = extract_exports;
38745
38863
  exports.Feasibility = feasibility_exports;