@langchain/core 0.3.17 → 0.3.18

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.
Files changed (33) hide show
  1. package/dist/callbacks/manager.cjs +2 -30
  2. package/dist/callbacks/manager.d.ts +2 -30
  3. package/dist/callbacks/manager.js +2 -30
  4. package/dist/callbacks/promises.cjs +4 -43
  5. package/dist/callbacks/promises.d.ts +2 -11
  6. package/dist/callbacks/promises.js +2 -37
  7. package/dist/language_models/base.d.ts +2 -0
  8. package/dist/language_models/chat_models.cjs +3 -0
  9. package/dist/language_models/chat_models.js +3 -0
  10. package/dist/retrievers/index.cjs +52 -3
  11. package/dist/retrievers/index.d.ts +90 -4
  12. package/dist/retrievers/index.js +52 -3
  13. package/dist/singletons/async_local_storage/globals.cjs +12 -0
  14. package/dist/singletons/async_local_storage/globals.d.ts +8 -0
  15. package/dist/singletons/async_local_storage/globals.js +7 -0
  16. package/dist/singletons/async_local_storage/index.cjs +67 -0
  17. package/dist/singletons/async_local_storage/index.d.ts +15 -0
  18. package/dist/singletons/async_local_storage/index.js +63 -0
  19. package/dist/singletons/callbacks.cjs +66 -0
  20. package/dist/singletons/callbacks.d.ts +13 -0
  21. package/dist/singletons/callbacks.js +57 -0
  22. package/dist/singletons/index.cjs +5 -64
  23. package/dist/singletons/index.d.ts +2 -19
  24. package/dist/singletons/index.js +2 -62
  25. package/dist/singletons/tracer.cjs +19 -0
  26. package/dist/singletons/tracer.d.ts +2 -0
  27. package/dist/singletons/tracer.js +15 -0
  28. package/dist/tracers/tracer_langchain.cjs +2 -8
  29. package/dist/tracers/tracer_langchain.js +2 -8
  30. package/dist/vectorstores.cjs +267 -7
  31. package/dist/vectorstores.d.ts +519 -11
  32. package/dist/vectorstores.js +267 -7
  33. package/package.json +1 -1
@@ -8,7 +8,34 @@ import { CallbackManagerForRetrieverRun, Callbacks } from "./callbacks/manager.j
8
8
  */
9
9
  type AddDocumentOptions = Record<string, any>;
10
10
  /**
11
- * Type for options when performing a maximal marginal relevance search.
11
+ * Options for configuring a maximal marginal relevance (MMR) search.
12
+ *
13
+ * MMR search optimizes for both similarity to the query and diversity
14
+ * among the results, balancing the retrieval of relevant documents
15
+ * with variation in the content returned.
16
+ *
17
+ * Fields:
18
+ *
19
+ * - `fetchK` (optional): The initial number of documents to retrieve from the
20
+ * vector store before applying the MMR algorithm. This larger set provides a
21
+ * pool of documents from which the algorithm can select the most diverse
22
+ * results based on relevance to the query.
23
+ *
24
+ * - `filter` (optional): A filter of type `FilterType` to refine the search
25
+ * results, allowing additional conditions to target specific subsets
26
+ * of documents.
27
+ *
28
+ * - `k`: The number of documents to return in the final results. This is the
29
+ * primary count of documents that are most relevant to the query.
30
+ *
31
+ * - `lambda` (optional): A value between 0 and 1 that determines the balance
32
+ * between relevance and diversity:
33
+ * - A `lambda` of 0 emphasizes diversity, maximizing content variation.
34
+ * - A `lambda` of 1 emphasizes similarity to the query, focusing on relevance.
35
+ * Values between 0 and 1 provide a mix of relevance and diversity.
36
+ *
37
+ * @template FilterType - The type used for filtering results, as defined
38
+ * by the vector store.
12
39
  */
