conare 0.15.0 → 0.16.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/README.md +9 -0
- package/dist/index.d.ts +33 -5
- package/dist/index.js +32 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,6 +50,9 @@ for await (const doc of docs.list()) {} // every document, page by page (
|
|
|
50
50
|
await docs.delete("refunds"); // 404 document_not_found if it does not exist
|
|
51
51
|
await docs.deleteMany(["a", "b"]); // up to 1000 ids in one call; missing ids are skipped. Returns the count
|
|
52
52
|
await docs.deleteWhere({ team: "support" }); // every document matching the filter, whole documents. Returns the count
|
|
53
|
+
await docs.uploadFile(bytes, "report.pdf"); // a PDF (one document per page) or an .xlsx (Markdown tables per sheet),
|
|
54
|
+
// up to 20 MiB. The same name (or { id }) again replaces it.
|
|
55
|
+
// Returns { fileId, type, ids, pages, sheets, pagesWithoutText }
|
|
53
56
|
await docs.drop(); // delete the namespace and its documents (succeeds if already emptied; 404 namespace_not_found if never written)
|
|
54
57
|
await docs.create({ sparse: true }); // create it with a sparse (SPLADE) index, before its first write
|
|
55
58
|
|
|
@@ -102,6 +105,12 @@ await conare.embed(["some text"], { type: "query" }); // number[][];
|
|
|
102
105
|
await conare.rerank("refund window", ["a", "b"], { topK: 1 }); // [{ index, score, document }], plus .unscored
|
|
103
106
|
```
|
|
104
107
|
|
|
108
|
+
`rerank` takes 1-100 documents of 1-24,000 characters each (the query at most 8,192 characters, all
|
|
109
|
+
together at most 256,000); more than 100 is a 400 `invalid_request`. More than 20 go through a
|
|
110
|
+
tournament of 20-document windows that settles the exact order of the best `topK` (at most 20). A
|
|
111
|
+
document no window read before the one-second budget ended, or whose window failed, is listed by
|
|
112
|
+
index in `.unscored` and is not in the results; its score from another call would not compare.
|
|
113
|
+
|
|
105
114
|
### Sources
|
|
106
115
|
|
|
107
116
|
Connect an app such as HubSpot or Gmail. It keeps syncing into one namespace, and each record
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.16.0";
|
|
2
2
|
/** A metadata value: string, number, boolean or an array of strings. */
|
|
3
3
|
export type MetadataValue = string | number | boolean | string[];
|
|
4
4
|
export type Metadata = Record<string, MetadataValue>;
|
|
@@ -40,6 +40,19 @@ export interface DocumentInput {
|
|
|
40
40
|
*/
|
|
41
41
|
ifVersion?: number;
|
|
42
42
|
}
|
|
43
|
+
/** What `uploadFile` stored. */
|
|
44
|
+
export interface FileUpload {
|
|
45
|
+
fileId: string;
|
|
46
|
+
type: "pdf" | "xlsx";
|
|
47
|
+
/** The documents it made, in reading order. */
|
|
48
|
+
ids: string[];
|
|
49
|
+
/** A PDF's pages (null for a workbook). */
|
|
50
|
+
pages: number | null;
|
|
51
|
+
/** A workbook's sheets (null for a PDF). */
|
|
52
|
+
sheets: number | null;
|
|
53
|
+
/** PDF pages without a text layer (scans, images): not stored. */
|
|
54
|
+
pagesWithoutText: number[];
|
|
55
|
+
}
|
|
43
56
|
export interface Document {
|
|
44
57
|
id: string;
|
|
45
58
|
text: string;
|
|
@@ -75,7 +88,7 @@ export interface RerankResult {
|
|
|
75
88
|
score: number;
|
|
76
89
|
document: string;
|
|
77
90
|
}
|
|
78
|
-
/** Rerank results, best first, and the indexes of the documents no window read
|
|
91
|
+
/** Rerank results, best first, and the indexes of the documents no window read (the budget ended, or their window failed); those are not in the results. */
|
|
79
92
|
export type RerankResults = RerankResult[] & {
|
|
80
93
|
unscored: number[];
|
|
81
94
|
};
|
|
@@ -147,7 +160,11 @@ export declare class Conare {
|
|
|
147
160
|
embed(input: string | string[], options?: RequestOptions & {
|
|
148
161
|
type?: "document" | "query";
|
|
149
162
|
}): Promise<number[][]>;
|
|
150
|
-
/**
|
|
163
|
+
/**
|
|
164
|
+
* Rerank 1-100 documents against a query, best first. Each document is 1-24,000 characters, the query at
|
|
165
|
+
* most 8,192, and all of them together at most 256,000; more than 100 documents is a 400 `invalid_request`.
|
|
166
|
+
* Check `unscored`: documents left unread are missing from the results.
|
|
167
|
+
*/
|
|
151
168
|
rerank(query: string, documents: string[], options?: RequestOptions & {
|
|
152
169
|
topK?: number;
|
|
153
170
|
}): Promise<RerankResults>;
|
|
@@ -184,11 +201,22 @@ export declare class Namespace {
|
|
|
184
201
|
id: string;
|
|
185
202
|
version: number | null;
|
|
186
203
|
}[]>;
|
|
204
|
+
/**
|
|
205
|
+
* Store a PDF or an Excel workbook (.xlsx), at most 20 MiB: one document per PDF page with a
|
|
206
|
+
* text layer (`<fileId>:page-3`) and Markdown tables per worksheet (`<fileId>:Sheet1-1`), each
|
|
207
|
+
* with `file`, `file_id`, `file_type` and `page` or `sheet` metadata. `fileId` defaults to the
|
|
208
|
+
* name in id characters; uploading the same one again replaces every document it made. Pages
|
|
209
|
+
* without a text layer (scans, images) are listed in `pagesWithoutText` and not stored.
|
|
210
|
+
*/
|
|
211
|
+
uploadFile(file: Blob | Uint8Array | ArrayBuffer, name: string, options?: RequestOptions & {
|
|
212
|
+
id?: string;
|
|
213
|
+
}): Promise<FileUpload>;
|
|
187
214
|
/**
|
|
188
215
|
* Hybrid search, reranked. One result per document: its best passage. `retrievers` picks what
|
|
189
216
|
* the search fuses (default `["vector", "keyword"]`); `"sparse"` needs a namespace created with
|
|
190
|
-
* a sparse index. `rerankDepth` (1-100) has the reranker
|
|
191
|
-
* that many
|
|
217
|
+
* a sparse index. `rerankDepth` (1-100) has the reranker rank every passage among the first
|
|
218
|
+
* that many in a tournament of 20-passage windows (exact order for the first `topK`, at most
|
|
219
|
+
* 20); unset, it reads one window of 20.
|
|
192
220
|
*/
|
|
193
221
|
query(query: string, options?: RequestOptions & {
|
|
194
222
|
topK?: number;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// conare: TypeScript client for the Conare API. Zero dependencies; uses global fetch.
|
|
2
|
-
export const VERSION = "0.
|
|
2
|
+
export const VERSION = "0.16.0";
|
|
3
3
|
const DEFAULT_BASE_URL = "https://api.conare.ai";
|
|
4
4
|
const BATCH_SIZE = 100;
|
|
5
5
|
// ---- Errors ----------------------------------------------------------------
|
|
@@ -77,7 +77,11 @@ export class Conare {
|
|
|
77
77
|
const body = await this.request("POST", "/embed", { input: Array.isArray(input) ? input : [input], type: options.type ?? "document" }, options, true);
|
|
78
78
|
return body.embeddings;
|
|
79
79
|
}
|
|
80
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* Rerank 1-100 documents against a query, best first. Each document is 1-24,000 characters, the query at
|
|
82
|
+
* most 8,192, and all of them together at most 256,000; more than 100 documents is a 400 `invalid_request`.
|
|
83
|
+
* Check `unscored`: documents left unread are missing from the results.
|
|
84
|
+
*/
|
|
81
85
|
async rerank(query, documents, options = {}) {
|
|
82
86
|
const body = await this.request("POST", "/rerank", { query, documents, top_k: options.topK }, options, true);
|
|
83
87
|
const results = body.results.map((r) => ({ index: r.index, score: r.score, document: documents[r.index] ?? "" }));
|
|
@@ -127,15 +131,17 @@ export class Conare {
|
|
|
127
131
|
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
128
132
|
if (options.signal?.aborted)
|
|
129
133
|
controller.abort();
|
|
134
|
+
// A file (uploadFile) goes as its bytes; everything else as JSON.
|
|
135
|
+
const raw = body instanceof Uint8Array || body instanceof ArrayBuffer || (typeof Blob !== "undefined" && body instanceof Blob);
|
|
130
136
|
try {
|
|
131
137
|
const res = await this.fetchFn(this.baseURL + path, {
|
|
132
138
|
method,
|
|
133
139
|
headers: {
|
|
134
140
|
Authorization: `Bearer ${this.apiKey}`,
|
|
135
141
|
Accept: "application/json",
|
|
136
|
-
...(body === undefined ? {} : { "Content-Type": "application/json" }),
|
|
142
|
+
...(body === undefined ? {} : { "Content-Type": raw ? "application/octet-stream" : "application/json" }),
|
|
137
143
|
},
|
|
138
|
-
body: body === undefined ? undefined : JSON.stringify(body),
|
|
144
|
+
body: body === undefined ? undefined : raw ? body : JSON.stringify(body),
|
|
139
145
|
signal: controller.signal,
|
|
140
146
|
});
|
|
141
147
|
return [res, await res.text()];
|
|
@@ -205,11 +211,31 @@ export class Namespace {
|
|
|
205
211
|
}
|
|
206
212
|
return out;
|
|
207
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Store a PDF or an Excel workbook (.xlsx), at most 20 MiB: one document per PDF page with a
|
|
216
|
+
* text layer (`<fileId>:page-3`) and Markdown tables per worksheet (`<fileId>:Sheet1-1`), each
|
|
217
|
+
* with `file`, `file_id`, `file_type` and `page` or `sheet` metadata. `fileId` defaults to the
|
|
218
|
+
* name in id characters; uploading the same one again replaces every document it made. Pages
|
|
219
|
+
* without a text layer (scans, images) are listed in `pagesWithoutText` and not stored.
|
|
220
|
+
*/
|
|
221
|
+
async uploadFile(file, name, options = {}) {
|
|
222
|
+
const query = new URLSearchParams({ name, ...(options.id ? { id: options.id } : {}) });
|
|
223
|
+
const body = await this.client.request("POST", this.path(`/files?${query}`), file, { timeout: 120_000, ...options }, true);
|
|
224
|
+
return {
|
|
225
|
+
fileId: body.file_id,
|
|
226
|
+
type: body.type,
|
|
227
|
+
ids: body.ids,
|
|
228
|
+
pages: body.pages ?? null,
|
|
229
|
+
sheets: body.sheets ?? null,
|
|
230
|
+
pagesWithoutText: body.pages_without_text ?? [],
|
|
231
|
+
};
|
|
232
|
+
}
|
|
208
233
|
/**
|
|
209
234
|
* Hybrid search, reranked. One result per document: its best passage. `retrievers` picks what
|
|
210
235
|
* the search fuses (default `["vector", "keyword"]`); `"sparse"` needs a namespace created with
|
|
211
|
-
* a sparse index. `rerankDepth` (1-100) has the reranker
|
|
212
|
-
* that many
|
|
236
|
+
* a sparse index. `rerankDepth` (1-100) has the reranker rank every passage among the first
|
|
237
|
+
* that many in a tournament of 20-passage windows (exact order for the first `topK`, at most
|
|
238
|
+
* 20); unset, it reads one window of 20.
|
|
213
239
|
*/
|
|
214
240
|
async query(query, options = {}) {
|
|
215
241
|
const body = await this.client.request("POST", this.path("/query"), { query, top_k: options.topK, filter: options.filter, rerank: options.rerank, rerank_depth: options.rerankDepth, retrievers: options.retrievers }, options, true);
|