conare 0.14.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 CHANGED
@@ -7,7 +7,7 @@ No dependencies. Works on Node 18+, Bun, Deno and edge runtimes.
7
7
 
8
8
  ```bash
9
9
  npm install conare
10
- export CONARE_API_KEY=sk-conare-... # conare.ai/console/keys
10
+ export CONARE_API_KEY=sk-conare-... # conare.ai/dashboard/keys
11
11
  ```
12
12
 
13
13
  ```ts
@@ -50,10 +50,14 @@ 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
 
56
59
  await conare.namespaces(); // [{ name, documents }]
60
+ await conare.namespaces({ prefix: "u7f3a9c-" }); // one user's namespaces
57
61
  ```
58
62
 
59
63
  Namespace names: 1-64 characters of `a-z 0-9 _ -`. Ids: up to 256 characters of
@@ -101,6 +105,12 @@ await conare.embed(["some text"], { type: "query" }); // number[][];
101
105
  await conare.rerank("refund window", ["a", "b"], { topK: 1 }); // [{ index, score, document }], plus .unscored
102
106
  ```
103
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
+
104
114
  ### Sources
105
115
 
106
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.14.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 before the budget ended. */
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
  };
@@ -136,13 +149,22 @@ export declare class Conare {
136
149
  constructor(options?: ConareOptions);
137
150
  /** A handle to one namespace. Nothing is sent until you call a method; the first write creates it. */
138
151
  namespace(name: string): Namespace;
139
- /** Every namespace in the organization with its document count. */
140
- namespaces(options?: RequestOptions): Promise<NamespaceInfo[]>;
152
+ /**
153
+ * Every namespace in the organization (a scoped key: every one it reaches) with its document
154
+ * count; with `prefix`, only those whose name starts with it, e.g. one user's `"u7f3a9c-"`.
155
+ */
156
+ namespaces(options?: RequestOptions & {
157
+ prefix?: string;
158
+ }): Promise<NamespaceInfo[]>;
141
159
  /** Embed texts. Use type "query" for search queries and "document" (default) for stored text. */
142
160
  embed(input: string | string[], options?: RequestOptions & {
143
161
  type?: "document" | "query";
144
162
  }): Promise<number[][]>;
145
- /** Rerank documents against a query, best first. */
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
+ */
146
168
  rerank(query: string, documents: string[], options?: RequestOptions & {
147
169
  topK?: number;
148
170
  }): Promise<RerankResults>;
@@ -179,15 +201,28 @@ export declare class Namespace {
179
201
  id: string;
180
202
  version: number | null;
181
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>;
182
214
  /**
183
215
  * Hybrid search, reranked. One result per document: its best passage. `retrievers` picks what
184
216
  * the search fuses (default `["vector", "keyword"]`); `"sparse"` needs a namespace created with
185
- * a sparse index.
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.
186
220
  */
187
221
  query(query: string, options?: RequestOptions & {
188
222
  topK?: number;
189
223
  filter?: Filter;
190
224
  rerank?: boolean;
225
+ rerankDepth?: number;
191
226
  retrievers?: Retriever[];
192
227
  }): Promise<QueryResult[]>;
193
228
  /** One document by id, or null if it does not exist. */
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.14.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 ----------------------------------------------------------------
@@ -63,9 +63,13 @@ export class Conare {
63
63
  namespace(name) {
64
64
  return new Namespace(this, name);
65
65
  }
66
- /** Every namespace in the organization with its document count. */
67
- async namespaces(options) {
68
- const body = await this.request("GET", "/namespaces", undefined, options);
66
+ /**
67
+ * Every namespace in the organization (a scoped key: every one it reaches) with its document
68
+ * count; with `prefix`, only those whose name starts with it, e.g. one user's `"u7f3a9c-"`.
69
+ */
70
+ async namespaces(options = {}) {
71
+ const path = options.prefix ? `/namespaces?prefix=${encodeURIComponent(options.prefix)}` : "/namespaces";
72
+ const body = await this.request("GET", path, undefined, options);
69
73
  return body.namespaces;
70
74
  }
71
75
  /** Embed texts. Use type "query" for search queries and "document" (default) for stored text. */
@@ -73,7 +77,11 @@ export class Conare {
73
77
  const body = await this.request("POST", "/embed", { input: Array.isArray(input) ? input : [input], type: options.type ?? "document" }, options, true);
74
78
  return body.embeddings;
75
79
  }
76
- /** Rerank documents against a query, best first. */
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
+ */
77
85
  async rerank(query, documents, options = {}) {
78
86
  const body = await this.request("POST", "/rerank", { query, documents, top_k: options.topK }, options, true);
79
87
  const results = body.results.map((r) => ({ index: r.index, score: r.score, document: documents[r.index] ?? "" }));
@@ -123,15 +131,17 @@ export class Conare {
123
131
  options.signal?.addEventListener("abort", onAbort, { once: true });
124
132
  if (options.signal?.aborted)
125
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);
126
136
  try {
127
137
  const res = await this.fetchFn(this.baseURL + path, {
128
138
  method,
129
139
  headers: {
130
140
  Authorization: `Bearer ${this.apiKey}`,
131
141
  Accept: "application/json",
132
- ...(body === undefined ? {} : { "Content-Type": "application/json" }),
142
+ ...(body === undefined ? {} : { "Content-Type": raw ? "application/octet-stream" : "application/json" }),
133
143
  },
134
- body: body === undefined ? undefined : JSON.stringify(body),
144
+ body: body === undefined ? undefined : raw ? body : JSON.stringify(body),
135
145
  signal: controller.signal,
136
146
  });
137
147
  return [res, await res.text()];
@@ -201,13 +211,34 @@ export class Namespace {
201
211
  }
202
212
  return out;
203
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
+ }
204
233
  /**
205
234
  * Hybrid search, reranked. One result per document: its best passage. `retrievers` picks what
206
235
  * the search fuses (default `["vector", "keyword"]`); `"sparse"` needs a namespace created with
207
- * a sparse index.
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.
208
239
  */
209
240
  async query(query, options = {}) {
210
- const body = await this.client.request("POST", this.path("/query"), { query, top_k: options.topK, filter: options.filter, rerank: options.rerank, retrievers: options.retrievers }, options, true);
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);
211
242
  return body.results;
212
243
  }
213
244
  /** One document by id, or null if it does not exist. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conare",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "TypeScript client for Conare: add documents, query them, connect apps.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",