ragpack-js 0.1.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 +128 -0
- package/dist/index.cjs +330 -0
- package/dist/index.d.cts +350 -0
- package/dist/index.d.ts +350 -0
- package/dist/index.js +302 -0
- package/package.json +41 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Controls how ingested documents are split into chunks before embedding.
|
|
3
|
+
*
|
|
4
|
+
* - `"auto"` — picks the best strategy based on the file's MIME type (default).
|
|
5
|
+
* - `"paragraph"` — splits on blank lines; good for prose (plain text, DOCX).
|
|
6
|
+
* - `"sliding_window"` — fixed-size rolling window with overlap; good for dense text like PDFs.
|
|
7
|
+
* - `"section"` — splits on headings, preserving section context; good for Markdown and HTML.
|
|
8
|
+
* - `"unit"` — one chunk per logical unit (e.g. one slide for PPTX); good for structured presentations.
|
|
9
|
+
* - `"row_group"` — groups rows with a repeated header row per chunk; good for spreadsheets (XLSX).
|
|
10
|
+
*/
|
|
11
|
+
type ChunkStrategy = "auto" | "paragraph" | "sliding_window" | "section" | "unit" | "row_group";
|
|
12
|
+
interface RagPackConfig {
|
|
13
|
+
/** Base URL of your RagPack backend (e.g. `http://localhost:9000`). */
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
/** API key generated on first backend startup. */
|
|
16
|
+
apiKey: string;
|
|
17
|
+
}
|
|
18
|
+
/** Per-collection chunking overrides. Omitted when all fields use server defaults. */
|
|
19
|
+
interface ChunkConfig {
|
|
20
|
+
strategy?: ChunkStrategy;
|
|
21
|
+
/** Max characters per chunk. */
|
|
22
|
+
size?: number;
|
|
23
|
+
/** Characters of overlap carried into the next chunk for context continuity. */
|
|
24
|
+
overlap?: number;
|
|
25
|
+
}
|
|
26
|
+
interface Collection {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
/** URL-safe identifier used in API calls. */
|
|
30
|
+
slug: string;
|
|
31
|
+
embed_model: string;
|
|
32
|
+
vector_dim: number;
|
|
33
|
+
created_at: string;
|
|
34
|
+
/** Present only when this collection overrides the server chunking defaults. */
|
|
35
|
+
chunk_config?: ChunkConfig;
|
|
36
|
+
}
|
|
37
|
+
interface Job {
|
|
38
|
+
id: string;
|
|
39
|
+
collection_id: string;
|
|
40
|
+
file_uri: string;
|
|
41
|
+
mime_type: string;
|
|
42
|
+
status: "pending" | "processing" | "complete" | "failed";
|
|
43
|
+
error?: string;
|
|
44
|
+
created_at: string;
|
|
45
|
+
updated_at: string;
|
|
46
|
+
}
|
|
47
|
+
interface Document {
|
|
48
|
+
id: string;
|
|
49
|
+
collection_id: string;
|
|
50
|
+
job_id: string;
|
|
51
|
+
file_uri: string;
|
|
52
|
+
mime_type: string;
|
|
53
|
+
chunk_count: number;
|
|
54
|
+
status: "ingesting" | "complete" | "failed";
|
|
55
|
+
error?: string;
|
|
56
|
+
created_at: string;
|
|
57
|
+
updated_at: string;
|
|
58
|
+
}
|
|
59
|
+
interface Prompt {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
slug: string;
|
|
63
|
+
/** Template content. Use `{{context}}` and `{{question}}` as placeholders. */
|
|
64
|
+
content: string;
|
|
65
|
+
is_system: boolean;
|
|
66
|
+
created_at: string;
|
|
67
|
+
updated_at: string;
|
|
68
|
+
}
|
|
69
|
+
interface RagChunk {
|
|
70
|
+
source: string;
|
|
71
|
+
file_uri: string;
|
|
72
|
+
chunk_index: number;
|
|
73
|
+
chunk_header: string | null;
|
|
74
|
+
chunk_text: string | null;
|
|
75
|
+
similarity: number;
|
|
76
|
+
}
|
|
77
|
+
interface RagResult {
|
|
78
|
+
formatted_prompt: string;
|
|
79
|
+
answer: string;
|
|
80
|
+
chunks: RagChunk[];
|
|
81
|
+
prompt_slug: string;
|
|
82
|
+
}
|
|
83
|
+
interface QueryResult {
|
|
84
|
+
source: string;
|
|
85
|
+
file_uri: string;
|
|
86
|
+
mime_type: string;
|
|
87
|
+
chunk_index: number;
|
|
88
|
+
/** The matched text chunk. */
|
|
89
|
+
chunk_text: string | null;
|
|
90
|
+
/** Optional metadata attached at ingest time. */
|
|
91
|
+
extra_json: string | null;
|
|
92
|
+
distance: number;
|
|
93
|
+
/** Cosine similarity score between 0 and 1. Higher is more relevant. */
|
|
94
|
+
similarity: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
type Requester = <T>(path: string, init?: RequestInit) => Promise<T>;
|
|
98
|
+
declare class RagPackError extends Error {
|
|
99
|
+
readonly status: number;
|
|
100
|
+
constructor(status: number, message: string);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
interface WaitOptions {
|
|
104
|
+
/** How often to poll for job status, in milliseconds. Defaults to 1500. */
|
|
105
|
+
pollIntervalMs?: number;
|
|
106
|
+
/** Maximum time to wait before throwing, in milliseconds. Defaults to 300000 (5 min). */
|
|
107
|
+
timeoutMs?: number;
|
|
108
|
+
}
|
|
109
|
+
declare class JobsResource {
|
|
110
|
+
private readonly req;
|
|
111
|
+
private readonly slug?;
|
|
112
|
+
constructor(req: Requester, slug?: string | undefined);
|
|
113
|
+
/** List ingestion jobs for this collection, or all jobs if no collection is scoped. */
|
|
114
|
+
list(): Promise<Job[]>;
|
|
115
|
+
/**
|
|
116
|
+
* Get a single ingestion job by ID.
|
|
117
|
+
* @param id - The job ID.
|
|
118
|
+
*/
|
|
119
|
+
get(id: string): Promise<Job>;
|
|
120
|
+
/**
|
|
121
|
+
* Poll until the job reaches a terminal state (`complete` or `failed`).
|
|
122
|
+
* Throws {@link RagPackError} if the job fails or the timeout is exceeded.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const job = await collection.ingest(file);
|
|
127
|
+
* await collection.jobs.waitUntilComplete(job.id);
|
|
128
|
+
* console.log("ingestion done, ready to search");
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
waitUntilComplete(id: string, options?: WaitOptions): Promise<Job>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
declare class DocumentsResource {
|
|
135
|
+
private readonly req;
|
|
136
|
+
private readonly slug?;
|
|
137
|
+
constructor(req: Requester, slug?: string | undefined);
|
|
138
|
+
/**
|
|
139
|
+
* List documents in this collection.
|
|
140
|
+
* @param options.limit - Max number of documents to return. Defaults to 50.
|
|
141
|
+
* @param options.offset - Pagination offset. Defaults to 0.
|
|
142
|
+
*/
|
|
143
|
+
list(options?: {
|
|
144
|
+
limit?: number;
|
|
145
|
+
offset?: number;
|
|
146
|
+
}): Promise<Document[]>;
|
|
147
|
+
/**
|
|
148
|
+
* Delete a document and all its chunks from this collection.
|
|
149
|
+
* @param id - The document ID.
|
|
150
|
+
*/
|
|
151
|
+
delete(id: string): Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface RagOptions {
|
|
155
|
+
/** Slug of the prompt template to use. Defaults to `"basic_rag"` if omitted. */
|
|
156
|
+
promptSlug?: string;
|
|
157
|
+
/** The user's question. Substituted into `{{question}}`. */
|
|
158
|
+
query: string;
|
|
159
|
+
/** Number of chunks to retrieve. Defaults to 5. */
|
|
160
|
+
topK?: number;
|
|
161
|
+
/** LLM model name to use (e.g. `"gpt-4o"`, `"claude-opus-4-8"`). Falls back to server default. */
|
|
162
|
+
model?: string;
|
|
163
|
+
/** Minimum similarity score (0–100) a chunk must meet to be included in context. Omit to include all top_k results. */
|
|
164
|
+
minSimilarity?: number;
|
|
165
|
+
}
|
|
166
|
+
interface FindSimilarOptions {
|
|
167
|
+
/** The search query text. */
|
|
168
|
+
query: string;
|
|
169
|
+
/** Number of results to return. Defaults to 5. */
|
|
170
|
+
topK?: number;
|
|
171
|
+
}
|
|
172
|
+
interface IngestUriOptions {
|
|
173
|
+
/** Remote file URI (e.g. `s3://bucket/file.pdf`). */
|
|
174
|
+
uri: string;
|
|
175
|
+
/** MIME type of the file. Detected from the file extension if omitted. */
|
|
176
|
+
mimeType?: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A collection-scoped client. All operations target the collection
|
|
180
|
+
* this was created with.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* const collection = client.collection("my-docs");
|
|
185
|
+
*
|
|
186
|
+
* await collection.ingest(file);
|
|
187
|
+
* await collection.ingest({ uri: "s3://bucket/file.pdf", mimeType: "application/pdf" });
|
|
188
|
+
* const results = await collection.findSimilar({ query: "how does auth work?" });
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare class CollectionClient {
|
|
192
|
+
private readonly slug;
|
|
193
|
+
/** Inspect ingestion jobs for this collection. */
|
|
194
|
+
readonly jobs: JobsResource;
|
|
195
|
+
/** Manage indexed documents in this collection. */
|
|
196
|
+
readonly documents: DocumentsResource;
|
|
197
|
+
private readonly _req;
|
|
198
|
+
private readonly _query;
|
|
199
|
+
constructor(slug: string, req: Requester);
|
|
200
|
+
/**
|
|
201
|
+
* Ingest a document into this collection.
|
|
202
|
+
*
|
|
203
|
+
* Pass a `File` or `Blob` to upload directly, or an object with `uri` and
|
|
204
|
+
* `mimeType` to ingest from a remote URI.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* // File upload
|
|
209
|
+
* await collection.ingest(file);
|
|
210
|
+
*
|
|
211
|
+
* // Remote URI
|
|
212
|
+
* await collection.ingest({ uri: "s3://bucket/report.pdf", mimeType: "application/pdf" });
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
ingest(file: File | Blob, filename?: string): Promise<Job>;
|
|
216
|
+
ingest(options: IngestUriOptions): Promise<Job>;
|
|
217
|
+
/**
|
|
218
|
+
* Find semantically similar content in this collection.
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* const results = await collection.findSimilar({ query: "what is RagPack?", topK: 10 });
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
findSimilar(options: FindSimilarOptions): Promise<QueryResult[]>;
|
|
225
|
+
/**
|
|
226
|
+
* Full RAG pipeline: retrieve relevant chunks, build context, expand the
|
|
227
|
+
* prompt template, and call the configured LLM — all server-side.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* const { answer, chunks } = await collection.rag({
|
|
232
|
+
* prompt: "basic-rag",
|
|
233
|
+
* query: "How do I reset my password?",
|
|
234
|
+
* });
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
rag(options: RagOptions): Promise<RagResult>;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
declare class CollectionsResource {
|
|
241
|
+
private readonly req;
|
|
242
|
+
constructor(req: Requester);
|
|
243
|
+
/** List all collections. */
|
|
244
|
+
list(): Promise<Collection[]>;
|
|
245
|
+
/**
|
|
246
|
+
* Create a new collection and return a scoped client for it.
|
|
247
|
+
* @param name - Display name for the collection.
|
|
248
|
+
* @param options.embedModel - Embedding model to use. Defaults to the server's configured provider.
|
|
249
|
+
* @param options.chunkConfig - Override chunking behaviour for this collection.
|
|
250
|
+
* Omit to use server defaults.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* const collection = await client.collections.create("my-docs");
|
|
255
|
+
* await collection.ingest(file);
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
create(name: string, options?: {
|
|
259
|
+
embedModel?: string;
|
|
260
|
+
chunkConfig?: ChunkConfig;
|
|
261
|
+
}): Promise<CollectionClient>;
|
|
262
|
+
/**
|
|
263
|
+
* Get a collection by its slug.
|
|
264
|
+
* @param slug - The collection's URL-safe identifier.
|
|
265
|
+
*/
|
|
266
|
+
get(slug: string): Promise<Collection>;
|
|
267
|
+
/**
|
|
268
|
+
* Delete a collection and all its documents.
|
|
269
|
+
* @param slug - The collection's URL-safe identifier.
|
|
270
|
+
*/
|
|
271
|
+
delete(slug: string): Promise<void>;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
declare class PromptsResource {
|
|
275
|
+
private readonly req;
|
|
276
|
+
constructor(req: Requester);
|
|
277
|
+
/** List all prompt templates (built-in system prompts first, then custom). */
|
|
278
|
+
list(): Promise<Prompt[]>;
|
|
279
|
+
/** Fetch a prompt template by slug. */
|
|
280
|
+
get(slug: string): Promise<Prompt>;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
interface LLMInfo {
|
|
284
|
+
models: string[];
|
|
285
|
+
default: string;
|
|
286
|
+
}
|
|
287
|
+
declare class LLMsResource {
|
|
288
|
+
private readonly req;
|
|
289
|
+
constructor(req: Requester);
|
|
290
|
+
/** List all configured LLM models and the server default. */
|
|
291
|
+
list(): Promise<LLMInfo>;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
interface EmbedderInfo {
|
|
295
|
+
models: string[];
|
|
296
|
+
default: string;
|
|
297
|
+
}
|
|
298
|
+
declare class EmbeddersResource {
|
|
299
|
+
private readonly req;
|
|
300
|
+
constructor(req: Requester);
|
|
301
|
+
/** List all configured embedding models and the server default. */
|
|
302
|
+
list(): Promise<EmbedderInfo>;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* RagPack client for interacting with a self-hosted RagPack RAG engine.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* const client = new RagPack({ baseUrl: "http://localhost:9000", apiKey: "rp_..." });
|
|
311
|
+
*
|
|
312
|
+
* // Manage collections
|
|
313
|
+
* const col = await client.collections.create("my-docs");
|
|
314
|
+
*
|
|
315
|
+
* // Scope to a collection for all operations
|
|
316
|
+
* const collection = client.collection(col.slug);
|
|
317
|
+
* await collection.ingest(file);
|
|
318
|
+
* const results = await collection.findSimilar({ query: "what is RagPack?" });
|
|
319
|
+
*
|
|
320
|
+
* // Discover configured providers
|
|
321
|
+
* const { models, default: defaultModel } = await client.llms.list();
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
declare class RagPack {
|
|
325
|
+
/** Create and manage collections. */
|
|
326
|
+
readonly collections: CollectionsResource;
|
|
327
|
+
/** Fetch and expand prompt templates. */
|
|
328
|
+
readonly prompts: PromptsResource;
|
|
329
|
+
/** List configured LLM models. */
|
|
330
|
+
readonly llms: LLMsResource;
|
|
331
|
+
/** List configured embedding models. */
|
|
332
|
+
readonly embedders: EmbeddersResource;
|
|
333
|
+
private readonly _req;
|
|
334
|
+
constructor(config: RagPackConfig);
|
|
335
|
+
/**
|
|
336
|
+
* Scope all operations to a specific collection.
|
|
337
|
+
* @param slug - The collection's URL-safe identifier.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```ts
|
|
341
|
+
* const collection = client.collection("my-docs");
|
|
342
|
+
* await collection.ingest(file);
|
|
343
|
+
* await collection.findSimilar({ query: "..." });
|
|
344
|
+
* await collection.jobs.list();
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
collection(slug: string): CollectionClient;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export { type Collection, type Document, type EmbedderInfo, type FindSimilarOptions, type IngestUriOptions, type Job, type LLMInfo, type Prompt, type QueryResult, type RagChunk, type RagOptions, RagPack, type RagPackConfig, RagPackError, type RagResult };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Controls how ingested documents are split into chunks before embedding.
|
|
3
|
+
*
|
|
4
|
+
* - `"auto"` — picks the best strategy based on the file's MIME type (default).
|
|
5
|
+
* - `"paragraph"` — splits on blank lines; good for prose (plain text, DOCX).
|
|
6
|
+
* - `"sliding_window"` — fixed-size rolling window with overlap; good for dense text like PDFs.
|
|
7
|
+
* - `"section"` — splits on headings, preserving section context; good for Markdown and HTML.
|
|
8
|
+
* - `"unit"` — one chunk per logical unit (e.g. one slide for PPTX); good for structured presentations.
|
|
9
|
+
* - `"row_group"` — groups rows with a repeated header row per chunk; good for spreadsheets (XLSX).
|
|
10
|
+
*/
|
|
11
|
+
type ChunkStrategy = "auto" | "paragraph" | "sliding_window" | "section" | "unit" | "row_group";
|
|
12
|
+
interface RagPackConfig {
|
|
13
|
+
/** Base URL of your RagPack backend (e.g. `http://localhost:9000`). */
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
/** API key generated on first backend startup. */
|
|
16
|
+
apiKey: string;
|
|
17
|
+
}
|
|
18
|
+
/** Per-collection chunking overrides. Omitted when all fields use server defaults. */
|
|
19
|
+
interface ChunkConfig {
|
|
20
|
+
strategy?: ChunkStrategy;
|
|
21
|
+
/** Max characters per chunk. */
|
|
22
|
+
size?: number;
|
|
23
|
+
/** Characters of overlap carried into the next chunk for context continuity. */
|
|
24
|
+
overlap?: number;
|
|
25
|
+
}
|
|
26
|
+
interface Collection {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
/** URL-safe identifier used in API calls. */
|
|
30
|
+
slug: string;
|
|
31
|
+
embed_model: string;
|
|
32
|
+
vector_dim: number;
|
|
33
|
+
created_at: string;
|
|
34
|
+
/** Present only when this collection overrides the server chunking defaults. */
|
|
35
|
+
chunk_config?: ChunkConfig;
|
|
36
|
+
}
|
|
37
|
+
interface Job {
|
|
38
|
+
id: string;
|
|
39
|
+
collection_id: string;
|
|
40
|
+
file_uri: string;
|
|
41
|
+
mime_type: string;
|
|
42
|
+
status: "pending" | "processing" | "complete" | "failed";
|
|
43
|
+
error?: string;
|
|
44
|
+
created_at: string;
|
|
45
|
+
updated_at: string;
|
|
46
|
+
}
|
|
47
|
+
interface Document {
|
|
48
|
+
id: string;
|
|
49
|
+
collection_id: string;
|
|
50
|
+
job_id: string;
|
|
51
|
+
file_uri: string;
|
|
52
|
+
mime_type: string;
|
|
53
|
+
chunk_count: number;
|
|
54
|
+
status: "ingesting" | "complete" | "failed";
|
|
55
|
+
error?: string;
|
|
56
|
+
created_at: string;
|
|
57
|
+
updated_at: string;
|
|
58
|
+
}
|
|
59
|
+
interface Prompt {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
slug: string;
|
|
63
|
+
/** Template content. Use `{{context}}` and `{{question}}` as placeholders. */
|
|
64
|
+
content: string;
|
|
65
|
+
is_system: boolean;
|
|
66
|
+
created_at: string;
|
|
67
|
+
updated_at: string;
|
|
68
|
+
}
|
|
69
|
+
interface RagChunk {
|
|
70
|
+
source: string;
|
|
71
|
+
file_uri: string;
|
|
72
|
+
chunk_index: number;
|
|
73
|
+
chunk_header: string | null;
|
|
74
|
+
chunk_text: string | null;
|
|
75
|
+
similarity: number;
|
|
76
|
+
}
|
|
77
|
+
interface RagResult {
|
|
78
|
+
formatted_prompt: string;
|
|
79
|
+
answer: string;
|
|
80
|
+
chunks: RagChunk[];
|
|
81
|
+
prompt_slug: string;
|
|
82
|
+
}
|
|
83
|
+
interface QueryResult {
|
|
84
|
+
source: string;
|
|
85
|
+
file_uri: string;
|
|
86
|
+
mime_type: string;
|
|
87
|
+
chunk_index: number;
|
|
88
|
+
/** The matched text chunk. */
|
|
89
|
+
chunk_text: string | null;
|
|
90
|
+
/** Optional metadata attached at ingest time. */
|
|
91
|
+
extra_json: string | null;
|
|
92
|
+
distance: number;
|
|
93
|
+
/** Cosine similarity score between 0 and 1. Higher is more relevant. */
|
|
94
|
+
similarity: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
type Requester = <T>(path: string, init?: RequestInit) => Promise<T>;
|
|
98
|
+
declare class RagPackError extends Error {
|
|
99
|
+
readonly status: number;
|
|
100
|
+
constructor(status: number, message: string);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
interface WaitOptions {
|
|
104
|
+
/** How often to poll for job status, in milliseconds. Defaults to 1500. */
|
|
105
|
+
pollIntervalMs?: number;
|
|
106
|
+
/** Maximum time to wait before throwing, in milliseconds. Defaults to 300000 (5 min). */
|
|
107
|
+
timeoutMs?: number;
|
|
108
|
+
}
|
|
109
|
+
declare class JobsResource {
|
|
110
|
+
private readonly req;
|
|
111
|
+
private readonly slug?;
|
|
112
|
+
constructor(req: Requester, slug?: string | undefined);
|
|
113
|
+
/** List ingestion jobs for this collection, or all jobs if no collection is scoped. */
|
|
114
|
+
list(): Promise<Job[]>;
|
|
115
|
+
/**
|
|
116
|
+
* Get a single ingestion job by ID.
|
|
117
|
+
* @param id - The job ID.
|
|
118
|
+
*/
|
|
119
|
+
get(id: string): Promise<Job>;
|
|
120
|
+
/**
|
|
121
|
+
* Poll until the job reaches a terminal state (`complete` or `failed`).
|
|
122
|
+
* Throws {@link RagPackError} if the job fails or the timeout is exceeded.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const job = await collection.ingest(file);
|
|
127
|
+
* await collection.jobs.waitUntilComplete(job.id);
|
|
128
|
+
* console.log("ingestion done, ready to search");
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
waitUntilComplete(id: string, options?: WaitOptions): Promise<Job>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
declare class DocumentsResource {
|
|
135
|
+
private readonly req;
|
|
136
|
+
private readonly slug?;
|
|
137
|
+
constructor(req: Requester, slug?: string | undefined);
|
|
138
|
+
/**
|
|
139
|
+
* List documents in this collection.
|
|
140
|
+
* @param options.limit - Max number of documents to return. Defaults to 50.
|
|
141
|
+
* @param options.offset - Pagination offset. Defaults to 0.
|
|
142
|
+
*/
|
|
143
|
+
list(options?: {
|
|
144
|
+
limit?: number;
|
|
145
|
+
offset?: number;
|
|
146
|
+
}): Promise<Document[]>;
|
|
147
|
+
/**
|
|
148
|
+
* Delete a document and all its chunks from this collection.
|
|
149
|
+
* @param id - The document ID.
|
|
150
|
+
*/
|
|
151
|
+
delete(id: string): Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface RagOptions {
|
|
155
|
+
/** Slug of the prompt template to use. Defaults to `"basic_rag"` if omitted. */
|
|
156
|
+
promptSlug?: string;
|
|
157
|
+
/** The user's question. Substituted into `{{question}}`. */
|
|
158
|
+
query: string;
|
|
159
|
+
/** Number of chunks to retrieve. Defaults to 5. */
|
|
160
|
+
topK?: number;
|
|
161
|
+
/** LLM model name to use (e.g. `"gpt-4o"`, `"claude-opus-4-8"`). Falls back to server default. */
|
|
162
|
+
model?: string;
|
|
163
|
+
/** Minimum similarity score (0–100) a chunk must meet to be included in context. Omit to include all top_k results. */
|
|
164
|
+
minSimilarity?: number;
|
|
165
|
+
}
|
|
166
|
+
interface FindSimilarOptions {
|
|
167
|
+
/** The search query text. */
|
|
168
|
+
query: string;
|
|
169
|
+
/** Number of results to return. Defaults to 5. */
|
|
170
|
+
topK?: number;
|
|
171
|
+
}
|
|
172
|
+
interface IngestUriOptions {
|
|
173
|
+
/** Remote file URI (e.g. `s3://bucket/file.pdf`). */
|
|
174
|
+
uri: string;
|
|
175
|
+
/** MIME type of the file. Detected from the file extension if omitted. */
|
|
176
|
+
mimeType?: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A collection-scoped client. All operations target the collection
|
|
180
|
+
* this was created with.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* const collection = client.collection("my-docs");
|
|
185
|
+
*
|
|
186
|
+
* await collection.ingest(file);
|
|
187
|
+
* await collection.ingest({ uri: "s3://bucket/file.pdf", mimeType: "application/pdf" });
|
|
188
|
+
* const results = await collection.findSimilar({ query: "how does auth work?" });
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare class CollectionClient {
|
|
192
|
+
private readonly slug;
|
|
193
|
+
/** Inspect ingestion jobs for this collection. */
|
|
194
|
+
readonly jobs: JobsResource;
|
|
195
|
+
/** Manage indexed documents in this collection. */
|
|
196
|
+
readonly documents: DocumentsResource;
|
|
197
|
+
private readonly _req;
|
|
198
|
+
private readonly _query;
|
|
199
|
+
constructor(slug: string, req: Requester);
|
|
200
|
+
/**
|
|
201
|
+
* Ingest a document into this collection.
|
|
202
|
+
*
|
|
203
|
+
* Pass a `File` or `Blob` to upload directly, or an object with `uri` and
|
|
204
|
+
* `mimeType` to ingest from a remote URI.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* // File upload
|
|
209
|
+
* await collection.ingest(file);
|
|
210
|
+
*
|
|
211
|
+
* // Remote URI
|
|
212
|
+
* await collection.ingest({ uri: "s3://bucket/report.pdf", mimeType: "application/pdf" });
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
ingest(file: File | Blob, filename?: string): Promise<Job>;
|
|
216
|
+
ingest(options: IngestUriOptions): Promise<Job>;
|
|
217
|
+
/**
|
|
218
|
+
* Find semantically similar content in this collection.
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* const results = await collection.findSimilar({ query: "what is RagPack?", topK: 10 });
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
findSimilar(options: FindSimilarOptions): Promise<QueryResult[]>;
|
|
225
|
+
/**
|
|
226
|
+
* Full RAG pipeline: retrieve relevant chunks, build context, expand the
|
|
227
|
+
* prompt template, and call the configured LLM — all server-side.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* const { answer, chunks } = await collection.rag({
|
|
232
|
+
* prompt: "basic-rag",
|
|
233
|
+
* query: "How do I reset my password?",
|
|
234
|
+
* });
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
rag(options: RagOptions): Promise<RagResult>;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
declare class CollectionsResource {
|
|
241
|
+
private readonly req;
|
|
242
|
+
constructor(req: Requester);
|
|
243
|
+
/** List all collections. */
|
|
244
|
+
list(): Promise<Collection[]>;
|
|
245
|
+
/**
|
|
246
|
+
* Create a new collection and return a scoped client for it.
|
|
247
|
+
* @param name - Display name for the collection.
|
|
248
|
+
* @param options.embedModel - Embedding model to use. Defaults to the server's configured provider.
|
|
249
|
+
* @param options.chunkConfig - Override chunking behaviour for this collection.
|
|
250
|
+
* Omit to use server defaults.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* const collection = await client.collections.create("my-docs");
|
|
255
|
+
* await collection.ingest(file);
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
create(name: string, options?: {
|
|
259
|
+
embedModel?: string;
|
|
260
|
+
chunkConfig?: ChunkConfig;
|
|
261
|
+
}): Promise<CollectionClient>;
|
|
262
|
+
/**
|
|
263
|
+
* Get a collection by its slug.
|
|
264
|
+
* @param slug - The collection's URL-safe identifier.
|
|
265
|
+
*/
|
|
266
|
+
get(slug: string): Promise<Collection>;
|
|
267
|
+
/**
|
|
268
|
+
* Delete a collection and all its documents.
|
|
269
|
+
* @param slug - The collection's URL-safe identifier.
|
|
270
|
+
*/
|
|
271
|
+
delete(slug: string): Promise<void>;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
declare class PromptsResource {
|
|
275
|
+
private readonly req;
|
|
276
|
+
constructor(req: Requester);
|
|
277
|
+
/** List all prompt templates (built-in system prompts first, then custom). */
|
|
278
|
+
list(): Promise<Prompt[]>;
|
|
279
|
+
/** Fetch a prompt template by slug. */
|
|
280
|
+
get(slug: string): Promise<Prompt>;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
interface LLMInfo {
|
|
284
|
+
models: string[];
|
|
285
|
+
default: string;
|
|
286
|
+
}
|
|
287
|
+
declare class LLMsResource {
|
|
288
|
+
private readonly req;
|
|
289
|
+
constructor(req: Requester);
|
|
290
|
+
/** List all configured LLM models and the server default. */
|
|
291
|
+
list(): Promise<LLMInfo>;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
interface EmbedderInfo {
|
|
295
|
+
models: string[];
|
|
296
|
+
default: string;
|
|
297
|
+
}
|
|
298
|
+
declare class EmbeddersResource {
|
|
299
|
+
private readonly req;
|
|
300
|
+
constructor(req: Requester);
|
|
301
|
+
/** List all configured embedding models and the server default. */
|
|
302
|
+
list(): Promise<EmbedderInfo>;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* RagPack client for interacting with a self-hosted RagPack RAG engine.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* const client = new RagPack({ baseUrl: "http://localhost:9000", apiKey: "rp_..." });
|
|
311
|
+
*
|
|
312
|
+
* // Manage collections
|
|
313
|
+
* const col = await client.collections.create("my-docs");
|
|
314
|
+
*
|
|
315
|
+
* // Scope to a collection for all operations
|
|
316
|
+
* const collection = client.collection(col.slug);
|
|
317
|
+
* await collection.ingest(file);
|
|
318
|
+
* const results = await collection.findSimilar({ query: "what is RagPack?" });
|
|
319
|
+
*
|
|
320
|
+
* // Discover configured providers
|
|
321
|
+
* const { models, default: defaultModel } = await client.llms.list();
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
declare class RagPack {
|
|
325
|
+
/** Create and manage collections. */
|
|
326
|
+
readonly collections: CollectionsResource;
|
|
327
|
+
/** Fetch and expand prompt templates. */
|
|
328
|
+
readonly prompts: PromptsResource;
|
|
329
|
+
/** List configured LLM models. */
|
|
330
|
+
readonly llms: LLMsResource;
|
|
331
|
+
/** List configured embedding models. */
|
|
332
|
+
readonly embedders: EmbeddersResource;
|
|
333
|
+
private readonly _req;
|
|
334
|
+
constructor(config: RagPackConfig);
|
|
335
|
+
/**
|
|
336
|
+
* Scope all operations to a specific collection.
|
|
337
|
+
* @param slug - The collection's URL-safe identifier.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```ts
|
|
341
|
+
* const collection = client.collection("my-docs");
|
|
342
|
+
* await collection.ingest(file);
|
|
343
|
+
* await collection.findSimilar({ query: "..." });
|
|
344
|
+
* await collection.jobs.list();
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
collection(slug: string): CollectionClient;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export { type Collection, type Document, type EmbedderInfo, type FindSimilarOptions, type IngestUriOptions, type Job, type LLMInfo, type Prompt, type QueryResult, type RagChunk, type RagOptions, RagPack, type RagPackConfig, RagPackError, type RagResult };
|