@rushdb/javascript-sdk 2.11.0 → 3.0.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
@@ -172,14 +172,67 @@ const relationships = await db.relationships.find({
172
172
 
173
173
  ---
174
174
 
175
+ ## RushDB Cloud or a self-hosted engine
176
+
177
+ The SDK works with RushDB in one of two ways:
178
+
179
+ | | RushDB Cloud | Self-hosted RushDB engine (direct mode) |
180
+ | --- | --- | --- |
181
+ | What you run | nothing: the managed service at [app.rushdb.com](https://app.rushdb.com) | one `rushdbd` binary, on your own infrastructure |
182
+ | Connect with | an API key | the engine URL and the engine token |
183
+
184
+ The engine is what you can self-host. RushDB Cloud runs that engine for you and adds the dashboard,
185
+ managed embeddings and the AI features (natural-language search, relationship-pattern suggestions),
186
+ which exist only in RushDB Cloud.
187
+
188
+ ```typescript
189
+ // RushDB Cloud
190
+ const db = new RushDB('RUSHDB_API_KEY')
191
+
192
+ // A self-hosted engine
193
+ const db = new RushDB('ENGINE_TOKEN', {
194
+ direct: true,
195
+ engineUrl: 'http://127.0.0.1:3000',
196
+ scope: 'tenant-1' // only for an engine started with --multitenant
197
+ })
198
+ ```
199
+
200
+ What each offers:
201
+
202
+ | Feature | Cloud | Self-hosted engine |
203
+ | --- | :---: | :---: |
204
+ | Records: create, read, update, set, upsert, delete, `find` with `where`, `orderBy`, `select`, `groupBy` | ✓ | ✓ |
205
+ | Relationships: `attach`/`detach`, `relationships.createMany`/`deleteMany`/`find` | ✓ | ✓ |
206
+ | Labels, properties, property values | ✓ | ✓ |
207
+ | Import JSON and CSV, export CSV | ✓ | ✓ |
208
+ | Text indexes and keyword search (`records.textSearch`) | ✓ | ✓ |
209
+ | External vector indexes; vector and hybrid search with a `queryVector` you supply | ✓ | ✓ |
210
+ | Raw openCypher (`query.raw`; the engine needs `--languages cypher`) | ✓ | ✓ |
211
+ | Schema (`ai.getSchema`, `ai.getSchemaMarkdown`) | ✓ | ✓ |
212
+ | Transactions | ✓ | record creates, updates, sets, deletes by id, attaches and imports are staged; other writes refuse a transaction |
213
+ | Managed embeddings: managed indexes, `records.vectorSearch` by text `query` | ✓ | — |
214
+ | Natural-language search (`ai.search`) | ✓ | — |
215
+ | Relationship-pattern suggestions (`relationships.patterns.*`) | ✓ | — |
216
+ | Project settings (`settings.get`), dashboard, projects, team access, MCP over HTTP with OAuth | ✓ | — |
217
+
218
+ In direct mode a Cloud-only method throws `CloudOnlyError` (with `method` and `reason`) before
219
+ sending anything, and no request ever goes to RushDB Cloud. A write the engine cannot stage into a
220
+ transaction throws `DirectModeError`, also before sending anything. The list is available in code:
221
+
222
+ ```typescript
223
+ import { CLOUD_ONLY_METHODS, CloudOnlyError, isCloudOnlyMethod } from '@rushdb/javascript-sdk'
224
+ ```
225
+
226
+ ---
227
+
175
228
  ## SDK configuration
176
229
 
177
230
  ```typescript
178
231
  import RushDB from '@rushdb/javascript-sdk'
179
232
 
180
233
  const db = new RushDB('RUSHDB_API_KEY', {
181
- // Override for self-hosted or staging
182
- url: 'http://your-rushdb-server.com/api/v1',
234
+ // A different RushDB Cloud API endpoint (default: https://api.rushdb.com/api/v1)
235
+ url: 'https://api.rushdb.com/api/v1',
183
236
  timeout: 30000
184
237
  })
185
238
  ```
@@ -191,6 +244,7 @@ Key options:
191
244
  - `timeout` — request timeout in ms (default: 10000)
192
245
  - `httpClient` — custom HTTP client for advanced use
193
246
  - `options.allowForceDelete` — allow deleting all records without criteria (default: false)
247
+ - `direct`, `engineUrl`, `scope` — direct mode against a standalone engine (see above)
194
248
 
195
249
  Full config reference: [docs.rushdb.com/typescript-sdk/introduction#sdk-configuration-options](https://docs.rushdb.com/typescript-sdk/introduction#sdk-configuration-options)
196
250
 
package/dist/api/api.d.ts CHANGED
@@ -1,16 +1,23 @@
1
1
  import type { HttpClient } from '../network/HttpClient.js';
2
+ import { DirectEngine } from '../direct/engine.js';
2
3
  import type { DBRecordCreationOptions, DBRecordTarget, Relation, RelationDetachOptions, RelationDirection, RelationOptions, RelationTarget } from '../sdk/record.js';
3
4
  import { DBRecordInstance, DBRecordsArrayInstance } from '../sdk/record.js';
4
5
  import type { SDKConfig } from '../sdk/types.js';
5
6
  import type { FlatObject, InferSchemaTypesWrite, MaybeArray, OrderDirection, Property, PropertyDraft, PropertyValuesData, Schema, RelationshipSearchQuery, SearchQuery, Where } from '../types/index.js';
6
7
  import type { ApiResponse } from './types.js';
7
- import type { CreateEmbeddingIndexParams, DeleteRelationshipPatternOptions, EmbeddingIndex, EmbeddingIndexStats, RelationshipPatternListResponse, SmartSearchOptions, UpsertEmbeddingVectorsParams, UpsertEmbeddingVectorsResult, VectorEntry, VectorSearchParams } from './types.js';
8
+ import type { CreateEmbeddingIndexParams, DeleteRelationshipPatternOptions, EmbeddingIndex, EmbeddingIndexStats, RelationshipPatternListResponse, SmartSearchOptions, UpsertEmbeddingVectorsParams, UpsertEmbeddingVectorsResult, CreateTextIndexParams, TextIndex, TextSearchParams, VectorEntry, VectorSearchParams } from './types.js';
8
9
  import { createFetcher } from '../network/index.js';
9
10
  import { Transaction } from '../sdk/transaction.js';
10
11
  export declare class RestAPI {
11
12
  fetcher: ReturnType<typeof createFetcher>;
12
13
  options: SDKConfig['options'];
13
14
  logger: SDKConfig['logger'];
15
+ /**
16
+ * Direct engine transport (standalone `rushdbd`) when `direct` mode is set.
17
+ * In direct mode every request is answered from the engine; nothing is sent
18
+ * to RushDB Cloud.
19
+ */
20
+ direct: DirectEngine | undefined;
14
21
  constructor(token?: string, config?: SDKConfig & {
15
22
  httpClient: HttpClient;
16
23
  });
@@ -61,6 +68,8 @@ export declare class RestAPI {
61
68
  * @param transaction - Optional transaction for atomic operations
62
69
  * @returns Promise resolving to the created DBRecordInstance
63
70
  * @throws Error if data is not a flat object and createMany should be used instead
71
+ * @remarks In direct mode a record created inside a transaction is staged into it, with an id
72
+ * generated by the SDK. An upsert or inline vectors inside a transaction throw `DirectModeError`.
64
73
  */
65
74
  create: <S extends Schema = any>({ label, data: rawData, options, vectors }: {
66
75
  label: string;
@@ -188,9 +197,20 @@ export declare class RestAPI {
188
197
  * RushDB narrows candidates by `labels` and optional `where` filters first, then ranks them by
189
198
  * similarity. Pass either `query` for managed indexes or `queryVector` for external/custom vectors.
190
199
  *
200
+ * @remarks In direct mode (a standalone engine) only `queryVector` works: a text `query` is embedded
201
+ * with RushDB Cloud's managed model, so it throws `CloudOnlyError` without sending a request.
202
+ *
191
203
  * @param params - Vector search parameters including the indexed property, labels, and query input
192
204
  */
193
205
  vectorSearch: <S extends Schema = any>(params: VectorSearchParams, transaction?: Transaction | string) => Promise<DBRecordsArrayInstance<S>>;
206
+ /**
207
+ * Keyword (BM25) search over a text index: the records matching `query`,
208
+ * best first (`__score`), among those `labels` and `where` select.
209
+ * `total` counts every match, not just the page.
210
+ *
211
+ * @param params - Keywords, the index (or the label whose one text index to use) and filters
212
+ */
213
+ textSearch: <S extends Schema = any>(params: TextSearchParams, transaction?: Transaction | string) => Promise<DBRecordsArrayInstance<S>>;
194
214
  /**
195
215
  * Retrieves record(s) by ID
196
216
  * @param idOrIds - Single ID or array of IDs to retrieve
@@ -278,25 +298,30 @@ export declare class RestAPI {
278
298
  patterns: {
279
299
  /**
280
300
  * Lists inferred relationship patterns, schema relationships, and analysis status.
301
+ * @remarks **RushDB Cloud only.** In direct mode this throws `CloudOnlyError` without sending a request.
281
302
  */
282
303
  list: () => Promise<ApiResponse<RelationshipPatternListResponse>>;
283
304
  /**
284
305
  * Queues schema analysis to generate relationship pattern suggestions.
306
+ * @remarks **RushDB Cloud only.** In direct mode this throws `CloudOnlyError` without sending a request.
285
307
  */
286
308
  analyze: () => Promise<ApiResponse<{
287
309
  queued: true;
288
310
  }>>;
289
311
  /**
290
312
  * Approves and applies a suggested relationship pattern.
313
+ * @remarks **RushDB Cloud only.** In direct mode this throws `CloudOnlyError` without sending a request.
291
314
  */
292
315
  approve: (id: string) => Promise<ApiResponse<import("./types.js").RelationshipPatternDto | undefined>>;
293
316
  /**
294
317
  * Ignores a suggested relationship pattern without applying it.
318
+ * @remarks **RushDB Cloud only.** In direct mode this throws `CloudOnlyError` without sending a request.
295
319
  */
296
320
  ignore: (id: string) => Promise<ApiResponse<import("./types.js").RelationshipPatternDto | undefined>>;
297
321
  /**
298
322
  * Deletes a saved relationship pattern.
299
323
  * Pass deleteExisting to also remove relationships materialized by the pattern.
324
+ * @remarks **RushDB Cloud only.** In direct mode this throws `CloudOnlyError` without sending a request.
300
325
  */
301
326
  delete: (id: string, options?: DeleteRelationshipPatternOptions) => Promise<ApiResponse<{
302
327
  deleted: true;
@@ -425,6 +450,7 @@ export declare class RestAPI {
425
450
  */
426
451
  begin: (config?: Partial<{
427
452
  ttl: number;
453
+ autocommit: boolean;
428
454
  }>) => Promise<Transaction>;
429
455
  /**
430
456
  * Commits a transaction, making its changes permanent
@@ -453,19 +479,19 @@ export declare class RestAPI {
453
479
  }>>;
454
480
  };
455
481
  settings: {
482
+ /**
483
+ * The project's settings.
484
+ * @remarks **RushDB Cloud only.** In direct mode this throws `CloudOnlyError` without sending a request.
485
+ */
456
486
  get: () => Promise<ApiResponse<{
457
487
  selfHosted: boolean;
458
- customDB?: boolean;
459
- managedDB?: boolean;
460
488
  } | undefined>>;
461
489
  };
462
490
  query: {
463
491
  /**
464
- * Executes a raw query against the underlying database engine.
465
- *
466
- * NOTE: This endpoint is cloud-only — available only on the RushDB managed
467
- * service or when your project is connected to a custom database through
468
- * RushDB Cloud. It will not work for self-hosted or local-only deployments.
492
+ * Executes an openCypher statement against the project's data and
493
+ * returns `{ records }`, one object per row. The engine must run with the
494
+ * `cypher` language enabled (the bundled deploy templates enable it).
469
495
  *
470
496
  * @param param0 - Object containing the query and optional params
471
497
  * @param param0.query - Query string to execute
@@ -481,6 +507,28 @@ export declare class RestAPI {
481
507
  /**
482
508
  * API methods for AI-assisted graph exploration.
483
509
  */
510
+ /**
511
+ * BM25 text indexes, searched with `db.records.textSearch()` or as the
512
+ * keyword leg of a hybrid `db.records.vectorSearch({ text })`.
513
+ */
514
+ textIndexes: {
515
+ /** Lists the project's text indexes. */
516
+ find: () => Promise<ApiResponse<TextIndex[]>>;
517
+ /**
518
+ * Declares a text index over one property of a label, or every string of
519
+ * it (`property: '*'`). It is built online; its `status` turns `ready`.
520
+ */
521
+ create: (params: CreateTextIndexParams) => Promise<ApiResponse<TextIndex>>;
522
+ /** The name a new text index would get by default, unique in the project. */
523
+ suggestName: (params: Pick<CreateTextIndexParams, "label" | "property">) => Promise<ApiResponse<{
524
+ name: string;
525
+ }>>;
526
+ /** Drops a text index by name. */
527
+ delete: (name: string) => Promise<ApiResponse<{
528
+ deleted: boolean;
529
+ }>>;
530
+ };
531
+ private textIndexRequest;
484
532
  ai: {
485
533
  /**
486
534
  * Returns the full graph schema as structured JSON.
@@ -488,8 +536,8 @@ export declare class RestAPI {
488
536
  * and cross-label relationships with direction.
489
537
  * Properties may include a `vectorIndexes` array when one or more embedding indexes
490
538
  * exist for that property — a non-empty array means the property is queryable with
491
- * `db.records.vectorSearch()`. Each entry exposes: id, sourceType, similarityFunction, dimensions,
492
- * status, and modelKey.
539
+ * `db.records.vectorSearch()`. Each entry exposes: id, name, sourceType, similarityFunction,
540
+ * dimensions, status, and modelKey.
493
541
  * Use property `id` fields to pass to db.properties.values() for deeper drill-down.
494
542
  * @param params - Optional filter. `labels` scopes to specific labels only.
495
543
  * `force: true` bypasses the 1-hour schema cache and triggers a full recalculation.
@@ -524,9 +572,12 @@ export declare class RestAPI {
524
572
  find: () => Promise<ApiResponse<EmbeddingIndex[]>>;
525
573
  /**
526
574
  * Creates a new embedding index policy for a string property.
575
+ * @param params.name - Index name, unique within the project (defaults to
576
+ * `<label>.<property>.<model>.<dimensions>.<similarity>`)
527
577
  * @param params.propertyName - Name of the property to index
528
- * @param params.modelKey - Embedding model identifier (e.g. 'text-embedding-3-small')
529
578
  * @param params.dimensions - Vector dimensionality produced by the model
579
+ * @remarks In direct mode (a standalone engine) only external indexes (`external: true`) can be
580
+ * created; a managed index is filled by RushDB Cloud's embedding model, so it throws `CloudOnlyError`.
530
581
  */
531
582
  create: (params: CreateEmbeddingIndexParams) => Promise<ApiResponse<EmbeddingIndex>>;
532
583
  /**
@@ -543,7 +594,7 @@ export declare class RestAPI {
543
594
  deleted: boolean;
544
595
  }>>;
545
596
  /**
546
- * Returns Neo4j-level statistics for an embedding index.
597
+ * Returns indexing statistics for an embedding index.
547
598
  * @param id - The ID of the embedding index
548
599
  */
549
600
  stats: (id: string) => Promise<ApiResponse<EmbeddingIndexStats>>;
@@ -556,6 +607,8 @@ export declare class RestAPI {
556
607
  *
557
608
  * Use `db.records.vectorSearch({ ... })` for direct vector similarity over embedding indexes.
558
609
  *
610
+ * @remarks **RushDB Cloud only.** In direct mode this throws `CloudOnlyError` without sending a request.
611
+ *
559
612
  * @param prompt - Natural-language search request to convert into a SearchQuery and execute
560
613
  * @param options - Optional smart-search context and transaction
561
614
  */
@@ -1,2 +1,2 @@
1
1
  export { RestAPI } from './api.js';
2
- export { ApiResponse, CreateEmbeddingIndexParams, DeleteRelationshipPatternOptions, EmbeddingIndex, EmbeddingIndexStats, RelationshipPattern, RelationshipPatternDirection, RelationshipPatternDto, RelationshipPatternEndpoint, RelationshipPatternListResponse, RelationshipPatternMode, RelationshipPatternOrigin, RelationshipPatternStatus, SemanticSearchParams, SemanticSearchResult, SmartSearchOptions, SmartSearchQueryResponse, UpsertEmbeddingVectorItem, UpsertEmbeddingVectorsParams, UpsertEmbeddingVectorsResult, VectorSearchParams, VectorSearchResult } from './types.js';
2
+ export { ApiResponse, CreateEmbeddingIndexParams, CreateTextIndexParams, DeleteRelationshipPatternOptions, EmbeddingIndex, EmbeddingIndexStats, RelationshipPattern, RelationshipPatternDirection, RelationshipPatternDto, RelationshipPatternEndpoint, RelationshipPatternListResponse, RelationshipPatternMode, RelationshipPatternOrigin, RelationshipPatternStatus, SemanticSearchParams, SemanticSearchResult, SmartSearchOptions, SmartSearchQueryResponse, TextIndex, TextSearchParams, TextSearchReport, UpsertEmbeddingVectorItem, UpsertEmbeddingVectorsParams, UpsertEmbeddingVectorsResult, VectorSearchParams, VectorSearchReport, VectorSearchResult } from './types.js';
@@ -8,8 +8,14 @@ export type ApiResponse<T, E = Record<string, any>> = {
8
8
  /** An embedding index policy stored in RushDB. */
9
9
  export type EmbeddingIndex = {
10
10
  id: string;
11
+ /**
12
+ * Public index name, unique within the project, e.g.
13
+ * `Book.description.text-embedding-3-small.1536.cosine`. Search and inline
14
+ * vectors may address the index by it.
15
+ */
16
+ name: string;
11
17
  projectId: string;
12
- /** Neo4j label this index is scoped to (e.g. "Book"). */
18
+ /** Record label this index is scoped to (e.g. "Book"). */
13
19
  label: string;
14
20
  propertyName: string;
15
21
  modelKey: string;
@@ -25,7 +31,13 @@ export type EmbeddingIndex = {
25
31
  };
26
32
  /** Parameters for creating a new embedding index. */
27
33
  export type CreateEmbeddingIndexParams = {
28
- /** Neo4j label to scope this index to (e.g. "Book", "Task"). */
34
+ /**
35
+ * Index name, unique within the project: 1–64 characters of letters,
36
+ * digits, `.`, `_`, `:` or `-`. Defaults to
37
+ * `<label>.<property>.<model>.<dimensions>.<similarity>`.
38
+ */
39
+ name?: string;
40
+ /** Record label to scope this index to (e.g. "Book", "Task"). */
29
41
  label: string;
30
42
  propertyName: string;
31
43
  sourceType?: 'managed' | 'external';
@@ -51,6 +63,8 @@ export type VectorEntry = {
51
63
  * `similarityFunction`. Omit when there is only one matching index.
52
64
  */
53
65
  similarityFunction?: 'cosine' | 'euclidean';
66
+ /** The index to write to, by name (or id). Overrides selection by shape. */
67
+ index?: string;
54
68
  };
55
69
  export type UpsertEmbeddingVectorItem = {
56
70
  recordId: string;
@@ -63,25 +77,30 @@ export type UpsertEmbeddingVectorsResult = {
63
77
  updated: number;
64
78
  requested: number;
65
79
  };
66
- /** Neo4j-level stats for an embedding index. */
80
+ /** Indexing statistics for an embedding index. */
67
81
  export type EmbeddingIndexStats = {
68
82
  totalRecords: number;
69
83
  indexedRecords: number;
70
84
  };
71
85
  /** Parameters for vector search over an embedding index. */
72
86
  export type VectorSearchParams = {
73
- /** Name of the indexed property to search against. */
74
- propertyName: string;
87
+ /**
88
+ * The index to search, by name (or id). When given, `propertyName` and
89
+ * `labels` default to the index's own.
90
+ */
91
+ index?: string;
92
+ /** Name of the indexed property to search against. Required unless `index` is given. */
93
+ propertyName?: string;
75
94
  /** Free-text query that will be embedded and compared against indexed vectors. */
76
95
  query?: string;
77
96
  /** External vector query. Use instead of query text for external indexes. */
78
97
  queryVector?: number[];
79
98
  /**
80
- * One or more Neo4j labels to scope the search.
99
+ * One or more record labels to scope the search.
81
100
  * The first label is used to resolve which embedding index to use.
82
- * Required — always provide at least one label.
101
+ * Required unless `index` is given.
83
102
  */
84
- labels: string[];
103
+ labels?: string[];
85
104
  sourceType?: 'managed' | 'external';
86
105
  similarityFunction?: 'cosine' | 'euclidean';
87
106
  dimensions?: number;
@@ -92,10 +111,92 @@ export type VectorSearchParams = {
92
111
  where?: Record<string, unknown>;
93
112
  /** Number of results to skip for pagination (default 0). */
94
113
  skip?: number;
95
- /** Max candidates to fetch from the vector index in direct vector-index mode. */
96
- topK?: number;
114
+ /**
115
+ * How the search ranks candidates. `auto` (default): the engine scores every
116
+ * vector of a small index exactly and uses its ANN graph on a large one.
117
+ * `exact` / `ann` force a path (`ann` needs a cosine index).
118
+ */
119
+ mode?: 'auto' | 'exact' | 'ann';
120
+ /** ANN gather breadth when the search runs on the ANN graph. */
121
+ ef?: number;
122
+ /**
123
+ * Keep only results scoring at least this much. Scores depend on the
124
+ * embedding model, so pick the threshold per model; a page may then hold
125
+ * fewer than `limit` results.
126
+ */
127
+ scoreThreshold?: number;
97
128
  /** Maximum number of results to return (default 20). */
98
129
  limit?: number;
130
+ /**
131
+ * Adds a BM25 keyword leg, making it a hybrid search: the engine ranks both
132
+ * legs among the same filtered records and fuses the two rankings. `query`
133
+ * defaults to the semantic `query`; the text index defaults to the one ready
134
+ * text index of the first label.
135
+ */
136
+ text?: Partial<Pick<TextSearchParams, 'query' | 'index' | 'property' | 'allTerms' | 'phrase'>> & {
137
+ /** This leg's share of the fused score (≥ 0, default 1). */
138
+ weight?: number;
139
+ /** Hits this leg ranks before fusion (1–10,000; default 4 × (skip + limit)). */
140
+ prefetchLimit?: number;
141
+ };
142
+ /** Hybrid only: the vector leg's share of the fused score (≥ 0, default 1). */
143
+ weight?: number;
144
+ /** Hybrid only: hits the vector leg ranks before fusion (1–10,000). */
145
+ prefetchLimit?: number;
146
+ /**
147
+ * Hybrid only: how the legs combine. `rrf` (default) fuses ranks; `dbsf`
148
+ * fuses each leg's scores normalized by its own distribution (mean ± 3σ).
149
+ */
150
+ fusion?: 'rrf' | 'dbsf';
151
+ /** Hybrid only: the RRF smoothing constant (default 60). */
152
+ rrfK?: number;
153
+ };
154
+ /** A BM25 text index. */
155
+ export type TextIndex = {
156
+ /** Index name, unique within the project. */
157
+ name: string;
158
+ label: string;
159
+ /** The indexed property, or `*` for every string of the record. */
160
+ property: string;
161
+ /** `eventual` (searches see changes shortly after they commit) or `immediate`. */
162
+ consistency: 'eventual' | 'immediate';
163
+ status: 'building' | 'ready' | 'dropping';
164
+ /** Changes the index has not applied yet. */
165
+ pending: number;
166
+ };
167
+ export type CreateTextIndexParams = {
168
+ label: string;
169
+ /** A property name, or `*` for every string of the record. */
170
+ property: string;
171
+ /** Defaults to `<label>.<property>.text` (`all` for `*`), unique within the project. */
172
+ name?: string;
173
+ consistency?: 'eventual' | 'immediate';
174
+ };
175
+ /** Parameters for keyword (BM25) search. */
176
+ export type TextSearchParams = {
177
+ /** Keywords; `"a phrase"`, `-excluded` and `+required` follow the query syntax. */
178
+ query: string;
179
+ /** The text index, by name; otherwise the one ready text index of the first label. */
180
+ index?: string;
181
+ /** Narrows the choice of text index to one over this property. */
182
+ property?: string;
183
+ labels?: string[];
184
+ /** Filter applied before ranking. */
185
+ where?: Record<string, unknown>;
186
+ skip?: number;
187
+ /** Maximum number of results (default 10). */
188
+ limit?: number;
189
+ /** Every keyword must match (AND) instead of any (OR). */
190
+ allTerms?: boolean;
191
+ /** Match the keywords as one phrase. */
192
+ phrase?: boolean;
193
+ };
194
+ /** How the engine ran a keyword search, or the keyword leg of a hybrid one. */
195
+ export type TextSearchReport = {
196
+ /** Records matching the keywords among the filtered records. */
197
+ matches: number;
198
+ /** Changes the index had not applied when the search ran. */
199
+ pending: number;
99
200
  };
100
201
  /**
101
202
  * A record returned by db.records.vectorSearch().
@@ -107,6 +208,21 @@ export type VectorSearchParams = {
107
208
  export type VectorSearchResult<S extends Schema = Schema> = DBRecord<S> & {
108
209
  readonly __score: number;
109
210
  };
211
+ /** How the engine ran a vector search. */
212
+ export type VectorSearchReport = {
213
+ /** The path that produced the results. */
214
+ mode: 'exact' | 'ann';
215
+ /** Gather breadth, for an ANN search. */
216
+ ef?: number;
217
+ /**
218
+ * Why a search that would use the ANN graph was answered exactly:
219
+ * `metric`, `budget`, `lowConfidence`, or `annWarming` (the graph is being
220
+ * built; later searches use it).
221
+ */
222
+ fallback?: 'metric' | 'budget' | 'lowConfidence' | 'annWarming';
223
+ /** Vectors in the index. */
224
+ pool: number;
225
+ };
110
226
  /** @deprecated Use VectorSearchParams. */
111
227
  export type SemanticSearchParams = VectorSearchParams;
112
228
  /** @deprecated Use VectorSearchResult. */
@@ -0,0 +1,27 @@
1
+ /**
2
+ * What RushDB Cloud adds over a standalone engine, as SDK methods. One list:
3
+ * the direct-mode router refuses these with `CloudOnlyError`, the MCP server
4
+ * hides the tools built on them, and the docs mark them.
5
+ *
6
+ * Everything else the SDK offers runs against a standalone `rushdbd` too.
7
+ */
8
+ export declare const CLOUD_ONLY_METHODS: {
9
+ readonly 'ai.search': "natural-language search turns the prompt into a query with an LLM";
10
+ readonly 'relationships.patterns.list': "relationship-pattern suggestions are produced and stored by the platform";
11
+ readonly 'relationships.patterns.analyze': "relationship-pattern suggestions are produced and stored by the platform";
12
+ readonly 'relationships.patterns.approve': "relationship-pattern suggestions are produced and stored by the platform";
13
+ readonly 'relationships.patterns.ignore': "relationship-pattern suggestions are produced and stored by the platform";
14
+ readonly 'relationships.patterns.delete': "relationship-pattern suggestions are produced and stored by the platform";
15
+ readonly 'settings.get': "project settings belong to the platform";
16
+ };
17
+ /**
18
+ * Methods available in direct mode in one form only; the other form needs
19
+ * RushDB Cloud.
20
+ */
21
+ export declare const CLOUD_ONLY_FORMS: {
22
+ readonly 'records.vectorSearch': "a text `query` is embedded with the managed embedding model; in direct mode pass `queryVector`";
23
+ readonly 'ai.indexes.create': "a managed index is filled by the managed embedding model; in direct mode create an external index (`external: true`) and supply vectors";
24
+ };
25
+ export type CloudOnlyMethod = keyof typeof CLOUD_ONLY_METHODS;
26
+ /** Whether `method` (e.g. `relationships.patterns.list`) needs RushDB Cloud. */
27
+ export declare const isCloudOnlyMethod: (method: string) => method is CloudOnlyMethod;
@@ -0,0 +1,45 @@
1
+ import type { HttpClient } from '../network/HttpClient.js';
2
+ /**
3
+ * Protocol operation envelope (v1) sent to `POST /protocol/v1/execute`.
4
+ */
5
+ export type ProtocolEnvelope = {
6
+ protocolVersion: 1;
7
+ context?: {
8
+ scope?: string;
9
+ };
10
+ operation: Record<string, any>;
11
+ };
12
+ export type ProtocolResponse = {
13
+ response: {
14
+ kind: string;
15
+ [key: string]: any;
16
+ };
17
+ error?: {
18
+ code: string;
19
+ message: string;
20
+ };
21
+ };
22
+ /**
23
+ * Direct engine transport: executes protocol operations against a standalone
24
+ * `rushdbd` (`/protocol/v1/execute`) over HTTP. This is the SDK's "direct
25
+ * mode" — no RushDB Cloud. `scope` is the tenant on a multitenant engine
26
+ * (`X-RushDB-Tenant`); auth is the engine token.
27
+ */
28
+ export declare class DirectEngine {
29
+ private readonly baseUrl;
30
+ private readonly token;
31
+ private readonly httpClient;
32
+ private readonly scope?;
33
+ constructor(config: {
34
+ engineUrl: string;
35
+ token: string;
36
+ httpClient: HttpClient;
37
+ scope?: string;
38
+ });
39
+ /**
40
+ * Runs one protocol operation and returns its `response`. A refused
41
+ * operation throws an `Error` with `status` (the engine's HTTP status) and a
42
+ * `"<status> <message>"` message, as a RushDB Cloud error does.
43
+ */
44
+ execute(operation: Record<string, any>): Promise<Record<string, any>>;
45
+ }
@@ -0,0 +1,20 @@
1
+ import type { MakeRequestConfig } from '../network/HttpClient.js';
2
+ import type { DirectEngine } from './engine.js';
3
+ /**
4
+ * Direct mode answers the SDK's REST calls itself, with protocol operations
5
+ * against a standalone engine, so every SDK method keeps one code path and
6
+ * returns the same shapes in both modes. Each route mirrors what RushDB Cloud
7
+ * does for it; a Cloud-only route throws `CloudOnlyError` before anything is
8
+ * sent. No request ever goes to RushDB Cloud.
9
+ */
10
+ type Body = Record<string, any>;
11
+ /** An engine record (`{ id, label, properties, propertyTypes, score }`) in the SDK's shape. */
12
+ export declare const toSdkRecord: (record: Body | undefined) => Body | undefined;
13
+ /** The routes direct mode answers, as `METHOD pattern` (for tests and docs). */
14
+ export declare const DIRECT_ROUTES: string[];
15
+ /**
16
+ * A fetcher with `createFetcher`'s signature that answers from a standalone
17
+ * engine instead of sending the request to RushDB Cloud.
18
+ */
19
+ export declare const createDirectFetcher: (engine: DirectEngine) => <Data extends Record<string, any> = Record<string, any>>(input: URL | string, { method, headers, requestData }: MakeRequestConfig<any>) => Promise<Data>;
20
+ export {};
@@ -0,0 +1,48 @@
1
+ import type { DirectEngine } from './engine.js';
2
+ /**
3
+ * `ai.getSchema` and `ai.getSchemaMarkdown` in direct mode: the engine's
4
+ * `describe.schema` arranged per label exactly as RushDB Cloud arranges it,
5
+ * with each property's vector indexes attached.
6
+ */
7
+ type Body = Record<string, any>;
8
+ export type SchemaVectorIndex = {
9
+ id: string;
10
+ name: string;
11
+ sourceType: string;
12
+ similarityFunction: string;
13
+ dimensions: number;
14
+ status: string;
15
+ modelKey: string;
16
+ };
17
+ export type SchemaProperty = {
18
+ id: string;
19
+ name: string;
20
+ type: string;
21
+ isArray?: boolean;
22
+ min?: number | string;
23
+ max?: number | string;
24
+ values?: Array<string | number>;
25
+ recordsCount?: number;
26
+ vectorIndexes?: SchemaVectorIndex[];
27
+ };
28
+ export type SchemaRelationship = {
29
+ label: string;
30
+ type: string;
31
+ direction: 'in' | 'out';
32
+ count?: number;
33
+ properties?: Array<{
34
+ name: string;
35
+ type: string;
36
+ relationshipsCount?: number;
37
+ }>;
38
+ };
39
+ export type SchemaItem = {
40
+ label: string;
41
+ count: number;
42
+ properties: SchemaProperty[];
43
+ relationships: SchemaRelationship[];
44
+ };
45
+ export declare const buildSchema: (engine: DirectEngine, labels: string[] | undefined, toEmbeddingIndex: (index: Body) => Body) => Promise<SchemaItem[]>;
46
+ /** The schema as compact Markdown tables, for an LLM to read. */
47
+ export declare const buildSchemaMarkdown: (schema: SchemaItem[]) => string;
48
+ export {};