13
40
  export type MaxMarginalRelevanceSearchOptions<FilterType> = {
14
41
  k: number;
@@ -17,15 +44,73 @@ export type MaxMarginalRelevanceSearchOptions<FilterType> = {
17
44
  filter?: FilterType;
18
45
  };
19
46
  /**
20
- * Type for options when performing a maximal marginal relevance search
21
- * with the VectorStoreRetriever.
47
+ * Options for configuring a maximal marginal relevance (MMR) search
48
+ * when using the `VectorStoreRetriever`.
49
+ *
50
+ * These parameters control how the MMR algorithm balances relevance to the
51
+ * query and diversity among the retrieved documents.
52
+ *
53
+ * Fields:
54
+ * - `fetchK` (optional): Specifies the initial number of documents to fetch
55
+ * before applying the MMR algorithm. This larger set provides a pool of
56
+ * documents from which the algorithm can select the most diverse results
57
+ * based on relevance to the query.
58
+ *
59
+ * - `lambda` (optional): A value between 0 and 1 that determines the balance
60
+ * between relevance and diversity:
61
+ * - A `lambda` of 0 maximizes diversity among the results, prioritizing varied content.
62
+ * - A `lambda` of 1 maximizes similarity to the query, prioritizing relevance.
63
+ * Values between 0 and 1 provide a mix of relevance and diversity.
22
64
  */
23
65
  export type VectorStoreRetrieverMMRSearchKwargs = {
24
66
  fetchK?: number;
25
67
  lambda?: number;
26
68
  };
27
69
  /**
28
- * Type for input when creating a VectorStoreRetriever instance.
70
+ * Input configuration options for creating a `VectorStoreRetriever` instance.
71
+ *
72
+ * This type combines properties from `BaseRetrieverInput` with specific settings
73
+ * for the `VectorStoreRetriever`, including options for similarity or maximal
74
+ * marginal relevance (MMR) search types.
75
+ *
76
+ * Fields:
77
+ *
78
+ * - `callbacks` (optional): An array of callback functions that handle various
79
+ * events during retrieval, such as logging, error handling, or progress updates.
80
+ *
81
+ * - `tags` (optional): An array of strings used to add contextual tags to
82
+ * retrieval operations, allowing for easier categorization and tracking.
83
+ *
84
+ * - `metadata` (optional): A record of key-value pairs to store additional
85
+ * contextual information for retrieval operations, which can be useful
86
+ * for logging or auditing purposes.
87
+ *
88
+ * - `verbose` (optional): A boolean flag that, if set to `true`, enables
89
+ * detailed logging and output during the retrieval process. Defaults to `false`.
90
+ *
91
+ * - `vectorStore`: The `VectorStore` instance implementing `VectorStoreInterface`
92
+ * that will be used for document storage and retrieval.
93
+ *
94
+ * - `k` (optional): Specifies the number of documents to retrieve per search
95
+ * query. Defaults to 4 if not specified.
96
+ *
97
+ * - `filter` (optional): A filter of type `FilterType` (defined by the vector store)
98
+ * to refine the set of documents returned, allowing for targeted search results.
99
+ *
100
+ * - `searchType`: Determines the type of search to perform:
101
+ * - `"similarity"`: Executes a similarity search, retrieving documents based purely
102
+ * on vector similarity to the query.
103
+ * - `"mmr"`: Executes a maximal marginal relevance (MMR) search, balancing similarity
104
+ * and diversity in the search results.
105
+ *
106
+ * - `searchKwargs` (optional): Used only if `searchType` is `"mmr"`, this object
107
+ * provides additional options for MMR search, including:
108
+ * - `fetchK`: Specifies the number of documents to initially fetch before applying
109
+ * the MMR algorithm, providing a pool from which the most diverse results are selected.
110
+ * - `lambda`: A diversity parameter, where 0 emphasizes diversity and 1 emphasizes
111
+ * relevance to the query. Values between 0 and 1 provide a balance of relevance and diversity.
112
+ *
113
+ * @template V - The type of vector store implementing `VectorStoreInterface`.
29
114
  */
30
115
  export type VectorStoreRetrieverInput<V extends VectorStoreInterface> = BaseRetrieverInput & ({
31
116
  vectorStore: V;
@@ -39,36 +124,255 @@ export type VectorStoreRetrieverInput<V extends VectorStoreInterface> = BaseRetr
39
124
  searchType: "mmr";
40
125
  searchKwargs?: VectorStoreRetrieverMMRSearchKwargs;
41
126
  });
127
+ /**
128
+ * Interface for a retriever that uses a vector store to store and retrieve
129
+ * document embeddings. This retriever interface allows for adding documents
130
+ * to the underlying vector store and conducting retrieval operations.
131
+ *
132
+ * `VectorStoreRetrieverInterface` extends `BaseRetrieverInterface` to provide
133
+ * document retrieval capabilities based on vector similarity.
134
+ *
135
+ * @interface VectorStoreRetrieverInterface
136
+ * @extends BaseRetrieverInterface
137
+ */
42
138
  export interface VectorStoreRetrieverInterface<V extends VectorStoreInterface = VectorStoreInterface> extends BaseRetrieverInterface {
43
139
  vectorStore: V;
140
+ /**
141
+ * Adds an array of documents to the vector store.
142
+ *
143
+ * This method embeds the provided documents and stores them within the
144
+ * vector store. Additional options can be specified for custom behavior
145
+ * during the addition process.
146
+ *
147
+ * @param documents - An array of documents to embed and add to the vector store.
148
+ * @param options - Optional settings to customize document addition.
149
+ * @returns A promise that resolves to an array of document IDs or `void`,
150
+ * depending on the implementation.
151
+ */
44
152
  addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;
45
153
  }
46
154
  /**
47
- * Class for performing document retrieval from a VectorStore. Can perform
48
- * similarity search or maximal marginal relevance search.
155
+ * Class for retrieving documents from a `VectorStore` based on vector similarity
156
+ * or maximal marginal relevance (MMR).
157
+ *
158
+ * `VectorStoreRetriever` extends `BaseRetriever`, implementing methods for
159
+ * adding documents to the underlying vector store and performing document
160
+ * retrieval with optional configurations.
161
+ *
162
+ * @class VectorStoreRetriever
163
+ * @extends BaseRetriever
164
+ * @implements VectorStoreRetrieverInterface
165
+ * @template V - Type of vector store implementing `VectorStoreInterface`.
49
166
  */
50
167
  export declare class VectorStoreRetriever<V extends VectorStoreInterface = VectorStoreInterface> extends BaseRetriever implements VectorStoreRetrieverInterface {
51
168
  static lc_name(): string;
52
169
  get lc_namespace(): string[];
170
+ /**
171
+ * The instance of `VectorStore` used for storing and retrieving document embeddings.
172
+ * This vector store must implement the `VectorStoreInterface` to be compatible
173
+ * with the retriever’s operations.
174
+ */
53
175
  vectorStore: V;
176
+ /**
177
+ * Specifies the number of documents to retrieve for each search query.
178
+ * Defaults to 4 if not specified, providing a basic result count for similarity or MMR searches.
179
+ */
54
180
  k: number;
181
+ /**
182
+ * Determines the type of search operation to perform on the vector store.
183
+ *
184
+ * - `"similarity"` (default): Conducts a similarity search based purely on vector similarity
185
+ * to the query.
186
+ * - `"mmr"`: Executes a maximal marginal relevance (MMR) search, balancing relevance and
187
+ * diversity in the retrieved results.
188
+ */
55
189
  searchType: string;
190
+ /**
191
+ * Additional options specific to maximal marginal relevance (MMR) search, applicable
192
+ * only if `searchType` is set to `"mmr"`.
193
+ *
194
+ * Includes:
195
+ * - `fetchK`: The initial number of documents fetched before applying the MMR algorithm,
196
+ * allowing for a larger selection from which to choose the most diverse results.
197
+ * - `lambda`: A parameter between 0 and 1 to adjust the relevance-diversity balance,
198
+ * where 0 prioritizes diversity and 1 prioritizes relevance.
199
+ */
56
200
  searchKwargs?: VectorStoreRetrieverMMRSearchKwargs;
201
+ /**
202
+ * Optional filter applied to search results, defined by the `FilterType` of the vector store.
203
+ * Allows for refined, targeted results by restricting the returned documents based
204
+ * on specified filter criteria.
205
+ */
57
206
  filter?: V["FilterType"];
207
+ /**
208
+ * Returns the type of vector store, as defined by the `vectorStore` instance.
209
+ *
210
+ * @returns {string} The vector store type.
211
+ */
58
212
  _vectorstoreType(): string;
213
+ /**
214
+ * Initializes a new instance of `VectorStoreRetriever` with the specified configuration.
215
+ *
216
+ * This constructor configures the retriever to interact with a given `VectorStore`
217
+ * and supports different retrieval strategies, including similarity search and maximal
218
+ * marginal relevance (MMR) search. Various options allow customization of the number
219
+ * of documents retrieved per query, filtering based on conditions, and fine-tuning
220
+ * MMR-specific parameters.
221
+ *
222
+ * @param fields - Configuration options for setting up the retriever:
223
+ *
224
+ * - `vectorStore` (required): The `VectorStore` instance implementing `VectorStoreInterface`
225
+ * that will be used to store and retrieve document embeddings. This is the core component
226
+ * of the retriever, enabling vector-based similarity and MMR searches.
227
+ *
228
+ * - `k` (optional): Specifies the number of documents to retrieve per search query. If not
229
+ * provided, defaults to 4. This count determines the number of most relevant documents returned
230
+ * for each search operation, balancing performance with comprehensiveness.
231
+ *
232
+ * - `searchType` (optional): Defines the search approach used by the retriever, allowing for
233
+ * flexibility between two methods:
234
+ * - `"similarity"` (default): A similarity-based search, retrieving documents with high vector
235
+ * similarity to the query. This type prioritizes relevance and is often used when diversity
236
+ * among results is less critical.
237
+ * - `"mmr"`: Maximal Marginal Relevance search, which combines relevance with diversity. MMR
238
+ * is useful for scenarios where varied content is essential, as it selects results that
239
+ * both match the query and introduce content diversity.
240
+ *
241
+ * - `filter` (optional): A filter of type `FilterType`, defined by the vector store, that allows
242
+ * for refined and targeted search results. This filter applies specified conditions to limit
243
+ * which documents are eligible for retrieval, offering control over the scope of results.
244
+ *
245
+ * - `searchKwargs` (optional, applicable only if `searchType` is `"mmr"`): Additional settings
246
+ * for configuring MMR-specific behavior. These parameters allow further tuning of the MMR
247
+ * search process:
248
+ * - `fetchK`: The initial number of documents fetched from the vector store before the MMR
249
+ * algorithm is applied. Fetching a larger set enables the algorithm to select a more
250
+ * diverse subset of documents.
251
+ * - `lambda`: A parameter controlling the relevance-diversity balance, where 0 emphasizes
252
+ * diversity and 1 prioritizes relevance. Intermediate values provide a blend of the two,
253
+ * allowing customization based on the importance of content variety relative to query relevance.
254
+ */
59
255
  constructor(fields: VectorStoreRetrieverInput<V>);
256
+ /**
257
+ * Retrieves relevant documents based on the specified query, using either
258
+ * similarity or maximal marginal relevance (MMR) search.
259
+ *
260
+ * If `searchType` is set to `"mmr"`, performs an MMR search to balance
261
+ * similarity and diversity among results. If `searchType` is `"similarity"`,
262
+ * retrieves results purely based on similarity to the query.
263
+ *
264
+ * @param query - The query string used to find relevant documents.
265
+ * @param runManager - Optional callback manager for tracking retrieval progress.
266
+ * @returns A promise that resolves to an array of `DocumentInterface` instances
267
+ * representing the most relevant documents to the query.
268
+ * @throws {Error} Throws an error if MMR search is requested but not supported
269
+ * by the vector store.
270
+ * @protected
271
+ */
60
272
  _getRelevantDocuments(query: string, runManager?: CallbackManagerForRetrieverRun): Promise<DocumentInterface[]>;
273
+ /**
274
+ * Adds an array of documents to the vector store, embedding them as part of
275
+ * the storage process.
276
+ *
277
+ * This method delegates document embedding and storage to the `addDocuments`
278
+ * method of the underlying vector store.
279
+ *
280
+ * @param documents - An array of documents to embed and add to the vector store.
281
+ * @param options - Optional settings to customize document addition.
282
+ * @returns A promise that resolves to an array of document IDs or `void`,
283
+ * depending on the vector store's implementation.
284
+ */
61
285
  addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;
62
286
  }
287
+ /**
288
+ * Interface defining the structure and operations of a vector store, which
289
+ * facilitates the storage, retrieval, and similarity search of document vectors.
290
+ *
291
+ * `VectorStoreInterface` provides methods for adding, deleting, and searching
292
+ * documents based on vector embeddings, including support for similarity
293
+ * search with optional filtering and relevance-based retrieval.
294
+ *
295
+ * @extends Serializable
296
+ */
63
297
  export interface VectorStoreInterface extends Serializable {
298
+ /**
299
+ * Defines the filter type used in search and delete operations. Can be an
300
+ * object for structured conditions or a string for simpler filtering.
301
+ */
64
302
  FilterType: object | string;
303
+ /**
304
+ * Instance of `EmbeddingsInterface` used to generate vector embeddings for
305
+ * documents, enabling vector-based search operations.
306
+ */
65
307
  embeddings: EmbeddingsInterface;
308
+ /**
309
+ * Returns a string identifying the type of vector store implementation,
310
+ * useful for distinguishing between different vector storage backends.
311
+ *
312
+ * @returns {string} A string indicating the vector store type.
313
+ */
66
314
  _vectorstoreType(): string;
315
+ /**
316
+ * Adds precomputed vectors and their corresponding documents to the vector store.
317
+ *
318
+ * @param vectors - An array of vectors, with each vector representing a document.
319
+ * @param documents - An array of `DocumentInterface` instances corresponding to each vector.
320
+ * @param options - Optional configurations for adding documents, potentially covering indexing or metadata handling.
321
+ * @returns A promise that resolves to an array of document IDs or void, depending on implementation.
322
+ */
67
323
  addVectors(vectors: number[][], documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;
324
+ /**
325
+ * Adds an array of documents to the vector store.
326
+ *
327
+ * @param documents - An array of documents to be embedded and stored in the vector store.
328
+ * @param options - Optional configurations for embedding and storage operations.
329
+ * @returns A promise that resolves to an array of document IDs or void, depending on implementation.
330
+ */
68
331
  addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;
332
+ /**
333
+ * Deletes documents from the vector store based on the specified parameters.
334
+ *
335
+ * @param _params - A flexible object containing key-value pairs that define
336
+ * the conditions for selecting documents to delete.
337
+ * @returns A promise that resolves once the deletion operation is complete.
338
+ */
69
339
  delete(_params?: Record<string, any>): Promise<void>;
340
+ /**
341
+ * Searches for documents similar to a given vector query and returns them
342
+ * with similarity scores.
343
+ *
344
+ * @param query - A vector representing the query for similarity search.
345
+ * @param k - The number of similar documents to return.
346
+ * @param filter - Optional filter based on `FilterType` to restrict results.
347
+ * @returns A promise that resolves to an array of tuples, each containing a
348
+ * `DocumentInterface` and its corresponding similarity score.
349
+ */
70
350
  similaritySearchVectorWithScore(query: number[], k: number, filter?: this["FilterType"]): Promise<[DocumentInterface, number][]>;
351
+ /**
352
+ * Searches for documents similar to a text query, embedding the query
353
+ * and retrieving documents based on vector similarity.
354
+ *
355
+ * @param query - The text query to search for.
356
+ * @param k - Optional number of similar documents to return.
357
+ * @param filter - Optional filter based on `FilterType` to restrict results.
358
+ * @param callbacks - Optional callbacks for tracking progress or events
359
+ * during the search process.
360
+ * @returns A promise that resolves to an array of `DocumentInterface`
361
+ * instances representing similar documents.
362
+ */
71
363
  similaritySearch(query: string, k?: number, filter?: this["FilterType"], callbacks?: Callbacks): Promise<DocumentInterface[]>;
364
+ /**
365
+ * Searches for documents similar to a text query and includes similarity
366
+ * scores in the result.
367
+ *
368
+ * @param query - The text query to search for.
369
+ * @param k - Optional number of similar documents to return.
370
+ * @param filter - Optional filter based on `FilterType` to restrict results.
371
+ * @param callbacks - Optional callbacks for tracking progress or events
372
+ * during the search process.
373
+ * @returns A promise that resolves to an array of tuples, each containing
374
+ * a `DocumentInterface` and its similarity score.
375
+ */
72
376
  similaritySearchWithScore(query: string, k?: number, filter?: this["FilterType"], callbacks?: Callbacks): Promise<[DocumentInterface, number][]>;
73
377
  /**
74
378
  * Return documents selected using the maximal marginal relevance.
@@ -86,24 +390,124 @@ export interface VectorStoreInterface extends Serializable {
86
390
  * @returns {Promise<DocumentInterface[]>} - List of documents selected by maximal marginal relevance.
87
391
  */
88
392
  maxMarginalRelevanceSearch?(query: string, options: MaxMarginalRelevanceSearchOptions<this["FilterType"]>, callbacks: Callbacks | undefined): Promise<DocumentInterface[]>;
393
+ /**
394
+ * Converts the vector store into a retriever, making it suitable for use in
395
+ * retrieval-based workflows and allowing additional configuration.
396
+ *
397
+ * @param kOrFields - Optional parameter for specifying either the number of
398
+ * documents to retrieve or partial retriever configurations.
399
+ * @param filter - Optional filter based on `FilterType` for retrieval restriction.
400
+ * @param callbacks - Optional callbacks for tracking retrieval events or progress.
401
+ * @param tags - General-purpose tags to add contextual information to the retriever.
402
+ * @param metadata - General-purpose metadata providing additional context
403
+ * for retrieval.
404
+ * @param verbose - If `true`, enables detailed logging during retrieval.
405
+ * @returns An instance of `VectorStoreRetriever` configured with the specified options.
406
+ */
89
407
  asRetriever(kOrFields?: number | Partial<VectorStoreRetrieverInput<this>>, filter?: this["FilterType"], callbacks?: Callbacks, tags?: string[], metadata?: Record<string, unknown>, verbose?: boolean): VectorStoreRetriever<this>;
90
408
  }
91
409
  /**
92
- * Abstract class representing a store of vectors. Provides methods for
93
- * adding vectors and documents, deleting from the store, and searching
94
- * the store.
410
+ * Abstract class representing a vector storage system for performing
411
+ * similarity searches on embedded documents.
412
+ *
413
+ * `VectorStore` provides methods for adding precomputed vectors or documents,
414
+ * removing documents based on criteria, and performing similarity searches
415
+ * with optional scoring. Subclasses are responsible for implementing specific
416
+ * storage mechanisms and the exact behavior of certain abstract methods.
417
+ *
418
+ * @abstract
419
+ * @extends Serializable
420
+ * @implements VectorStoreInterface
95
421
  */
96
422
  export declare abstract class VectorStore extends Serializable implements VectorStoreInterface {
97
423
  FilterType: object | string;
424
+ /**
425
+ * Namespace within LangChain to uniquely identify this vector store's
426
+ * location, based on the vector store type.
427
+ *
428
+ * @internal
429
+ */
98
430
  lc_namespace: string[];
431
+ /**
432
+ * Embeddings interface for generating vector embeddings from text queries,
433
+ * enabling vector-based similarity searches.
434
+ */
99
435
  embeddings: EmbeddingsInterface;
436
+ /**
437
+ * Initializes a new vector store with embeddings and database configuration.
438
+ *
439
+ * @param embeddings - Instance of `EmbeddingsInterface` used to embed queries.
440
+ * @param dbConfig - Configuration settings for the database or storage system.
441
+ */
100
442
  constructor(embeddings: EmbeddingsInterface, dbConfig: Record<string, any>);
443
+ /**
444
+ * Returns a string representing the type of vector store, which subclasses
445
+ * must implement to identify their specific vector storage type.
446
+ *
447
+ * @returns {string} A string indicating the vector store type.
448
+ * @abstract
449
+ */
101
450
  abstract _vectorstoreType(): string;
451
+ /**
452
+ * Adds precomputed vectors and corresponding documents to the vector store.
453
+ *
454
+ * @param vectors - An array of vectors representing each document.
455
+ * @param documents - Array of documents associated with each vector.
456
+ * @param options - Optional configuration for adding vectors, such as indexing.
457
+ * @returns A promise resolving to an array of document IDs or void, based on implementation.
458
+ * @abstract
459
+ */
102
460
  abstract addVectors(vectors: number[][], documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;
461
+ /**
462
+ * Adds documents to the vector store, embedding them first through the
463
+ * `embeddings` instance.
464
+ *
465
+ * @param documents - Array of documents to embed and add.
466
+ * @param options - Optional configuration for embedding and storing documents.
467
+ * @returns A promise resolving to an array of document IDs or void, based on implementation.
468
+ * @abstract
469
+ */
103
470
  abstract addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;
471
+ /**
472
+ * Deletes documents from the vector store based on the specified parameters.
473
+ *
474
+ * @param _params - Flexible key-value pairs defining conditions for document deletion.
475
+ * @returns A promise that resolves once the deletion is complete.
476
+ */
104
477
  delete(_params?: Record<string, any>): Promise<void>;
478
+ /**
479
+ * Performs a similarity search using a vector query and returns results
480
+ * along with their similarity scores.
481
+ *
482
+ * @param query - Vector representing the search query.
483
+ * @param k - Number of similar results to return.
484
+ * @param filter - Optional filter based on `FilterType` to restrict results.
485
+ * @returns A promise resolving to an array of tuples containing documents and their similarity scores.
486
+ * @abstract
487
+ */
105
488
  abstract similaritySearchVectorWithScore(query: number[], k: number, filter?: this["FilterType"]): Promise<[DocumentInterface, number][]>;
489
+ /**
490
+ * Searches for documents similar to a text query by embedding the query and
491
+ * performing a similarity search on the resulting vector.
492
+ *
493
+ * @param query - Text query for finding similar documents.
494
+ * @param k - Number of similar results to return. Defaults to 4.
495
+ * @param filter - Optional filter based on `FilterType`.
496
+ * @param _callbacks - Optional callbacks for monitoring search progress
497
+ * @returns A promise resolving to an array of `DocumentInterface` instances representing similar documents.
498
+ */
106
499
  similaritySearch(query: string, k?: number, filter?: this["FilterType"] | undefined, _callbacks?: Callbacks | undefined): Promise<DocumentInterface[]>;
500
+ /**
501
+ * Searches for documents similar to a text query by embedding the query,
502
+ * and returns results with similarity scores.
503
+ *
504
+ * @param query - Text query for finding similar documents.
505
+ * @param k - Number of similar results to return. Defaults to 4.
506
+ * @param filter - Optional filter based on `FilterType`.
507
+ * @param _callbacks - Optional callbacks for monitoring search progress
508
+ * @returns A promise resolving to an array of tuples, each containing a
509
+ * document and its similarity score.
510
+ */
107
511
  similaritySearchWithScore(query: string, k?: number, filter?: this["FilterType"] | undefined, _callbacks?: Callbacks | undefined): Promise<[DocumentInterface, number][]>;
108
512
  /**
109
513
  * Return documents selected using the maximal marginal relevance.
@@ -121,16 +525,120 @@ export declare abstract class VectorStore extends Serializable implements Vector
121
525
  * @returns {Promise<DocumentInterface[]>} - List of documents selected by maximal marginal relevance.
122
526
  */
123
527
  maxMarginalRelevanceSearch?(query: string, options: MaxMarginalRelevanceSearchOptions<this["FilterType"]>, _callbacks: Callbacks | undefined): Promise<DocumentInterface[]>;
528
+ /**
529
+ * Creates a `VectorStore` instance from an array of text strings and optional
530
+ * metadata, using the specified embeddings and database configuration.
531
+ *
532
+ * Subclasses must implement this method to define how text and metadata
533
+ * are embedded and stored in the vector store. Throws an error if not overridden.
534
+ *
535
+ * @param _texts - Array of strings representing the text documents to be stored.
536
+ * @param _metadatas - Metadata for the texts, either as an array (one for each text)
537
+ * or a single object (applied to all texts).
538
+ * @param _embeddings - Instance of `EmbeddingsInterface` to embed the texts.
539
+ * @param _dbConfig - Database configuration settings.
540
+ * @returns A promise that resolves to a new `VectorStore` instance.
541
+ * @throws {Error} Throws an error if this method is not overridden by a subclass.
542
+ */
124
543
  static fromTexts(_texts: string[], _metadatas: object[] | object, _embeddings: EmbeddingsInterface, _dbConfig: Record<string, any>): Promise<VectorStore>;
544
+ /**
545
+ * Creates a `VectorStore` instance from an array of documents, using the specified
546
+ * embeddings and database configuration.
547
+ *
548
+ * Subclasses must implement this method to define how documents are embedded
549
+ * and stored. Throws an error if not overridden.
550
+ *
551
+ * @param _docs - Array of `DocumentInterface` instances representing the documents to be stored.
552
+ * @param _embeddings - Instance of `EmbeddingsInterface` to embed the documents.
553
+ * @param _dbConfig - Database configuration settings.
554
+ * @returns A promise that resolves to a new `VectorStore` instance.
555
+ * @throws {Error} Throws an error if this method is not overridden by a subclass.
556
+ */
125
557
  static fromDocuments(_docs: DocumentInterface[], _embeddings: EmbeddingsInterface, _dbConfig: Record<string, any>): Promise<VectorStore>;
558
+ /**
559
+ * Creates a `VectorStoreRetriever` instance with flexible configuration options.
560
+ *
561
+ * @param kOrFields
562
+ * - If a number is provided, it sets the `k` parameter (number of items to retrieve).
563
+ * - If an object is provided, it should contain various configuration options.
564
+ * @param filter
565
+ * - Optional filter criteria to limit the items retrieved based on the specified filter type.
566
+ * @param callbacks
567
+ * - Optional callbacks that may be triggered at specific stages of the retrieval process.
568
+ * @param tags
569
+ * - Tags to categorize or label the `VectorStoreRetriever`. Defaults to an empty array if not provided.
570
+ * @param metadata
571
+ * - Additional metadata as key-value pairs to add contextual information for the retrieval process.
572
+ * @param verbose
573
+ * - If `true`, enables detailed logging for the retrieval process. Defaults to `false`.
574
+ *
575
+ * @returns
576
+ * - A configured `VectorStoreRetriever` instance based on the provided parameters.
577
+ *
578
+ * @example
579
+ * Basic usage with a `k` value:
580
+ * ```typescript
581
+ * const retriever = myVectorStore.asRetriever(5);
582
+ * ```
583
+ *
584
+ * Usage with a configuration object:
585
+ * ```typescript
586
+ * const retriever = myVectorStore.asRetriever({
587
+ * k: 10,
588
+ * filter: myFilter,
589
+ * tags: ['example', 'test'],
590
+ * verbose: true,
591
+ * searchType: 'mmr',
592
+ * searchKwargs: { alpha: 0.5 },
593
+ * });
594
+ * ```
595
+ */
126
596
  asRetriever(kOrFields?: number | Partial<VectorStoreRetrieverInput<this>>, filter?: this["FilterType"], callbacks?: Callbacks, tags?: string[], metadata?: Record<string, unknown>, verbose?: boolean): VectorStoreRetriever<this>;
127
597
  }
128
598
  /**
129
- * Abstract class extending VectorStore with functionality for saving and
130
- * loading the vector store.
599
+ * Abstract class extending `VectorStore` that defines a contract for saving
600
+ * and loading vector store instances.
601
+ *
602
+ * The `SaveableVectorStore` class allows vector store implementations to
603
+ * persist their data and retrieve it when needed.The format for saving and
604
+ * loading data is left to the implementing subclass.
605
+ *
606
+ * Subclasses must implement the `save` method to handle their custom
607
+ * serialization logic, while the `load` method enables reconstruction of a
608
+ * vector store from saved data, requiring compatible embeddings through the
609
+ * `EmbeddingsInterface`.
610
+ *
611
+ * @abstract
612
+ * @extends VectorStore
131
613
  */
132
614
  export declare abstract class SaveableVectorStore extends VectorStore {
615
+ /**
616
+ * Saves the current state of the vector store to the specified directory.
617
+ *
618
+ * This method must be implemented by subclasses to define their own
619
+ * serialization process for persisting vector data. The implementation
620
+ * determines the structure and format of the saved data.
621
+ *
622
+ * @param directory - The directory path where the vector store data
623
+ * will be saved.
624
+ * @abstract
625
+ */
133
626
  abstract save(directory: string): Promise<void>;
627
+ /**
628
+ * Loads a vector store instance from the specified directory, using the
629
+ * provided embeddings to ensure compatibility.
630
+ *
631
+ * This static method reconstructs a `SaveableVectorStore` from previously
632
+ * saved data. Implementations should interpret the saved data format to
633
+ * recreate the vector store instance.
634
+ *
635
+ * @param _directory - The directory path from which the vector store
636
+ * data will be loaded.
637
+ * @param _embeddings - An instance of `EmbeddingsInterface` to align
638
+ * the embeddings with the loaded vector data.
639
+ * @returns A promise that resolves to a `SaveableVectorStore` instance
640
+ * constructed from the saved data.
641
+ */
134
642
  static load(_directory: string, _embeddings: EmbeddingsInterface): Promise<SaveableVectorStore>;
135
643
  }
136
644
  export {};