vecmindb 1.0.0-beta

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.
@@ -0,0 +1,934 @@
1
+ /**
2
+ * @module models
3
+ * @description TypeScript type definitions for the VecminDB SDK.
4
+ * Covers all API request/response types, configuration options,
5
+ * and data structures used across the SDK.
6
+ */
7
+ /** Options for constructing a {@link VecminClient} instance. */
8
+ interface VecminClientOptions {
9
+ /** Base URL of the VecminDB server (e.g. `http://localhost:8080`). */
10
+ baseUrl: string;
11
+ /** API key for authentication via `x-api-key` header. */
12
+ apiKey?: string;
13
+ /** JWT token for authentication. If provided alongside `apiKey`, JWT takes precedence on protected routes. */
14
+ jwt?: string;
15
+ /** Request timeout in milliseconds. @default 30_000 */
16
+ timeout?: number;
17
+ /** Maximum number of automatic retries on transient failures. @default 3 */
18
+ maxRetries?: number;
19
+ /** Backoff multiplier (seconds) for exponential retry delay. @default 0.5 */
20
+ backoffFactor?: number;
21
+ /** Custom HTTP headers included with every request. */
22
+ defaultHeaders?: Record<string, string>;
23
+ /** Optional agent identifier injected via `x-agent-id` header. */
24
+ agentId?: string;
25
+ /** Optional model identifier injected via `x-model-id` header. */
26
+ modelId?: string;
27
+ }
28
+ /** Standardised response envelope returned by every VecminDB API endpoint. */
29
+ interface VecminResponse<T> {
30
+ /** HTTP-style status code. */
31
+ code: number;
32
+ /** Human-readable status message. */
33
+ message: string;
34
+ /** Response payload. */
35
+ data: T;
36
+ }
37
+ /** Parameters for creating a new collection. */
38
+ interface CreateCollectionParams {
39
+ /** Unique name for the collection. */
40
+ name: string;
41
+ /** Dimensionality of the vectors stored in the collection. */
42
+ dimension: number;
43
+ /** Distance metric. @default "Cosine" */
44
+ metric_type?: MetricType;
45
+ /** Index algorithm. @default "HNSW" */
46
+ index_type?: IndexType;
47
+ /** Algorithm-specific parameters. */
48
+ index_params?: Record<string, unknown>;
49
+ }
50
+ /** A VecminDB collection. */
51
+ interface Collection {
52
+ /** Collection name. */
53
+ name: string;
54
+ /** Vector dimensionality. */
55
+ dimension: number;
56
+ /** Distance metric used. */
57
+ metric_type: MetricType;
58
+ /** Index algorithm used. */
59
+ index_type: IndexType;
60
+ /** Index hyper-parameters. */
61
+ index_params: Record<string, unknown>;
62
+ /** Number of vectors stored. */
63
+ vector_count?: number;
64
+ /** ISO-8601 creation timestamp. */
65
+ created_at?: string;
66
+ /** ISO-8601 last-update timestamp. */
67
+ updated_at?: string;
68
+ }
69
+ /** Statistical summary of a collection. */
70
+ interface CollectionStats {
71
+ /** Collection name. */
72
+ name: string;
73
+ /** Number of stored vectors. */
74
+ vector_count: number;
75
+ /** Storage consumption in bytes. */
76
+ storage_bytes: number;
77
+ /** Index build progress (0–100). */
78
+ index_progress?: number;
79
+ /** ISO-8601 creation timestamp. */
80
+ created_at?: string;
81
+ }
82
+ /** Parameters for inserting a single vector. */
83
+ interface InsertParams {
84
+ /** Unique identifier for the vector. If omitted the server generates one. */
85
+ id?: string;
86
+ /** The vector embedding. */
87
+ vector: number[];
88
+ /** Arbitrary key-value metadata attached to the vector. */
89
+ metadata?: Record<string, unknown>;
90
+ }
91
+ /** Parameters for searching vectors. */
92
+ interface SearchParams {
93
+ /** Query vector. */
94
+ query: number[];
95
+ /** Number of nearest neighbours to return. @default 10 */
96
+ k?: number;
97
+ /** HNSW ef-search parameter. @default 50 */
98
+ ef_search?: number;
99
+ /** Override the collection's default metric for this query. */
100
+ metric?: MetricType;
101
+ /** Metadata filter expression (server-side). */
102
+ filter?: Record<string, unknown>;
103
+ }
104
+ /** A single search result item. */
105
+ interface SearchResult {
106
+ /** Vector identifier. */
107
+ id: string;
108
+ /** Similarity score (higher = more similar for cosine/inner-product). */
109
+ score: number;
110
+ /** The vector itself (may be omitted by the server for efficiency). */
111
+ vector?: number[];
112
+ /** Attached metadata. */
113
+ metadata?: Record<string, unknown>;
114
+ }
115
+ /** A stored vector record. */
116
+ interface Vector {
117
+ /** Unique identifier. */
118
+ id: string;
119
+ /** The vector embedding. */
120
+ vector: number[];
121
+ /** Attached metadata. */
122
+ metadata?: Record<string, unknown>;
123
+ }
124
+ /** Index summary returned by the list-indexes endpoint. */
125
+ interface IndexInfo {
126
+ /** Index name. */
127
+ name: string;
128
+ /** Algorithm used. */
129
+ index_type: IndexType;
130
+ /** Collection this index belongs to. */
131
+ collection: string;
132
+ /** Build status. */
133
+ status?: string;
134
+ }
135
+ /** Login credentials for JWT authentication. */
136
+ interface LoginParams {
137
+ /** Username or API key. */
138
+ username: string;
139
+ /** Password or secret. */
140
+ password: string;
141
+ }
142
+ /** A node in the VecminDB cluster. */
143
+ interface Node {
144
+ /** Unique node identifier. */
145
+ id: string;
146
+ /** Network address (host:port). */
147
+ address: string;
148
+ /** Node role. */
149
+ role: "leader" | "follower" | "candidate";
150
+ /** `true` if the node is reachable. */
151
+ healthy: boolean;
152
+ }
153
+ /** Cluster-wide status overview. */
154
+ interface ClusterStatus {
155
+ /** Cluster health indicator. */
156
+ status: "healthy" | "degraded" | "unavailable";
157
+ /** Current leader node ID. */
158
+ leader_id: string;
159
+ /** Total number of nodes. */
160
+ node_count: number;
161
+ /** Number of healthy nodes. */
162
+ healthy_count: number;
163
+ /** Raft term. */
164
+ term?: number;
165
+ /** Raft commit index. */
166
+ commit_index?: number;
167
+ }
168
+ /** Options for MCP operations. */
169
+ interface MCPOptions {
170
+ /** Collection to store/search memories in. @default "agent_memory_mcp" */
171
+ collection?: string;
172
+ /** Source tag for the memory. */
173
+ source?: string;
174
+ /** Embedding dimension. @default 384 */
175
+ dimension?: number;
176
+ }
177
+ /** A single MCP search result. */
178
+ interface MCPSearchResult {
179
+ /** Document ID. */
180
+ id: string;
181
+ /** Similarity score. */
182
+ score: number;
183
+ /** The original text content. */
184
+ content: string;
185
+ /** Agent that stored this memory. */
186
+ agent_id: string;
187
+ /** Source tag. */
188
+ source?: string;
189
+ /** Full metadata object. */
190
+ metadata?: Record<string, unknown>;
191
+ }
192
+ /** MCP client configuration. */
193
+ interface MCPClientOptions {
194
+ /** API key for authenticating MCP requests. */
195
+ apiKey?: string;
196
+ /** JWT token. */
197
+ jwt?: string;
198
+ /** Agent identifier. */
199
+ agentId?: string;
200
+ /** Model identifier. */
201
+ modelId?: string;
202
+ }
203
+ /** Parameters for the `store_memory` MCP tool. */
204
+ interface StoreMemoryParams {
205
+ /** The text content to store. */
206
+ text: string;
207
+ /** Agent identifier. */
208
+ agent_id: string;
209
+ /** Source tag. */
210
+ source?: string;
211
+ /** Override target collection. */
212
+ collection?: string;
213
+ }
214
+ /** Parameters for the `search_memory` MCP tool. */
215
+ interface SearchMemoryParams {
216
+ /** Natural-language query. */
217
+ query: string;
218
+ /** Agent identifier to scope the search. */
219
+ agent_id: string;
220
+ /** Number of results. @default 5 */
221
+ top_k?: number;
222
+ /** Override target collection. */
223
+ collection?: string;
224
+ }
225
+ /** JSON-RPC 2.0 request envelope. */
226
+ interface JsonRpcRequest {
227
+ jsonrpc: "2.0";
228
+ id: number;
229
+ method: string;
230
+ params?: Record<string, unknown>;
231
+ }
232
+ /** JSON-RPC 2.0 success response. */
233
+ interface JsonRpcResponse<T = unknown> {
234
+ jsonrpc: "2.0";
235
+ id: number;
236
+ result?: T;
237
+ error?: {
238
+ code: number;
239
+ message: string;
240
+ data?: unknown;
241
+ };
242
+ }
243
+ /** Options for constructing a {@link VecminDBVectorStore}. */
244
+ interface VecminVectorStoreOptions {
245
+ /** VecminDB base URL. */
246
+ baseUrl: string;
247
+ /** API key. */
248
+ apiKey?: string;
249
+ /** Collection name. @default "langchain_memory" */
250
+ collectionName?: string;
251
+ /** Vector dimensionality. @default 1536 */
252
+ dimension?: number;
253
+ /** Distance metric. @default "Cosine" */
254
+ metricType?: MetricType;
255
+ /** Index type. @default "HNSW" */
256
+ indexType?: IndexType;
257
+ /** Index hyper-parameters. */
258
+ indexParams?: Record<string, unknown>;
259
+ /** Request timeout. */
260
+ timeout?: number;
261
+ }
262
+ /** Supported distance metrics. */
263
+ type MetricType = "Cosine" | "L2" | "InnerProduct";
264
+ /** Supported index algorithms. */
265
+ type IndexType = "HNSW" | "IVF" | "Flat";
266
+ /** Configuration for the retry policy. */
267
+ interface RetryOptions {
268
+ /** Maximum retry attempts. @default 3 */
269
+ maxRetries?: number;
270
+ /** Backoff multiplier in seconds. @default 0.5 */
271
+ backoffFactor?: number;
272
+ /** HTTP status codes that trigger a retry. @default [429,500,502,503,504] */
273
+ retryableStatusCodes?: number[];
274
+ }
275
+
276
+ /**
277
+ * @module client
278
+ * @description Main VecminDB SDK client.
279
+ *
280
+ * `VecminClient` is the primary entry-point for interacting with a
281
+ * VecminDB server. It provides typed, async methods for every API endpoint
282
+ * and transparently handles authentication, retries, and response unwrapping.
283
+ */
284
+
285
+ /**
286
+ * Official TypeScript client for VecminDB.
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * const client = new VecminClient({ baseUrl: "http://localhost:8080", apiKey: "my-key" });
291
+ *
292
+ * await client.createCollection({ name: "docs", dimension: 1536 });
293
+ * const id = await client.insert("docs", { vector: [0.1, 0.2, ...], metadata: { title: "Hello" } });
294
+ * const results = await client.search("docs", { query: [0.1, 0.2, ...], k: 5 });
295
+ * ```
296
+ */
297
+ declare class VecminClient {
298
+ /** Resolved base URL (trailing slash stripped). */
299
+ private readonly baseUrl;
300
+ /** API path prefix. */
301
+ private readonly apiUrl;
302
+ /** MCP path prefix. */
303
+ private readonly mcpUrl;
304
+ /** Authentication manager. */
305
+ private readonly auth;
306
+ /** Request timeout in milliseconds. */
307
+ private readonly timeout;
308
+ /** Retry configuration propagated to every request. */
309
+ private readonly retryOptions;
310
+ /** Default headers merged into every request. */
311
+ private readonly defaultHeaders;
312
+ /** Abort controllers for in-flight requests (used by `close()`). */
313
+ private readonly controllers;
314
+ /** Whether the client has been closed. */
315
+ private closed;
316
+ constructor(options: VecminClientOptions);
317
+ /** Build the full headers map for an outgoing request. */
318
+ private buildHeaders;
319
+ /** Create an AbortController with the configured timeout and track it. */
320
+ private createController;
321
+ /** Perform a JSON GET request. */
322
+ private get;
323
+ /** Perform a JSON POST request. */
324
+ private post;
325
+ /** Perform a JSON DELETE request. */
326
+ private del;
327
+ /** Throw if the client has been closed. */
328
+ private assertOpen;
329
+ /**
330
+ * Create a new collection.
331
+ *
332
+ * @example
333
+ * ```ts
334
+ * const col = await client.createCollection({
335
+ * name: "docs",
336
+ * dimension: 1536,
337
+ * metric_type: "Cosine",
338
+ * index_type: "HNSW",
339
+ * });
340
+ * ```
341
+ */
342
+ createCollection(params: CreateCollectionParams): Promise<Collection>;
343
+ /**
344
+ * List all collections.
345
+ *
346
+ * @example
347
+ * ```ts
348
+ * const collections = await client.listCollections();
349
+ * ```
350
+ */
351
+ listCollections(): Promise<Collection[]>;
352
+ /**
353
+ * Get details for a specific collection.
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * const col = await client.getCollection("docs");
358
+ * ```
359
+ */
360
+ getCollection(name: string): Promise<Collection>;
361
+ /**
362
+ * Delete a collection and all its data.
363
+ *
364
+ * @example
365
+ * ```ts
366
+ * await client.deleteCollection("docs");
367
+ * ```
368
+ */
369
+ deleteCollection(name: string): Promise<void>;
370
+ /**
371
+ * Get statistics for a collection.
372
+ *
373
+ * @example
374
+ * ```ts
375
+ * const stats = await client.getCollectionStats("docs");
376
+ * console.log(`Vectors: ${stats.vector_count}`);
377
+ * ```
378
+ */
379
+ getCollectionStats(name: string): Promise<CollectionStats>;
380
+ /**
381
+ * Insert a single vector into a collection.
382
+ *
383
+ * @returns The vector ID (either the caller-supplied ID or a server-generated one).
384
+ *
385
+ * @example
386
+ * ```ts
387
+ * const id = await client.insert("docs", {
388
+ * vector: [0.1, 0.2, /* ... *\/],
389
+ * metadata: { title: "Hello" },
390
+ * });
391
+ * ```
392
+ */
393
+ insert(collection: string, params: InsertParams): Promise<string>;
394
+ /**
395
+ * Insert multiple vectors in a single request.
396
+ *
397
+ * @returns An array of vector IDs in the same order as the input.
398
+ *
399
+ * @example
400
+ * ```ts
401
+ * const ids = await client.batchInsert("docs", [
402
+ * { vector: [0.1, 0.2], metadata: { title: "A" } },
403
+ * { vector: [0.3, 0.4], metadata: { title: "B" } },
404
+ * ]);
405
+ * ```
406
+ */
407
+ batchInsert(collection: string, vectors: InsertParams[]): Promise<string[]>;
408
+ /**
409
+ * Search for the nearest neighbours of a query vector.
410
+ *
411
+ * @example
412
+ * ```ts
413
+ * const results = await client.search("docs", {
414
+ * query: [0.1, 0.2, /* ... *\/],
415
+ * k: 5,
416
+ * ef_search: 100,
417
+ * });
418
+ * for (const r of results) {
419
+ * console.log(r.id, r.score);
420
+ * }
421
+ * ```
422
+ */
423
+ search(collection: string, params: SearchParams): Promise<SearchResult[]>;
424
+ /**
425
+ * Retrieve a single vector by its ID.
426
+ *
427
+ * @example
428
+ * ```ts
429
+ * const vec = await client.getVector("docs", "abc-123");
430
+ * ```
431
+ */
432
+ getVector(collection: string, id: string): Promise<Vector>;
433
+ /**
434
+ * Delete a single vector by its ID.
435
+ *
436
+ * @example
437
+ * ```ts
438
+ * await client.deleteVector("docs", "abc-123");
439
+ * ```
440
+ */
441
+ deleteVector(collection: string, id: string): Promise<void>;
442
+ /**
443
+ * Trigger an index rebuild for a collection.
444
+ *
445
+ * @example
446
+ * ```ts
447
+ * await client.rebuildIndex("docs");
448
+ * ```
449
+ */
450
+ rebuildIndex(collection: string): Promise<void>;
451
+ /**
452
+ * List all indexes in the cluster.
453
+ *
454
+ * @example
455
+ * ```ts
456
+ * const indexes = await client.listIndexes();
457
+ * ```
458
+ */
459
+ listIndexes(): Promise<IndexInfo[]>;
460
+ /**
461
+ * Rebuild a named index.
462
+ *
463
+ * @example
464
+ * ```ts
465
+ * await client.rebuildNamedIndex("docs_hnsw");
466
+ * ```
467
+ */
468
+ rebuildNamedIndex(name: string): Promise<void>;
469
+ /**
470
+ * Optimize a named index.
471
+ *
472
+ * @example
473
+ * ```ts
474
+ * await client.optimizeIndex("docs_hnsw");
475
+ * ```
476
+ */
477
+ optimizeIndex(name: string): Promise<void>;
478
+ /**
479
+ * Authenticate and obtain a JWT token.
480
+ * The token is cached and automatically refreshed before expiry.
481
+ *
482
+ * @returns The JWT string.
483
+ *
484
+ * @example
485
+ * ```ts
486
+ * const jwt = await client.login({ username: "admin", password: "secret" });
487
+ * ```
488
+ */
489
+ login(credentials: LoginParams): Promise<string>;
490
+ /**
491
+ * List all nodes in the cluster.
492
+ *
493
+ * @example
494
+ * ```ts
495
+ * const nodes = await client.listNodes();
496
+ * ```
497
+ */
498
+ listNodes(): Promise<Node[]>;
499
+ /**
500
+ * Get the overall cluster status.
501
+ *
502
+ * @example
503
+ * ```ts
504
+ * const status = await client.clusterStatus();
505
+ * console.log(status.status, status.leader_id);
506
+ * ```
507
+ */
508
+ clusterStatus(): Promise<ClusterStatus>;
509
+ /**
510
+ * Create a cluster snapshot.
511
+ *
512
+ * @example
513
+ * ```ts
514
+ * await client.createSnapshot();
515
+ * ```
516
+ */
517
+ createSnapshot(): Promise<void>;
518
+ /**
519
+ * Store a memory via the MCP `store_memory` tool.
520
+ *
521
+ * This is a convenience wrapper that calls the MCP JSON-RPC endpoint.
522
+ *
523
+ * @example
524
+ * ```ts
525
+ * await client.mcpStoreMemory("User prefers dark mode", "agent-1");
526
+ * ```
527
+ */
528
+ mcpStoreMemory(text: string, agentId: string, options?: MCPOptions): Promise<void>;
529
+ /**
530
+ * Search memories via the MCP `search_memory` tool.
531
+ *
532
+ * @example
533
+ * ```ts
534
+ * const results = await client.mcpSearchMemory("user preferences", "agent-1", 5);
535
+ * ```
536
+ */
537
+ mcpSearchMemory(query: string, agentId: string, topK?: number): Promise<MCPSearchResult[]>;
538
+ /**
539
+ * Gracefully shut down the client.
540
+ * Aborts all in-flight requests and releases resources.
541
+ *
542
+ * @example
543
+ * ```ts
544
+ * await client.close();
545
+ * ```
546
+ */
547
+ close(): Promise<void>;
548
+ }
549
+
550
+ /**
551
+ * @module mcp
552
+ * @description MCP (Model Context Protocol) client for VecminDB.
553
+ *
554
+ * Provides:
555
+ * - SSE event-stream connection (`GET /mcp/sse`)
556
+ * - JSON-RPC 2.0 tool invocation (`POST /mcp/messages`)
557
+ *
558
+ * The MCP protocol enables AI agents to store and retrieve memories
559
+ * through a standardised tool interface.
560
+ */
561
+
562
+ /** Events emitted by {@link VecminMCPClient}. */
563
+ type MCPEventMap = {
564
+ /** Fired when the SSE connection is established. */
565
+ connected: void;
566
+ /** Fired when the SSE connection is closed. */
567
+ disconnected: void;
568
+ /** Fired for each SSE event received from the server. */
569
+ event: {
570
+ event: string;
571
+ data: string;
572
+ };
573
+ /** Fired when a JSON-RPC response is received. */
574
+ result: {
575
+ id: number;
576
+ result: unknown;
577
+ };
578
+ /** Fired when an error occurs. */
579
+ error: Error;
580
+ };
581
+ type EventHandler<T> = (data: T) => void;
582
+ /**
583
+ * Low-level MCP client that connects to a VecminDB server's
584
+ * Model Context Protocol endpoints.
585
+ *
586
+ * ### SSE (Server-Sent Events)
587
+ * The client opens a persistent connection to `GET /mcp/sse` and parses
588
+ * incoming events using the `eventsource-parser` library.
589
+ *
590
+ * ### JSON-RPC 2.0
591
+ * Tool invocations (`store_memory`, `search_memory`) are sent as JSON-RPC
592
+ * requests to `POST /mcp/messages`.
593
+ *
594
+ * @example
595
+ * ```ts
596
+ * const mcp = new VecminMCPClient("http://localhost:8080", { apiKey: "my-key" });
597
+ * await mcp.connect();
598
+ *
599
+ * mcp.on("event", ({ event, data }) => console.log(event, data));
600
+ *
601
+ * await mcp.storeMemory({ text: "Hello world", agent_id: "agent-1" });
602
+ * const results = await mcp.searchMemory({ query: "hello", agent_id: "agent-1" });
603
+ *
604
+ * await mcp.disconnect();
605
+ * ```
606
+ */
607
+ declare class VecminMCPClient {
608
+ private readonly baseUrl;
609
+ private readonly mcpUrl;
610
+ private readonly options;
611
+ private readonly handlers;
612
+ private rpcId;
613
+ private readonly pendingRpc;
614
+ private abortController;
615
+ private reader;
616
+ private connected;
617
+ constructor(baseUrl: string, options?: MCPClientOptions);
618
+ /**
619
+ * Register an event handler.
620
+ *
621
+ * @param event - One of the {@link MCPEventMap} keys.
622
+ * @param handler - Callback invoked when the event fires.
623
+ */
624
+ on<K extends keyof MCPEventMap>(event: K, handler: EventHandler<MCPEventMap[K]>): void;
625
+ /**
626
+ * Remove a previously registered event handler.
627
+ */
628
+ off<K extends keyof MCPEventMap>(event: K, handler: EventHandler<MCPEventMap[K]>): void;
629
+ private emit;
630
+ /**
631
+ * Open the SSE event-stream connection to `GET /mcp/sse`.
632
+ *
633
+ * The connection remains open until {@link disconnect} is called.
634
+ * Events are parsed and emitted via the `on("event", ...)` interface.
635
+ */
636
+ connect(): Promise<void>;
637
+ /**
638
+ * Read and parse an SSE stream using `eventsource-parser`.
639
+ */
640
+ private readSSEStream;
641
+ /**
642
+ * Send a JSON-RPC 2.0 request to `POST /mcp/messages`.
643
+ *
644
+ * @returns The `result` field of the JSON-RPC response.
645
+ */
646
+ private rpc;
647
+ /**
648
+ * Call the `store_memory` MCP tool.
649
+ *
650
+ * @example
651
+ * ```ts
652
+ * await mcp.storeMemory({ text: "User prefers dark mode", agent_id: "agent-1" });
653
+ * ```
654
+ */
655
+ storeMemory(params: StoreMemoryParams): Promise<void>;
656
+ /**
657
+ * Call the `search_memory` MCP tool.
658
+ *
659
+ * @example
660
+ * ```ts
661
+ * const results = await mcp.searchMemory({ query: "preferences", agent_id: "agent-1", top_k: 5 });
662
+ * ```
663
+ */
664
+ searchMemory(params: SearchMemoryParams): Promise<MCPSearchResult[]>;
665
+ /**
666
+ * Close the SSE connection and release all resources.
667
+ */
668
+ disconnect(): Promise<void>;
669
+ }
670
+
671
+ /**
672
+ * @module langchain
673
+ * @description LangChain.js VectorStore adapter for VecminDB.
674
+ *
675
+ * Implements the {@link VectorStore} interface from `@langchain/core`,
676
+ * enabling drop-in usage of VecminDB as a vector store within the
677
+ * LangChain.js ecosystem.
678
+ *
679
+ * **Note:** `@langchain/core` is an optional peer dependency.
680
+ * If it is not installed, importing this module will throw at runtime.
681
+ */
682
+
683
+ /**
684
+ * LangChain.js VectorStore adapter backed by VecminDB.
685
+ *
686
+ * Extends the abstract `VectorStore` class from `@langchain/core`
687
+ * so it can be used anywhere LangChain expects a vector store —
688
+ * retrievers, chains, agents, etc.
689
+ *
690
+ * @example
691
+ * ```ts
692
+ * import { OpenAIEmbeddings } from "@langchain/openai";
693
+ * import { VecminDBVectorStore } from "@vecmindb/sdk/langchain";
694
+ *
695
+ * const embeddings = new OpenAIEmbeddings();
696
+ * const store = new VecminDBVectorStore(embeddings, {
697
+ * baseUrl: "http://localhost:8080",
698
+ * apiKey: "my-key",
699
+ * collectionName: "my_docs",
700
+ * dimension: 1536,
701
+ * });
702
+ *
703
+ * await store.addDocuments([
704
+ * { pageContent: "Hello world", metadata: { source: "test" } },
705
+ * ]);
706
+ *
707
+ * const results = await store.similaritySearch("hello", 5);
708
+ * ```
709
+ */
710
+ declare class VecminDBVectorStore {
711
+ /** Underlying VecminDB client used for all I/O. */
712
+ readonly client: VecminClient;
713
+ /** LangChain embeddings instance. */
714
+ private readonly _embeddings;
715
+ /** Collection name in VecminDB. */
716
+ private readonly collectionName;
717
+ /** Vector dimensionality. */
718
+ private readonly dimension;
719
+ /** Whether the collection has been ensured to exist. */
720
+ private ensured;
721
+ /** @internal */ lc_namespace: string[];
722
+ /** @internal */ lc_serializable: boolean;
723
+ constructor(embeddings: unknown, options: VecminVectorStoreOptions);
724
+ /**
725
+ * Ensure the target collection exists in VecminDB.
726
+ * Called lazily before the first write operation.
727
+ */
728
+ private ensureCollection;
729
+ /**
730
+ * Add documents to the vector store.
731
+ * Embeds the document texts and inserts them into VecminDB.
732
+ */
733
+ addDocuments(documents: Array<{
734
+ pageContent: string;
735
+ metadata: Record<string, unknown>;
736
+ }>): Promise<string[]>;
737
+ /**
738
+ * Add pre-computed vectors to the vector store.
739
+ */
740
+ addVectors(vectors: number[][], documents: Array<{
741
+ pageContent: string;
742
+ metadata: Record<string, unknown>;
743
+ }>, metadatas?: Array<Record<string, unknown>>): Promise<string[]>;
744
+ /**
745
+ * Search for the most similar vectors and return results with scores.
746
+ *
747
+ * @param query - Query vector.
748
+ * @param k - Number of results. @default 4
749
+ */
750
+ similaritySearchVectorWithScore(query: number[], k?: number): Promise<Array<[{
751
+ pageContent: string;
752
+ metadata: Record<string, unknown>;
753
+ }, number]>>;
754
+ /**
755
+ * Convenience method: search for similar documents (without scores).
756
+ */
757
+ similaritySearch(query: string, k?: number): Promise<Array<{
758
+ pageContent: string;
759
+ metadata: Record<string, unknown>;
760
+ }>>;
761
+ /**
762
+ * Convenience method: search for similar documents with scores.
763
+ */
764
+ similaritySearchWithScore(query: string, k?: number): Promise<Array<[{
765
+ pageContent: string;
766
+ metadata: Record<string, unknown>;
767
+ }, number]>>;
768
+ /**
769
+ * Create a VecminDBVectorStore from an array of Document objects.
770
+ *
771
+ * @example
772
+ * ```ts
773
+ * const store = await VecminDBVectorStore.fromDocuments(
774
+ * [{ pageContent: "Hello", metadata: {} }],
775
+ * embeddings,
776
+ * { baseUrl: "http://localhost:8080" },
777
+ * );
778
+ * ```
779
+ */
780
+ static fromDocuments(documents: Array<{
781
+ pageContent: string;
782
+ metadata: Record<string, unknown>;
783
+ }>, embeddings: unknown, options: VecminVectorStoreOptions): Promise<VecminDBVectorStore>;
784
+ /**
785
+ * Create a VecminDBVectorStore from an array of texts.
786
+ *
787
+ * @example
788
+ * ```ts
789
+ * const store = await VecminDBVectorStore.fromTexts(
790
+ * ["Hello world", "Goodbye world"],
791
+ * [{}, {}],
792
+ * embeddings,
793
+ * { baseUrl: "http://localhost:8080" },
794
+ * );
795
+ * ```
796
+ */
797
+ static fromTexts(texts: string[], metadatas: Array<Record<string, unknown>>, embeddings: unknown, options: VecminVectorStoreOptions): Promise<VecminDBVectorStore>;
798
+ /**
799
+ * Close the underlying client connection.
800
+ */
801
+ close(): Promise<void>;
802
+ }
803
+
804
+ /**
805
+ * @module auth
806
+ * @description Authentication manager for the VecminDB SDK.
807
+ *
808
+ * Handles:
809
+ * - API-Key injection via the `x-api-key` header.
810
+ * - JWT token management with automatic refresh (5 minutes before expiry).
811
+ * - Token caching and thread-safe access.
812
+ */
813
+
814
+ /**
815
+ * Manages authentication state for the SDK client.
816
+ *
817
+ * ### API-Key mode
818
+ * Injects `x-api-key: <key>` on every request.
819
+ *
820
+ * ### JWT mode
821
+ * Injects `Authorization: Bearer <jwt>`.
822
+ * When the JWT is within 5 minutes of expiry the manager automatically
823
+ * re-authenticates via `POST /api/v1/cluster/login`.
824
+ */
825
+ declare class AuthManager {
826
+ private apiKey?;
827
+ private jwt?;
828
+ private loginParams?;
829
+ private baseUrl;
830
+ private refreshPromise;
831
+ constructor(baseUrl: string, options: VecminClientOptions);
832
+ /**
833
+ * Store login credentials so the manager can automatically refresh the JWT.
834
+ * Called internally by {@link VecminClient.login}.
835
+ */
836
+ setLoginCredentials(params: LoginParams, jwt: string): void;
837
+ /**
838
+ * Return the HTTP headers needed for the next request.
839
+ *
840
+ * If a JWT is present and not expiring soon, uses `Authorization: Bearer`.
841
+ * Otherwise falls back to `x-api-key` (if configured).
842
+ *
843
+ * When both are configured, JWT takes precedence; if the JWT is expiring
844
+ * the method triggers a background refresh and falls back to the API key
845
+ * for the current request.
846
+ */
847
+ getHeaders(): Promise<Record<string, string>>;
848
+ /**
849
+ * Attempt to refresh the JWT by re-posting the stored login credentials.
850
+ * Uses a singleton promise so concurrent calls don't trigger multiple logins.
851
+ */
852
+ private refreshJwt;
853
+ }
854
+
855
+ /**
856
+ * @module retry
857
+ * @description Configurable exponential-backoff retry strategy for transient failures.
858
+ */
859
+
860
+ /**
861
+ * Resolve the effective retry options by merging caller-provided values
862
+ * with SDK defaults.
863
+ */
864
+ declare function resolveRetryOptions(opts?: RetryOptions): Required<RetryOptions>;
865
+ /**
866
+ * Execute an async function with exponential-backoff retry semantics.
867
+ *
868
+ * @param fn - The async operation to attempt.
869
+ * @param options - Retry configuration.
870
+ * @returns - The result of `fn` on success.
871
+ * @throws - The last {@link VecminError} when all retries are exhausted.
872
+ *
873
+ * @example
874
+ * ```ts
875
+ * const data = await withRetry(() => fetchJson("/api/v1/collections"), { maxRetries: 5 });
876
+ * ```
877
+ */
878
+ declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
879
+ /**
880
+ * Lightweight wrapper around `fetch` that:
881
+ * 1. Throws structured {@link VecminError} subclasses on non-2xx responses.
882
+ * 2. Parses the standard VecminDB response envelope `{code, message, data}`.
883
+ *
884
+ * This is the single point of HTTP I/O for the SDK.
885
+ */
886
+ declare function fetchJson<T>(url: string, init: RequestInit, retryOpts?: RetryOptions): Promise<T>;
887
+
888
+ /**
889
+ * @module errors
890
+ * @description Custom error hierarchy for the VecminDB SDK.
891
+ *
892
+ * Every error thrown by the SDK is a subclass of {@link VecminError},
893
+ * making it straightforward to catch and inspect failures.
894
+ */
895
+ /**
896
+ * Base error class for all VecminDB SDK errors.
897
+ * Carries the HTTP status code for easy programmatic handling.
898
+ */
899
+ declare class VecminError extends Error {
900
+ /** HTTP-style status code from the server response. */
901
+ readonly code: number;
902
+ constructor(message: string, code: number);
903
+ }
904
+ /** Thrown when the request lacks valid credentials (HTTP 401). */
905
+ declare class AuthenticationError extends VecminError {
906
+ constructor(message?: string);
907
+ }
908
+ /** Thrown when the authenticated identity lacks the required permission (HTTP 403). */
909
+ declare class PermissionError extends VecminError {
910
+ constructor(message?: string);
911
+ }
912
+ /** Thrown when subscription payment or a valid license key is required (HTTP 402). */
913
+ declare class PaymentRequiredError extends VecminError {
914
+ constructor(message?: string);
915
+ }
916
+ /** Thrown when the requested resource does not exist (HTTP 404). */
917
+ declare class NotFoundError extends VecminError {
918
+ constructor(message?: string);
919
+ }
920
+ /** Thrown when the server rate-limits the request (HTTP 429). */
921
+ declare class RateLimitError extends VecminError {
922
+ constructor(message?: string);
923
+ }
924
+ /** Thrown for any 5xx server-side failure. */
925
+ declare class ServerError extends VecminError {
926
+ constructor(message?: string, code?: number);
927
+ }
928
+ /**
929
+ * Maps an HTTP status code to the most specific {@link VecminError} subclass.
930
+ * Falls back to a generic {@link VecminError} for unrecognised codes.
931
+ */
932
+ declare function createErrorFromStatus(status: number, message: string): VecminError;
933
+
934
+ export { AuthManager, AuthenticationError, type ClusterStatus, type Collection, type CollectionStats, type CreateCollectionParams, type IndexInfo, type IndexType, type InsertParams, type JsonRpcRequest, type JsonRpcResponse, type LoginParams, type MCPClientOptions, type MCPEventMap, type MCPOptions, type MCPSearchResult, type MetricType, type Node, NotFoundError, PaymentRequiredError, PermissionError, RateLimitError, type RetryOptions, type SearchMemoryParams, type SearchParams, type SearchResult, ServerError, type StoreMemoryParams, VecminClient, type VecminClientOptions, VecminDBVectorStore, VecminError, VecminMCPClient, type VecminResponse, type VecminVectorStoreOptions, type Vector, createErrorFromStatus, fetchJson, resolveRetryOptions, withRetry };