conare 0.11.0 → 0.13.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
@@ -48,6 +48,7 @@ await docs.delete("refunds"); // 404 document_not_found if it d
48
48
  await docs.deleteMany(["a", "b"]); // up to 1000 ids in one call; missing ids are skipped. Returns the count
49
49
  await docs.deleteWhere({ team: "support" }); // every document matching the filter, whole documents. Returns the count
50
50
  await docs.drop(); // delete the namespace and its documents (also succeeds if it is empty)
51
+ await docs.create({ sparse: true }); // create it with a sparse (SPLADE) index, before its first write
51
52
 
52
53
  await conare.namespaces(); // [{ name, documents }]
53
54
  ```
@@ -62,23 +63,33 @@ await docs.query("how do refunds work?", {
62
63
  topK: 10, // 1-100, default 10
63
64
  filter: { team: "support" }, // optional metadata filter
64
65
  rerank: true, // default true
66
+ retrievers: ["vector", "keyword"], // default; add "sparse" in a namespace created with a sparse index
65
67
  });
66
68
  ```
67
69
 
68
- Hybrid search (vector and keyword), reranked. One result per document: its best passage.
70
+ Hybrid search, reranked. One result per document: its best passage. `retrievers` picks what it
71
+ fuses: `"vector"` (the embedding model), `"keyword"` (BM25; alone, BM25 alone) and `"sparse"` (the
72
+ learned-sparse SPLADE model, in a namespace created with `create({ sparse: true })`).
69
73
  `score` is the reranker's when `reranked` is true, else the fused rank score of a result past the
70
74
  rerank window (or of a query not reranked); the two scales do not compare.
71
75
 
72
- Filters match metadata values exactly: `{ key: value }` means equals (or, for an array value,
73
- contains). Operators: `$eq` and `$in`. Combine with `$and` and `$or`:
76
+ Filters match metadata values: `{ key: value }` means equals (or, for an array value,
77
+ contains). Operators: `$eq`, `$in` and the ranges below. Combine with `$and` and `$or`:
74
78
 
75
79
  ```ts
76
80
  { $or: [{ team: "support" }, { year: { $in: [2024, 2025] } }] }
77
81
  { $and: [{ lang: { $in: ["en", "de"] } }, { draft: false }] }
78
82
  ```
79
83
 
80
- There is no `$ne`, `$nin` or range operator (`$gt $gte $lt $lte`): the API answers 400
81
- `invalid_filter`. Store a value you want to filter on as its own metadata key instead.
84
+ Ranges `$gt $gte $lt $lte` compare a number or string value (not an array item): number bounds
85
+ compare numbers, string bounds compare strings by their UTF-8 bytes, so ISO dates sort as dates.
86
+
87
+ ```ts
88
+ { year: { $gte: 2020, $lt: 2025 } }
89
+ { published_at: { $gte: "2025-06-01" } }
90
+ ```
91
+
92
+ There is no `$ne` or `$nin`: the API answers 400 `invalid_filter`.
82
93
 
83
94
  ### Embed and rerank
84
95
 
package/dist/index.d.ts CHANGED
@@ -1,26 +1,28 @@
1
- export declare const VERSION = "0.11.0";
1
+ export declare const VERSION = "0.13.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>;
5
5
  type Scalar = string | number | boolean;
6
6
  /**
7
- * Operators for one metadata key: `$eq` and `$in`. Filters match values exactly; the API
8
- * answers 400 invalid_filter for the operators typed `never` here, so they do not compile.
7
+ * Operators for one metadata key: `$eq`, `$in` and the ranges `$gt` `$gte` `$lt` `$lte`. A range
8
+ * compares a number or string value (not an array item): number bounds compare numbers, string
9
+ * bounds compare strings by their UTF-8 bytes (ISO dates sort as dates). The API answers 400
10
+ * invalid_filter for the operators typed `never` here, so they do not compile.
9
11
  */
10
12
  export interface FilterOperators {
11
13
  $eq?: Scalar;
12
14
  $in?: Scalar[];
15
+ $gt?: number | string;
16
+ $gte?: number | string;
17
+ $lt?: number | string;
18
+ $lte?: number | string;
13
19
  $ne?: never;
14
20
  $nin?: never;
15
- $gt?: never;
16
- $gte?: never;
17
- $lt?: never;
18
- $lte?: never;
19
21
  }
