conare 0.20.0 → 0.21.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 +61 -36
- package/dist/index.d.ts +453 -45
- package/dist/index.js +565 -52
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# conare
|
|
2
2
|
|
|
3
|
-
TypeScript client for [Conare](https://conare.ai): add documents, query them, connect apps.
|
|
3
|
+
TypeScript client for [Conare](https://conare.ai): add documents, query them, connect apps, sync your own.
|
|
4
4
|
No dependencies. Works on Node 18+, Bun, Deno and edge runtimes.
|
|
5
5
|
|
|
6
6
|
## Quickstart
|
|
@@ -31,10 +31,16 @@ A namespace is created by its first write. Writing the same id again replaces th
|
|
|
31
31
|
```ts
|
|
32
32
|
new Conare() // CONARE_API_KEY from the environment
|
|
33
33
|
new Conare({ apiKey, baseURL, timeout: 60_000, maxRetries: 2 })
|
|
34
|
+
await conare.organizations() // [{ id, name, role }]: the organizations the key acts for
|
|
35
|
+
new Conare({ organization: "org_…" }) // acts for that one (X-Conare-Org)
|
|
34
36
|
```
|
|
35
37
|
|
|
36
38
|
Every method also takes `{ signal, timeout }` as its last option.
|
|
37
39
|
|
|
40
|
+
A key acts for its own organization. A multi-organization key (made in the console by an admin of
|
|
41
|
+
each organization it names) acts for any of them: make one client per organization with
|
|
42
|
+
`organization`. Without it, such a key answers 400 on every call but `organizations()`.
|
|
43
|
+
|
|
38
44
|
### Namespaces and documents
|
|
39
45
|
|
|
40
46
|
```ts
|
|
@@ -58,8 +64,8 @@ await docs.uploadFile(bytes, "report.pdf"); // a PDF (one document per page)
|
|
|
58
64
|
// up to 20 MiB. The same name (or { id }) again replaces it.
|
|
59
65
|
// Returns { fileId, type, ids, pages, sheets, pagesOcr, pagesWithoutText, ocrPending }:
|
|
60
66
|
// scanned pages are OCR'd after the answer (ocrPending; { wait: true } reads them first)
|
|
67
|
+
await docs.getFile("report.pdf"); // that upload's outcome, OCR after the answer included (kept 7 days)
|
|
61
68
|
await docs.drop(); // delete the namespace and its documents (succeeds if already emptied; 404 namespace_not_found if never written)
|
|
62
|
-
await docs.create({ sparse: true }); // create it with a sparse (SPLADE) index, before its first write
|
|
63
69
|
|
|
64
70
|
await conare.namespaces(); // [{ name, documents }]
|
|
65
71
|
await conare.namespaces({ prefix: "u7f3a9c-" }); // one user's namespaces
|
|
@@ -75,13 +81,12 @@ await docs.query("how do refunds work?", {
|
|
|
75
81
|
topK: 10, // 1-100, default 10
|
|
76
82
|
filter: { team: "support" }, // optional metadata filter
|
|
77
83
|
rerank: true, // default true
|
|
78
|
-
retrievers: ["vector", "keyword"], // default;
|
|
84
|
+
retrievers: ["vector", "keyword"], // default; one of them alone searches with it alone
|
|
79
85
|
});
|
|
80
86
|
```
|
|
81
87
|
|
|
82
88
|
Hybrid search, reranked. One result per document: its best passage. `retrievers` picks what it
|
|
83
|
-
fuses: `"vector"` (the embedding model)
|
|
84
|
-
learned-sparse SPLADE model, in a namespace created with `create({ sparse: true })`).
|
|
89
|
+
fuses: `"vector"` (the embedding model) and `"keyword"` (BM25; alone, BM25 alone).
|
|
85
90
|
`score` is the reranker's when `reranked` is true, else the fused rank score of a result past the
|
|
86
91
|
rerank window (or of a query not reranked); the two scales do not compare.
|
|
87
92
|
|
|
@@ -107,14 +112,19 @@ There is no `$ne` or `$nin`: the API answers 400 `invalid_filter`.
|
|
|
107
112
|
|
|
108
113
|
```ts
|
|
109
114
|
await conare.embed(["some text"], { type: "query" }); // number[][]; type defaults to "document"
|
|
115
|
+
await conare.embed(["some text"], { outputDtype: "int8" }); // { values: Int8Array[], scales }; dequantize() gives floats
|
|
110
116
|
await conare.rerank("refund window", ["a", "b"], { topK: 1 }); // [{ index, score, document }], plus .unscored
|
|
111
117
|
```
|
|
112
118
|
|
|
119
|
+
`outputDtype: "int8"` returns each vector as int8 values plus one scale (vector ≈ values × scale, scale = max|x| / 127):
|
|
120
|
+
a quarter of the bytes. Cosine on the values alone equals cosine on the floats, so they can be stored and searched as
|
|
121
|
+
they are. On our embedder's real vectors this cost no measurable retrieval quality (nDCG@10 -0.00 [-0.10, +0.10] on 1M
|
|
122
|
+
chunks). There is no binary output: 1-bit vectors lost 4 to 7.5 nDCG@10 points there.
|
|
123
|
+
|
|
113
124
|
`rerank` takes 1-100 documents of 1-24,000 characters each (the query at most 8,192 characters, all
|
|
114
|
-
together at most 256,000); more than 100 is a 400 `invalid_request`.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
index in `.unscored` and is not in the results; its score from another call would not compare.
|
|
125
|
+
together at most 256,000); more than 100 is a 400 `invalid_request`. A document not read before the
|
|
126
|
+
one-second budget ended, or whose read failed, is listed by index in `.unscored` and is not in the
|
|
127
|
+
results; its score from another call would not compare.
|
|
118
128
|
|
|
119
129
|
### Sources
|
|
120
130
|
|
|
@@ -133,10 +143,51 @@ await conare.sources.types(); // [{ type, name, logoUrl }]
|
|
|
133
143
|
await conare.sources.list(); // [Source]
|
|
134
144
|
await conare.sources.get(source.id); // { id, type, name, namespace, status, error, documents, lastSyncedAt, createdAt }
|
|
135
145
|
await conare.sources.sync(source.id); // sync now
|
|
146
|
+
await conare.sources.sync(source.id, { full: true }); // re-read everything (Gmail and apps Conare reads itself); Gmail's rows are billed again
|
|
147
|
+
await conare.sources.update(source.id, { syncIntervalSeconds: 3600 }); // every hour; null is automatic
|
|
136
148
|
await conare.sources.delete(source.id, { deleteDocuments: true });
|
|
137
149
|
```
|
|
138
150
|
|
|
139
|
-
`status` is `connecting`, `syncing`, `ready` or `error`.
|
|
151
|
+
`status` is `connecting`, `syncing`, `ready` or `error`. A source syncs on an automatic interval
|
|
152
|
+
picked from what each sync reads, or on one you set from 5 minutes to 30 days. `source.cost` holds
|
|
153
|
+
what an estimate of a month at any interval needs: the rows the last sync read, whether syncs read
|
|
154
|
+
only changes, and the prices.
|
|
155
|
+
|
|
156
|
+
### Custom sources
|
|
157
|
+
|
|
158
|
+
A custom source is a set of documents you push from your own system, keyed by your own ids.
|
|
159
|
+
Conare answers per document what each write did, keeps a deleted one out, and can mirror a whole
|
|
160
|
+
set: what a snapshot run never saw is deleted.
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
const src = await conare.sources.create({ type: "custom", namespace: "kb", name: "Help center" });
|
|
164
|
+
|
|
165
|
+
await conare.sources.documents.put(src.id, [
|
|
166
|
+
{ externalId: "article-12", text: "Refunds take 5 days.", seq: 1759698843000, tag: "etag-9" },
|
|
167
|
+
]); // [{ externalId, key, result, storedSeq?, code? }], 100 a call:
|
|
168
|
+
// created, updated, unchanged, stale (a lower seq), deleted, rejected
|
|
169
|
+
await conare.sources.documents.check(src.id, [{ externalId: "article-12", tag: "etag-9" }]); // { need, excluded }
|
|
170
|
+
for await (const d of conare.sources.documents.list(src.id)) {} // { externalId, key, tag, seq, user, version }
|
|
171
|
+
await conare.sources.documents.get(src.id, "article-12"); // with text and metadata, or null
|
|
172
|
+
await conare.sources.documents.delete(src.id, ["article-12"], { exclude: true }); // kept out until restored
|
|
173
|
+
await conare.sources.documents.restore(src.id, ["article-12"]);
|
|
174
|
+
|
|
175
|
+
// Mirror the whole set: push (or check, when unchanged) every document through a run, then complete it.
|
|
176
|
+
const run = await conare.runs.open(src.id, { expected: 2 });
|
|
177
|
+
await run.put([{ externalId: "a", text: "..." }]);
|
|
178
|
+
await run.check([{ externalId: "b", tag: "etag-1" }]);
|
|
179
|
+
const done = await run.complete(); // { state, sweep, counts: { seen, live, planned, deleted } }
|
|
180
|
+
// sweep "held": over 10% (and over 1,000) would go at once; a run 24 h later that agrees applies it.
|
|
181
|
+
|
|
182
|
+
await conare.imports.create(src.id, jsonl, { mode: "snapshot" }); // a JSON-lines file, up to 1 GiB: a Run
|
|
183
|
+
await conare.runs.get(runId); // follow any run
|
|
184
|
+
await conare.users.delete("tenant-7:u_42"); // everything of a user, in every namespace: a purge Run
|
|
185
|
+
await conare.users.deletePrefix("tenant-7:");
|
|
186
|
+
await conare.events.list({ cursor: "0", types: ["run.*"] }); // { data: [{ seq, type, runId, data }], nextCursor }
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`sources.list()` and `sources.get()` answer custom sources too, with `kind: "custom"`. These
|
|
190
|
+
calls send an `Idempotency-Key` when they create or delete something, so their retries are safe.
|
|
140
191
|
|
|
141
192
|
### Errors
|
|
142
193
|
|
|
@@ -179,32 +230,6 @@ const context = await user.query("how should we contact them?");
|
|
|
179
230
|
|
|
180
231
|
Keep the API key on your server. It can read and write every namespace in your organization.
|
|
181
232
|
|
|
182
|
-
## MCP
|
|
183
|
-
|
|
184
|
-
Conare is also an MCP server at `https://api.conare.ai/mcp`, with tools to search, fetch, save
|
|
185
|
-
and delete documents and list namespaces. Clients that sign in over OAuth (claude.ai connectors,
|
|
186
|
-
ChatGPT) need only the URL; the rest take a key:
|
|
187
|
-
|
|
188
|
-
Claude Code:
|
|
189
|
-
|
|
190
|
-
```bash
|
|
191
|
-
claude mcp add --transport http conare https://api.conare.ai/mcp \
|
|
192
|
-
--header "Authorization: Bearer $CONARE_API_KEY"
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
Cursor (`~/.cursor/mcp.json`):
|
|
196
|
-
|
|
197
|
-
```json
|
|
198
|
-
{
|
|
199
|
-
"mcpServers": {
|
|
200
|
-
"conare": {
|
|
201
|
-
"url": "https://api.conare.ai/mcp",
|
|
202
|
-
"headers": { "Authorization": "Bearer sk-conare-..." }
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
```
|
|
207
|
-
|
|
208
233
|
## The `conare` command: sync sessions and GitHub
|
|
209
234
|
|
|
210
235
|
The package also ships a command (the library never loads it). It runs under Node and Bun:
|