conare 0.15.0 → 0.17.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 +36 -5
- package/dist/index.js +34 -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.17.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,21 @@ 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 read by OCR because they had no text layer (scans, images); stored like the rest. */
|
|
54
|
+
pagesOcr: number;
|
|
55
|
+
/** PDF pages with no text even after OCR (blank, or OCR could not read them): not stored. */
|
|
56
|
+
pagesWithoutText: number[];
|
|
57
|
+
}
|
|
43
58
|
export interface Document {
|
|
44
59
|
id: string;
|
|
45
60
|
text: string;
|
|
@@ -75,7 +90,7 @@ export interface RerankResult {
|
|
|
75
90
|
score: number;
|
|
76
91
|
document: string;
|
|
77
92
|
}
|
|
78
|
-
/** Rerank results, best first, and the indexes of the documents no window read
|
|
93
|
+
/** 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
94
|
export type RerankResults = RerankResult[] & {
|
|
80
95
|
unscored: number[];
|
|
81
96
|
};
|
|
@@ -147,7 +162,11 @@ export declare class Conare {
|
|
|
147
162
|
embed(input: string | string[], options?: RequestOptions & {
|
|
148
163
|
type?: "document" | "query";
|
|
149
164
|
}): Promise<number[][]>;
|
|
150
|
-
/**
|
|
165
|
+
/**
|
|
166
|
+
* Rerank 1-100 documents against a query, best first. Each document is 1-24,000 characters, the query at
|
|
167
|
+
* most 8,192, and all of them together at most 256,000; more than 100 documents is a 400 `invalid_request`.
|
|
168
|
+
* Check `unscored`: documents left unread are missing from the results.
|
|
169
|
+
*/
|
|
151
170
|
rerank(query: string, documents: string[], options?: RequestOptions & {
|
|
152
171
|
topK?: number;
|
|
153
172
|
}): Promise<RerankResults>;
|
|
@@ -184,11 +203,23 @@ export declare class Namespace {
|
|
|
184
203
|
id: string;
|
|
185
204
|
version: number | null;
|
|
186
205
|
}[]>;
|
|
206
|
+
/**
|
|
207
|
+
* Store a PDF or an Excel workbook (.xlsx), at most 20 MiB: one document per PDF page with a
|
|
208
|
+
* text layer (`<fileId>:page-3`) and Markdown tables per worksheet (`<fileId>:Sheet1-1`), each
|
|
209
|
+
* with `file`, `file_id`, `file_type` and `page` or `sheet` metadata. `fileId` defaults to the
|
|
210
|
+
* name in id characters; uploading the same one again replaces every document it made. Pages
|
|
211
|
+
* without a text layer (scans, images) are read by OCR and counted in `pagesOcr`; pages with no
|
|
212
|
+
* text even then are listed in `pagesWithoutText` and not stored.
|
|
213
|
+
*/
|
|
214
|
+
uploadFile(file: Blob | Uint8Array | ArrayBuffer, name: string, options?: RequestOptions & {
|
|
215
|
+
id?: string;
|
|
216
|
+
}): Promise<FileUpload>;
|
|
187
217
|
/**
|
|
188
218
|
* Hybrid search, reranked. One result per document: its best passage. `retrievers` picks what
|
|
189
219
|
* 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
|
|
220
|
+
* a sparse index. `rerankDepth` (1-100) has the reranker rank every passage among the first
|
|
221
|
+
* that many in a tournament of 20-passage windows (exact order for the first `topK`, at most
|
|
222
|
+
* 20); unset, it reads one window of 20.
|
|
192
223
|
*/
|
|
193
224
|
query(query: string, options?: RequestOptions & {
|
|
194
225
|
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.17.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,33 @@ 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 read by OCR and counted in `pagesOcr`; pages with no
|
|
220
|
+
* text even then are listed in `pagesWithoutText` and not stored.
|
|
221
|
+
*/
|
|
222
|
+
async uploadFile(file, name, options = {}) {
|
|
223
|
+
const query = new URLSearchParams({ name, ...(options.id ? { id: options.id } : {}) });
|
|
224
|
+
const body = await this.client.request("POST", this.path(`/files?${query}`), file, { timeout: 120_000, ...options }, true);
|
|
225
|
+
return {
|
|
226
|
+
fileId: body.file_id,
|
|
227
|
+
type: body.type,
|
|
228
|
+
ids: body.ids,
|
|
229
|
+
pages: body.pages ?? null,
|
|
230
|
+
sheets: body.sheets ?? null,
|
|
231
|
+
pagesOcr: body.pages_ocr ?? 0,
|
|
232
|
+
pagesWithoutText: body.pages_without_text ?? [],
|
|
233
|
+
};
|
|
234
|
+
}
|
|
208
235
|
/**
|
|
209
236
|
* Hybrid search, reranked. One result per document: its best passage. `retrievers` picks what
|
|
210
237
|
* 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
|
|
238
|
+
* a sparse index. `rerankDepth` (1-100) has the reranker rank every passage among the first
|
|
239
|
+
* that many in a tournament of 20-passage windows (exact order for the first `topK`, at most
|
|
240
|
+
* 20); unset, it reads one window of 20.
|
|
213
241
|
*/
|
|
214
242
|
async query(query, options = {}) {
|
|
215
243
|
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);
|