20
22
  /**
21
23
  * A metadata filter. `{ team: "support" }` means equals (or, for an array value, contains);
22
- * use `$eq` / `$in` per key and `$and` / `$or` to combine:
23
- * `{ $or: [{ team: "support" }, { year: { $in: [2024, 2025] } }] }`.
24
+ * use `$eq` / `$in` / ranges per key and `$and` / `$or` to combine:
25
+ * `{ $or: [{ team: "support" }, { year: { $gte: 2024 } }] }`.
24
26
  */
25
27
  export interface Filter {
26
28
  $and?: Filter[];
@@ -54,6 +56,8 @@ export interface QueryResult {
54
56
  reranked: boolean;
55
57
  metadata: Metadata;
56
58
  }
59
+ /** What a query fuses: the embedding model, BM25 keywords, or the learned-sparse (SPLADE) model. */
60
+ export type Retriever = "vector" | "keyword" | "sparse";
57
61
  export interface NamespaceInfo {
58
62
  name: string;
59
63
  documents: number;
@@ -142,16 +146,31 @@ export declare class Namespace {
142
146
  readonly name: string;
143
147
  constructor(client: Conare, name: string);
144
148
  private path;
149
+ /**
150
+ * Create the namespace before its first write. Only a namespace with a sparse (SPLADE) index
151
+ * needs this: a write creates one without. Its index never changes: creating it again with the
152
+ * other setting is a 409. Returns whether it has a sparse index.
153
+ */
154
+ create(options?: RequestOptions & {
155
+ sparse?: boolean;
156
+ }): Promise<{
157
+ sparse: boolean;
158
+ }>;
145
159
  /**
146
160
  * Add or replace documents. Accepts one or many; sends them in batches of 100. Returns the ids.
147
161
  * A document without an id gets one here, so a retried batch replaces instead of duplicating.
148
162
  */
149
163
  add(documents: DocumentInput | DocumentInput[], options?: RequestOptions): Promise<string[]>;
150
- /** Hybrid search, reranked. One result per document: its best passage. */
164
+ /**
165
+ * Hybrid search, reranked. One result per document: its best passage. `retrievers` picks what
166
+ * the search fuses (default `["vector", "keyword"]`); `"sparse"` needs a namespace created with
167
+ * a sparse index.
168
+ */
151
169
  query(query: string, options?: RequestOptions & {
152
170
  topK?: number;
153
171
  filter?: Filter;
154
172
  rerank?: boolean;
173
+ retrievers?: Retriever[];
155
174
  }): Promise<QueryResult[]>;
156
175
  /** One document by id, or null if it does not exist. */
157
176
  get(id: string, options?: RequestOptions): Promise<Document | null>;
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.11.0";
2
+ export const VERSION = "0.13.0";
3
3
  const DEFAULT_BASE_URL = "https://api.conare.ai";
4
4
  const BATCH_SIZE = 100;
5
5
  // ---- Errors ----------------------------------------------------------------
@@ -150,6 +150,15 @@ export class Namespace {
150
150
  path(suffix = "") {
151
151
  return `/namespaces/${encodeURIComponent(this.name)}${suffix}`;
152
152
  }
153
+ /**
154
+ * Create the namespace before its first write. Only a namespace with a sparse (SPLADE) index
155
+ * needs this: a write creates one without. Its index never changes: creating it again with the
156
+ * other setting is a 409. Returns whether it has a sparse index.
157
+ */
158
+ async create(options = {}) {
159
+ const body = await this.client.request("POST", "/namespaces", { name: this.name, sparse: options.sparse ?? false }, options, true);
160
+ return { sparse: body.sparse };
161
+ }
153
162
  /**
154
163
  * Add or replace documents. Accepts one or many; sends them in batches of 100. Returns the ids.
155
164
  * A document without an id gets one here, so a retried batch replaces instead of duplicating.
@@ -164,9 +173,13 @@ export class Namespace {
164
173
  }
165
174
  return ids;
166
175
  }
167
- /** Hybrid search, reranked. One result per document: its best passage. */
176
+ /**
177
+ * Hybrid search, reranked. One result per document: its best passage. `retrievers` picks what
178
+ * the search fuses (default `["vector", "keyword"]`); `"sparse"` needs a namespace created with
179
+ * a sparse index.
180
+ */
168
181
  async query(query, options = {}) {
169
- const body = await this.client.request("POST", this.path("/query"), { query, top_k: options.topK, filter: options.filter, rerank: options.rerank }, options, true);
182
+ 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);
170
183
  return body.results;
171
184
  }
172
185
  /** 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.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "TypeScript client for Conare: add documents, query them, connect apps.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",