pareta 1.0.0 → 1.1.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 +84 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -2
- package/dist/index.d.ts +58 -2
- package/dist/index.mjs +82 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -142,6 +142,30 @@ declare class EvalRun extends BaseModel {
|
|
|
142
142
|
get cost(): string;
|
|
143
143
|
get results(): EvalResult[];
|
|
144
144
|
}
|
|
145
|
+
/** One row of `Rerank.results` — a document's position + calibrated score. */
|
|
146
|
+
declare class RerankResult extends BaseModel {
|
|
147
|
+
/** Position of this document in YOUR request's documents array. */
|
|
148
|
+
get index(): number;
|
|
149
|
+
/** Calibrated P(relevant) in (0, 1) — thresholdable, not just ordinal. */
|
|
150
|
+
get relevanceScore(): number;
|
|
151
|
+
}
|
|
152
|
+
/** Result of `pa.rerank(...)`: `.results` ordered most-relevant-first;
|
|
153
|
+
* `.pairs` is the number of documents scored (the metered unit). */
|
|
154
|
+
declare class Rerank extends BaseModel {
|
|
155
|
+
get results(): RerankResult[];
|
|
156
|
+
get model(): string | null;
|
|
157
|
+
get pairs(): number | null;
|
|
158
|
+
/** Map the ranked indices back onto the documents you sent — best first. */
|
|
159
|
+
topDocuments(documents: string[]): string[];
|
|
160
|
+
}
|
|
161
|
+
/** Result of `pa.embeddings(...)`: unit-normalized vectors in input order
|
|
162
|
+
* (cosine similarity is a plain dot product); `.promptTokens` is metered. */
|
|
163
|
+
declare class Embeddings extends BaseModel {
|
|
164
|
+
get vectors(): number[][];
|
|
165
|
+
get model(): string | null;
|
|
166
|
+
get promptTokens(): number | null;
|
|
167
|
+
get length(): number;
|
|
168
|
+
}
|
|
145
169
|
|
|
146
170
|
/**
|
|
147
171
|
* `client.chat.completions` — OpenAI-compatible chat completions.
|
|
@@ -366,6 +390,34 @@ declare class Auto {
|
|
|
366
390
|
}): Promise<FrontierComparison>;
|
|
367
391
|
}
|
|
368
392
|
|
|
393
|
+
/**
|
|
394
|
+
* `pa.rerank(...)` + `pa.embeddings(...)` — the Retrieval capability lanes
|
|
395
|
+
* (the RAG stack: embeddings for recall, reranking for precision).
|
|
396
|
+
*
|
|
397
|
+
* Both are dedicated routes, not `chat.completions`:
|
|
398
|
+
* POST /v1/rerank {query, documents[], top_n?} -> ordered
|
|
399
|
+
* {index, relevance_score} rows (calibrated P(relevant))
|
|
400
|
+
* POST /v1/embeddings {input[], input_type?} -> unit-normalized vectors
|
|
401
|
+
*
|
|
402
|
+
* Rerank is metered per document scored; embeddings per input token. You never
|
|
403
|
+
* pick a serving model — Pareta resolves the lane (`pareta-rerank-1` / `bge-1`),
|
|
404
|
+
* exactly as `model:"auto"` does for chat.
|
|
405
|
+
*
|
|
406
|
+
* Exposed as callable client fields (`pa.rerank(...)`) rather than resource
|
|
407
|
+
* objects — call-parity with the Python SDK, and neither lane has sub-methods.
|
|
408
|
+
*/
|
|
409
|
+
|
|
410
|
+
interface RerankOptions {
|
|
411
|
+
/** Truncate the response to the best N (all documents are still scored and metered). */
|
|
412
|
+
topN?: number;
|
|
413
|
+
}
|
|
414
|
+
type RerankFn = (query: string, documents: string[], opts?: RerankOptions) => Promise<Rerank>;
|
|
415
|
+
interface EmbeddingsOptions {
|
|
416
|
+
/** `"query"` embeds a retrieval QUERY (asymmetric); default embeds documents raw. */
|
|
417
|
+
inputType?: "query" | "document";
|
|
418
|
+
}
|
|
419
|
+
type EmbeddingsFn = (input: string | string[], opts?: EmbeddingsOptions) => Promise<Embeddings>;
|
|
420
|
+
|
|
369
421
|
/**
|
|
370
422
|
* The `Pareta` client — one class (no sync/async split; JS is Promise-only).
|
|
371
423
|
* A faithful port of the Python `_client.py` transport: header construction,
|
|
@@ -420,6 +472,10 @@ declare class Pareta implements Transport {
|
|
|
420
472
|
readonly tasks: Tasks;
|
|
421
473
|
readonly evals: Evals;
|
|
422
474
|
readonly auto: Auto;
|
|
475
|
+
/** Document reranking (the Retrieval precision lane) — `pa.rerank(query, docs, {topN})`. */
|
|
476
|
+
readonly rerank: RerankFn;
|
|
477
|
+
/** Text embeddings (the Retrieval recall lane) — `pa.embeddings(input, {inputType})`. */
|
|
478
|
+
readonly embeddings: EmbeddingsFn;
|
|
423
479
|
constructor(options?: ParetaOptions);
|
|
424
480
|
/** Build from PARETA_API_KEY (+ optional PARETA_BASE_URL); explicit opts win. */
|
|
425
481
|
static fromEnv(options?: ParetaOptions): Pareta;
|
|
@@ -443,7 +499,7 @@ declare class Pareta implements Transport {
|
|
|
443
499
|
stream<T = unknown>(method: string, path: string, opts?: StreamOptions): AsyncGenerator<T>;
|
|
444
500
|
}
|
|
445
501
|
|
|
446
|
-
declare const VERSION = "1.
|
|
502
|
+
declare const VERSION = "1.1.0";
|
|
447
503
|
|
|
448
504
|
/**
|
|
449
505
|
* Typed error hierarchy for the Pareta SDK — a faithful port of the Python
|
|
@@ -535,4 +591,4 @@ declare class EndpointNotReadyError extends APIStatusError {
|
|
|
535
591
|
constructor(message: string, init: APIStatusErrorInit);
|
|
536
592
|
}
|
|
537
593
|
|
|
538
|
-
export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, type ChatCompletionCreateParams, type ChatMessage, Choice, ConflictError, EndpointNotReadyError, type ErrorDetail, EvalItemResult, EvalResult, EvalRun, type EvalRunCreateParams, EvalRuns, EvalSet, EvalSets, type FileInput, type FilePart, FrontierModel, type FrontierSpec, InsufficientCreditsError, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, type ParetaOptions, PermissionDeniedError, RateLimitError, type SSEEvent, Task, TaskMatch, TaskMatchCandidate, type Transport, Usage, VERSION, type ValidationErrorItem };
|
|
594
|
+
export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, type ChatCompletionCreateParams, type ChatMessage, Choice, ConflictError, Embeddings, type EmbeddingsFn, type EmbeddingsOptions, EndpointNotReadyError, type ErrorDetail, EvalItemResult, EvalResult, EvalRun, type EvalRunCreateParams, EvalRuns, EvalSet, EvalSets, type FileInput, type FilePart, FrontierModel, type FrontierSpec, InsufficientCreditsError, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, type ParetaOptions, PermissionDeniedError, RateLimitError, Rerank, type RerankFn, type RerankOptions, RerankResult, type SSEEvent, Task, TaskMatch, TaskMatchCandidate, type Transport, Usage, VERSION, type ValidationErrorItem };
|
package/dist/index.d.ts
CHANGED
|
@@ -142,6 +142,30 @@ declare class EvalRun extends BaseModel {
|
|
|
142
142
|
get cost(): string;
|
|
143
143
|
get results(): EvalResult[];
|
|
144
144
|
}
|
|
145
|
+
/** One row of `Rerank.results` — a document's position + calibrated score. */
|
|
146
|
+
declare class RerankResult extends BaseModel {
|
|
147
|
+
/** Position of this document in YOUR request's documents array. */
|
|
148
|
+
get index(): number;
|
|
149
|
+
/** Calibrated P(relevant) in (0, 1) — thresholdable, not just ordinal. */
|
|
150
|
+
get relevanceScore(): number;
|
|
151
|
+
}
|
|
152
|
+
/** Result of `pa.rerank(...)`: `.results` ordered most-relevant-first;
|
|
153
|
+
* `.pairs` is the number of documents scored (the metered unit). */
|
|
154
|
+
declare class Rerank extends BaseModel {
|
|
155
|
+
get results(): RerankResult[];
|
|
156
|
+
get model(): string | null;
|
|
157
|
+
get pairs(): number | null;
|
|
158
|
+
/** Map the ranked indices back onto the documents you sent — best first. */
|
|
159
|
+
topDocuments(documents: string[]): string[];
|
|
160
|
+
}
|
|
161
|
+
/** Result of `pa.embeddings(...)`: unit-normalized vectors in input order
|
|
162
|
+
* (cosine similarity is a plain dot product); `.promptTokens` is metered. */
|
|
163
|
+
declare class Embeddings extends BaseModel {
|
|
164
|
+
get vectors(): number[][];
|
|
165
|
+
get model(): string | null;
|
|
166
|
+
get promptTokens(): number | null;
|
|
167
|
+
get length(): number;
|
|
168
|
+
}
|
|
145
169
|
|
|
146
170
|
/**
|
|
147
171
|
* `client.chat.completions` — OpenAI-compatible chat completions.
|
|
@@ -366,6 +390,34 @@ declare class Auto {
|
|
|
366
390
|
}): Promise<FrontierComparison>;
|
|
367
391
|
}
|
|
368
392
|
|
|
393
|
+
/**
|
|
394
|
+
* `pa.rerank(...)` + `pa.embeddings(...)` — the Retrieval capability lanes
|
|
395
|
+
* (the RAG stack: embeddings for recall, reranking for precision).
|
|
396
|
+
*
|
|
397
|
+
* Both are dedicated routes, not `chat.completions`:
|
|
398
|
+
* POST /v1/rerank {query, documents[], top_n?} -> ordered
|
|
399
|
+
* {index, relevance_score} rows (calibrated P(relevant))
|
|
400
|
+
* POST /v1/embeddings {input[], input_type?} -> unit-normalized vectors
|
|
401
|
+
*
|
|
402
|
+
* Rerank is metered per document scored; embeddings per input token. You never
|
|
403
|
+
* pick a serving model — Pareta resolves the lane (`pareta-rerank-1` / `bge-1`),
|
|
404
|
+
* exactly as `model:"auto"` does for chat.
|
|
405
|
+
*
|
|
406
|
+
* Exposed as callable client fields (`pa.rerank(...)`) rather than resource
|
|
407
|
+
* objects — call-parity with the Python SDK, and neither lane has sub-methods.
|
|
408
|
+
*/
|
|
409
|
+
|
|
410
|
+
interface RerankOptions {
|
|
411
|
+
/** Truncate the response to the best N (all documents are still scored and metered). */
|
|
412
|
+
topN?: number;
|
|
413
|
+
}
|
|
414
|
+
type RerankFn = (query: string, documents: string[], opts?: RerankOptions) => Promise<Rerank>;
|
|
415
|
+
interface EmbeddingsOptions {
|
|
416
|
+
/** `"query"` embeds a retrieval QUERY (asymmetric); default embeds documents raw. */
|
|
417
|
+
inputType?: "query" | "document";
|
|
418
|
+
}
|
|
419
|
+
type EmbeddingsFn = (input: string | string[], opts?: EmbeddingsOptions) => Promise<Embeddings>;
|
|
420
|
+
|
|
369
421
|
/**
|
|
370
422
|
* The `Pareta` client — one class (no sync/async split; JS is Promise-only).
|
|
371
423
|
* A faithful port of the Python `_client.py` transport: header construction,
|
|
@@ -420,6 +472,10 @@ declare class Pareta implements Transport {
|
|
|
420
472
|
readonly tasks: Tasks;
|
|
421
473
|
readonly evals: Evals;
|
|
422
474
|
readonly auto: Auto;
|
|
475
|
+
/** Document reranking (the Retrieval precision lane) — `pa.rerank(query, docs, {topN})`. */
|
|
476
|
+
readonly rerank: RerankFn;
|
|
477
|
+
/** Text embeddings (the Retrieval recall lane) — `pa.embeddings(input, {inputType})`. */
|
|
478
|
+
readonly embeddings: EmbeddingsFn;
|
|
423
479
|
constructor(options?: ParetaOptions);
|
|
424
480
|
/** Build from PARETA_API_KEY (+ optional PARETA_BASE_URL); explicit opts win. */
|
|
425
481
|
static fromEnv(options?: ParetaOptions): Pareta;
|
|
@@ -443,7 +499,7 @@ declare class Pareta implements Transport {
|
|
|
443
499
|
stream<T = unknown>(method: string, path: string, opts?: StreamOptions): AsyncGenerator<T>;
|
|
444
500
|
}
|
|
445
501
|
|
|
446
|
-
declare const VERSION = "1.
|
|
502
|
+
declare const VERSION = "1.1.0";
|
|
447
503
|
|
|
448
504
|
/**
|
|
449
505
|
* Typed error hierarchy for the Pareta SDK — a faithful port of the Python
|
|
@@ -535,4 +591,4 @@ declare class EndpointNotReadyError extends APIStatusError {
|
|
|
535
591
|
constructor(message: string, init: APIStatusErrorInit);
|
|
536
592
|
}
|
|
537
593
|
|
|
538
|
-
export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, type ChatCompletionCreateParams, type ChatMessage, Choice, ConflictError, EndpointNotReadyError, type ErrorDetail, EvalItemResult, EvalResult, EvalRun, type EvalRunCreateParams, EvalRuns, EvalSet, EvalSets, type FileInput, type FilePart, FrontierModel, type FrontierSpec, InsufficientCreditsError, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, type ParetaOptions, PermissionDeniedError, RateLimitError, type SSEEvent, Task, TaskMatch, TaskMatchCandidate, type Transport, Usage, VERSION, type ValidationErrorItem };
|
|
594
|
+
export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, type ChatCompletionCreateParams, type ChatMessage, Choice, ConflictError, Embeddings, type EmbeddingsFn, type EmbeddingsOptions, EndpointNotReadyError, type ErrorDetail, EvalItemResult, EvalResult, EvalRun, type EvalRunCreateParams, EvalRuns, EvalSet, EvalSets, type FileInput, type FilePart, FrontierModel, type FrontierSpec, InsufficientCreditsError, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, type ParetaOptions, PermissionDeniedError, RateLimitError, Rerank, type RerankFn, type RerankOptions, RerankResult, type SSEEvent, Task, TaskMatch, TaskMatchCandidate, type Transport, Usage, VERSION, type ValidationErrorItem };
|
package/dist/index.mjs
CHANGED
|
@@ -172,7 +172,7 @@ function parseSSE(reader, opts) {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
// src/version.ts
|
|
175
|
-
var VERSION = "1.
|
|
175
|
+
var VERSION = "1.1.0";
|
|
176
176
|
|
|
177
177
|
// src/money.ts
|
|
178
178
|
var MICRO_PER_CENT = 10000n;
|
|
@@ -443,6 +443,47 @@ var EvalRun = class extends BaseModel {
|
|
|
443
443
|
return (this.raw.results ?? []).map((r) => new EvalResult(r));
|
|
444
444
|
}
|
|
445
445
|
};
|
|
446
|
+
var RerankResult = class extends BaseModel {
|
|
447
|
+
/** Position of this document in YOUR request's documents array. */
|
|
448
|
+
get index() {
|
|
449
|
+
return Number(this.raw.index ?? -1);
|
|
450
|
+
}
|
|
451
|
+
/** Calibrated P(relevant) in (0, 1) — thresholdable, not just ordinal. */
|
|
452
|
+
get relevanceScore() {
|
|
453
|
+
return Number(this.raw.relevance_score ?? 0);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
var Rerank = class extends BaseModel {
|
|
457
|
+
get results() {
|
|
458
|
+
return (this.raw.results ?? []).map((r) => new RerankResult(r));
|
|
459
|
+
}
|
|
460
|
+
get model() {
|
|
461
|
+
return this.raw.model ?? null;
|
|
462
|
+
}
|
|
463
|
+
get pairs() {
|
|
464
|
+
return this.raw.pairs ?? null;
|
|
465
|
+
}
|
|
466
|
+
/** Map the ranked indices back onto the documents you sent — best first. */
|
|
467
|
+
topDocuments(documents) {
|
|
468
|
+
return this.results.filter((r) => r.index >= 0 && r.index < documents.length).map((r) => documents[r.index]);
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
var Embeddings = class extends BaseModel {
|
|
472
|
+
get vectors() {
|
|
473
|
+
const rows = [...this.raw.data ?? []];
|
|
474
|
+
rows.sort((a, b) => Number(a.index ?? 0) - Number(b.index ?? 0));
|
|
475
|
+
return rows.map((r) => r.embedding ?? []);
|
|
476
|
+
}
|
|
477
|
+
get model() {
|
|
478
|
+
return this.raw.model ?? null;
|
|
479
|
+
}
|
|
480
|
+
get promptTokens() {
|
|
481
|
+
return this.raw.usage?.prompt_tokens ?? null;
|
|
482
|
+
}
|
|
483
|
+
get length() {
|
|
484
|
+
return (this.raw.data ?? []).length;
|
|
485
|
+
}
|
|
486
|
+
};
|
|
446
487
|
|
|
447
488
|
// src/resources/chat.ts
|
|
448
489
|
var PATH = "/v1/chat/completions";
|
|
@@ -745,6 +786,39 @@ var Auto = class {
|
|
|
745
786
|
}
|
|
746
787
|
};
|
|
747
788
|
|
|
789
|
+
// src/resources/retrieval.ts
|
|
790
|
+
function makeRerank(client) {
|
|
791
|
+
return (query, documents, opts = {}) => {
|
|
792
|
+
if (!query || !query.trim()) throw new ParetaError("query is required");
|
|
793
|
+
if (!Array.isArray(documents) || documents.length === 0) {
|
|
794
|
+
throw new ParetaError("documents must be a non-empty array of strings");
|
|
795
|
+
}
|
|
796
|
+
const body = { query, documents };
|
|
797
|
+
if (opts.topN !== void 0) body.top_n = opts.topN;
|
|
798
|
+
return client.request("POST", "/v1/rerank", {
|
|
799
|
+
body,
|
|
800
|
+
cast: (raw) => new Rerank(raw)
|
|
801
|
+
});
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
function makeEmbeddings(client) {
|
|
805
|
+
return (input, opts = {}) => {
|
|
806
|
+
const texts = typeof input === "string" ? [input] : input;
|
|
807
|
+
if (!Array.isArray(texts) || texts.length === 0 || texts.some((t) => typeof t !== "string" || !t.trim())) {
|
|
808
|
+
throw new ParetaError("input must be a non-empty string or array of non-empty strings");
|
|
809
|
+
}
|
|
810
|
+
if (opts.inputType !== void 0 && opts.inputType !== "query" && opts.inputType !== "document") {
|
|
811
|
+
throw new ParetaError('inputType must be "query" or "document"');
|
|
812
|
+
}
|
|
813
|
+
const body = { input: texts };
|
|
814
|
+
if (opts.inputType !== void 0) body.input_type = opts.inputType;
|
|
815
|
+
return client.request("POST", "/v1/embeddings", {
|
|
816
|
+
body,
|
|
817
|
+
cast: (raw) => new Embeddings(raw)
|
|
818
|
+
});
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
|
|
748
822
|
// src/client.ts
|
|
749
823
|
var DEFAULT_BASE_URL = "https://api.pareta.ai";
|
|
750
824
|
function randomKey() {
|
|
@@ -772,6 +846,10 @@ var Pareta = class _Pareta {
|
|
|
772
846
|
tasks;
|
|
773
847
|
evals;
|
|
774
848
|
auto;
|
|
849
|
+
/** Document reranking (the Retrieval precision lane) — `pa.rerank(query, docs, {topN})`. */
|
|
850
|
+
rerank;
|
|
851
|
+
/** Text embeddings (the Retrieval recall lane) — `pa.embeddings(input, {inputType})`. */
|
|
852
|
+
embeddings;
|
|
775
853
|
constructor(options = {}) {
|
|
776
854
|
if (!options.apiKey) {
|
|
777
855
|
throw new ParetaError(
|
|
@@ -792,6 +870,8 @@ var Pareta = class _Pareta {
|
|
|
792
870
|
this.tasks = new Tasks(this);
|
|
793
871
|
this.evals = new Evals(this);
|
|
794
872
|
this.auto = new Auto(this);
|
|
873
|
+
this.rerank = makeRerank(this);
|
|
874
|
+
this.embeddings = makeEmbeddings(this);
|
|
795
875
|
}
|
|
796
876
|
/** Build from PARETA_API_KEY (+ optional PARETA_BASE_URL); explicit opts win. */
|
|
797
877
|
static fromEnv(options = {}) {
|
|
@@ -972,6 +1052,6 @@ var Pareta = class _Pareta {
|
|
|
972
1052
|
}
|
|
973
1053
|
};
|
|
974
1054
|
|
|
975
|
-
export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, Choice, ConflictError, EndpointNotReadyError, EvalItemResult, EvalResult, EvalRun, EvalRuns, EvalSet, EvalSets, FrontierModel, InsufficientCreditsError, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, PermissionDeniedError, RateLimitError, Task, TaskMatch, TaskMatchCandidate, Usage, VERSION };
|
|
1055
|
+
export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, Choice, ConflictError, Embeddings, EndpointNotReadyError, EvalItemResult, EvalResult, EvalRun, EvalRuns, EvalSet, EvalSets, FrontierModel, InsufficientCreditsError, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, PermissionDeniedError, RateLimitError, Rerank, RerankResult, Task, TaskMatch, TaskMatchCandidate, Usage, VERSION };
|
|
976
1056
|
//# sourceMappingURL=index.mjs.map
|
|
977
1057
|
//# sourceMappingURL=index.mjs.map
|