conare 0.12.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,10 +63,13 @@ 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
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "0.12.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>;
@@ -56,6 +56,8 @@ export interface QueryResult {
56
56
  reranked: boolean;
57
57
  metadata: Metadata;
58
58
  }
59
+ /** What a query fuses: the embedding model, BM25 keywords, or the learned-sparse (SPLADE) model. */
60
+ export type Retriever = "vector" | "keyword" | "sparse";
59
61
  export interface NamespaceInfo {
60
62
  name: string;
61
63
  documents: number;
@@ -144,16 +146,31 @@ export declare class Namespace {
144
146
  readonly name: string;
145
147
  constructor(client: Conare, name: string);
146
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
+ }>;
147
159
  /**
148
160
  * Add or replace documents. Accepts one or many; sends them in batches of 100. Returns the ids.
149
161
  * A document without an id gets one here, so a retried batch replaces instead of duplicating.
150
162
  */
151
163
  add(documents: DocumentInput | DocumentInput[], options?: RequestOptions): Promise<string[]>;
152
- /** 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
+ */
153
169
  query(query: string, options?: RequestOptions & {
154
170
  topK?: number;
155
171
  filter?: Filter;
156
172
  rerank?: boolean;
173
+ retrievers?: Retriever[];
157
174
  }): Promise<QueryResult[]>;
158
175
  /** One document by id, or null if it does not exist. */
159
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.12.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.12.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",